MCPcopy Index your code
hub / github.com/adobe/react-spectrum / ShadcnCommand

Function ShadcnCommand

packages/dev/s2-docs/src/ShadcnCommand.tsx:10–96  ·  view source on GitHub ↗
({
  type,
  component,
  preRef
}: {
  type?: 'vanilla' | 'tailwind';
  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';
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 = type === 'vanilla' || storedType === 'Vanilla CSS' ? 'css' : 'tailwind';
33 let componentName = component ? '-' + component.toLowerCase() : '';
34 let specifier =
35 process.env.DOCS_ENV === 'prod'
36 ? `@react-aria/${shadcnType}${componentName}`
37 : `${getBaseUrl('react-aria')}/registry/${shadcnType}${componentName}.json`;
38
39 let cmd = `${command} shadcn@latest add ${specifier}`;
40
41 return (
42 <div
43 className={style({
44 backgroundColor: 'layer-1',
45 borderRadius: 'xl',
46 padding: 16,
47 display: 'flex',
48 flexDirection: 'column',
49 gap: 16
50 })}>
51 <div
52 className={style({
53 display: 'flex',
54 flexWrap: 'wrap',
55 gap: 16
56 })}>
57 <SegmentedControl
58 aria-label="Package manager"
59 selectedKey={packageManager}
60 onSelectionChange={onSelectionChange}>
61 <SegmentedControlItem id="npm">npm</SegmentedControlItem>
62 <SegmentedControlItem id="yarn">yarn</SegmentedControlItem>
63 <SegmentedControlItem id="pnpm">pnpm</SegmentedControlItem>
64 </SegmentedControl>
65 {!type && (
66 <SegmentedControl
67 aria-label="Style"

Callers

nothing calls this directly

Calls 3

useLocalStorageFunction · 0.90
getBaseUrlFunction · 0.90
iconStyleFunction · 0.90

Tested by

no test coverage detected