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

Function renderImports

packages/dev/s2-docs/src/VisualExampleClient.tsx:612–652  ·  view source on GitHub ↗
(name: string, importSource: string, props: Props)

Source from the content-addressed store, hash-verified

610}
611
612function renderImports(name: string, importSource: string, props: Props) {
613 let imports: ReactNode[] = [];
614 let components = [name];
615 if (props.children?.badge) {
616 components.push('NotificationBadge');
617 }
618
619 if (
620 components.length > 1 ||
621 ((props.children?.icon || props.children?.avatar) && props.children?.text)
622 ) {
623 components.push('Text');
624 }
625
626 imports.push(renderImport(components.join(', '), importSource));
627
628 if (props.children?.avatar) {
629 imports.push('\n', renderImport('Avatar', '@react-spectrum/s2/Avatar'));
630 }
631
632 if (props.contextualHelp) {
633 imports.push(
634 '\n',
635 renderImport('ContextualHelp, Heading, Content', '@react-spectrum/s2/ContextualHelp')
636 );
637 }
638
639 if (props.children?.icon && !props.children?.avatar) {
640 imports.push(
641 '\n',
642 renderImport(
643 props.children.icon.replace(/^(\d)/, '_$1'),
644 `@react-spectrum/s2/icons/${props.children.icon}`,
645 true
646 )
647 );
648 }
649
650 imports.push('\n\n');
651 return imports;
652}
653
654function renderImport(name, from, isDefault = false) {
655 return (

Callers 1

CodeOutputFunction · 0.85

Calls 2

renderImportFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected