@gridui/choice 1.1.1 → 1.2.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @gridui/choice
2
2
 
3
- Core family. Public API: `Checkbox`, `CheckboxProps`, `Switch`, `SwitchProps`, `ToggleGroup`, `ToggleGroupItem`, `ToggleGroupItemProps`, `ToggleGroupProps`.
3
+ Core family. Public components: `Checkbox`, `Switch`, `SwitchGroup`, `SwitchPanel`, `ToggleGroup`, and `ToggleGroupItem`. Each exports its named Props contract. Switch presentation types and `SwitchGroupItem` describe their supported configuration.
4
4
 
5
5
  Import components from `@gridui/choice` and load `@gridui/choice/styles.css` after Theme.
6
6
  Load styles for any composed dependency used by this family. Applications own routes, labels, state persistence, and branding.
@@ -31,3 +31,10 @@ reports an empty array or one value, matching the rendered selection. Disabled
31
31
  items, keyboard roving, and native non-submitting button behavior are preserved.
32
32
  Use Tabs when choices switch content panels, and RadioGroup when a form needs one
33
33
  radio value.
34
+
35
+ ## Switch family
36
+
37
+ Use [Switch, SwitchGroup and SwitchPanel](docs/switches.md) for independent
38
+ boolean settings. All three support the `rail` and `state` variants and share
39
+ native form, reset, cancellation and accessibility behavior. They do not share
40
+ a selected value or implement radio-style keyboard navigation.
package/dist/index.d.ts CHANGED
@@ -6,8 +6,13 @@
6
6
  */
7
7
  export type { CheckboxProps } from "./checkbox/checkbox";
8
8
  export { Checkbox } from "./checkbox/checkbox";
9
+ export type { SwitchStateLabels, SwitchVariant } from "./shared/switch-presentation";
9
10
  export type { SwitchProps } from "./switch/switch";
10
11
  export { Switch } from "./switch/switch";
12
+ export type { SwitchGroupItem, SwitchGroupProps } from "./switch-group/switch-group";
13
+ export { SwitchGroup } from "./switch-group/switch-group";
14
+ export type { SwitchPanelProps } from "./switch-panel/switch-panel";
15
+ export { SwitchPanel } from "./switch-panel/switch-panel";
11
16
  export type { ToggleGroupProps } from "./toggle-group/toggle-group";
12
17
  export { ToggleGroup } from "./toggle-group/toggle-group";
13
18
  export type { ToggleGroupItemProps } from "./toggle-group-item/toggle-group-item";
package/dist/index.js CHANGED
@@ -147,16 +147,12 @@ var Checkbox = (props) => {
147
147
  ] });
148
148
  };
149
149
 
150
- // src/switch/style.ts
151
- import { cva as cva2 } from "class-variance-authority";
152
- var switchStyles = cva2("gridui-switch gridui-u-inline-flex gridui-u-h-6 gridui-u-w-11 gridui-u-shrink-0 gridui-u-cursor-pointer gridui-u-items-center gridui-u-rounded-control gridui-u-border gridui-u-border-control-border gridui-u-bg-surface gridui-u-p-0.5 gridui-u-align-middle gridui-u-data-[state=checked]:bg-accent-background gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50 gridui-u-data-readonly:cursor-default gridui-u-aria-invalid:border-danger-foreground");
153
-
154
- // src/switch/switch.tsx
150
+ // src/shared/switch-control.tsx
155
151
  import { cn as cn2 } from "@gridui/style-utils";
156
- import * as Primitive2 from "@radix-ui/react-switch";
157
152
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
158
- var Switch = (props) => {
153
+ var SwitchControl = (props) => {
159
154
  const {
155
+ children,
160
156
  className,
161
157
  inputRef,
162
158
  onCheckedChange,
@@ -169,6 +165,7 @@ var Switch = (props) => {
169
165
  form,
170
166
  required,
171
167
  onClick,
168
+ type = "button",
172
169
  ...restProps
173
170
  } = props;
174
171
  const { current, input, control, change, invalid } = useChoice({
@@ -180,11 +177,15 @@ var Switch = (props) => {
180
177
  });
181
178
  return /* @__PURE__ */ jsxs2(Fragment2, { children: [
182
179
  /* @__PURE__ */ jsx2(
183
- Primitive2.Root,
180
+ "button",
184
181
  {
185
182
  ...restProps,
186
183
  ref: control,
187
- checked: current,
184
+ type,
185
+ role: "switch",
186
+ "aria-checked": current,
187
+ "data-state": current ? "checked" : "unchecked",
188
+ "data-disabled": props.disabled ? "" : void 0,
188
189
  "aria-required": required,
189
190
  "aria-readonly": readOnly,
190
191
  "data-readonly": readOnly ? "" : void 0,
@@ -195,13 +196,8 @@ var Switch = (props) => {
195
196
  }
196
197
  event.preventDefault();
197
198
  },
198
- className: cn2(switchStyles(), className),
199
- children: /* @__PURE__ */ jsx2(
200
- Primitive2.Thumb,
201
- {
202
- className: "gridui-switch-thumb"
203
- }
204
- )
199
+ className: cn2("gridui-switch-control", className),
200
+ children: children(current)
205
201
  }
206
202
  ),
207
203
  /* @__PURE__ */ jsx2(
@@ -238,6 +234,221 @@ var Switch = (props) => {
238
234
  ] });
239
235
  };
240
236
 
237
+ // src/shared/switch-indicator.tsx
238
+ import { Check as Check2, Minus as Minus2 } from "lucide-react";
239
+ import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
240
+ var SwitchIndicator = (props) => {
241
+ const { checked, variant = "rail", stateLabels = {
242
+ checked: "On",
243
+ unchecked: "Off"
244
+ } } = props;
245
+ return /* @__PURE__ */ jsx3(
246
+ "span",
247
+ {
248
+ className: "gridui-switch-indicator gridui-u-type-caption",
249
+ "data-variant": variant,
250
+ "data-state": checked ? "checked" : "unchecked",
251
+ "aria-hidden": "true",
252
+ children: variant === "rail" ? /* @__PURE__ */ jsx3(
253
+ "span",
254
+ {
255
+ className: "gridui-switch-thumb"
256
+ }
257
+ ) : /* @__PURE__ */ jsxs3(Fragment3, { children: [
258
+ checked ? /* @__PURE__ */ jsx3(
259
+ Check2,
260
+ {
261
+ className: "gridui-switch-state-icon"
262
+ }
263
+ ) : /* @__PURE__ */ jsx3(
264
+ Minus2,
265
+ {
266
+ className: "gridui-switch-state-icon"
267
+ }
268
+ ),
269
+ /* @__PURE__ */ jsx3(
270
+ "span",
271
+ {
272
+ className: "gridui-switch-state-label",
273
+ children: checked ? stateLabels.checked : stateLabels.unchecked
274
+ }
275
+ )
276
+ ] })
277
+ }
278
+ );
279
+ };
280
+
281
+ // src/switch/style.ts
282
+ import { cva as cva2 } from "class-variance-authority";
283
+ var switchStyles = cva2("gridui-switch gridui-u-inline-flex gridui-u-w-fit gridui-u-max-w-full gridui-u-min-h-gridui-control gridui-u-min-w-gridui-control gridui-u-shrink-0 gridui-u-items-center gridui-u-justify-center gridui-u-border-0 gridui-u-bg-transparent gridui-u-p-0 gridui-u-align-middle gridui-u-rounded-control");
284
+
285
+ // src/switch/switch.tsx
286
+ import { cn as cn3 } from "@gridui/style-utils";
287
+ import { jsx as jsx4 } from "react/jsx-runtime";
288
+ var Switch = (props) => {
289
+ const { variant, stateLabels, className, ...restProps } = props;
290
+ return /* @__PURE__ */ jsx4(
291
+ SwitchControl,
292
+ {
293
+ ...restProps,
294
+ className: cn3(switchStyles(), className),
295
+ children: (checked) => {
296
+ return /* @__PURE__ */ jsx4(
297
+ SwitchIndicator,
298
+ {
299
+ checked,
300
+ variant,
301
+ stateLabels
302
+ }
303
+ );
304
+ }
305
+ }
306
+ );
307
+ };
308
+
309
+ // src/shared/switch-setting.tsx
310
+ import { cn as cn4 } from "@gridui/style-utils";
311
+ import { useId } from "react";
312
+ import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
313
+ var SwitchSetting = (props) => {
314
+ const { control, label, description } = props;
315
+ const { variant, stateLabels, className, ...controlProps } = control;
316
+ const id = useId();
317
+ const labelId = `${id}-label`;
318
+ const descriptionId = `${id}-description`;
319
+ const hasDescription = description !== void 0 && description !== null;
320
+ const describedBy = [
321
+ controlProps["aria-describedby"],
322
+ hasDescription ? descriptionId : void 0
323
+ ].filter(Boolean).join(" ") || void 0;
324
+ return /* @__PURE__ */ jsx5(
325
+ SwitchControl,
326
+ {
327
+ ...controlProps,
328
+ className: cn4("gridui-switch-setting gridui-focus-contained", className),
329
+ "aria-labelledby": controlProps["aria-labelledby"] ?? (controlProps["aria-label"] ? void 0 : labelId),
330
+ "aria-describedby": describedBy,
331
+ children: (checked) => {
332
+ return /* @__PURE__ */ jsxs4(Fragment4, { children: [
333
+ /* @__PURE__ */ jsxs4(
334
+ "span",
335
+ {
336
+ className: "gridui-switch-setting-copy",
337
+ children: [
338
+ /* @__PURE__ */ jsx5(
339
+ "span",
340
+ {
341
+ id: labelId,
342
+ className: "gridui-u-type-ui",
343
+ children: label
344
+ }
345
+ ),
346
+ hasDescription && /* @__PURE__ */ jsx5(
347
+ "span",
348
+ {
349
+ id: descriptionId,
350
+ className: "gridui-switch-setting-description gridui-u-type-supporting",
351
+ children: description
352
+ }
353
+ )
354
+ ]
355
+ }
356
+ ),
357
+ /* @__PURE__ */ jsx5(
358
+ "span",
359
+ {
360
+ className: "gridui-switch-setting-end",
361
+ children: /* @__PURE__ */ jsx5(
362
+ SwitchIndicator,
363
+ {
364
+ checked,
365
+ variant,
366
+ stateLabels
367
+ }
368
+ )
369
+ }
370
+ )
371
+ ] });
372
+ }
373
+ }
374
+ );
375
+ };
376
+
377
+ // src/switch-group/switch-group.tsx
378
+ import { cn as cn5 } from "@gridui/style-utils";
379
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
380
+ var SwitchGroup = (props) => {
381
+ const { items, legend, density = "compact", variant, stateLabels, className, ...restProps } = props;
382
+ return /* @__PURE__ */ jsxs5(
383
+ "fieldset",
384
+ {
385
+ ...restProps,
386
+ className: cn5("gridui-switch-group", className),
387
+ "data-density": density,
388
+ children: [
389
+ legend !== void 0 && legend !== null && /* @__PURE__ */ jsx6(
390
+ "legend",
391
+ {
392
+ className: "gridui-switch-group-legend gridui-u-type-ui",
393
+ children: legend
394
+ }
395
+ ),
396
+ items.map((item) => {
397
+ const { label, description, ...control } = item;
398
+ return /* @__PURE__ */ jsx6(
399
+ SwitchSetting,
400
+ {
401
+ label,
402
+ description,
403
+ control: {
404
+ ...control,
405
+ variant: item.variant ?? variant,
406
+ stateLabels: item.stateLabels ?? stateLabels
407
+ }
408
+ },
409
+ item.id
410
+ );
411
+ })
412
+ ]
413
+ }
414
+ );
415
+ };
416
+
417
+ // src/switch-panel/switch-panel.tsx
418
+ import { cn as cn6 } from "@gridui/style-utils";
419
+ import { Children } from "react";
420
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
421
+ var SwitchPanel = (props) => {
422
+ const { label, description, control, children, className, ...restProps } = props;
423
+ const hasContent = Children.toArray(children).some((child) => {
424
+ return child !== "";
425
+ });
426
+ return /* @__PURE__ */ jsxs6(
427
+ "div",
428
+ {
429
+ ...restProps,
430
+ className: cn6("gridui-switch-panel", className),
431
+ children: [
432
+ /* @__PURE__ */ jsx7(
433
+ SwitchSetting,
434
+ {
435
+ label,
436
+ description,
437
+ control
438
+ }
439
+ ),
440
+ hasContent && /* @__PURE__ */ jsx7(
441
+ "div",
442
+ {
443
+ className: "gridui-switch-panel-content",
444
+ children
445
+ }
446
+ )
447
+ ]
448
+ }
449
+ );
450
+ };
451
+
241
452
  // src/shared/context.ts
242
453
  import { createContext } from "react";
243
454
  var ToggleGroupContext = createContext("standard");
@@ -255,10 +466,10 @@ var toggleGroupStyles = cva3("gridui-toggle-group gridui-u-inline-flex gridui-u-
255
466
  });
256
467
 
257
468
  // src/toggle-group/toggle-group.tsx
258
- import { cn as cn3 } from "@gridui/style-utils";
259
- import * as Primitive3 from "@radix-ui/react-toggle-group";
469
+ import { cn as cn7 } from "@gridui/style-utils";
470
+ import * as Primitive2 from "@radix-ui/react-toggle-group";
260
471
  import { useState as useState2 } from "react";
261
- import { jsx as jsx3 } from "react/jsx-runtime";
472
+ import { jsx as jsx8 } from "react/jsx-runtime";
262
473
  var ToggleGroup = (props) => {
263
474
  const { className, multiple, value, defaultValue, onValueChange, loopFocus = true, layout = "standard", ...restProps } = props;
264
475
  const [
@@ -266,16 +477,16 @@ var ToggleGroup = (props) => {
266
477
  setLocal
267
478
  ] = useState2(defaultValue ?? []);
268
479
  const current = value ?? local;
269
- return /* @__PURE__ */ jsx3(
480
+ return /* @__PURE__ */ jsx8(
270
481
  ToggleGroupContext.Provider,
271
482
  {
272
483
  value: layout,
273
- children: /* @__PURE__ */ jsx3(
274
- Primitive3.Root,
484
+ children: /* @__PURE__ */ jsx8(
485
+ Primitive2.Root,
275
486
  {
276
487
  ...restProps,
277
488
  loop: loopFocus,
278
- className: cn3(toggleGroupStyles({ layout }), className),
489
+ className: cn7(toggleGroupStyles({ layout }), className),
279
490
  "data-layout": layout,
280
491
  type: "multiple",
281
492
  value: multiple ? current : current.slice(-1),
@@ -294,7 +505,7 @@ var ToggleGroup = (props) => {
294
505
 
295
506
  // src/toggle-group-item/style.ts
296
507
  import { cva as cva4 } from "class-variance-authority";
297
- var toggleStyles = cva4("gridui-focus-contained gridui-u-min-h-11 gridui-u-cursor-pointer gridui-u-border-0 gridui-u-bg-background gridui-u-px-gridui-16 gridui-u-py-gridui-8 gridui-u-text-foreground gridui-u-type-ui gridui-u-data-[state=on]:bg-brand-tint gridui-u-data-[state=on]:text-foreground gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50", {
508
+ var toggleStyles = cva4("gridui-focus-contained gridui-u-min-h-gridui-control gridui-u-cursor-pointer gridui-u-border-0 gridui-u-bg-background gridui-u-px-gridui-16 gridui-u-py-gridui-8 gridui-u-text-foreground gridui-u-type-ui gridui-u-data-[state=on]:bg-brand-tint gridui-u-data-[state=on]:text-foreground gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50", {
298
509
  variants: {
299
510
  layout: {
300
511
  standard: "",
@@ -307,24 +518,26 @@ var toggleStyles = cva4("gridui-focus-contained gridui-u-min-h-11 gridui-u-curso
307
518
  });
308
519
 
309
520
  // src/toggle-group-item/toggle-group-item.tsx
310
- import { cn as cn4 } from "@gridui/style-utils";
311
- import * as Primitive4 from "@radix-ui/react-toggle-group";
521
+ import { cn as cn8 } from "@gridui/style-utils";
522
+ import * as Primitive3 from "@radix-ui/react-toggle-group";
312
523
  import { useContext } from "react";
313
- import { jsx as jsx4 } from "react/jsx-runtime";
524
+ import { jsx as jsx9 } from "react/jsx-runtime";
314
525
  var ToggleGroupItem = (props) => {
315
526
  const { className, ...restProps } = props;
316
527
  const layout = useContext(ToggleGroupContext);
317
- return /* @__PURE__ */ jsx4(
318
- Primitive4.Item,
528
+ return /* @__PURE__ */ jsx9(
529
+ Primitive3.Item,
319
530
  {
320
531
  ...restProps,
321
- className: cn4(toggleStyles({ layout }), className)
532
+ className: cn8(toggleStyles({ layout }), className)
322
533
  }
323
534
  );
324
535
  };
325
536
  export {
326
537
  Checkbox,
327
538
  Switch,
539
+ SwitchGroup,
540
+ SwitchPanel,
328
541
  ToggleGroup,
329
542
  ToggleGroupItem
330
543
  };
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/shared/use-choice.ts", "../src/checkbox/style.ts", "../src/checkbox/checkbox.tsx", "../src/switch/style.ts", "../src/switch/switch.tsx", "../src/shared/context.ts", "../src/toggle-group/style.ts", "../src/toggle-group/toggle-group.tsx", "../src/toggle-group-item/style.ts", "../src/toggle-group-item/toggle-group-item.tsx"],
4
- "sourcesContent": ["/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Use Choice\n */\n\nimport { focusInvalidControl, useFormReset } from \"@gridui/form\";\nimport { type ChangeDetails, changeDetails } from \"@gridui/interaction\";\nimport { type ComponentPropsWithRef, type Ref, type SyntheticEvent, useImperativeHandle, useRef, useState } from \"react\";\n\nexport type ChoiceProps = Omit<ComponentPropsWithRef<\"button\">, \"children\" | \"onChange\" | \"defaultChecked\"> & {\n readonly checked?: boolean | undefined;\n readonly defaultChecked?: boolean | undefined;\n readonly readOnly?: boolean | undefined;\n readonly required?: boolean | undefined;\n readonly uncheckedValue?: string | undefined;\n readonly inputRef?: Ref<HTMLInputElement> | undefined;\n readonly onCheckedChange?: ((checked: boolean, details: ChangeDetails) => void) | undefined;\n};\n\nexport const useChoice = (props: ChoiceProps) => {\n const { checked, defaultChecked = false, onCheckedChange, readOnly, disabled, inputRef, form } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultChecked);\n const input = useRef<HTMLInputElement>(null);\n const control = useRef<HTMLButtonElement>(null);\n const initial = useRef(defaultChecked);\n useImperativeHandle(props.ref, () => {\n return control.current as HTMLButtonElement;\n });\n useImperativeHandle(inputRef, () => {\n return input.current as HTMLInputElement;\n });\n useFormReset(input, () => {\n if (checked === undefined) {\n setLocal(initial.current);\n }\n }, form);\n const current = checked ?? local;\n const invalid = (event: SyntheticEvent<HTMLInputElement>) => {\n focusInvalidControl(event, () => {\n control.current?.focus();\n });\n };\n const change = (next: boolean, event: Event) => {\n if (readOnly || disabled || input.current?.matches(\":disabled\")) {\n return;\n }\n const details = changeDetails(event);\n onCheckedChange?.(next, details);\n if (!details.isCanceled && checked === undefined) {\n setLocal(next);\n }\n };\n return {\n current,\n input,\n control,\n change,\n invalid,\n };\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Checkbox\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const choiceStyles = cva(\"gridui-u-inline-flex gridui-u-size-5 gridui-u-shrink-0 gridui-u-cursor-pointer gridui-u-items-center gridui-u-justify-center gridui-u-rounded-control gridui-u-border gridui-u-border-control-border gridui-u-bg-background gridui-u-text-foreground gridui-u-align-middle gridui-u-data-[state=checked]:bg-accent-background gridui-u-data-[state=checked]:text-accent-foreground gridui-u-data-[state=indeterminate]:bg-accent-background gridui-u-data-[state=indeterminate]:text-accent-foreground gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50 gridui-u-data-readonly:cursor-default gridui-u-aria-invalid:border-danger-foreground\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Checkbox\n * @description Checkbox\n */\n\nimport { type ChoiceProps, useChoice } from \"../shared/use-choice\";\nimport { choiceStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-checkbox\";\nimport { Check, Minus } from \"lucide-react\";\nimport type { FC } from \"react\";\n\nexport type CheckboxProps = ChoiceProps & {\n readonly indeterminate?: boolean | undefined;\n};\n\nexport const Checkbox: FC<CheckboxProps> = (props: CheckboxProps) => {\n const { className, indeterminate, inputRef, onCheckedChange, checked, defaultChecked,\n readOnly, uncheckedValue, name, value = \"on\", form, required, onClick, ...restProps } = props;\n const { current, input, control, change, invalid } = useChoice({\n ...props,\n inputRef,\n onCheckedChange,\n checked,\n defaultChecked,\n });\n return (<>\n <Primitive.Root\n {...restProps}\n ref={control}\n checked={indeterminate ? \"indeterminate\" : current}\n aria-required={required}\n aria-readonly={readOnly}\n data-readonly={readOnly ? \"\" : undefined}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n change(indeterminate ? true : !current, event.nativeEvent);\n }\n event.preventDefault();\n }}\n className={cn(choiceStyles(), className)}\n >\n <Primitive.Indicator>\n {indeterminate ? (<Minus\n size={16}\n aria-hidden=\"true\"\n />) : (<Check\n size={16}\n aria-hidden=\"true\"\n />)}\n </Primitive.Indicator>\n </Primitive.Root>\n <input\n ref={input}\n type=\"checkbox\"\n className=\"gridui-u-sr-only\"\n tabIndex={-1}\n aria-hidden=\"true\"\n name={name}\n value={value}\n form={form}\n required={required}\n disabled={props.disabled}\n checked={current}\n readOnly={readOnly}\n onInvalid={invalid}\n onChange={(event) => {\n change(event.target.checked, event.nativeEvent);\n }}\n />\n {!current && uncheckedValue !== undefined && (<input\n type=\"hidden\"\n name={name}\n form={form}\n value={uncheckedValue}\n disabled={props.disabled}\n />)}\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Switch\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const switchStyles = cva(\"gridui-switch gridui-u-inline-flex gridui-u-h-6 gridui-u-w-11 gridui-u-shrink-0 gridui-u-cursor-pointer gridui-u-items-center gridui-u-rounded-control gridui-u-border gridui-u-border-control-border gridui-u-bg-surface gridui-u-p-0.5 gridui-u-align-middle gridui-u-data-[state=checked]:bg-accent-background gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50 gridui-u-data-readonly:cursor-default gridui-u-aria-invalid:border-danger-foreground\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Switch\n * @description Switch\n */\n\nimport { type ChoiceProps, useChoice } from \"../shared/use-choice\";\nimport { switchStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-switch\";\nimport type { FC } from \"react\";\n\nexport type SwitchProps = ChoiceProps;\n\nexport const Switch: FC<SwitchProps> = (props: SwitchProps) => {\n const { className, inputRef, onCheckedChange, checked, defaultChecked,\n readOnly, uncheckedValue, name, value = \"on\", form, required, onClick, ...restProps } = props;\n const { current, input, control, change, invalid } = useChoice({\n ...props,\n inputRef,\n onCheckedChange,\n checked,\n defaultChecked,\n });\n return (<>\n <Primitive.Root\n {...restProps}\n ref={control}\n checked={current}\n aria-required={required}\n aria-readonly={readOnly}\n data-readonly={readOnly ? \"\" : undefined}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n change(!current, event.nativeEvent);\n }\n event.preventDefault();\n }}\n className={cn(switchStyles(), className)}\n >\n <Primitive.Thumb\n className=\"gridui-switch-thumb\"\n />\n </Primitive.Root>\n <input\n ref={input}\n type=\"checkbox\"\n className=\"gridui-u-sr-only\"\n tabIndex={-1}\n aria-hidden=\"true\"\n name={name}\n value={value}\n form={form}\n required={required}\n disabled={props.disabled}\n checked={current}\n readOnly={readOnly}\n onInvalid={invalid}\n onChange={(event) => {\n change(event.target.checked, event.nativeEvent);\n }}\n />\n {!current && uncheckedValue !== undefined && (<input\n type=\"hidden\"\n name={name}\n form={form}\n value={uncheckedValue}\n disabled={props.disabled}\n />)}\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Context\n */\n\nimport { createContext } from \"react\";\n\nexport const ToggleGroupContext = createContext<\"standard\" | \"cells\">(\"standard\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroup\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const toggleGroupStyles = cva(\"gridui-toggle-group gridui-u-inline-flex gridui-u-max-w-full gridui-u-flex-wrap gridui-u-gap-px gridui-u-border gridui-u-border-border gridui-u-bg-border gridui-u-data-[orientation=vertical]:flex-col\", {\n variants: {\n layout: {\n standard: \"\",\n cells: \"gridui-u-grid gridui-u-w-full gridui-u-grid-flow-col gridui-u-auto-cols-fr gridui-u-data-[orientation=vertical]:grid-flow-row gridui-u-data-[orientation=vertical]:auto-rows-fr gridui-u-data-[orientation=vertical]:grid-cols-1\",\n },\n },\n defaultVariants: { layout: \"standard\" },\n});\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroup\n * @description Toggle Group\n */\n\nimport { ToggleGroupContext } from \"../shared/context\";\nimport { toggleGroupStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-toggle-group\";\nimport { type ComponentPropsWithRef, type FC, useState } from \"react\";\n\nexport type ToggleGroupProps = Omit<ComponentPropsWithRef<typeof Primitive.Root>, \"type\" | \"value\" | \"defaultValue\" | \"onValueChange\" | \"loop\"> & {\n readonly multiple?: boolean | undefined;\n readonly value?: string[] | undefined;\n readonly defaultValue?: string[] | undefined;\n readonly onValueChange?: ((value: string[]) => void) | undefined;\n readonly loopFocus?: boolean | undefined;\n readonly layout?: \"standard\" | \"cells\" | undefined;\n};\n\nexport const ToggleGroup: FC<ToggleGroupProps> = (props: ToggleGroupProps) => {\n const { className, multiple, value, defaultValue, onValueChange, loopFocus = true, layout = \"standard\", ...restProps } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultValue ?? []);\n const current = value ?? local;\n return (<ToggleGroupContext.Provider\n value={layout}\n >\n <Primitive.Root\n {...restProps}\n loop={loopFocus}\n className={cn(toggleGroupStyles({ layout }), className)}\n data-layout={layout}\n type=\"multiple\"\n value={multiple ? current : current.slice(-1)}\n onValueChange={(next) => {\n const selected = multiple ? next : next.slice(-1);\n if (value === undefined) {\n setLocal(selected);\n }\n onValueChange?.(selected);\n }}\n />\n </ToggleGroupContext.Provider>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroupItem\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const toggleStyles = cva(\"gridui-focus-contained gridui-u-min-h-11 gridui-u-cursor-pointer gridui-u-border-0 gridui-u-bg-background gridui-u-px-gridui-16 gridui-u-py-gridui-8 gridui-u-text-foreground gridui-u-type-ui gridui-u-data-[state=on]:bg-brand-tint gridui-u-data-[state=on]:text-foreground gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50\", {\n variants: {\n layout: {\n standard: \"\",\n cells: \"gridui-u-w-full gridui-u-min-w-0 gridui-u-whitespace-normal gridui-u-wrap-anywhere gridui-u-border-x-0 gridui-u-border-t-0 gridui-u-border-solid gridui-u-border-transparent gridui-u-px-gridui-8 gridui-u-py-gridui-16 gridui-u-text-center gridui-u-data-[orientation=horizontal]:border-b-2 gridui-u-data-[orientation=vertical]:border-b-0 gridui-u-data-[orientation=vertical]:border-r-2 gridui-u-rtl:data-[orientation=vertical]:border-r-0 gridui-u-rtl:data-[orientation=vertical]:border-l-2 gridui-u-data-[state=on]:font-medium\",\n },\n },\n defaultVariants: {\n layout: \"standard\",\n },\n});\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroupItem\n * @description Toggle Group Item\n */\n\nimport { ToggleGroupContext } from \"../shared/context\";\nimport { toggleStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-toggle-group\";\nimport { type ComponentPropsWithRef, type FC, useContext } from \"react\";\n\nexport type ToggleGroupItemProps = ComponentPropsWithRef<typeof Primitive.Item>;\n\nexport const ToggleGroupItem: FC<ToggleGroupItemProps> = (props: ToggleGroupItemProps) => {\n const { className, ...restProps } = props;\n const layout = useContext(ToggleGroupContext);\n return (<Primitive.Item\n {...restProps}\n className={cn(toggleStyles({ layout }), className)}\n />);\n};\n"],
5
- "mappings": ";AAOA,SAAS,qB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A,MACL,OAAO;AAAA,MAEP,0BAAAA;AAAA,QAAW;AAAA,QAAV;AAAA,UACI,GAAG;AAAA,UACJ,MAAM;AAAA,UACN,WAAWH,IAAG,kBAAkB,EAAE,OAAO,CAAC,GAAG,SAAS;AAAA,UACtD,eAAa;AAAA,UACb,MAAK;AAAA,UACL,OAAO,WAAW,UAAU,QAAQ,MAAM,EAAE;AAAA,UAC5C,eAAe,CAAC,SAAS;AACrB,kBAAM,WAAW,WAAW,OAAO,KAAK,MAAM,EAAE;AAChD,gBAAI,UAAU,QAAW;AACrB,uBAAS,QAAQ;AAAA,YACrB;AACA,4BAAgB,QAAQ;AAAA,UAC5B;AAAA;AAAA,MACJ;AAAA;AAAA,EACJ;AACJ;;;ACzCA,SAAS,OAAAI,YAAW;AAEb,IAAM,eAAeA,KAAI,8VAA8V;AAAA,EAC1X,UAAU;AAAA,IACN,QAAQ;AAAA,MACJ,UAAU;AAAA,MACV,OAAO;AAAA,IACX;AAAA,EACJ;AAAA,EACA,iBAAiB;AAAA,IACb,QAAQ;AAAA,EACZ;AACJ,CAAC;;;ACVD,SAAS,MAAAC,WAAU;AACnB,YAAYC,gBAAe;AAC3B,SAA8C,kBAAkB;AAOpD,gBAAAC,YAAA;AAHL,IAAM,kBAA4C,CAAC,UAAgC;AACtF,QAAM,EAAE,WAAW,GAAG,UAAU,IAAI;AACpC,QAAM,SAAS,WAAW,kBAAkB;AAC5C,SAAQ,gBAAAA;AAAA,IAAW;AAAA,IAAV;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWF,IAAG,aAAa,EAAE,OAAO,CAAC,GAAG,SAAS;AAAA;AAAA,EACrD;AACJ;",
6
- "names": ["cva", "cn", "Primitive", "Fragment", "jsx", "jsxs", "cva", "cn", "Primitive", "useState", "jsx", "cva", "cn", "Primitive", "jsx"]
3
+ "sources": ["../src/shared/use-choice.ts", "../src/checkbox/style.ts", "../src/checkbox/checkbox.tsx", "../src/shared/switch-control.tsx", "../src/shared/switch-indicator.tsx", "../src/switch/style.ts", "../src/switch/switch.tsx", "../src/shared/switch-setting.tsx", "../src/switch-group/switch-group.tsx", "../src/switch-panel/switch-panel.tsx", "../src/shared/context.ts", "../src/toggle-group/style.ts", "../src/toggle-group/toggle-group.tsx", "../src/toggle-group-item/style.ts", "../src/toggle-group-item/toggle-group-item.tsx"],
4
+ "sourcesContent": ["/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Use Choice\n */\n\nimport { focusInvalidControl, useFormReset } from \"@gridui/form\";\nimport { type ChangeDetails, changeDetails } from \"@gridui/interaction\";\nimport { type ComponentPropsWithRef, type Ref, type SyntheticEvent, useImperativeHandle, useRef, useState } from \"react\";\n\nexport type ChoiceProps = Omit<ComponentPropsWithRef<\"button\">, \"children\" | \"onChange\" | \"defaultChecked\"> & {\n readonly checked?: boolean | undefined;\n readonly defaultChecked?: boolean | undefined;\n readonly readOnly?: boolean | undefined;\n readonly required?: boolean | undefined;\n readonly uncheckedValue?: string | undefined;\n readonly inputRef?: Ref<HTMLInputElement> | undefined;\n readonly onCheckedChange?: ((checked: boolean, details: ChangeDetails) => void) | undefined;\n};\n\nexport const useChoice = (props: ChoiceProps) => {\n const { checked, defaultChecked = false, onCheckedChange, readOnly, disabled, inputRef, form } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultChecked);\n const input = useRef<HTMLInputElement>(null);\n const control = useRef<HTMLButtonElement>(null);\n const initial = useRef(defaultChecked);\n useImperativeHandle(props.ref, () => {\n return control.current as HTMLButtonElement;\n });\n useImperativeHandle(inputRef, () => {\n return input.current as HTMLInputElement;\n });\n useFormReset(input, () => {\n if (checked === undefined) {\n setLocal(initial.current);\n }\n }, form);\n const current = checked ?? local;\n const invalid = (event: SyntheticEvent<HTMLInputElement>) => {\n focusInvalidControl(event, () => {\n control.current?.focus();\n });\n };\n const change = (next: boolean, event: Event) => {\n if (readOnly || disabled || input.current?.matches(\":disabled\")) {\n return;\n }\n const details = changeDetails(event);\n onCheckedChange?.(next, details);\n if (!details.isCanceled && checked === undefined) {\n setLocal(next);\n }\n };\n return {\n current,\n input,\n control,\n change,\n invalid,\n };\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Checkbox\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const choiceStyles = cva(\"gridui-u-inline-flex gridui-u-size-5 gridui-u-shrink-0 gridui-u-cursor-pointer gridui-u-items-center gridui-u-justify-center gridui-u-rounded-control gridui-u-border gridui-u-border-control-border gridui-u-bg-background gridui-u-text-foreground gridui-u-align-middle gridui-u-data-[state=checked]:bg-accent-background gridui-u-data-[state=checked]:text-accent-foreground gridui-u-data-[state=indeterminate]:bg-accent-background gridui-u-data-[state=indeterminate]:text-accent-foreground gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50 gridui-u-data-readonly:cursor-default gridui-u-aria-invalid:border-danger-foreground\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Checkbox\n * @description Checkbox\n */\n\nimport { type ChoiceProps, useChoice } from \"../shared/use-choice\";\nimport { choiceStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-checkbox\";\nimport { Check, Minus } from \"lucide-react\";\nimport type { FC } from \"react\";\n\nexport type CheckboxProps = ChoiceProps & {\n readonly indeterminate?: boolean | undefined;\n};\n\nexport const Checkbox: FC<CheckboxProps> = (props: CheckboxProps) => {\n const { className, indeterminate, inputRef, onCheckedChange, checked, defaultChecked,\n readOnly, uncheckedValue, name, value = \"on\", form, required, onClick, ...restProps } = props;\n const { current, input, control, change, invalid } = useChoice({\n ...props,\n inputRef,\n onCheckedChange,\n checked,\n defaultChecked,\n });\n return (<>\n <Primitive.Root\n {...restProps}\n ref={control}\n checked={indeterminate ? \"indeterminate\" : current}\n aria-required={required}\n aria-readonly={readOnly}\n data-readonly={readOnly ? \"\" : undefined}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n change(indeterminate ? true : !current, event.nativeEvent);\n }\n event.preventDefault();\n }}\n className={cn(choiceStyles(), className)}\n >\n <Primitive.Indicator>\n {indeterminate ? (<Minus\n size={16}\n aria-hidden=\"true\"\n />) : (<Check\n size={16}\n aria-hidden=\"true\"\n />)}\n </Primitive.Indicator>\n </Primitive.Root>\n <input\n ref={input}\n type=\"checkbox\"\n className=\"gridui-u-sr-only\"\n tabIndex={-1}\n aria-hidden=\"true\"\n name={name}\n value={value}\n form={form}\n required={required}\n disabled={props.disabled}\n checked={current}\n readOnly={readOnly}\n onInvalid={invalid}\n onChange={(event) => {\n change(event.target.checked, event.nativeEvent);\n }}\n />\n {!current && uncheckedValue !== undefined && (<input\n type=\"hidden\"\n name={name}\n form={form}\n value={uncheckedValue}\n disabled={props.disabled}\n />)}\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Switch Control\n */\n\nimport { type ChoiceProps, useChoice } from \"./use-choice\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { FC, ReactNode } from \"react\";\n\nexport type SwitchControlProps = ChoiceProps & {\n readonly children: (checked: boolean) => ReactNode;\n};\n\nexport const SwitchControl: FC<SwitchControlProps> = (props: SwitchControlProps) => {\n const { children, className, inputRef, onCheckedChange, checked, defaultChecked,\n readOnly, uncheckedValue, name, value = \"on\", form, required, onClick, type = \"button\", ...restProps } = props;\n const { current, input, control, change, invalid } = useChoice({\n ...props,\n inputRef,\n onCheckedChange,\n checked,\n defaultChecked,\n });\n return (<>\n <button\n {...restProps}\n ref={control}\n type={type}\n role=\"switch\"\n aria-checked={current}\n data-state={current ? \"checked\" : \"unchecked\"}\n data-disabled={props.disabled ? \"\" : undefined}\n aria-required={required}\n aria-readonly={readOnly}\n data-readonly={readOnly ? \"\" : undefined}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) {\n change(!current, event.nativeEvent);\n }\n event.preventDefault();\n }}\n className={cn(\"gridui-switch-control\", className)}\n >\n {children(current)}\n </button>\n <input\n ref={input}\n type=\"checkbox\"\n className=\"gridui-u-sr-only\"\n tabIndex={-1}\n aria-hidden=\"true\"\n name={name}\n value={value}\n form={form}\n required={required}\n disabled={props.disabled}\n checked={current}\n readOnly={readOnly}\n onInvalid={invalid}\n onChange={(event) => {\n change(event.target.checked, event.nativeEvent);\n }}\n />\n {!current && uncheckedValue !== undefined && (<input\n type=\"hidden\"\n name={name}\n form={form}\n value={uncheckedValue}\n disabled={props.disabled}\n />)}\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Switch Indicator\n */\n\nimport type { SwitchPresentationProps } from \"./switch-presentation\";\nimport { Check, Minus } from \"lucide-react\";\nimport type { FC } from \"react\";\n\nexport type SwitchIndicatorProps = SwitchPresentationProps & {\n readonly checked: boolean;\n};\n\nexport const SwitchIndicator: FC<SwitchIndicatorProps> = (props: SwitchIndicatorProps) => {\n const { checked, variant = \"rail\", stateLabels = {\n checked: \"On\",\n unchecked: \"Off\",\n } } = props;\n return (<span\n className=\"gridui-switch-indicator gridui-u-type-caption\"\n data-variant={variant}\n data-state={checked ? \"checked\" : \"unchecked\"}\n aria-hidden=\"true\"\n >\n {variant === \"rail\" ? (<span\n className=\"gridui-switch-thumb\"\n />) : (<>\n {checked ? (<Check\n className=\"gridui-switch-state-icon\"\n />) : (<Minus\n className=\"gridui-switch-state-icon\"\n />)}\n <span\n className=\"gridui-switch-state-label\"\n >\n {checked ? stateLabels.checked : stateLabels.unchecked}\n </span>\n </>)}\n </span>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Switch\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const switchStyles = cva(\"gridui-switch gridui-u-inline-flex gridui-u-w-fit gridui-u-max-w-full gridui-u-min-h-gridui-control gridui-u-min-w-gridui-control gridui-u-shrink-0 gridui-u-items-center gridui-u-justify-center gridui-u-border-0 gridui-u-bg-transparent gridui-u-p-0 gridui-u-align-middle gridui-u-rounded-control\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Switch\n * @description Switch\n */\n\nimport { SwitchControl } from \"../shared/switch-control\";\nimport { SwitchIndicator } from \"../shared/switch-indicator\";\nimport type { SwitchPresentationProps } from \"../shared/switch-presentation\";\nimport type { ChoiceProps } from \"../shared/use-choice\";\nimport { switchStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { FC } from \"react\";\n\nexport type SwitchProps = ChoiceProps & SwitchPresentationProps;\n\nexport const Switch: FC<SwitchProps> = (props: SwitchProps) => {\n const { variant, stateLabels, className, ...restProps } = props;\n return (<SwitchControl\n {...restProps}\n className={cn(switchStyles(), className)}\n >\n {(checked) => {\n return (<SwitchIndicator\n checked={checked}\n variant={variant}\n stateLabels={stateLabels}\n />);\n }}\n </SwitchControl>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Switch Setting\n */\n\nimport type { SwitchProps } from \"../switch/switch\";\nimport { SwitchControl } from \"./switch-control\";\nimport { SwitchIndicator } from \"./switch-indicator\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type FC, type ReactNode, useId } from \"react\";\n\nexport type SwitchSettingProps = {\n readonly control: SwitchProps;\n readonly label: ReactNode;\n readonly description?: ReactNode;\n};\n\nexport const SwitchSetting: FC<SwitchSettingProps> = (props: SwitchSettingProps) => {\n const { control, label, description } = props;\n const { variant, stateLabels, className, ...controlProps } = control;\n const id = useId();\n const labelId = `${id}-label`;\n const descriptionId = `${id}-description`;\n const hasDescription = description !== undefined && description !== null;\n const describedBy = [\n controlProps[\"aria-describedby\"],\n hasDescription ? descriptionId : undefined,\n ].filter(Boolean).join(\" \") || undefined;\n return (<SwitchControl\n {...controlProps}\n className={cn(\"gridui-switch-setting gridui-focus-contained\", className)}\n aria-labelledby={controlProps[\"aria-labelledby\"] ?? (controlProps[\"aria-label\"] ? undefined : labelId)}\n aria-describedby={describedBy}\n >\n {(checked) => {\n return (<>\n <span\n className=\"gridui-switch-setting-copy\"\n >\n <span\n id={labelId}\n className=\"gridui-u-type-ui\"\n >\n {label}\n </span>\n {hasDescription && (<span\n id={descriptionId}\n className=\"gridui-switch-setting-description gridui-u-type-supporting\"\n >\n {description}\n </span>)}\n </span>\n <span\n className=\"gridui-switch-setting-end\"\n >\n <SwitchIndicator\n checked={checked}\n variant={variant}\n stateLabels={stateLabels}\n />\n </span>\n </>);\n }}\n </SwitchControl>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace SwitchGroup\n * @description Switch Group\n */\n\nimport type { SwitchPresentationProps } from \"../shared/switch-presentation\";\nimport { SwitchSetting } from \"../shared/switch-setting\";\nimport type { SwitchProps } from \"../switch/switch\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC, ReactNode } from \"react\";\n\nexport type SwitchGroupItem = SwitchProps & {\n /** Stable item identity and native control ID. */\n readonly id: string;\n readonly label: ReactNode;\n readonly description?: ReactNode;\n};\n\nexport type SwitchGroupProps = Omit<ComponentPropsWithRef<\"fieldset\">, \"children\"> & SwitchPresentationProps & {\n readonly items: readonly SwitchGroupItem[];\n readonly legend?: ReactNode;\n readonly density?: \"compact\" | \"comfortable\";\n};\n\nexport const SwitchGroup: FC<SwitchGroupProps> = (props: SwitchGroupProps) => {\n const { items, legend, density = \"compact\", variant, stateLabels, className, ...restProps } = props;\n return (<fieldset\n {...restProps}\n className={cn(\"gridui-switch-group\", className)}\n data-density={density}\n >\n {legend !== undefined && legend !== null && (<legend\n className=\"gridui-switch-group-legend gridui-u-type-ui\"\n >\n {legend}\n </legend>)}\n {items.map((item) => {\n const { label, description, ...control } = item;\n return (<SwitchSetting\n key={item.id}\n label={label}\n description={description}\n control={{\n ...control,\n variant: item.variant ?? variant,\n stateLabels: item.stateLabels ?? stateLabels,\n }}\n />);\n })}\n </fieldset>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace SwitchPanel\n * @description Switch Panel\n */\n\nimport { SwitchSetting } from \"../shared/switch-setting\";\nimport type { SwitchProps } from \"../switch/switch\";\nimport { cn } from \"@gridui/style-utils\";\nimport { Children, type ComponentPropsWithRef, type FC, type ReactNode } from \"react\";\n\nexport type SwitchPanelProps = ComponentPropsWithRef<\"div\"> & {\n readonly label: ReactNode;\n readonly description?: ReactNode;\n /** State, form attributes, accessible overrides and ref for the switch button. */\n readonly control: SwitchProps;\n};\n\nexport const SwitchPanel: FC<SwitchPanelProps> = (props: SwitchPanelProps) => {\n const { label, description, control, children, className, ...restProps } = props;\n const hasContent = Children.toArray(children).some((child) => {\n return child !== \"\";\n });\n return (<div\n {...restProps}\n className={cn(\"gridui-switch-panel\", className)}\n >\n <SwitchSetting\n label={label}\n description={description}\n control={control}\n />\n {hasContent && (<div\n className=\"gridui-switch-panel-content\"\n >\n {children}\n </div>)}\n </div>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace Shared\n * @description Context\n */\n\nimport { createContext } from \"react\";\n\nexport const ToggleGroupContext = createContext<\"standard\" | \"cells\">(\"standard\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroup\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const toggleGroupStyles = cva(\"gridui-toggle-group gridui-u-inline-flex gridui-u-max-w-full gridui-u-flex-wrap gridui-u-gap-px gridui-u-border gridui-u-border-border gridui-u-bg-border gridui-u-data-[orientation=vertical]:flex-col\", {\n variants: {\n layout: {\n standard: \"\",\n cells: \"gridui-u-grid gridui-u-w-full gridui-u-grid-flow-col gridui-u-auto-cols-fr gridui-u-data-[orientation=vertical]:grid-flow-row gridui-u-data-[orientation=vertical]:auto-rows-fr gridui-u-data-[orientation=vertical]:grid-cols-1\",\n },\n },\n defaultVariants: { layout: \"standard\" },\n});\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroup\n * @description Toggle Group\n */\n\nimport { ToggleGroupContext } from \"../shared/context\";\nimport { toggleGroupStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-toggle-group\";\nimport { type ComponentPropsWithRef, type FC, useState } from \"react\";\n\nexport type ToggleGroupProps = Omit<ComponentPropsWithRef<typeof Primitive.Root>, \"type\" | \"value\" | \"defaultValue\" | \"onValueChange\" | \"loop\"> & {\n readonly multiple?: boolean | undefined;\n readonly value?: string[] | undefined;\n readonly defaultValue?: string[] | undefined;\n readonly onValueChange?: ((value: string[]) => void) | undefined;\n readonly loopFocus?: boolean | undefined;\n readonly layout?: \"standard\" | \"cells\" | undefined;\n};\n\nexport const ToggleGroup: FC<ToggleGroupProps> = (props: ToggleGroupProps) => {\n const { className, multiple, value, defaultValue, onValueChange, loopFocus = true, layout = \"standard\", ...restProps } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultValue ?? []);\n const current = value ?? local;\n return (<ToggleGroupContext.Provider\n value={layout}\n >\n <Primitive.Root\n {...restProps}\n loop={loopFocus}\n className={cn(toggleGroupStyles({ layout }), className)}\n data-layout={layout}\n type=\"multiple\"\n value={multiple ? current : current.slice(-1)}\n onValueChange={(next) => {\n const selected = multiple ? next : next.slice(-1);\n if (value === undefined) {\n setLocal(selected);\n }\n onValueChange?.(selected);\n }}\n />\n </ToggleGroupContext.Provider>);\n};\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroupItem\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const toggleStyles = cva(\"gridui-focus-contained gridui-u-min-h-gridui-control gridui-u-cursor-pointer gridui-u-border-0 gridui-u-bg-background gridui-u-px-gridui-16 gridui-u-py-gridui-8 gridui-u-text-foreground gridui-u-type-ui gridui-u-data-[state=on]:bg-brand-tint gridui-u-data-[state=on]:text-foreground gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50\", {\n variants: {\n layout: {\n standard: \"\",\n cells: \"gridui-u-w-full gridui-u-min-w-0 gridui-u-whitespace-normal gridui-u-wrap-anywhere gridui-u-border-x-0 gridui-u-border-t-0 gridui-u-border-solid gridui-u-border-transparent gridui-u-px-gridui-8 gridui-u-py-gridui-16 gridui-u-text-center gridui-u-data-[orientation=horizontal]:border-b-2 gridui-u-data-[orientation=vertical]:border-b-0 gridui-u-data-[orientation=vertical]:border-r-2 gridui-u-rtl:data-[orientation=vertical]:border-r-0 gridui-u-rtl:data-[orientation=vertical]:border-l-2 gridui-u-data-[state=on]:font-medium\",\n },\n },\n defaultVariants: {\n layout: \"standard\",\n },\n});\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroupItem\n * @description Toggle Group Item\n */\n\nimport { ToggleGroupContext } from \"../shared/context\";\nimport { toggleStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-toggle-group\";\nimport { type ComponentPropsWithRef, type FC, useContext } from \"react\";\n\nexport type ToggleGroupItemProps = ComponentPropsWithRef<typeof Primitive.Item>;\n\nexport const ToggleGroupItem: FC<ToggleGroupItemProps> = (props: ToggleGroupItemProps) => {\n const { className, ...restProps } = props;\n const layout = useContext(ToggleGroupContext);\n return (<Primitive.Item\n {...restProps}\n className={cn(toggleStyles({ layout }), className)}\n />);\n};\n"],
5
+ "mappings": ";AAOA,SAAS,qBAAqB,oBAAoB;AAClD,SAA6B,qBAAqB;AAClD,SAAoE,qBAAqB,QAAQ,gBAAgB;AAY1G,IAAM,YAAY,CAAC,UAAuB;AAC7C,QAAM,EAAE,SAAS,iBAAiB,OAAO,iBAAiB,UAAU,UAAU,UAAU,KAAK,IAAI;AACjG,QAAM;AAAA,IACF;AAAA,IACA;AAAA,EACJ,IAAI,SAAS,cAAc;AAC3B,QAAM,QAAQ,OAAyB,IAAI;AAC3C,QAAM,UAAU,OAA0B,IAAI;AAC9C,QAAM,UAAU,OAAO,cAAc;AACrC,sBAAoB,MAAM,KAAK,MAAM;AACjC,WAAO,QAAQ;AAAA,EACnB,CAAC;AACD,sBAAoB,UAAU,MAAM;AAChC,WAAO,MAAM;AAAA,EACjB,CAAC;AACD,eAAa,OAAO,MAAM;AACtB,QAAI,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AAgB,QAAQ;AAAA,UAC5B;AAAA;AAAA,MACJ;AAAA;AAAA,EACJ;AACJ;;;ACzCA,SAAS,OAAAI,YAAW;AAEb,IAAM,eAAeA,KAAI,0WAA0W;AAAA,EACtY,UAAU;AAAA,IACN,QAAQ;AAAA,MACJ,UAAU;AAAA,MACV,OAAO;AAAA,IACX;AAAA,EACJ;AAAA,EACA,iBAAiB;AAAA,IACb,QAAQ;AAAA,EACZ;AACJ,CAAC;;;ACVD,SAAS,MAAAC,WAAU;AACnB,YAAYC,gBAAe;AAC3B,SAA8C,kBAAkB;AAOpD,gBAAAC,YAAA;AAHL,IAAM,kBAA4C,CAAC,UAAgC;AACtF,QAAM,EAAE,WAAW,GAAG,UAAU,IAAI;AACpC,QAAM,SAAS,WAAW,kBAAkB;AAC5C,SAAQ,gBAAAA;AAAA,IAAW;AAAA,IAAV;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWF,IAAG,aAAa,EAAE,OAAO,CAAC,GAAG,SAAS;AAAA;AAAA,EACrD;AACJ;",
6
+ "names": ["cn", "Fragment", "jsx", "jsxs", "Check", "Minus", "Fragment", "jsx", "jsxs", "cva", "cn", "jsx", "cn", "Fragment", "jsx", "jsxs", "cn", "jsx", "jsxs", "cn", "jsx", "jsxs", "cva", "cn", "Primitive", "useState", "jsx", "cva", "cn", "Primitive", "jsx"]
7
7
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Choice
4
+ * @namespace Shared
5
+ * @description Switch Control
6
+ */
7
+ import { type ChoiceProps } from "./use-choice";
8
+ import type { FC, ReactNode } from "react";
9
+ export type SwitchControlProps = ChoiceProps & {
10
+ readonly children: (checked: boolean) => ReactNode;
11
+ };
12
+ export declare const SwitchControl: FC<SwitchControlProps>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Choice
4
+ * @namespace Shared
5
+ * @description Switch Indicator
6
+ */
7
+ import type { SwitchPresentationProps } from "./switch-presentation";
8
+ import type { FC } from "react";
9
+ export type SwitchIndicatorProps = SwitchPresentationProps & {
10
+ readonly checked: boolean;
11
+ };
12
+ export declare const SwitchIndicator: FC<SwitchIndicatorProps>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Choice
4
+ * @namespace Shared
5
+ * @description Switch Presentation
6
+ */
7
+ export type SwitchVariant = "rail" | "state";
8
+ export type SwitchStateLabels = {
9
+ readonly checked: string;
10
+ readonly unchecked: string;
11
+ };
12
+ export type SwitchPresentationProps = {
13
+ readonly variant?: SwitchVariant | undefined;
14
+ /** Visible state words; the accessible name must describe the setting. */
15
+ readonly stateLabels?: SwitchStateLabels | undefined;
16
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Choice
4
+ * @namespace Shared
5
+ * @description Switch Setting
6
+ */
7
+ import type { SwitchProps } from "../switch/switch";
8
+ import { type FC, type ReactNode } from "react";
9
+ export type SwitchSettingProps = {
10
+ readonly control: SwitchProps;
11
+ readonly label: ReactNode;
12
+ readonly description?: ReactNode;
13
+ };
14
+ export declare const SwitchSetting: FC<SwitchSettingProps>;
package/dist/styles.css CHANGED
@@ -29,14 +29,11 @@
29
29
  width: calc(var(--spacing) * 5);
30
30
  height: calc(var(--spacing) * 5);
31
31
  }
32
- .gridui-u-h-6 {
33
- height: calc(var(--spacing) * 6);
32
+ .gridui-u-min-h-gridui-control {
33
+ min-height: var(--gridui-control-min-height);
34
34
  }
35
- .gridui-u-min-h-11 {
36
- min-height: calc(var(--spacing) * 11);
37
- }
38
- .gridui-u-w-11 {
39
- width: calc(var(--spacing) * 11);
35
+ .gridui-u-w-fit {
36
+ width: fit-content;
40
37
  }
41
38
  .gridui-u-w-full {
42
39
  width: 100%;
@@ -47,6 +44,9 @@
47
44
  .gridui-u-min-w-0 {
48
45
  min-width: 0px;
49
46
  }
47
+ .gridui-u-min-w-gridui-control {
48
+ min-width: var(--gridui-control-min-height);
49
+ }
50
50
  .gridui-u-shrink-0 {
51
51
  flex-shrink: 0;
52
52
  }
@@ -109,11 +109,11 @@
109
109
  .gridui-u-bg-border {
110
110
  background-color: var(--gridui-border);
111
111
  }
112
- .gridui-u-bg-surface {
113
- background-color: var(--gridui-surface);
112
+ .gridui-u-bg-transparent {
113
+ background-color: transparent;
114
114
  }
115
- .gridui-u-p-0\.5 {
116
- padding: calc(var(--spacing) * 0.5);
115
+ .gridui-u-p-0 {
116
+ padding: 0px;
117
117
  }
118
118
  .gridui-u-px-gridui-8 {
119
119
  padding-inline: var(--gridui-space-8);
@@ -133,6 +133,14 @@
133
133
  .gridui-u-align-middle {
134
134
  vertical-align: middle;
135
135
  }
136
+ .gridui-u-type-caption {
137
+ font: var(--gridui-type-caption);
138
+ letter-spacing: normal;
139
+ }
140
+ .gridui-u-type-supporting {
141
+ font: var(--gridui-type-supporting);
142
+ letter-spacing: normal;
143
+ }
136
144
  .gridui-u-type-ui {
137
145
  font: var(--gridui-type-ui);
138
146
  letter-spacing: normal;
@@ -214,26 +222,190 @@
214
222
  }
215
223
  }
216
224
  @layer components {
225
+ .gridui-switch-control, .gridui-switch-indicator, .gridui-switch-setting-copy, .gridui-switch-setting-end {
226
+ box-sizing: border-box;
227
+ }
228
+ .gridui-switch-control {
229
+ color: var(--gridui-foreground);
230
+ border-radius: var(--gridui-control-radius);
231
+ cursor: pointer;
232
+ }
233
+ .gridui-switch-control:disabled {
234
+ cursor: not-allowed;
235
+ opacity: 0.5;
236
+ }
237
+ .gridui-switch-control[data-readonly] {
238
+ cursor: default;
239
+ }
240
+ .gridui-switch-indicator {
241
+ --_gridui-switch-thumb-size: 1.125rem;
242
+ display: inline-flex;
243
+ flex-shrink: 0;
244
+ align-items: center;
245
+ width: 3rem;
246
+ height: 1.625rem;
247
+ padding: var(--gridui-space-2);
248
+ border: 1px solid var(--gridui-control-border);
249
+ border-radius: var(--gridui-control-radius);
250
+ background: var(--gridui-background);
251
+ color: var(--gridui-foreground);
252
+ pointer-events: none;
253
+ transition: background-color var(--gridui-motion-duration-quick), border-color var(--gridui-motion-duration-quick);
254
+ }
255
+ .gridui-switch-indicator[data-state="checked"] {
256
+ border-color: var(--gridui-accent-background);
257
+ background: var(--gridui-brand-tint);
258
+ }
217
259
  .gridui-switch-thumb {
218
- width: 16px;
219
- height: 16px;
220
- border-radius: 2px;
221
- background: var(--gridui-foreground);
222
- transform: translateX(0);
223
- transition: transform var(--gridui-motion-duration-quick) var(--gridui-motion-ease-out);
260
+ flex-shrink: 0;
261
+ width: var(--_gridui-switch-thumb-size);
262
+ height: var(--_gridui-switch-thumb-size);
263
+ margin-inline-start: 0;
264
+ border-radius: var(--gridui-control-radius);
265
+ background: var(--gridui-muted);
266
+ transition: margin-inline-start var(--gridui-motion-duration-quick) var(--gridui-motion-ease-out);
267
+ }
268
+ .gridui-switch-indicator[data-state="checked"] .gridui-switch-thumb {
269
+ margin-inline-start: max(0px, calc(100% - var(--_gridui-switch-thumb-size)));
270
+ background: var(--gridui-accent-background);
271
+ }
272
+ .gridui-switch-indicator[data-variant="state"] {
273
+ justify-content: center;
274
+ gap: var(--gridui-space-4);
275
+ width: max-content;
276
+ min-width: min(4.5rem, 100%);
277
+ max-width: 100%;
278
+ height: auto;
279
+ min-height: 2rem;
280
+ padding: var(--gridui-space-4) var(--gridui-space-8);
224
281
  }
225
- .gridui-switch-thumb[data-state="checked"] {
226
- background: var(--gridui-accent-foreground);
227
- transform: translateX(18px);
282
+ .gridui-switch-indicator[data-variant="state"][data-state="checked"] {
283
+ color: var(--gridui-accent-foreground);
284
+ background: var(--gridui-accent-background);
285
+ }
286
+ .gridui-switch-state-icon {
287
+ flex-shrink: 0;
288
+ width: var(--gridui-icon-size);
289
+ height: var(--gridui-icon-size);
228
290
  }
229
- .gridui-switch:dir(rtl) .gridui-switch-thumb[data-state="checked"] {
230
- transform: translateX(-18px);
291
+ .gridui-switch-state-label {
292
+ min-width: 0;
293
+ text-align: center;
294
+ overflow-wrap: anywhere;
295
+ }
296
+ .gridui-switch-control[aria-invalid="true"] .gridui-switch-indicator {
297
+ border-color: var(--gridui-danger-foreground);
298
+ }
299
+ .gridui-switch-setting {
300
+ display: flex;
301
+ align-items: center;
302
+ justify-content: space-between;
303
+ gap: var(--gridui-space-16);
304
+ width: 100%;
305
+ min-width: 0;
306
+ min-height: var(--gridui-control-min-height);
307
+ padding: var(--gridui-space-12) var(--gridui-space-16);
308
+ border: 0;
309
+ background: var(--gridui-background);
310
+ text-align: start;
311
+ }
312
+ .gridui-switch-setting-copy {
313
+ display: grid;
314
+ gap: var(--gridui-space-4);
315
+ flex: 1;
316
+ min-width: 0;
317
+ overflow-wrap: anywhere;
318
+ }
319
+ .gridui-switch-setting-description {
320
+ color: var(--gridui-muted);
321
+ }
322
+ .gridui-switch-setting-end {
323
+ display: flex;
324
+ align-items: center;
325
+ justify-content: center;
326
+ flex-shrink: 0;
327
+ max-width: 45%;
231
328
  }
232
329
  @media (prefers-reduced-motion: reduce) {
233
- .gridui-switch-thumb {
330
+ .gridui-switch-indicator, .gridui-switch-thumb {
234
331
  transition: none;
235
332
  }
236
333
  }
334
+ .gridui-switch-group {
335
+ box-sizing: border-box;
336
+ min-width: 0;
337
+ margin: 0;
338
+ padding: 0;
339
+ border: 1px solid var(--gridui-border);
340
+ border-radius: var(--gridui-control-radius);
341
+ }
342
+ .gridui-switch-group-legend {
343
+ margin-inline: var(--gridui-space-8);
344
+ padding-inline: var(--gridui-space-8);
345
+ color: var(--gridui-foreground);
346
+ }
347
+ .gridui-switch-group > .gridui-switch-setting ~ .gridui-switch-setting {
348
+ border-block-start: 1px solid var(--gridui-border);
349
+ }
350
+ .gridui-switch-group[data-density="compact"] > .gridui-switch-setting {
351
+ min-height: 3.75rem;
352
+ padding-block: var(--gridui-space-8);
353
+ }
354
+ .gridui-switch-group[data-density="comfortable"] > .gridui-switch-setting {
355
+ min-height: 4.75rem;
356
+ padding-block: var(--gridui-space-16);
357
+ }
358
+ .gridui-switch-panel {
359
+ box-sizing: border-box;
360
+ min-width: 0;
361
+ border: 1px solid var(--gridui-border);
362
+ border-radius: var(--gridui-control-radius);
363
+ background: var(--gridui-background);
364
+ color: var(--gridui-foreground);
365
+ }
366
+ .gridui-switch-panel > .gridui-switch-setting {
367
+ align-items: stretch;
368
+ gap: 0;
369
+ min-height: 5rem;
370
+ padding: 0;
371
+ }
372
+ .gridui-switch-panel > .gridui-switch-setting > .gridui-switch-setting-copy {
373
+ align-content: center;
374
+ padding: var(--gridui-space-16);
375
+ }
376
+ .gridui-switch-panel > .gridui-switch-setting > .gridui-switch-setting-end {
377
+ width: 6rem;
378
+ border-inline-start: 1px solid var(--gridui-border);
379
+ background: var(--gridui-surface);
380
+ }
381
+ .gridui-switch-panel > .gridui-switch-setting > .gridui-switch-setting-end > .gridui-switch-indicator[data-variant="rail"] {
382
+ position: relative;
383
+ border-color: transparent;
384
+ background: transparent;
385
+ }
386
+ .gridui-switch-panel > .gridui-switch-setting > .gridui-switch-setting-end > .gridui-switch-indicator[data-variant="rail"]::before {
387
+ content: "";
388
+ position: absolute;
389
+ inset-inline: var(--gridui-space-2);
390
+ height: 1px;
391
+ background: var(--gridui-control-border);
392
+ }
393
+ .gridui-switch-panel > .gridui-switch-setting > .gridui-switch-setting-end > .gridui-switch-indicator > .gridui-switch-thumb {
394
+ position: relative;
395
+ }
396
+ .gridui-switch-panel > .gridui-switch-setting > .gridui-switch-setting-end > .gridui-switch-indicator[data-variant="state"] {
397
+ align-self: stretch;
398
+ width: 100%;
399
+ border: 0;
400
+ }
401
+ .gridui-switch-panel > .gridui-switch-setting[aria-invalid="true"] {
402
+ box-shadow: inset 0 0 0 1px var(--gridui-danger-foreground);
403
+ }
404
+ .gridui-switch-panel-content {
405
+ box-sizing: border-box;
406
+ padding: var(--gridui-space-16);
407
+ border-block-start: 1px solid var(--gridui-border);
408
+ }
237
409
  }
238
410
  @property --tw-border-style {
239
411
  syntax: "*";
@@ -4,7 +4,8 @@
4
4
  * @namespace Switch
5
5
  * @description Switch
6
6
  */
7
- import { type ChoiceProps } from "../shared/use-choice";
7
+ import type { SwitchPresentationProps } from "../shared/switch-presentation";
8
+ import type { ChoiceProps } from "../shared/use-choice";
8
9
  import type { FC } from "react";
9
- export type SwitchProps = ChoiceProps;
10
+ export type SwitchProps = ChoiceProps & SwitchPresentationProps;
10
11
  export declare const Switch: FC<SwitchProps>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Choice
4
+ * @namespace SwitchGroup
5
+ * @description Switch Group
6
+ */
7
+ import type { SwitchPresentationProps } from "../shared/switch-presentation";
8
+ import type { SwitchProps } from "../switch/switch";
9
+ import type { ComponentPropsWithRef, FC, ReactNode } from "react";
10
+ export type SwitchGroupItem = SwitchProps & {
11
+ /** Stable item identity and native control ID. */
12
+ readonly id: string;
13
+ readonly label: ReactNode;
14
+ readonly description?: ReactNode;
15
+ };
16
+ export type SwitchGroupProps = Omit<ComponentPropsWithRef<"fieldset">, "children"> & SwitchPresentationProps & {
17
+ readonly items: readonly SwitchGroupItem[];
18
+ readonly legend?: ReactNode;
19
+ readonly density?: "compact" | "comfortable";
20
+ };
21
+ export declare const SwitchGroup: FC<SwitchGroupProps>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Choice
4
+ * @namespace SwitchPanel
5
+ * @description Switch Panel
6
+ */
7
+ import type { SwitchProps } from "../switch/switch";
8
+ import { type ComponentPropsWithRef, type FC, type ReactNode } from "react";
9
+ export type SwitchPanelProps = ComponentPropsWithRef<"div"> & {
10
+ readonly label: ReactNode;
11
+ readonly description?: ReactNode;
12
+ /** State, form attributes, accessible overrides and ref for the switch button. */
13
+ readonly control: SwitchProps;
14
+ };
15
+ export declare const SwitchPanel: FC<SwitchPanelProps>;
@@ -0,0 +1,88 @@
1
+ # Switch family
2
+
3
+ Import `Switch`, `SwitchGroup`, and `SwitchPanel` from `@gridui/choice` and load
4
+ `@gridui/choice/styles.css` after Theme. The family has three independent public
5
+ components, with one private native-button/form implementation. Each switch has
6
+ one native checkbox bridge. Each component owns its layout; shared indicator
7
+ geometry and setting-row labeling stay package-local.
8
+
9
+ ## Presentation and state
10
+
11
+ `variant="rail"` is the default: a light rectangular rail and solid moving thumb.
12
+ `variant="state"` replaces the thumb with a check/minus icon and visible state
13
+ words. Both use Theme colors, square control geometry, shared focus/hover
14
+ indicators, rem dimensions and reduced-motion preferences. Radio circles and
15
+ other meaningful round indicators are unaffected.
16
+
17
+ `stateLabels={{ checked: "Enabled", unchecked: "Disabled" }}` localizes the
18
+ visible words; defaults are `On` and `Off`. State words are decorative and never
19
+ replace the setting's accessible name. Long labels wrap. Native Tab order and
20
+ Space/Enter activation apply; groups contain independent settings, not exclusive
21
+ options. A standalone control reserves the standard minimum control height for
22
+ its hit target independently of the smaller visible indicator.
23
+
24
+ All controls accept the existing `SwitchProps`: `checked`/`onCheckedChange` or
25
+ `defaultChecked`, `name`, `value`, `uncheckedValue`, `form`, `required`, `disabled`,
26
+ `readOnly`, visible-button `ref`, native `inputRef`, and accessibility attributes.
27
+ Canceled change details and prevented clicks preserve state. Uncontrolled native
28
+ form reset restores initial values; controlled owners handle their own reset.
29
+ Disabled fieldsets block interaction and exclude native values. Readonly controls
30
+ retain focus and values. Required validation focuses the visible button.
31
+
32
+ ```tsx
33
+ <Switch variant="rail" name="sync" aria-label="Background sync" defaultChecked />
34
+ <Switch variant="state" name="updates" aria-label="Automatic updates"
35
+ stateLabels={{ checked: "Enabled", unchecked: "Disabled" }} />
36
+ ```
37
+
38
+ ## Settings group
39
+
40
+ `SwitchGroup` owns a native fieldset with shared row seams. Supply `legend` or an
41
+ accessible group name. `disabled`, `form`, native fieldset props and its ref belong
42
+ to that fieldset. `items` is a readonly array of `SwitchGroupItem`: a stable,
43
+ document-unique `id`, `label`, optional `description`, and each item's own
44
+ `SwitchProps`. Stable IDs also preserve uncontrolled state when items reorder.
45
+
46
+ The entire row is one switch button. Labels and descriptions must contain
47
+ non-interactive content. Each gets an ID for accessible naming/description;
48
+ explicit ARIA names are honored and external description IDs are retained.
49
+ Group `variant` and `stateLabels` supply defaults; an item may override either.
50
+ `density="compact"` is the default; `comfortable` adds space without changing
51
+ state behavior. Items own their state and form names independently. As with
52
+ native fieldsets, the group's `form` attribute is not inherited by its controls;
53
+ set `form` on each item when associating controls with an external form.
54
+
55
+ ```tsx
56
+ <SwitchGroup aria-label="Editor preferences" variant="rail" items={[
57
+ { id: "save", label: "Auto save", description: "Keep changes while editing.",
58
+ name: "save", defaultChecked: true },
59
+ { id: "preview", label: "Live preview", name: "preview", checked: preview,
60
+ onCheckedChange: setPreview },
61
+ ]} />
62
+ ```
63
+
64
+ ## Integrated panel
65
+
66
+ `SwitchPanel` owns the outer frame, a full-row switch header, its flush end cell,
67
+ and an optional content region. `label` and `description` belong to the header and
68
+ must be non-interactive. `control` supplies the switch's `SwitchProps`, including
69
+ its variant, state, form ownership and button ref. Other native div props,
70
+ `className`, `style`, and the panel's `ref` belong to the outer frame.
71
+
72
+ `children` render outside the button. They may contain links, fields, or nested
73
+ switches; their styles and interactions remain independent. The panel does not
74
+ implicitly disable or hide children when unchecked, readonly, or disabled.
75
+ Applications own that behavior. Omit children for a header-only panel.
76
+
77
+ ```tsx
78
+ <SwitchPanel label="Automatic backups" description="Keep a daily snapshot."
79
+ control={{ variant: "state", name: "backup", checked: backup,
80
+ onCheckedChange: setBackup }}>
81
+ <a href="/settings/backups">Manage retention</a>
82
+ </SwitchPanel>
83
+ ```
84
+
85
+ Appearance/locale policy, persistence, side effects, and confirmation flows remain
86
+ application-owned. No new provider, token copies, or component-specific stylesheet
87
+ imports are required. Storybook's Switch family stories show both variants and
88
+ localized, disabled, and readonly states.
@@ -1,7 +1,8 @@
1
1
  # Tabs and choice controls
2
2
 
3
3
  Import Tabs from `@gridui/tabs`, Checkbox/Switch/ToggleGroup from `@gridui/choice`, and CopyButton from `@gridui/clipboard`. Load each rendered family stylesheet after Theme.
4
- They style the installed Radix primitives without adding routing or persistence.
4
+ Tabs, Checkbox, and ToggleGroup style the installed Radix primitives. Switch uses
5
+ a native button with the family-owned native form bridge. Neither adds routing or persistence.
5
6
  Native refs, form ownership, and accessibility props are forwarded. Choice change
6
7
  details expose the native `event`, `cancel()`, and `isCanceled`. GridUI accepts string class names, with semantic tokens and no required
7
8
  animation library. Provide a visible associated label or an accessible name.
@@ -53,6 +54,9 @@ preserving keyboard operation. Applications own visible error messages and
53
54
  <label><Switch name="notifications" defaultChecked /> Enable notifications</label>
54
55
  ```
55
56
 
57
+ See [the Switch family](switches.md) for rail/state presentation, independent
58
+ settings groups, and integrated panels.
59
+
56
60
  ## ToggleGroup
57
61
 
58
62
  Compose `ToggleGroup` and `ToggleGroupItem value="..."`. Both controlled `value`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridui/choice",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "GridUI React choice",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -29,17 +29,16 @@
29
29
  "dependencies": {
30
30
  "@gridui/form": "^3.0.0",
31
31
  "@gridui/interaction": "^1.1.2",
32
- "@gridui/style-utils": "^2.1.4",
33
- "@gridui/theme": "^2.4.0",
32
+ "@gridui/style-utils": "^2.2.0",
33
+ "@gridui/theme": "^2.5.0",
34
34
  "@radix-ui/react-checkbox": "1.4.1",
35
- "@radix-ui/react-switch": "1.4.1",
36
35
  "@radix-ui/react-toggle-group": "1.2.1",
37
36
  "class-variance-authority": "0.7.1",
38
37
  "lucide-react": "1.66.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@gridui-internal/configuration": "0.0.0-internal",
42
- "@gridui/button": "3.0.0",
41
+ "@gridui/button": "3.0.1",
43
42
  "@jest/globals": "30.5.2",
44
43
  "@storybook/react-vite": "10.6.5",
45
44
  "@types/jest": "30.0.0",