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

Function renderElement

packages/dev/s2-docs/src/VisualExampleClient.tsx:333–377  ·  view source on GitHub ↗
(name: string, props: Props, controls?: Controls, indent = '')

Source from the content-addressed store, hash-verified

331}
332
333function renderElement(name: string, props: Props, controls?: Controls, indent = '') {
334 let start = (
335 <>
336 &lt;<span className={style({color: 'red-1000'})}>{name}</span>
337 </>
338 );
339 let renderedProps = Object.keys(props)
340 .filter(prop => prop !== 'children')
341 .map(prop => renderProp(prop, props[prop], controls?.[prop], ' ' + indent))
342 .filter(Boolean);
343 let newlines = name.length + countChars(renderedProps) > 40;
344 renderedProps = renderedProps.map((p, i) => (
345 <Fragment key={i}>
346 {newlines ? '\n ' + indent : ' '}
347 {p}
348 </Fragment>
349 ));
350 if (props.children) {
351 let end = (
352 <>
353 &lt;/<span className={style({color: 'red-1000'})}>{name}</span>&gt;
354 </>
355 );
356 let children = renderChildren(props.children, indent);
357 if (typeof children !== 'string') {
358 newlines = true;
359 }
360 return (
361 <>
362 {start}
363 {renderedProps}&gt;{newlines ? '\n ' + indent : null}
364 {children}
365 {newlines ? '\n' + indent : null}
366 {end}
367 </>
368 );
369 }
370
371 return (
372 <>
373 {start}
374 {renderedProps} /&gt;
375 </>
376 );
377}
378
379function renderChildren(children, indent = '') {
380 if (children?.icon || children?.avatar || children?.badge) {

Callers 4

useId.test.jsxFile · 0.85
CodeOutputFunction · 0.85
renderChildrenFunction · 0.85
renderPropFunction · 0.85

Calls 4

renderPropFunction · 0.85
countCharsFunction · 0.85
renderChildrenFunction · 0.70
filterMethod · 0.65

Tested by

no test coverage detected