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

Function renderValue

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

Source from the content-addressed store, hash-verified

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

Callers 2

renderPropFunction · 0.85
Picker.tsxFile · 0.85

Calls 2

countCharsFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected