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

Function CodeOptions

src/components/code/CodeOptions.jsx:31–76  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

29);
30
31const CodeOptions = ({ children }) => {
32 const { languagePreset, setLanguagePreset, stylePreset, setStylePreset } = useOptions();
33 const currentLang = languagePreset || 'JS';
34
35 const buckets = { JS: { css: null, tailwind: null }, TS: { css: null, tailwind: null } };
36 Children.forEach(children, child => {
37 if (!child) return;
38 if (child.type === CSS) buckets.JS.css = child;
39 if (child.type === Tailwind) buckets.JS.tailwind = child;
40 if (child.type === TSCSS) buckets.TS.css = child;
41 if (child.type === TSTailwind) buckets.TS.tailwind = child;
42 });
43
44 const renderContent = variant => {
45 const node = currentLang === 'JS' ? buckets.JS[variant] : buckets.TS[variant];
46 return node?.props?.children ? node : UNSUPPORTED;
47 };
48
49 const styleVariant = stylePreset === 'TW' ? 'tailwind' : 'css';
50
51 return (
52 <Box mt={0} w="100%">
53 <Flex mb={2} w="100%" alignItems="center" gap={2}>
54 <IconSelect
55 collection={LANG_ITEMS}
56 value={currentLang}
57 onChange={setLanguagePreset}
58 iconMap={ICON_MAP}
59 labelMap={LABEL_MAP}
60 colorMap={COLOR_MAP}
61 width="150px"
62 />
63 <IconSelect
64 collection={STYLE_ITEMS}
65 value={stylePreset}
66 onChange={setStylePreset}
67 iconMap={ICON_MAP}
68 labelMap={LABEL_MAP}
69 colorMap={COLOR_MAP}
70 width="135px"
71 />
72 </Flex>
73 <Box>{renderContent(styleVariant)}</Box>
74 </Box>
75 );
76};
77
78export default CodeOptions;

Callers

nothing calls this directly

Calls 2

useOptionsFunction · 0.90
renderContentFunction · 0.85

Tested by

no test coverage detected