MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / CliInstallation

Function CliInstallation

src/components/code/CliInstallation.jsx:30–339  ·  view source on GitHub ↗
({ deps })

Source from the content-addressed store, hash-verified

28const CLI_LABEL_MAP = { shadcn: 'shadcn', jsrepo: 'jsrepo' };
29
30const CliInstallation = ({ deps }) => {
31 const { category, subcategory } = useActiveRoute();
32 const { languagePreset, stylePreset } = useOptions() || {};
33
34 const {
35 installMode: mode,
36 setInstallMode: setMode,
37 cliTool: cliLib,
38 setCliTool: setCliLib,
39 packageManager: pkg,
40 setPackageManager: setPkg
41 } = useInstallation();
42
43 const commands = useMemo(
44 () => generateCliCommands(languagePreset, stylePreset, category, subcategory, deps),
45 [languagePreset, stylePreset, category, subcategory, deps]
46 );
47
48 const hasManual = !!commands?.manual;
49
50 useEffect(() => {
51 if (!hasManual && mode === 'manual') {
52 setMode('cli');
53 }
54 }, [hasManual, mode, setMode]);
55
56
57
58 const [copied, setCopied] = useState(false);
59 const codeRef = useRef(null);
60 const [scrollMeta, setScrollMeta] = useState({ w: 0, l: 0, show: false });
61 const [dragging, setDragging] = useState(false);
62 const trackRef = useRef(null);
63 const dragOffsetRef = useRef(0);
64 const trackWidthRef = useRef(0);
65 const thumbWidthRef = useRef(0);
66
67 const currentCommand = useMemo(() => {
68 if (!commands) return '';
69 if (mode === 'manual') return commands.manual?.[pkg] || '';
70 const key = pkg === 'npm' ? 'npx' : pkg;
71 return cliLib === 'jsrepo' ? commands.jsrepo[key] : commands.shadcn[key];
72 }, [commands, mode, pkg, cliLib]);
73
74 const updateScrollMeta = useCallback(() => {
75 const el = codeRef.current;
76 if (!el) return;
77 const { scrollWidth, clientWidth, scrollLeft } = el;
78 if (scrollWidth <= clientWidth) {
79 if (scrollMeta.show) setScrollMeta({ w: 0, l: 0, show: false });
80 return;
81 }
82 const ratio = clientWidth / scrollWidth;
83 const thumbWidth = Math.max(24, clientWidth * ratio);
84 const maxTrack = clientWidth - thumbWidth;
85 const thumbLeft = (scrollLeft / (scrollWidth - clientWidth)) * maxTrack;
86 setScrollMeta({ w: thumbWidth, l: thumbLeft, show: true });
87 trackWidthRef.current = clientWidth;

Callers

nothing calls this directly

Calls 5

useActiveRouteFunction · 0.90
useOptionsFunction · 0.90
useInstallationFunction · 0.90
generateCliCommandsFunction · 0.90
renderPkgButtonsFunction · 0.85

Tested by

no test coverage detected