@sproutsocial/seeds-react-segmented-control 1.1.24 → 1.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  // src/SegmentedControl.tsx
2
- import * as React from "react";
3
- import { useState } from "react";
4
- import * as ToggleGroup from "@radix-ui/react-toggle-group";
2
+ import * as React3 from "react";
3
+
4
+ // src/SegmentedControlHybrid.tsx
5
+ import * as React2 from "react";
6
+ import * as ToggleGroup2 from "@radix-ui/react-toggle-group";
7
+ import { hasStyledProps } from "@sproutsocial/seeds-react-system-props";
5
8
 
6
9
  // src/styles.ts
7
10
  import styled, { css } from "styled-components";
@@ -102,71 +105,163 @@ var SegmentedControlLabel = styled(Button)`
102
105
  `}
103
106
  `;
104
107
 
105
- // src/SegmentedControl.tsx
108
+ // src/SegmentedControlTailwind.tsx
109
+ import * as React from "react";
110
+ import * as ToggleGroup from "@radix-ui/react-toggle-group";
106
111
  import { jsx } from "react/jsx-runtime";
107
- var nameCounter = 0;
108
- var SegmentedControlContext = React.createContext(null);
112
+ var SegmentedControlVariantContext = React.createContext("tailwind");
113
+ function cn(...inputs) {
114
+ const classes = [];
115
+ for (const input of inputs) {
116
+ if (!input) continue;
117
+ if (typeof input === "string") {
118
+ classes.push(input);
119
+ } else if (typeof input === "object") {
120
+ for (const [key, value] of Object.entries(input)) {
121
+ if (value) {
122
+ classes.push(key);
123
+ }
124
+ }
125
+ }
126
+ }
127
+ return classes.join(" ");
128
+ }
129
+ function createChangeHandler(onChange, onValueChange) {
130
+ return (e) => {
131
+ if (!e) return;
132
+ onValueChange?.(e);
133
+ const mockEvent = new Event("change", {
134
+ bubbles: true
135
+ });
136
+ Object.defineProperty(mockEvent, "target", { value: { value: e } });
137
+ Object.defineProperty(mockEvent, "currentTarget", {
138
+ value: { value: e }
139
+ });
140
+ onChange?.(mockEvent);
141
+ };
142
+ }
109
143
  var SegmentedControlItem = ({
110
144
  value,
111
145
  children,
112
146
  disabled: disabled2,
113
147
  ...rest
114
148
  }) => {
149
+ const variant = React.useContext(SegmentedControlVariantContext);
150
+ if (variant === "styled") {
151
+ return /* @__PURE__ */ jsx(ToggleGroup.Item, { value, disabled: disabled2, asChild: true, children: /* @__PURE__ */ jsx(
152
+ ToggleButton,
153
+ {
154
+ "data-qa-segmentedcontrol-item": value,
155
+ disabled: disabled2,
156
+ ...rest,
157
+ children
158
+ }
159
+ ) });
160
+ }
161
+ const Toggle = "button";
115
162
  return /* @__PURE__ */ jsx(ToggleGroup.Item, { value, disabled: disabled2, asChild: true, children: /* @__PURE__ */ jsx(
116
- ToggleButton,
163
+ Toggle,
117
164
  {
165
+ type: "button",
118
166
  "data-qa-segmentedcontrol-item": value,
119
167
  disabled: disabled2,
120
168
  ...rest,
169
+ className: "seeds-segmented-control-item",
121
170
  children
122
171
  }
123
172
  ) });
124
173
  };
125
- var SegmentedControl = ({
126
- selectedValue,
127
- label,
128
- onChange,
129
- onValueChange,
130
- children,
131
- disabled: disabled2,
132
- ...rest
133
- }) => {
134
- const [name] = useState(`Racine-segmented-control-${nameCounter++}`);
135
- return /* @__PURE__ */ jsx(
136
- ToggleGroup.Root,
137
- {
138
- className: "inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4",
139
- type: "single",
140
- value: selectedValue,
141
- "aria-label": label,
142
- disabled: disabled2,
143
- onValueChange: (e) => {
144
- if (!e) return;
145
- onValueChange?.(e);
146
- const mockEvent = new Event("change", {
147
- bubbles: true
148
- });
149
- Object.defineProperty(mockEvent, "target", { value: { value: e } });
150
- Object.defineProperty(mockEvent, "currentTarget", {
151
- value: { value: e }
152
- });
153
- onChange?.(mockEvent);
154
- },
155
- asChild: true,
156
- children: /* @__PURE__ */ jsx(
157
- SegmentedControlContainer,
158
- {
159
- "data-qa-segmentedcontrol": label,
160
- "data-qa-segmentedcontrol-value": selectedValue,
161
- disabled: disabled2,
162
- ...rest,
163
- children
164
- }
165
- )
166
- }
167
- );
168
- };
169
174
  SegmentedControlItem.displayName = "SegmentedControl.Item";
175
+ var SegmentedControlTailwind = React.forwardRef(
176
+ ({
177
+ selectedValue,
178
+ label,
179
+ onChange,
180
+ onValueChange,
181
+ children,
182
+ disabled: disabled2 = false,
183
+ className,
184
+ ...rest
185
+ }, ref) => {
186
+ const Container = "div";
187
+ return /* @__PURE__ */ jsx(
188
+ ToggleGroup.Root,
189
+ {
190
+ className: "inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4",
191
+ type: "single",
192
+ value: selectedValue,
193
+ "aria-label": label,
194
+ disabled: disabled2,
195
+ onValueChange: createChangeHandler(onChange, onValueChange),
196
+ asChild: true,
197
+ children: /* @__PURE__ */ jsx(
198
+ Container,
199
+ {
200
+ ref,
201
+ "data-qa-segmentedcontrol": label,
202
+ "data-qa-segmentedcontrol-value": selectedValue,
203
+ ...rest,
204
+ className: cn(
205
+ "seeds-segmented-control",
206
+ { "seeds-segmented-control-disabled": disabled2 },
207
+ className
208
+ ),
209
+ children
210
+ }
211
+ )
212
+ }
213
+ );
214
+ }
215
+ );
216
+ SegmentedControlTailwind.displayName = "SegmentedControlTailwind";
217
+
218
+ // src/SegmentedControlHybrid.tsx
219
+ import { jsx as jsx2 } from "react/jsx-runtime";
220
+ var SegmentedControlHybrid = React2.forwardRef((props, ref) => {
221
+ const {
222
+ selectedValue,
223
+ label,
224
+ onChange,
225
+ onValueChange,
226
+ children,
227
+ disabled: disabled2,
228
+ ...rest
229
+ } = props;
230
+ if (hasStyledProps(rest)) {
231
+ return /* @__PURE__ */ jsx2(SegmentedControlVariantContext.Provider, { value: "styled", children: /* @__PURE__ */ jsx2(
232
+ ToggleGroup2.Root,
233
+ {
234
+ className: "inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4",
235
+ type: "single",
236
+ value: selectedValue,
237
+ "aria-label": label,
238
+ disabled: disabled2,
239
+ onValueChange: createChangeHandler(onChange, onValueChange),
240
+ asChild: true,
241
+ children: /* @__PURE__ */ jsx2(
242
+ SegmentedControlContainer,
243
+ {
244
+ ref,
245
+ "data-qa-segmentedcontrol": label,
246
+ "data-qa-segmentedcontrol-value": selectedValue,
247
+ disabled: disabled2,
248
+ ...rest,
249
+ children
250
+ }
251
+ )
252
+ }
253
+ ) });
254
+ }
255
+ return /* @__PURE__ */ jsx2(SegmentedControlTailwind, { ...props, ref });
256
+ });
257
+ SegmentedControlHybrid.displayName = "SegmentedControl";
258
+ SegmentedControlHybrid.Item = SegmentedControlItem;
259
+ var SegmentedControlHybrid_default = SegmentedControlHybrid;
260
+
261
+ // src/SegmentedControl.tsx
262
+ import { jsx as jsx3 } from "react/jsx-runtime";
263
+ var SegmentedControl = React3.forwardRef((props, ref) => /* @__PURE__ */ jsx3(SegmentedControlHybrid_default, { ...props, ref }));
264
+ SegmentedControl.displayName = "SegmentedControl";
170
265
  SegmentedControl.Item = SegmentedControlItem;
171
266
  var SegmentedControl_default = SegmentedControl;
172
267
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/SegmentedControl.tsx","../../src/styles.ts","../../src/SegmentedControlTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useState } from \"react\";\nimport * as ToggleGroup from \"@radix-ui/react-toggle-group\";\nimport { SegmentedControlContainer, ToggleButton } from \"./styles\";\nimport type {\n TypeSegmentedControlProps,\n TypeSegmentedControlItemProps,\n} from \"./SegmentedControlTypes\";\n\nlet nameCounter = 0;\nlet idCounter = 0;\n\ninterface TypeSegmentedControlContext {\n name: string;\n selectedValue: string;\n onChange: (e: React.SyntheticEvent<HTMLInputElement>) => void;\n}\n\nconst SegmentedControlContext = React.createContext<\n TypeSegmentedControlContext | null | undefined\n>(null);\n\nconst SegmentedControlItem = ({\n value,\n children,\n disabled,\n ...rest\n}: TypeSegmentedControlItemProps) => {\n return (\n <ToggleGroup.Item value={value} disabled={disabled} asChild>\n <ToggleButton\n // TODO: Discuss dropping these\n // We'd need to keep context, which seems unnecessary now\n // data-segmentedcontrol-isactive={isChecked}\n data-qa-segmentedcontrol-item={value}\n // data-qa-segmentedcontrol-ischecked={isChecked === true}\n disabled={disabled}\n {...rest}\n >\n {children}\n </ToggleButton>\n </ToggleGroup.Item>\n );\n};\n\nconst SegmentedControl = ({\n selectedValue,\n label,\n onChange,\n onValueChange,\n children,\n disabled,\n ...rest\n}: TypeSegmentedControlProps) => {\n const [name] = useState(`Racine-segmented-control-${nameCounter++}`);\n return (\n <ToggleGroup.Root\n className=\"inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4\"\n type=\"single\"\n value={selectedValue}\n aria-label={label}\n disabled={disabled}\n onValueChange={(e) => {\n // Radix allows deselecting a value by clicking on it when it's already selected,\n // but we don't want to allow that behavior in our SegmentedControl.\n if (!e) return;\n\n onValueChange?.(e);\n // Create a mock event to pass to onChange for backwards compatibility.\n // We want to move towards onValueChange, but onChange is used by consumers currently so we need to support both for now.\n const mockEvent = new Event(\"change\", {\n bubbles: true,\n }) as unknown as React.SyntheticEvent<HTMLInputElement>;\n Object.defineProperty(mockEvent, \"target\", { value: { value: e } });\n Object.defineProperty(mockEvent, \"currentTarget\", {\n value: { value: e },\n });\n onChange?.(mockEvent);\n }}\n asChild\n >\n <SegmentedControlContainer\n data-qa-segmentedcontrol={label}\n data-qa-segmentedcontrol-value={selectedValue}\n disabled={disabled}\n {...rest}\n >\n {children}\n </SegmentedControlContainer>\n </ToggleGroup.Root>\n );\n};\n\nSegmentedControlItem.displayName = \"SegmentedControl.Item\";\nSegmentedControl.Item = SegmentedControlItem;\n\nexport default SegmentedControl;\n","import styled, { css } from \"styled-components\";\nimport {\n visuallyHidden,\n focusRing,\n disabled,\n} from \"@sproutsocial/seeds-react-mixins\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Button from \"@sproutsocial/seeds-react-button\";\nimport type {\n TypeSegmentedControlProps,\n TypeSegmentedControlItemProps,\n} from \"./SegmentedControlTypes\";\n\nexport const SegmentedControlContainer = styled(Box)<\n Pick<TypeSegmentedControlProps, \"disabled\">\n>`\n border: 1px solid\n ${(props) => props.theme.colors.button.secondary.border.base};\n border-radius: ${(props) => props.theme.radii.outer};\n padding: ${(props) => props.theme.space[100]};\n display: flex;\n\n ${(props) => props.disabled && disabled}\n`;\n\nexport const ToggleButton = styled(Button)`\n /* To match the height of buttons... 350 padding - 2px top and bottom padding of the parent - 1px border on top and bottom */\n padding: calc(${(props) => props.theme.space[350]} - 6px);\n flex: 1 1 auto;\n display: flex;\n align-items: center;\n justify-content: center;\n text-align: center;\n border: 0;\n\n & + & {\n margin-left: ${(props) => props.theme.space[100]};\n }\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.hover};\n }\n\n &[data-state=\"on\"] {\n color: ${(props) => props.theme.colors.text.inverse};\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n }\n }\n`;\n\nexport const SegmentedControlItemContainer = styled(Box)<\n Pick<TypeSegmentedControlItemProps, \"disabled\">\n>`\n flex: 1 1 auto;\n display: flex;\n cursor: pointer;\n\n & + & {\n margin-left: ${(props) => props.theme.space[100]};\n }\n\n &:focus-within label {\n ${focusRing}\n }\n\n input {\n ${visuallyHidden}\n }\n\n ${(props) => props.disabled && disabled}\n`;\n\ninterface TypeSegmentedControlState {\n isActive: boolean;\n}\n\nexport const SegmentedControlLabel = styled(Button)<TypeSegmentedControlState>`\n flex: 1 1 auto;\n display: flex;\n align-items: center;\n justify-content: center;\n text-align: center;\n color: ${(props) => props.theme.colors.text.body};\n cursor: pointer;\n font-size: ${(props) => props.theme.typography[200].fontSize};\n /**\n\t* Matches default line height of Icon. Also matches the overall height of\n\t* Input, Select, and Button.\n\t*/\n line-height: 16px;\n font-weight: ${(props) => props.theme.fontWeights.semibold};\n\n border-radius: ${(props) => props.theme.radii.inner};\n /* To match the height of buttons... 350 padding - 2px top and bottom padding of the parent - 1px border on top and bottom */\n padding: calc(${(props) => props.theme.space[350]} - 6px);\n transition: all ${(props) => props.theme.duration.fast};\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.hover};\n }\n\n ${(props) =>\n props.isActive &&\n css`\n color: ${(props) => props.theme.colors.text.inverse};\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n }\n `}\n`;\n","import type { TypeContainerProps } from \"@sproutsocial/seeds-react-box\";\nimport * as React from \"react\";\n\nexport interface TypeSegmentedControlItemProps {\n /** The value of this item. Should be unique among sibling items. */\n value: string;\n children: React.ReactNode;\n /** Disables user action and applies a disabled style on the component */\n disabled?: boolean;\n}\n\nexport interface TypeSegmentedControlProps extends TypeContainerProps {\n /** The value of the currently selected item. Should match the value prop of one of the child items */\n selectedValue: string;\n\n /** The title of the segmented control, used for accessibility purposes */\n label: string;\n\n /** Called when the user selects a new item. You can access the value of the newly selected item using \"event.target.value\" */\n onChange?: (e: React.SyntheticEvent<HTMLInputElement>) => void;\n\n /** Called when the user selects a new item. You can access the value of the newly selected item using \"event.target.value\" */\n onValueChange?: (value: string) => void;\n\n /** Disables user action and applies a disabled style on the component */\n disabled?: boolean;\n children: React.ReactNode;\n}\n","import SegmentedControl from \"./SegmentedControl\";\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport * from \"./SegmentedControlTypes\";\n"],"mappings":";AAAA,YAAY,WAAW;AACvB,SAAS,gBAAgB;AACzB,YAAY,iBAAiB;;;ACF7B,OAAO,UAAU,WAAW;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,SAAS;AAChB,OAAO,YAAY;AAMZ,IAAM,4BAA4B,OAAO,GAAG;AAAA;AAAA,MAI7C,CAAC,UAAU,MAAM,MAAM,OAAO,OAAO,UAAU,OAAO,IAAI;AAAA,mBAC7C,CAAC,UAAU,MAAM,MAAM,MA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CAAC;AACD,eAAO,eAAe,WAAW,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;AAClE,eAAO,eAAe,WAAW,iBAAiB;AAAA,UAChD,OAAO,EAAE,OAAO,EAAE;AAAA,QACpB,CAAC;AACD,mBAAW,SAAS;AAAA,MACtB;AAAA,MACA,SAAO;AAAA,MAEP;AAAA,QAAC;AAAA;AAAA,UACC,4BAA0B;AAAA,UAC1B,kCAAgC;AAAA,UAChC,UAAUA;AAAA,UACT,GAAG;AAAA,UAEH;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEA,qBAAqB,cAAc;AACnC,iBAAiB,OAAO;AAExB,IAAO,2BAAQ;;;AE/Ff,OAAuB;;;ACCvB,IAAO,gBAAQ;","names":["props","disabled"]}
1
+ {"version":3,"sources":["../../src/SegmentedControl.tsx","../../src/SegmentedControlHybrid.tsx","../../src/styles.ts","../../src/SegmentedControlTailwind.tsx","../../src/SegmentedControlTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport type { TypeSegmentedControlProps } from \"./SegmentedControlTypes\";\nimport SegmentedControlHybrid from \"./SegmentedControlHybrid\";\nimport { SegmentedControlItem } from \"./SegmentedControlTailwind\";\n\ntype TypeSegmentedControlComponent = React.ForwardRefExoticComponent<\n TypeSegmentedControlProps & React.RefAttributes<HTMLDivElement>\n> & {\n Item: typeof SegmentedControlItem;\n};\n\n/**\n * SegmentedControl routes between the Tailwind/CSS-class implementation\n * (preferred) and the legacy styled-components implementation via the hybrid\n * component. This entry file keeps a real component definition (mirroring\n * Button.tsx) so react-docgen's `generate:props-docs` step can discover it and\n * emit prop docs from TypeSegmentedControlProps. styles.ts is left untouched\n * for the styled path.\n */\nconst SegmentedControl = React.forwardRef<\n HTMLDivElement,\n TypeSegmentedControlProps\n>((props, ref) => (\n <SegmentedControlHybrid {...props} ref={ref} />\n)) as TypeSegmentedControlComponent;\n\nSegmentedControl.displayName = \"SegmentedControl\";\nSegmentedControl.Item = SegmentedControlItem;\n\nexport default SegmentedControl;\n","/**\n * Hybrid SegmentedControl Component\n * Automatically chooses between Tailwind and styled-components based on props.\n * Consumers using Box system props (flex, mr, ml, height, ...) or a\n * styled(SegmentedControl) extension keep the styled-components implementation;\n * everyone else gets the faster Tailwind path.\n */\n\nimport * as React from \"react\";\nimport * as ToggleGroup from \"@radix-ui/react-toggle-group\";\nimport { hasStyledProps } from \"@sproutsocial/seeds-react-system-props\";\nimport { SegmentedControlContainer } from \"./styles\";\nimport {\n SegmentedControlTailwind,\n SegmentedControlItem,\n SegmentedControlVariantContext,\n createChangeHandler,\n} from \"./SegmentedControlTailwind\";\nimport type { TypeSegmentedControlProps } from \"./SegmentedControlTypes\";\n\ntype TypeSegmentedControlComponent = React.ForwardRefExoticComponent<\n TypeSegmentedControlProps & React.RefAttributes<HTMLDivElement>\n> & {\n Item: typeof SegmentedControlItem;\n};\n\nconst SegmentedControlHybrid = React.forwardRef<\n HTMLDivElement,\n TypeSegmentedControlProps\n>((props, ref) => {\n const {\n selectedValue,\n label,\n onChange,\n onValueChange,\n children,\n disabled,\n ...rest\n } = props;\n\n if (hasStyledProps(rest)) {\n // Styled-components path: preserves Box system props and\n // styled(SegmentedControl) extensions. Mirrors the original\n // SegmentedControl.tsx body, sharing the change handler with the\n // Tailwind path. The variant provider (outside ToggleGroup.Root so it does\n // not interfere with the asChild prop-merge onto SegmentedControlContainer)\n // makes each child `.Item` render the styled `ToggleButton`, restoring the\n // styled-components item styling that consumers on this path rely on.\n return (\n <SegmentedControlVariantContext.Provider value=\"styled\">\n <ToggleGroup.Root\n className=\"inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4\"\n type=\"single\"\n value={selectedValue}\n aria-label={label}\n disabled={disabled}\n onValueChange={createChangeHandler(onChange, onValueChange)}\n asChild\n >\n <SegmentedControlContainer\n ref={ref}\n data-qa-segmentedcontrol={label}\n data-qa-segmentedcontrol-value={selectedValue}\n disabled={disabled}\n {...rest}\n >\n {children}\n </SegmentedControlContainer>\n </ToggleGroup.Root>\n </SegmentedControlVariantContext.Provider>\n );\n }\n\n // Tailwind path (preferred - better performance)\n return <SegmentedControlTailwind {...props} ref={ref} />;\n}) as TypeSegmentedControlComponent;\n\nSegmentedControlHybrid.displayName = \"SegmentedControl\";\nSegmentedControlHybrid.Item = SegmentedControlItem;\n\nexport default SegmentedControlHybrid;\n","import styled, { css } from \"styled-components\";\nimport {\n visuallyHidden,\n focusRing,\n disabled,\n} from \"@sproutsocial/seeds-react-mixins\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Button from \"@sproutsocial/seeds-react-button\";\nimport type {\n TypeSegmentedControlProps,\n TypeSegmentedControlItemProps,\n} from \"./SegmentedControlTypes\";\n\nexport const SegmentedControlContainer = styled(Box)<\n Pick<TypeSegmentedControlProps, \"disabled\">\n>`\n border: 1px solid\n ${(props) => props.theme.colors.button.secondary.border.base};\n border-radius: ${(props) => props.theme.radii.outer};\n padding: ${(props) => props.theme.space[100]};\n display: flex;\n\n ${(props) => props.disabled && disabled}\n`;\n\nexport const ToggleButton = styled(Button)`\n /* To match the height of buttons... 350 padding - 2px top and bottom padding of the parent - 1px border on top and bottom */\n padding: calc(${(props) => props.theme.space[350]} - 6px);\n flex: 1 1 auto;\n display: flex;\n align-items: center;\n justify-content: center;\n text-align: center;\n border: 0;\n\n & + & {\n margin-left: ${(props) => props.theme.space[100]};\n }\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.hover};\n }\n\n &[data-state=\"on\"] {\n color: ${(props) => props.theme.colors.text.inverse};\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n }\n }\n`;\n\nexport const SegmentedControlItemContainer = styled(Box)<\n Pick<TypeSegmentedControlItemProps, \"disabled\">\n>`\n flex: 1 1 auto;\n display: flex;\n cursor: pointer;\n\n & + & {\n margin-left: ${(props) => props.theme.space[100]};\n }\n\n &:focus-within label {\n ${focusRing}\n }\n\n input {\n ${visuallyHidden}\n }\n\n ${(props) => props.disabled && disabled}\n`;\n\ninterface TypeSegmentedControlState {\n isActive: boolean;\n}\n\nexport const SegmentedControlLabel = styled(Button)<TypeSegmentedControlState>`\n flex: 1 1 auto;\n display: flex;\n align-items: center;\n justify-content: center;\n text-align: center;\n color: ${(props) => props.theme.colors.text.body};\n cursor: pointer;\n font-size: ${(props) => props.theme.typography[200].fontSize};\n /**\n\t* Matches default line height of Icon. Also matches the overall height of\n\t* Input, Select, and Button.\n\t*/\n line-height: 16px;\n font-weight: ${(props) => props.theme.fontWeights.semibold};\n\n border-radius: ${(props) => props.theme.radii.inner};\n /* To match the height of buttons... 350 padding - 2px top and bottom padding of the parent - 1px border on top and bottom */\n padding: calc(${(props) => props.theme.space[350]} - 6px);\n transition: all ${(props) => props.theme.duration.fast};\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.hover};\n }\n\n ${(props) =>\n props.isActive &&\n css`\n color: ${(props) => props.theme.colors.text.inverse};\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n\n &:hover {\n background-color: ${(props) =>\n props.theme.colors.listItem.background.selected};\n }\n `}\n`;\n","/**\n * Tailwind CSS implementation of SegmentedControl component\n * Uses Seeds segmented-control CSS classes from segmented-control.css\n */\n\nimport * as React from \"react\";\nimport * as ToggleGroup from \"@radix-ui/react-toggle-group\";\nimport { ToggleButton } from \"./styles\";\nimport type {\n TypeSegmentedControlProps,\n TypeSegmentedControlItemProps,\n} from \"./SegmentedControlTypes\";\n\n/**\n * Identifies which rendering path the surrounding SegmentedControl took so the\n * compound `.Item` can match it. The styled-components path renders the legacy\n * styled `ToggleButton` (styled at runtime, no CSS-file dependency); the\n * Tailwind path renders the pure CSS-class button. The Hybrid Root provides\n * \"styled\" on its styled branch; the default is \"tailwind\".\n */\ntype SegmentedControlVariant = \"tailwind\" | \"styled\";\nexport const SegmentedControlVariantContext =\n React.createContext<SegmentedControlVariant>(\"tailwind\");\n\n// Utility for merging class names properly\nfunction cn(\n ...inputs: (string | undefined | null | false | Record<string, boolean>)[]\n): string {\n const classes: string[] = [];\n\n for (const input of inputs) {\n if (!input) continue;\n\n if (typeof input === \"string\") {\n classes.push(input);\n } else if (typeof input === \"object\") {\n for (const [key, value] of Object.entries(input)) {\n if (value) {\n classes.push(key);\n }\n }\n }\n }\n\n return classes.join(\" \");\n}\n\n/**\n * Builds the Radix `onValueChange` handler shared by both the Tailwind and the\n * styled-components paths. Preserves the deselect guard and the synthetic\n * `change` event used for `onChange` backwards compatibility.\n */\nexport function createChangeHandler(\n onChange?: (e: React.SyntheticEvent<HTMLInputElement>) => void,\n onValueChange?: (value: string) => void\n) {\n return (e: string) => {\n // Radix allows deselecting a value by clicking on it when it's already selected,\n // but we don't want to allow that behavior in our SegmentedControl.\n if (!e) return;\n\n onValueChange?.(e);\n // Create a mock event to pass to onChange for backwards compatibility.\n // We want to move towards onValueChange, but onChange is used by consumers\n // currently so we need to support both for now.\n const mockEvent = new Event(\"change\", {\n bubbles: true,\n }) as unknown as React.SyntheticEvent<HTMLInputElement>;\n Object.defineProperty(mockEvent, \"target\", { value: { value: e } });\n Object.defineProperty(mockEvent, \"currentTarget\", {\n value: { value: e },\n });\n onChange?.(mockEvent);\n };\n}\n\n/**\n * Compound item routed to match the surrounding container's path.\n *\n * On the styled-components path it renders the legacy styled `ToggleButton`\n * (styled at runtime by styled-components, with no dependency on the component\n * CSS file) — this preserves backward compatibility for consumers routed to\n * the styled branch via a Box system prop or a `styled(SegmentedControl)`\n * extension. On the Tailwind path it renders the pure CSS-class button. The\n * host element is typed as `any` so Radix's `asChild`-injected props\n * (data-state, role, keyboard handlers, onClick) and any forwarded props\n * spread cleanly — mirrors ButtonTailwind's `Component as any` pattern.\n */\nexport const SegmentedControlItem = ({\n value,\n children,\n disabled,\n ...rest\n}: TypeSegmentedControlItemProps) => {\n const variant = React.useContext(SegmentedControlVariantContext);\n\n if (variant === \"styled\") {\n // `Button` sets its own `type`, so we do not pass `type` here.\n return (\n <ToggleGroup.Item value={value} disabled={disabled} asChild>\n <ToggleButton\n data-qa-segmentedcontrol-item={value}\n disabled={disabled}\n {...rest}\n >\n {children}\n </ToggleButton>\n </ToggleGroup.Item>\n );\n }\n\n const Toggle = \"button\" as any;\n\n return (\n <ToggleGroup.Item value={value} disabled={disabled} asChild>\n <Toggle\n type=\"button\"\n data-qa-segmentedcontrol-item={value}\n disabled={disabled}\n {...rest}\n className=\"seeds-segmented-control-item\"\n >\n {children}\n </Toggle>\n </ToggleGroup.Item>\n );\n};\n\nSegmentedControlItem.displayName = \"SegmentedControl.Item\";\n\nexport const SegmentedControlTailwind = React.forwardRef<\n HTMLDivElement,\n TypeSegmentedControlProps\n>(\n (\n {\n selectedValue,\n label,\n onChange,\n onValueChange,\n children,\n disabled = false,\n className,\n ...rest\n }: TypeSegmentedControlProps,\n ref: React.Ref<HTMLDivElement>\n ) => {\n // Plain <div> container, typed as `any` so the `asChild`-merged className\n // and any forwarded props spread cleanly — mirrors ButtonTailwind.\n const Container = \"div\" as any;\n\n return (\n <ToggleGroup.Root\n className=\"inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4\"\n type=\"single\"\n value={selectedValue}\n aria-label={label}\n disabled={disabled}\n onValueChange={createChangeHandler(onChange, onValueChange)}\n asChild\n >\n <Container\n ref={ref}\n data-qa-segmentedcontrol={label}\n data-qa-segmentedcontrol-value={selectedValue}\n {...rest}\n // className is set last (after {...rest}) and merges any incoming\n // className — Radix Slot merges the Root's className onto this child,\n // and a consumer-provided className must be preserved too.\n className={cn(\n \"seeds-segmented-control\",\n { \"seeds-segmented-control-disabled\": disabled },\n className\n )}\n >\n {children}\n </Container>\n </ToggleGroup.Root>\n );\n }\n);\n\nSegmentedControlTailwind.displayName = \"SegmentedControlTailwind\";\n","import type { TypeContainerProps } from \"@sproutsocial/seeds-react-box\";\nimport * as React from \"react\";\n\nexport interface TypeSegmentedControlItemProps {\n /** The value of this item. Should be unique among sibling items. */\n value: string;\n children: React.ReactNode;\n /** Disables user action and applies a disabled style on the component */\n disabled?: boolean;\n}\n\nexport interface TypeSegmentedControlProps extends TypeContainerProps {\n /** The value of the currently selected item. Should match the value prop of one of the child items */\n selectedValue: string;\n\n /** The title of the segmented control, used for accessibility purposes */\n label: string;\n\n /** Called when the user selects a new item. You can access the value of the newly selected item using \"event.target.value\" */\n onChange?: (e: React.SyntheticEvent<HTMLInputElement>) => void;\n\n /** Called when the user selects a new item. You can access the value of the newly selected item using \"event.target.value\" */\n onValueChange?: (value: string) => void;\n\n /** Disables user action and applies a disabled style on the component */\n disabled?: boolean;\n children: React.ReactNode;\n}\n","import SegmentedControl from \"./SegmentedControl\";\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport * from \"./SegmentedControlTypes\";\n"],"mappings":";AAAA,YAAYA,YAAW;;;ACQvB,YAAYC,YAAW;AACvB,YAAYC,kBAAiB;AAC7B,SAAS,sBAAsB;;;ACV/B,OAAO,UAAU,WAAW;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,SAAS;AAChB,OAAO,YAAY;AAMZ,IAAM,4BAA4B,OAAO,GAAG;AAAA;AAAA,MAI7C,CAAC,UAAU,MAAM,MAAM,OAAO,OAAO,UAAU,OAAO,IAAI;AAAA,mBAC7C,CAAC,UAAU,MAAM,MAAM,MAAM,KAAK;AAAA,aACxC,CAAC,UAAU,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA,IAG1C,CAAC,UAAU,MAAM,YAAY,QAAQ;AAAA;AAGlC,IAAM,eAAe,OAAO,MAAM;AAAA;AAAA,kBAEvB,CAAC,UAAU,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAShC,CAAC,UAAU,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA,wBAI5B,C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,QACC,WAAU;AAAA,QACV,MAAK;AAAA,QACL,OAAO;AAAA,QACP,cAAY;AAAA,QACZ,UAAUC;AAAA,QACV,eAAe,oBAAoB,UAAU,aAAa;AAAA,QAC1D,SAAO;AAAA,QAEP,0BAAAD;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,4BAA0B;AAAA,YAC1B,kCAAgC;AAAA,YAChC,UAAUC;AAAA,YACT,GAAG;AAAA,YAEH;AAAA;AAAA,QACH;AAAA;AAAA,IACF,GACF;AAAA,EAEJ;AAGA,SAAO,gBAAAD,KAAC,4BAA0B,GAAG,OAAO,KAAU;AACxD,CAAC;AAED,uBAAuB,cAAc;AACrC,uBAAuB,OAAO;AAE9B,IAAO,iCAAQ;;;ADzDb,gBAAAE,YAAA;AAJF,IAAM,mBAAyB,kBAG7B,CAAC,OAAO,QACR,gBAAAA,KAAC,kCAAwB,GAAG,OAAO,KAAU,CAC9C;AAED,iBAAiB,cAAc;AAC/B,iBAAiB,OAAO;AAExB,IAAO,2BAAQ;;;AI5Bf,OAAuB;;;ACCvB,IAAO,gBAAQ;","names":["React","React","ToggleGroup","props","disabled","jsx","disabled","jsx"]}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { TypeContainerProps } from '@sproutsocial/seeds-react-box';
3
1
  import * as React from 'react';
2
+ import { TypeContainerProps } from '@sproutsocial/seeds-react-box';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  interface TypeSegmentedControlItemProps {
6
6
  /** The value of this item. Should be unique among sibling items. */
@@ -23,12 +23,34 @@ interface TypeSegmentedControlProps extends TypeContainerProps {
23
23
  children: React.ReactNode;
24
24
  }
25
25
 
26
- declare const SegmentedControl: {
27
- ({ selectedValue, label, onChange, onValueChange, children, disabled, ...rest }: TypeSegmentedControlProps): react_jsx_runtime.JSX.Element;
28
- Item: {
29
- ({ value, children, disabled, ...rest }: TypeSegmentedControlItemProps): react_jsx_runtime.JSX.Element;
30
- displayName: string;
31
- };
26
+ /**
27
+ * Compound item routed to match the surrounding container's path.
28
+ *
29
+ * On the styled-components path it renders the legacy styled `ToggleButton`
30
+ * (styled at runtime by styled-components, with no dependency on the component
31
+ * CSS file) — this preserves backward compatibility for consumers routed to
32
+ * the styled branch via a Box system prop or a `styled(SegmentedControl)`
33
+ * extension. On the Tailwind path it renders the pure CSS-class button. The
34
+ * host element is typed as `any` so Radix's `asChild`-injected props
35
+ * (data-state, role, keyboard handlers, onClick) and any forwarded props
36
+ * spread cleanly — mirrors ButtonTailwind's `Component as any` pattern.
37
+ */
38
+ declare const SegmentedControlItem: {
39
+ ({ value, children, disabled, ...rest }: TypeSegmentedControlItemProps): react_jsx_runtime.JSX.Element;
40
+ displayName: string;
41
+ };
42
+
43
+ type TypeSegmentedControlComponent = React.ForwardRefExoticComponent<TypeSegmentedControlProps & React.RefAttributes<HTMLDivElement>> & {
44
+ Item: typeof SegmentedControlItem;
32
45
  };
46
+ /**
47
+ * SegmentedControl routes between the Tailwind/CSS-class implementation
48
+ * (preferred) and the legacy styled-components implementation via the hybrid
49
+ * component. This entry file keeps a real component definition (mirroring
50
+ * Button.tsx) so react-docgen's `generate:props-docs` step can discover it and
51
+ * emit prop docs from TypeSegmentedControlProps. styles.ts is left untouched
52
+ * for the styled path.
53
+ */
54
+ declare const SegmentedControl: TypeSegmentedControlComponent;
33
55
 
34
56
  export { SegmentedControl, type TypeSegmentedControlItemProps, type TypeSegmentedControlProps, SegmentedControl as default };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { TypeContainerProps } from '@sproutsocial/seeds-react-box';
3
1
  import * as React from 'react';
2
+ import { TypeContainerProps } from '@sproutsocial/seeds-react-box';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  interface TypeSegmentedControlItemProps {
6
6
  /** The value of this item. Should be unique among sibling items. */
@@ -23,12 +23,34 @@ interface TypeSegmentedControlProps extends TypeContainerProps {
23
23
  children: React.ReactNode;
24
24
  }
25
25
 
26
- declare const SegmentedControl: {
27
- ({ selectedValue, label, onChange, onValueChange, children, disabled, ...rest }: TypeSegmentedControlProps): react_jsx_runtime.JSX.Element;
28
- Item: {
29
- ({ value, children, disabled, ...rest }: TypeSegmentedControlItemProps): react_jsx_runtime.JSX.Element;
30
- displayName: string;
31
- };
26
+ /**
27
+ * Compound item routed to match the surrounding container's path.
28
+ *
29
+ * On the styled-components path it renders the legacy styled `ToggleButton`
30
+ * (styled at runtime by styled-components, with no dependency on the component
31
+ * CSS file) — this preserves backward compatibility for consumers routed to
32
+ * the styled branch via a Box system prop or a `styled(SegmentedControl)`
33
+ * extension. On the Tailwind path it renders the pure CSS-class button. The
34
+ * host element is typed as `any` so Radix's `asChild`-injected props
35
+ * (data-state, role, keyboard handlers, onClick) and any forwarded props
36
+ * spread cleanly — mirrors ButtonTailwind's `Component as any` pattern.
37
+ */
38
+ declare const SegmentedControlItem: {
39
+ ({ value, children, disabled, ...rest }: TypeSegmentedControlItemProps): react_jsx_runtime.JSX.Element;
40
+ displayName: string;
41
+ };
42
+
43
+ type TypeSegmentedControlComponent = React.ForwardRefExoticComponent<TypeSegmentedControlProps & React.RefAttributes<HTMLDivElement>> & {
44
+ Item: typeof SegmentedControlItem;
32
45
  };
46
+ /**
47
+ * SegmentedControl routes between the Tailwind/CSS-class implementation
48
+ * (preferred) and the legacy styled-components implementation via the hybrid
49
+ * component. This entry file keeps a real component definition (mirroring
50
+ * Button.tsx) so react-docgen's `generate:props-docs` step can discover it and
51
+ * emit prop docs from TypeSegmentedControlProps. styles.ts is left untouched
52
+ * for the styled path.
53
+ */
54
+ declare const SegmentedControl: TypeSegmentedControlComponent;
33
55
 
34
56
  export { SegmentedControl, type TypeSegmentedControlItemProps, type TypeSegmentedControlProps, SegmentedControl as default };
package/dist/index.js CHANGED
@@ -36,9 +36,12 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/SegmentedControl.tsx
39
- var React = __toESM(require("react"));
40
- var import_react = require("react");
41
- var ToggleGroup = __toESM(require("@radix-ui/react-toggle-group"));
39
+ var React3 = __toESM(require("react"));
40
+
41
+ // src/SegmentedControlHybrid.tsx
42
+ var React2 = __toESM(require("react"));
43
+ var ToggleGroup2 = __toESM(require("@radix-ui/react-toggle-group"));
44
+ var import_seeds_react_system_props = require("@sproutsocial/seeds-react-system-props");
42
45
 
43
46
  // src/styles.ts
44
47
  var import_styled_components = __toESM(require("styled-components"));
@@ -135,76 +138,168 @@ var SegmentedControlLabel = (0, import_styled_components.default)(import_seeds_r
135
138
  `}
136
139
  `;
137
140
 
138
- // src/SegmentedControl.tsx
141
+ // src/SegmentedControlTailwind.tsx
142
+ var React = __toESM(require("react"));
143
+ var ToggleGroup = __toESM(require("@radix-ui/react-toggle-group"));
139
144
  var import_jsx_runtime = require("react/jsx-runtime");
140
- var nameCounter = 0;
141
- var SegmentedControlContext = React.createContext(null);
145
+ var SegmentedControlVariantContext = React.createContext("tailwind");
146
+ function cn(...inputs) {
147
+ const classes = [];
148
+ for (const input of inputs) {
149
+ if (!input) continue;
150
+ if (typeof input === "string") {
151
+ classes.push(input);
152
+ } else if (typeof input === "object") {
153
+ for (const [key, value] of Object.entries(input)) {
154
+ if (value) {
155
+ classes.push(key);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ return classes.join(" ");
161
+ }
162
+ function createChangeHandler(onChange, onValueChange) {
163
+ return (e) => {
164
+ if (!e) return;
165
+ onValueChange?.(e);
166
+ const mockEvent = new Event("change", {
167
+ bubbles: true
168
+ });
169
+ Object.defineProperty(mockEvent, "target", { value: { value: e } });
170
+ Object.defineProperty(mockEvent, "currentTarget", {
171
+ value: { value: e }
172
+ });
173
+ onChange?.(mockEvent);
174
+ };
175
+ }
142
176
  var SegmentedControlItem = ({
143
177
  value,
144
178
  children,
145
179
  disabled: disabled2,
146
180
  ...rest
147
181
  }) => {
182
+ const variant = React.useContext(SegmentedControlVariantContext);
183
+ if (variant === "styled") {
184
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroup.Item, { value, disabled: disabled2, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
185
+ ToggleButton,
186
+ {
187
+ "data-qa-segmentedcontrol-item": value,
188
+ disabled: disabled2,
189
+ ...rest,
190
+ children
191
+ }
192
+ ) });
193
+ }
194
+ const Toggle = "button";
148
195
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroup.Item, { value, disabled: disabled2, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
149
- ToggleButton,
196
+ Toggle,
150
197
  {
198
+ type: "button",
151
199
  "data-qa-segmentedcontrol-item": value,
152
200
  disabled: disabled2,
153
201
  ...rest,
202
+ className: "seeds-segmented-control-item",
154
203
  children
155
204
  }
156
205
  ) });
157
206
  };
158
- var SegmentedControl = ({
159
- selectedValue,
160
- label,
161
- onChange,
162
- onValueChange,
163
- children,
164
- disabled: disabled2,
165
- ...rest
166
- }) => {
167
- const [name] = (0, import_react.useState)(`Racine-segmented-control-${nameCounter++}`);
168
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
169
- ToggleGroup.Root,
170
- {
171
- className: "inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4",
172
- type: "single",
173
- value: selectedValue,
174
- "aria-label": label,
175
- disabled: disabled2,
176
- onValueChange: (e) => {
177
- if (!e) return;
178
- onValueChange?.(e);
179
- const mockEvent = new Event("change", {
180
- bubbles: true
181
- });
182
- Object.defineProperty(mockEvent, "target", { value: { value: e } });
183
- Object.defineProperty(mockEvent, "currentTarget", {
184
- value: { value: e }
185
- });
186
- onChange?.(mockEvent);
187
- },
188
- asChild: true,
189
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
190
- SegmentedControlContainer,
191
- {
192
- "data-qa-segmentedcontrol": label,
193
- "data-qa-segmentedcontrol-value": selectedValue,
194
- disabled: disabled2,
195
- ...rest,
196
- children
197
- }
198
- )
199
- }
200
- );
201
- };
202
207
  SegmentedControlItem.displayName = "SegmentedControl.Item";
208
+ var SegmentedControlTailwind = React.forwardRef(
209
+ ({
210
+ selectedValue,
211
+ label,
212
+ onChange,
213
+ onValueChange,
214
+ children,
215
+ disabled: disabled2 = false,
216
+ className,
217
+ ...rest
218
+ }, ref) => {
219
+ const Container = "div";
220
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
221
+ ToggleGroup.Root,
222
+ {
223
+ className: "inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4",
224
+ type: "single",
225
+ value: selectedValue,
226
+ "aria-label": label,
227
+ disabled: disabled2,
228
+ onValueChange: createChangeHandler(onChange, onValueChange),
229
+ asChild: true,
230
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
231
+ Container,
232
+ {
233
+ ref,
234
+ "data-qa-segmentedcontrol": label,
235
+ "data-qa-segmentedcontrol-value": selectedValue,
236
+ ...rest,
237
+ className: cn(
238
+ "seeds-segmented-control",
239
+ { "seeds-segmented-control-disabled": disabled2 },
240
+ className
241
+ ),
242
+ children
243
+ }
244
+ )
245
+ }
246
+ );
247
+ }
248
+ );
249
+ SegmentedControlTailwind.displayName = "SegmentedControlTailwind";
250
+
251
+ // src/SegmentedControlHybrid.tsx
252
+ var import_jsx_runtime2 = require("react/jsx-runtime");
253
+ var SegmentedControlHybrid = React2.forwardRef((props, ref) => {
254
+ const {
255
+ selectedValue,
256
+ label,
257
+ onChange,
258
+ onValueChange,
259
+ children,
260
+ disabled: disabled2,
261
+ ...rest
262
+ } = props;
263
+ if ((0, import_seeds_react_system_props.hasStyledProps)(rest)) {
264
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SegmentedControlVariantContext.Provider, { value: "styled", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
265
+ ToggleGroup2.Root,
266
+ {
267
+ className: "inline-flex space-x-px rounded bg-mauve6 shadow-[0_2px_10px] shadow-blackA4",
268
+ type: "single",
269
+ value: selectedValue,
270
+ "aria-label": label,
271
+ disabled: disabled2,
272
+ onValueChange: createChangeHandler(onChange, onValueChange),
273
+ asChild: true,
274
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
275
+ SegmentedControlContainer,
276
+ {
277
+ ref,
278
+ "data-qa-segmentedcontrol": label,
279
+ "data-qa-segmentedcontrol-value": selectedValue,
280
+ disabled: disabled2,
281
+ ...rest,
282
+ children
283
+ }
284
+ )
285
+ }
286
+ ) });
287
+ }
288
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SegmentedControlTailwind, { ...props, ref });
289
+ });
290
+ SegmentedControlHybrid.displayName = "SegmentedControl";
291
+ SegmentedControlHybrid.Item = SegmentedControlItem;
292
+ var SegmentedControlHybrid_default = SegmentedControlHybrid;
293
+
294
+ // src/SegmentedControl.tsx
295
+ var import_jsx_runtime3 = require("react/jsx-runtime");
296
+ var SegmentedControl = React3.forwardRef((props, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SegmentedControlHybrid_default, { ...props, ref }));
297
+ SegmentedControl.displayName = "SegmentedControl";
203
298
  SegmentedControl.Item = SegmentedControlItem;
204
299
  var SegmentedControl_default = SegmentedControl;
205
300
 
206
301
  // src/SegmentedControlTypes.ts
207
- var React2 = require("react");
302
+ var React4 = require("react");
208
303
 
209
304
  // src/index.ts
210
305
  var index_default = SegmentedControl_default;