(name: string, importSource: string, props: Props)
| 602 | } |
| 603 | |
| 604 | function 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 | |
| 646 | function renderImport(name, from, isDefault = false) { |
| 647 | return ( |
no test coverage detected