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

Function ShadcnCommand

packages/dev/s2-docs/src/ShadcnCommand.tsx:10–101  ·  view source on GitHub ↗
({
  type,
  component,
  preRef
}: {
  type?: 'vanilla' | 'tailwind' | 'hooks';
  component?: string;
  preRef?: RefObject<HTMLPreElement | null>;
})

Source from the content-addressed store, hash-verified

8import {useLocalStorage} from './useLocalStorage';
9
10export function ShadcnCommand({
11 type,
12 component,
13 preRef
14}: {
15 type?: 'vanilla' | 'tailwind' | 'hooks';
16 component?: string;
17 preRef?: RefObject<HTMLPreElement | null>;
18}) {
19 let [packageManager, setPackageManager] = useLocalStorage('packageManager', 'npm');
20 let command = packageManager;
21 if (packageManager === 'npm') {
22 command = 'npx';
23 } else if (packageManager === 'pnpm') {
24 command = 'pnpm dlx';
25 }
26
27 let onSelectionChange = (value: Key) => {
28 setPackageManager(String(value));
29 };
30
31 let [storedType, setStoredType] = useLocalStorage('style', type || 'Vanilla CSS');
32 let shadcnType =
33 type === 'hooks'
34 ? 'hooks'
35 : type === 'vanilla' || storedType === 'Vanilla CSS'
36 ? 'css'
37 : 'tailwind';
38 let componentName = component ? '-' + component.toLowerCase() : '';
39 let specifier =
40 process.env.DOCS_ENV === 'prod'
41 ? `@react-aria/${shadcnType}${componentName}`
42 : `${getBaseUrl('react-aria')}/registry/${shadcnType}${componentName}.json`;
43
44 let cmd = `${command} shadcn@latest add ${specifier}`;
45
46 return (
47 <div
48 className={style({
49 backgroundColor: 'layer-1',
50 borderRadius: 'xl',
51 padding: 16,
52 display: 'flex',
53 flexDirection: 'column',
54 gap: 16
55 })}>
56 <div
57 className={style({
58 display: 'flex',
59 flexWrap: 'wrap',
60 gap: 16
61 })}>
62 <SegmentedControl
63 aria-label="Package manager"
64 selectedKey={packageManager}
65 onSelectionChange={onSelectionChange}>
66 <SegmentedControlItem id="npm">npm</SegmentedControlItem>
67 <SegmentedControlItem id="yarn">yarn</SegmentedControlItem>

Callers

nothing calls this directly

Calls 4

useLocalStorageFunction · 0.90
getBaseUrlFunction · 0.90
iconStyleFunction · 0.90
StringFunction · 0.85

Tested by

no test coverage detected