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

Function renderImports

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

Source from the content-addressed store, hash-verified

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

Callers 1

CodeOutputFunction · 0.85

Calls 2

renderImportFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected