MCPcopy Create free account
hub / github.com/adobe/react-spectrum / renderValue

Function renderValue

packages/dev/s2-docs/src/VisualExampleClient.tsx:510–610  ·  view source on GitHub ↗
(value: any, indent = '')

Source from the content-addressed store, hash-verified

508}
509
510function renderValue(value: any, indent = '') {
511 switch (typeof value) {
512 case 'string':
513 return <span className={style({color: 'green-1000'})}>"{value}"</span>;
514 case 'number':
515 return <span className={style({color: 'pink-1000'})}>{String(value)}</span>;
516 case 'boolean':
517 return <span className={style({color: 'magenta-1000'})}>{String(value)}</span>;
518 case 'object': {
519 if (value == null) {
520 return <span className={style({color: 'magenta-1000'})}>{String(value)}</span>;
521 }
522 if (presetNames.has(value)) {
523 return <span className={style({color: 'red-1000'})}>{presetNames.get(value)}</span>;
524 }
525
526 if (Array.isArray(value)) {
527 let res: ReactNode[] = value.map((item, i) => {
528 let result = renderValue(item, indent);
529 if (i < value.length - 1) {
530 result = <>{result}, </>;
531 }
532 return <Fragment key={i}>{result}</Fragment>;
533 });
534
535 if (countChars(res) > 40) {
536 res = res.map((p, i) => (
537 <Fragment key={i}>
538 {'\n ' + indent}
539 {p}
540 </Fragment>
541 ));
542 res.push('\n ');
543 }
544
545 return (
546 <>
547 {'['}
548 {res}
549 {']'}
550 </>
551 );
552 }
553
554 if (value instanceof Size) {
555 return (
556 <>
557 <span className={style({color: 'magenta-1000'})}>new</span>{' '}
558 <span className={style({color: 'red-1000'})}>Size</span>(
559 <span className={style({color: 'pink-1000'})}>{value.width}</span>,{' '}
560 <span className={style({color: 'pink-1000'})}>{value.height}</span>)
561 </>
562 );
563 }
564
565 if (value instanceof Date) {
566 return (
567 <>

Callers 2

renderPropFunction · 0.85
Picker.tsxFile · 0.85

Calls 4

StringFunction · 0.85
countCharsFunction · 0.85
pushMethod · 0.80
hasMethod · 0.65

Tested by

no test coverage detected