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

Function renderElement

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

Source from the content-addressed store, hash-verified

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

Callers 3

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