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

Function renderProp

packages/dev/s2-docs/src/VisualExampleClient.tsx:436–508  ·  view source on GitHub ↗
(name: string, value: any, control?: PropControl, indent = '')

Source from the content-addressed store, hash-verified

434}
435
436function renderProp(name: string, value: any, control?: PropControl, indent = '') {
437 if (value === control?.default) {
438 return null;
439 }
440
441 let propName = <span className={style({color: 'indigo-1000'})}>{name}</span>;
442 let propValue: any = null;
443 if (typeof value === 'string') {
444 propValue = <span className={style({color: 'green-1000'})}>"{value}"</span>;
445 } else if (typeof value === 'number') {
446 propValue = (
447 <>
448 {'{'}
449 <span className={style({color: 'pink-1000'})}>{String(value)}</span>
450 {'}'}
451 </>
452 );
453 } else if (typeof value === 'boolean') {
454 if (value === false && control?.optional && !control?.default) {
455 return null;
456 }
457 if (name === 'contextualHelp') {
458 let res = renderElement(
459 'ContextualHelp',
460 {
461 children: [
462 renderElement('Heading', {children: 'Heading'}),
463 renderElement('Content', {children: 'Content'})
464 ]
465 },
466 undefined,
467 indent + ' '
468 );
469 propValue = (
470 <>
471 {`{\n ${indent}`}
472 {res}
473 {`\n ${indent}}`}
474 </>
475 );
476 } else {
477 propValue =
478 value === false ? (
479 <>
480 {'{'}
481 <span className={style({color: 'magenta-1000'})}>{String(value)}</span>
482 {'}'}
483 </>
484 ) : null;
485 }
486 } else if (value == null) {
487 return null;
488 } else if (typeof value === 'object') {
489 propValue = (
490 <>
491 {'{'}
492 {renderValue(value, indent)}
493 {'}'}

Callers 2

CodePropsFunction · 0.85
renderElementFunction · 0.85

Calls 3

StringFunction · 0.85
renderElementFunction · 0.85
renderValueFunction · 0.85

Tested by

no test coverage detected