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

Function renderChildren

packages/dev/s2-docs/src/VisualExampleClient.tsx:375–419  ·  view source on GitHub ↗
(children, indent = '')

Source from the content-addressed store, hash-verified

373}
374
375function renderChildren(children, indent = '') {
376 if (children?.icon || children?.avatar || children?.badge) {
377 let result: ReactNode = null;
378 if (children.avatar) {
379 result = renderElement('Avatar', {src: 'https://i.imgur.com/xIe7Wlb.png'}, undefined, indent);
380 } else if (children.icon) {
381 result = renderElement(children.icon.replace(/^(\d)/, '_$1'), {}, undefined, indent);
382 }
383
384 if (children.text) {
385 let text = renderElement('Text', {children: children.text}, undefined, indent);
386 result = (
387 <>
388 {result}
389 {result ? '\n ' + indent : null}
390 {text}
391 </>
392 );
393 }
394
395 if (children.badge) {
396 let badge = renderElement('NotificationBadge', {value: 12}, undefined, indent);
397 result = (
398 <>
399 {result}
400 {result ? '\n ' + indent : null}
401 {badge}
402 </>
403 );
404 }
405
406 return result;
407 } else if (children?.text != null) {
408 return children.text;
409 } else if (Array.isArray(children)) {
410 return children.map((c, i) => (
411 <React.Fragment key={i}>
412 {i > 0 ? '\n ' + indent : null}
413 {c}
414 </React.Fragment>
415 ));
416 }
417
418 return children;
419}
420
421function countChars(element: ReactNode) {
422 if (typeof element === 'string') {

Callers 1

renderElementFunction · 0.70

Calls 1

renderElementFunction · 0.85

Tested by

no test coverage detected