({pkg, flags, label, isCommand}: InstallCommandProps)
| 57 | } |
| 58 | |
| 59 | export function InstallCommand({pkg, flags, label, isCommand}: InstallCommandProps) { |
| 60 | let [manager, setManager] = useLocalStorage('packageManager', 'npm'); |
| 61 | |
| 62 | let onSelectionChange = (key: Key) => { |
| 63 | let value = String(key) as PkgManager; |
| 64 | setManager(value); |
| 65 | }; |
| 66 | |
| 67 | let command = useMemo(() => { |
| 68 | let parts: string[] = []; |
| 69 | if (isCommand) { |
| 70 | parts = ['npx', pkg]; |
| 71 | } else { |
| 72 | switch (manager) { |
| 73 | case 'yarn': |
| 74 | parts = ['yarn', 'add']; |
| 75 | break; |
| 76 | case 'npm': |
| 77 | parts = ['npm', 'install']; |
| 78 | break; |
| 79 | case 'pnpm': |
| 80 | parts = ['pnpm', 'add']; |
| 81 | break; |
| 82 | } |
| 83 | parts.push(pkg); |
| 84 | } |
| 85 | if (flags) { |
| 86 | parts.push(flags); |
| 87 | } |
| 88 | return parts.join(' '); |
| 89 | }, [isCommand, manager, pkg, flags]); |
| 90 | |
| 91 | return ( |
| 92 | <div className={container} data-example-switcher> |
| 93 | {!isCommand && ( |
| 94 | <SegmentedControl |
| 95 | selectedKey={manager} |
| 96 | onSelectionChange={onSelectionChange} |
| 97 | styles={switcher}> |
| 98 | <SegmentedControlItem id="npm">npm</SegmentedControlItem> |
| 99 | <SegmentedControlItem id="yarn">yarn</SegmentedControlItem> |
| 100 | <SegmentedControlItem id="pnpm">pnpm</SegmentedControlItem> |
| 101 | </SegmentedControl> |
| 102 | )} |
| 103 | <div className={codeWrap}> |
| 104 | {label && ( |
| 105 | <div className={style({font: 'body-sm', marginBottom: 8, color: 'body'})}>{label}</div> |
| 106 | )} |
| 107 | <div className={style({display: 'flex', alignItems: 'center', gap: 12, padding: 8})}> |
| 108 | <Prompt styles={iconStyle({size: 'L'})} /> |
| 109 | <pre className={preStyle}>{command}</pre> |
| 110 | <CopyButton ariaLabel="Copy command" tooltip="Copy command" text={command} /> |
| 111 | </div> |
| 112 | </div> |
| 113 | </div> |
| 114 | ); |
| 115 | } |
| 116 |
nothing calls this directly
no test coverage detected