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

Function renderValue

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

Source from the content-addressed store, hash-verified

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

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