-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathShadcnCommand.tsx
More file actions
66 lines (61 loc) · 2.24 KB
/
ShadcnCommand.tsx
File metadata and controls
66 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use client';
import CopyButton from './CopyButton';
import {getBaseUrl} from './pageUtils';
import {iconStyle, style} from '@react-spectrum/s2/style' with {type: 'macro'};
import {Key, SegmentedControl, SegmentedControlItem} from '@react-spectrum/s2';
import Prompt from '@react-spectrum/s2/icons/Prompt';
import {RefObject} from 'react';
import {useLocalStorage} from './useLocalStorage';
export function ShadcnCommand({type, component, preRef}: {type: 'vanilla' | 'tailwind', component: string, preRef?: RefObject<HTMLPreElement | null>}) {
let [packageManager, setPackageManager] = useLocalStorage('packageManager', 'npm');
let command = packageManager;
if (packageManager === 'npm') {
command = 'npx';
} else if (packageManager === 'pnpm') {
command = 'pnpm dlx';
}
let onSelectionChange = (value: Key) => {
setPackageManager(String(value));
};
let shadcnType = type === 'vanilla' ? 'css' : type;
let specifier = process.env.DOCS_ENV === 'prod'
? `@react-aria/${shadcnType}-${component.toLowerCase()}`
: `${getBaseUrl('react-aria')}/registry/${shadcnType}-${component.toLowerCase()}.json`;
let cmd = `${command} shadcn@latest add ${specifier}`;
return (
<div
className={style({
backgroundColor: 'layer-1',
borderRadius: 'xl',
padding: 16,
display: 'flex',
flexDirection: 'column',
gap: 16
})}>
<SegmentedControl aria-label="Package manager" selectedKey={packageManager} onSelectionChange={onSelectionChange}>
<SegmentedControlItem id="npm">npm</SegmentedControlItem>
<SegmentedControlItem id="yarn">yarn</SegmentedControlItem>
<SegmentedControlItem id="pnpm">pnpm</SegmentedControlItem>
</SegmentedControl>
<div
className={style({
display: 'flex',
alignItems: 'center',
gap: 12
})}>
<Prompt styles={iconStyle({size: 'L'})} />
<pre
ref={preRef}
className={style({
font: {default: 'code-xs', lg: 'code-sm'},
overflowX: 'auto',
padding: 0,
margin: 0
})}>
{cmd}
</pre>
<CopyButton ariaLabel="Copy command" tooltip="Copy command" text={cmd} />
</div>
</div>
);
}