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

Function renderImports

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

Source from the content-addressed store, hash-verified

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

Callers 1

CodeOutputFunction · 0.85

Calls 2

renderImportFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected