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

Function renderProp

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

Source from the content-addressed store, hash-verified

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

Callers 2

CodePropsFunction · 0.85
renderElementFunction · 0.85

Calls 2

renderElementFunction · 0.85
renderValueFunction · 0.85

Tested by

no test coverage detected