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

Function renderProp

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

Source from the content-addressed store, hash-verified

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

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