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

Function BundlerSwitcher

packages/dev/s2-docs/src/BundlerSwitcher.tsx:45–82  ·  view source on GitHub ↗
({children}: BundlerSwitcherProps)

Source from the content-addressed store, hash-verified

43}
44
45export function BundlerSwitcher({children}: BundlerSwitcherProps) {
46 let items = useMemo(() => {
47 let arr = Children.toArray(children) as ReactElement<BundlerSwitcherItemProps>[];
48 return arr
49 .filter(el => React.isValidElement(el))
50 .map(el => ({
51 id: el.props.id as SwitcherKey,
52 label: el.props.label,
53 content: el.props.children as ReactNode
54 }));
55 }, [children]);
56
57 let [bundler, setBundler] = useLocalStorage('bundler', items[0]?.id);
58 let active = items.find(it => it.id === bundler) ?? items[0];
59
60 let onSelectionChange = (key: Key) => {
61 let value = String(key) as SwitcherKey;
62 setBundler(value);
63 };
64
65 return (
66 <div className={container} data-example-switcher>
67 <div className={style({overflowX: 'auto', width: 'auto', flexGrow: 1})}>
68 <SegmentedControl
69 selectedKey={active?.id}
70 onSelectionChange={onSelectionChange}
71 styles={switcher}>
72 {items.map(it => (
73 <SegmentedControlItem key={it.id} id={it.id}>
74 {it.label}
75 </SegmentedControlItem>
76 ))}
77 </SegmentedControl>
78 </div>
79 {active?.content}
80 </div>
81 );
82}
83
84export default BundlerSwitcher;

Callers

nothing calls this directly

Calls 2

useLocalStorageFunction · 0.90
filterMethod · 0.65

Tested by

no test coverage detected