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

Function renderChildren

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

Source from the content-addressed store, hash-verified

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

Callers 1

renderElementFunction · 0.70

Calls 1

renderElementFunction · 0.85

Tested by

no test coverage detected