(name: string, importSource: string, props: Props)
| 610 | } |
| 611 | |
| 612 | function 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 | |
| 654 | function renderImport(name, from, isDefault = false) { |
| 655 | return ( |
no test coverage detected