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

Function renderElement

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

Source from the content-addressed store, hash-verified

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