@gridui/choice 1.0.2 → 1.1.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 +26 -1
- package/dist/index.js +52 -21
- package/dist/index.js.map +3 -3
- package/dist/shared/context.d.ts +7 -0
- package/dist/styles.css +135 -42
- package/dist/toggle-group/style.d.ts +3 -1
- package/dist/toggle-group/toggle-group.d.ts +1 -0
- package/dist/toggle-group-item/style.d.ts +3 -1
- package/docs/tabs-and-choices.md +83 -0
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -5,4 +5,29 @@ Core family. Public API: `Checkbox`, `CheckboxProps`, `Switch`, `SwitchProps`, `
|
|
|
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.
|
|
7
7
|
|
|
8
|
-
See [component ownership](
|
|
8
|
+
See [component ownership](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/component-ownership.md) and [release history](https://github.com/sudo-ui/GridUI-React-Monorepo/tree/main/packages-core/choice/.changeset/history).
|
|
9
|
+
|
|
10
|
+
## Full-width choice cells
|
|
11
|
+
|
|
12
|
+
`ToggleGroup layout="cells"` uses equal-width tracks, shared seams, wrapping
|
|
13
|
+
labels, and a tinted pressed surface with a foreground selection edge. It uses
|
|
14
|
+
the same visual treatment as `TabsList layout="cells"`, including vertical and
|
|
15
|
+
RTL presentation. The default `standard` layout remains unchanged.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
<ToggleGroup layout="cells" value={topics} onValueChange={setTopics}
|
|
19
|
+
aria-label="Optional topic">
|
|
20
|
+
<ToggleGroupItem value="replies">Customer replies</ToggleGroupItem>
|
|
21
|
+
<ToggleGroupItem value="files">Answers from files</ToggleGroupItem>
|
|
22
|
+
</ToggleGroup>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Values remain arrays. A single-selection group can clear its pressed item;
|
|
26
|
+
`multiple` allows independent pressed items. When `multiple` is false or omitted,
|
|
27
|
+
only the last supplied value is rendered as pressed. This applies to controlled
|
|
28
|
+
values, initial values, and switching from multiple to single selection. Rendering
|
|
29
|
+
does not mutate supplied arrays or emit `onValueChange`; the next interaction
|
|
30
|
+
reports an empty array or one value, matching the rendered selection. Disabled
|
|
31
|
+
items, keyboard roving, and native non-submitting button behavior are preserved.
|
|
32
|
+
Use Tabs when choices switch content panels, and RadioGroup when a form needs one
|
|
33
|
+
radio value.
|
package/dist/index.js
CHANGED
|
@@ -49,7 +49,7 @@ var useChoice = (props) => {
|
|
|
49
49
|
|
|
50
50
|
// src/checkbox/style.ts
|
|
51
51
|
import { cva } from "class-variance-authority";
|
|
52
|
-
var choiceStyles = cva("inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-control border border-control-border bg-background text-foreground align-middle data-[state=checked]:bg-accent-background data-[state=checked]:text-accent-foreground data-[state=indeterminate]:bg-accent-background data-[state=indeterminate]:text-accent-foreground data-disabled:cursor-not-allowed data-disabled:opacity-50 data-readonly:cursor-default aria-invalid:border-danger-foreground");
|
|
52
|
+
var 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");
|
|
53
53
|
|
|
54
54
|
// src/checkbox/checkbox.tsx
|
|
55
55
|
import { cn } from "@gridui/style-utils";
|
|
@@ -118,7 +118,7 @@ var Checkbox = (props) => {
|
|
|
118
118
|
{
|
|
119
119
|
ref: input,
|
|
120
120
|
type: "checkbox",
|
|
121
|
-
className: "sr-only",
|
|
121
|
+
className: "gridui-u-sr-only",
|
|
122
122
|
tabIndex: -1,
|
|
123
123
|
"aria-hidden": "true",
|
|
124
124
|
name,
|
|
@@ -149,7 +149,7 @@ var Checkbox = (props) => {
|
|
|
149
149
|
|
|
150
150
|
// src/switch/style.ts
|
|
151
151
|
import { cva as cva2 } from "class-variance-authority";
|
|
152
|
-
var switchStyles = cva2("gridui-switch inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-control border border-control-border bg-surface p-0.5 align-middle data-[state=checked]:bg-accent-background data-disabled:cursor-not-allowed data-disabled:opacity-50 data-readonly:cursor-default aria-invalid:border-danger-foreground");
|
|
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
153
|
|
|
154
154
|
// src/switch/switch.tsx
|
|
155
155
|
import { cn as cn2 } from "@gridui/style-utils";
|
|
@@ -209,7 +209,7 @@ var Switch = (props) => {
|
|
|
209
209
|
{
|
|
210
210
|
ref: input,
|
|
211
211
|
type: "checkbox",
|
|
212
|
-
className: "sr-only",
|
|
212
|
+
className: "gridui-u-sr-only",
|
|
213
213
|
tabIndex: -1,
|
|
214
214
|
"aria-hidden": "true",
|
|
215
215
|
name,
|
|
@@ -238,9 +238,21 @@ var Switch = (props) => {
|
|
|
238
238
|
] });
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
+
// src/shared/context.ts
|
|
242
|
+
import { createContext } from "react";
|
|
243
|
+
var ToggleGroupContext = createContext("standard");
|
|
244
|
+
|
|
241
245
|
// src/toggle-group/style.ts
|
|
242
246
|
import { cva as cva3 } from "class-variance-authority";
|
|
243
|
-
var toggleGroupStyles = cva3("inline-flex max-w-full flex-wrap gap-px border border-border bg-border data-[orientation=vertical]:flex-col"
|
|
247
|
+
var toggleGroupStyles = cva3("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", {
|
|
248
|
+
variants: {
|
|
249
|
+
layout: {
|
|
250
|
+
standard: "",
|
|
251
|
+
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"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
defaultVariants: { layout: "standard" }
|
|
255
|
+
});
|
|
244
256
|
|
|
245
257
|
// src/toggle-group/toggle-group.tsx
|
|
246
258
|
import { cn as cn3 } from "@gridui/style-utils";
|
|
@@ -248,46 +260,65 @@ import * as Primitive3 from "@radix-ui/react-toggle-group";
|
|
|
248
260
|
import { useState as useState2 } from "react";
|
|
249
261
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
250
262
|
var ToggleGroup = (props) => {
|
|
251
|
-
const { className, multiple, value, defaultValue, onValueChange, loopFocus = true, ...restProps } = props;
|
|
263
|
+
const { className, multiple, value, defaultValue, onValueChange, loopFocus = true, layout = "standard", ...restProps } = props;
|
|
252
264
|
const [
|
|
253
265
|
local,
|
|
254
266
|
setLocal
|
|
255
267
|
] = useState2(defaultValue ?? []);
|
|
268
|
+
const current = value ?? local;
|
|
256
269
|
return /* @__PURE__ */ jsx3(
|
|
257
|
-
|
|
270
|
+
ToggleGroupContext.Provider,
|
|
258
271
|
{
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
272
|
+
value: layout,
|
|
273
|
+
children: /* @__PURE__ */ jsx3(
|
|
274
|
+
Primitive3.Root,
|
|
275
|
+
{
|
|
276
|
+
...restProps,
|
|
277
|
+
loop: loopFocus,
|
|
278
|
+
className: cn3(toggleGroupStyles({ layout }), className),
|
|
279
|
+
"data-layout": layout,
|
|
280
|
+
type: "multiple",
|
|
281
|
+
value: multiple ? current : current.slice(-1),
|
|
282
|
+
onValueChange: (next) => {
|
|
283
|
+
const selected = multiple ? next : next.slice(-1);
|
|
284
|
+
if (value === void 0) {
|
|
285
|
+
setLocal(selected);
|
|
286
|
+
}
|
|
287
|
+
onValueChange?.(selected);
|
|
288
|
+
}
|
|
268
289
|
}
|
|
269
|
-
|
|
270
|
-
}
|
|
290
|
+
)
|
|
271
291
|
}
|
|
272
292
|
);
|
|
273
293
|
};
|
|
274
294
|
|
|
275
295
|
// src/toggle-group-item/style.ts
|
|
276
296
|
import { cva as cva4 } from "class-variance-authority";
|
|
277
|
-
var toggleStyles = cva4("min-h-11 cursor-pointer border-0 bg-background px-gridui-16 py-gridui-8 text-foreground type-ui hover:enabled:bg-surface-hover data-[state=on]:bg-accent-background data-[state=on]:text-accent-foreground data-[state=on]:hover:enabled:bg-accent-background data-disabled:cursor-not-allowed data-disabled:opacity-50"
|
|
297
|
+
var toggleStyles = cva4("gridui-hover-surface 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-hover:enabled:bg-surface-hover gridui-u-data-[state=on]:bg-accent-background gridui-u-data-[state=on]:text-accent-foreground gridui-u-data-[state=on]:hover:enabled:bg-accent-background gridui-u-data-disabled:cursor-not-allowed gridui-u-data-disabled:opacity-50", {
|
|
298
|
+
variants: {
|
|
299
|
+
layout: {
|
|
300
|
+
standard: "",
|
|
301
|
+
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]:bg-brand-tint gridui-u-data-[state=on]:text-foreground gridui-u-data-[state=on]:font-medium gridui-u-data-[state=on]:border-foreground gridui-u-data-[state=on]:hover:enabled:bg-brand-tint"
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
defaultVariants: {
|
|
305
|
+
layout: "standard"
|
|
306
|
+
}
|
|
307
|
+
});
|
|
278
308
|
|
|
279
309
|
// src/toggle-group-item/toggle-group-item.tsx
|
|
280
310
|
import { cn as cn4 } from "@gridui/style-utils";
|
|
281
311
|
import * as Primitive4 from "@radix-ui/react-toggle-group";
|
|
282
|
-
import "react";
|
|
312
|
+
import { useContext } from "react";
|
|
283
313
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
284
314
|
var ToggleGroupItem = (props) => {
|
|
285
315
|
const { className, ...restProps } = props;
|
|
316
|
+
const layout = useContext(ToggleGroupContext);
|
|
286
317
|
return /* @__PURE__ */ jsx4(
|
|
287
318
|
Primitive4.Item,
|
|
288
319
|
{
|
|
289
320
|
...restProps,
|
|
290
|
-
className: cn4(toggleStyles(), className)
|
|
321
|
+
className: cn4(toggleStyles({ layout }), className)
|
|
291
322
|
}
|
|
292
323
|
);
|
|
293
324
|
};
|
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/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(\"inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-control border border-control-border bg-background text-foreground align-middle data-[state=checked]:bg-accent-background data-[state=checked]:text-accent-foreground data-[state=indeterminate]:bg-accent-background data-[state=indeterminate]:text-accent-foreground data-disabled:cursor-not-allowed data-disabled:opacity-50 data-readonly:cursor-default 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=\"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 inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-control border border-control-border bg-surface p-0.5 align-middle data-[state=checked]:bg-accent-background data-disabled:cursor-not-allowed data-disabled:opacity-50 data-readonly:cursor-default 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=\"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 ToggleGroup\n * @description Style\n */\n\nimport { cva } from \"class-variance-authority\";\n\nexport const toggleGroupStyles = cva(\"inline-flex max-w-full flex-wrap gap-px border border-border bg-border data-[orientation=vertical]:flex-col\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroup\n * @description Toggle Group\n */\n\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};\n\nexport const ToggleGroup: FC<ToggleGroupProps> = (props: ToggleGroupProps) => {\n const { className, multiple, value, defaultValue, onValueChange, loopFocus = true, ...restProps } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultValue ?? []);\n return (<Primitive.Root\n {...restProps}\n loop={loopFocus}\n className={cn(toggleGroupStyles(), className)}\n type=\"multiple\"\n value={value ?? local}\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};\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(\"min-h-11 cursor-pointer border-0 bg-background px-gridui-16 py-gridui-8 text-foreground type-ui hover:enabled:bg-surface-hover data-[state=on]:bg-accent-background data-[state=on]:text-accent-foreground data-[state=on]:hover:enabled:bg-accent-background data-disabled:cursor-not-allowed data-disabled:opacity-50\");\n", "/**\n * @author WMXPY\n * @package Choice\n * @namespace ToggleGroupItem\n * @description Toggle Group Item\n */\n\nimport { toggleStyles } from \"./style\";\nimport { cn } from \"@gridui/style-utils\";\nimport * as Primitive from \"@radix-ui/react-toggle-group\";\nimport { type ComponentPropsWithRef, type FC } from \"react\";\n\nexport type ToggleGroupItemProps = ComponentPropsWithRef<typeof Primitive.Item>;\n\nexport const ToggleGroupItem: FC<ToggleGroupItemProps> = (props: ToggleGroupItemProps) => {\n const { className, ...restProps } = props;\n return (<Primitive.Item\n {...restProps}\n className={cn(toggleStyles(), 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,YAAY,QAAW;AACvB,eAAS,QAAQ,OAAO;AAAA,IAC5B;AAAA,EACJ,GAAG,IAAI;AACP,QAAM,UAAU,WAAW;AAC3B,QAAM,UAAU,CAAC,UAA4C;AACzD,wBAAoB,OAAO,MAAM;AAC7B,cAAQ,SAAS,MAAM;AAAA,IAC3B,CAAC;AAAA,EACL;AACA,QAAM,SAAS,CAAC,MAAe,UAAiB;AAC5C,QAAI,YAAY,YAAY,MAAM,SAAS,QAAQ,WAAW,GAAG;AAC7D;AAAA,IACJ;AACA,UAAM,UAAU,cAAc,KAAK;AACnC,sBAAkB,MAAM,OAAO;AAC/B,QAAI,CAAC,QAAQ,cAAc,YAAY,QAAW;AAC9C,eAAS,IAAI;AAAA,IACjB;AAAA,EACJ;AACA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;;;ACzDA,SAAS,WAAW;AAEb,IAAM,eAAe,IAAI,
|
|
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-hover-surface 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-hover:enabled:bg-surface-hover gridui-u-data-[state=on]:bg-accent-background gridui-u-data-[state=on]:text-accent-foreground gridui-u-data-[state=on]:hover:enabled:bg-accent-background 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]:bg-brand-tint gridui-u-data-[state=on]:text-foreground gridui-u-data-[state=on]:font-medium gridui-u-data-[state=on]:border-foreground gridui-u-data-[state=on]:hover:enabled:bg-brand-tint\",\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,YAAY,QAAW;AACvB,eAAS,QAAQ,OAAO;AAAA,IAC5B;AAAA,EACJ,GAAG,IAAI;AACP,QAAM,UAAU,WAAW;AAC3B,QAAM,UAAU,CAAC,UAA4C;AACzD,wBAAoB,OAAO,MAAM;AAC7B,cAAQ,SAAS,MAAM;AAAA,IAC3B,CAAC;AAAA,EACL;AACA,QAAM,SAAS,CAAC,MAAe,UAAiB;AAC5C,QAAI,YAAY,YAAY,MAAM,SAAS,QAAQ,WAAW,GAAG;AAC7D;AAAA,IACJ;AACA,UAAM,UAAU,cAAc,KAAK;AACnC,sBAAkB,MAAM,OAAO;AAC/B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AA,IAAW;AAAA,IAAV;AAAA,MACJ,GAAG;AAAA,MACJ,WAAWF,IAAG,aAAa,EAAE,OAAO,CAAC,GAAG,SAAS;AAAA;AAAA,EACrD;AACJ;",
|
|
6
6
|
"names": ["cva", "cn", "Primitive", "Fragment", "jsx", "jsxs", "cva", "cn", "Primitive", "useState", "jsx", "cva", "cn", "Primitive", "jsx"]
|
|
7
7
|
}
|
package/dist/styles.css
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
@layer theme {
|
|
5
5
|
:root, :host {
|
|
6
6
|
--spacing: 0.25rem;
|
|
7
|
+
--font-weight-medium: 500;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
@layer utilities {
|
|
10
|
-
.sr-only {
|
|
11
|
+
.gridui-u-sr-only {
|
|
11
12
|
position: absolute;
|
|
12
13
|
width: 1px;
|
|
13
14
|
height: 1px;
|
|
@@ -18,133 +19,220 @@
|
|
|
18
19
|
white-space: nowrap;
|
|
19
20
|
border-width: 0;
|
|
20
21
|
}
|
|
21
|
-
.
|
|
22
|
-
display:
|
|
22
|
+
.gridui-u-grid {
|
|
23
|
+
display: grid;
|
|
23
24
|
}
|
|
24
|
-
.inline-flex {
|
|
25
|
+
.gridui-u-inline-flex {
|
|
25
26
|
display: inline-flex;
|
|
26
27
|
}
|
|
27
|
-
.size-5 {
|
|
28
|
+
.gridui-u-size-5 {
|
|
28
29
|
width: calc(var(--spacing) * 5);
|
|
29
30
|
height: calc(var(--spacing) * 5);
|
|
30
31
|
}
|
|
31
|
-
.h-6 {
|
|
32
|
+
.gridui-u-h-6 {
|
|
32
33
|
height: calc(var(--spacing) * 6);
|
|
33
34
|
}
|
|
34
|
-
.min-h-11 {
|
|
35
|
+
.gridui-u-min-h-11 {
|
|
35
36
|
min-height: calc(var(--spacing) * 11);
|
|
36
37
|
}
|
|
37
|
-
.w-11 {
|
|
38
|
+
.gridui-u-w-11 {
|
|
38
39
|
width: calc(var(--spacing) * 11);
|
|
39
40
|
}
|
|
40
|
-
.
|
|
41
|
+
.gridui-u-w-full {
|
|
42
|
+
width: 100%;
|
|
43
|
+
}
|
|
44
|
+
.gridui-u-max-w-full {
|
|
41
45
|
max-width: 100%;
|
|
42
46
|
}
|
|
43
|
-
.
|
|
47
|
+
.gridui-u-min-w-0 {
|
|
48
|
+
min-width: 0px;
|
|
49
|
+
}
|
|
50
|
+
.gridui-u-shrink-0 {
|
|
44
51
|
flex-shrink: 0;
|
|
45
52
|
}
|
|
46
|
-
.cursor-pointer {
|
|
53
|
+
.gridui-u-cursor-pointer {
|
|
47
54
|
cursor: pointer;
|
|
48
55
|
}
|
|
49
|
-
.
|
|
56
|
+
.gridui-u-auto-cols-fr {
|
|
57
|
+
grid-auto-columns: minmax(0, 1fr);
|
|
58
|
+
}
|
|
59
|
+
.gridui-u-grid-flow-col {
|
|
60
|
+
grid-auto-flow: column;
|
|
61
|
+
}
|
|
62
|
+
.gridui-u-flex-wrap {
|
|
50
63
|
flex-wrap: wrap;
|
|
51
64
|
}
|
|
52
|
-
.items-center {
|
|
65
|
+
.gridui-u-items-center {
|
|
53
66
|
align-items: center;
|
|
54
67
|
}
|
|
55
|
-
.justify-center {
|
|
68
|
+
.gridui-u-justify-center {
|
|
56
69
|
justify-content: center;
|
|
57
70
|
}
|
|
58
|
-
.gap-px {
|
|
71
|
+
.gridui-u-gap-px {
|
|
59
72
|
gap: 1px;
|
|
60
73
|
}
|
|
61
|
-
.rounded-control {
|
|
74
|
+
.gridui-u-rounded-control {
|
|
62
75
|
border-radius: var(--gridui-control-radius);
|
|
63
76
|
}
|
|
64
|
-
.border {
|
|
77
|
+
.gridui-u-border {
|
|
65
78
|
border-style: var(--tw-border-style);
|
|
66
79
|
border-width: 1px;
|
|
67
80
|
}
|
|
68
|
-
.border-0 {
|
|
81
|
+
.gridui-u-border-0 {
|
|
69
82
|
border-style: var(--tw-border-style);
|
|
70
83
|
border-width: 0px;
|
|
71
84
|
}
|
|
72
|
-
.border-
|
|
85
|
+
.gridui-u-border-x-0 {
|
|
86
|
+
border-inline-style: var(--tw-border-style);
|
|
87
|
+
border-inline-width: 0px;
|
|
88
|
+
}
|
|
89
|
+
.gridui-u-border-t-0 {
|
|
90
|
+
border-top-style: var(--tw-border-style);
|
|
91
|
+
border-top-width: 0px;
|
|
92
|
+
}
|
|
93
|
+
.gridui-u-border-solid {
|
|
94
|
+
--tw-border-style: solid;
|
|
95
|
+
border-style: solid;
|
|
96
|
+
}
|
|
97
|
+
.gridui-u-border-border {
|
|
73
98
|
border-color: var(--gridui-border);
|
|
74
99
|
}
|
|
75
|
-
.border-control-border {
|
|
100
|
+
.gridui-u-border-control-border {
|
|
76
101
|
border-color: var(--gridui-control-border);
|
|
77
102
|
}
|
|
78
|
-
.
|
|
103
|
+
.gridui-u-border-transparent {
|
|
104
|
+
border-color: transparent;
|
|
105
|
+
}
|
|
106
|
+
.gridui-u-bg-background {
|
|
79
107
|
background-color: var(--gridui-background);
|
|
80
108
|
}
|
|
81
|
-
.bg-border {
|
|
109
|
+
.gridui-u-bg-border {
|
|
82
110
|
background-color: var(--gridui-border);
|
|
83
111
|
}
|
|
84
|
-
.bg-surface {
|
|
112
|
+
.gridui-u-bg-surface {
|
|
85
113
|
background-color: var(--gridui-surface);
|
|
86
114
|
}
|
|
87
|
-
.p-0\.5 {
|
|
115
|
+
.gridui-u-p-0\.5 {
|
|
88
116
|
padding: calc(var(--spacing) * 0.5);
|
|
89
117
|
}
|
|
90
|
-
.px-gridui-
|
|
118
|
+
.gridui-u-px-gridui-8 {
|
|
119
|
+
padding-inline: var(--gridui-space-8);
|
|
120
|
+
}
|
|
121
|
+
.gridui-u-px-gridui-16 {
|
|
91
122
|
padding-inline: var(--gridui-space-16);
|
|
92
123
|
}
|
|
93
|
-
.py-gridui-8 {
|
|
124
|
+
.gridui-u-py-gridui-8 {
|
|
94
125
|
padding-block: var(--gridui-space-8);
|
|
95
126
|
}
|
|
96
|
-
.
|
|
127
|
+
.gridui-u-py-gridui-16 {
|
|
128
|
+
padding-block: var(--gridui-space-16);
|
|
129
|
+
}
|
|
130
|
+
.gridui-u-text-center {
|
|
131
|
+
text-align: center;
|
|
132
|
+
}
|
|
133
|
+
.gridui-u-align-middle {
|
|
97
134
|
vertical-align: middle;
|
|
98
135
|
}
|
|
99
|
-
.type-ui {
|
|
136
|
+
.gridui-u-type-ui {
|
|
100
137
|
font: var(--gridui-type-ui);
|
|
101
138
|
letter-spacing: normal;
|
|
102
139
|
}
|
|
103
|
-
.
|
|
140
|
+
.gridui-u-wrap-anywhere {
|
|
141
|
+
overflow-wrap: anywhere;
|
|
142
|
+
}
|
|
143
|
+
.gridui-u-whitespace-normal {
|
|
144
|
+
white-space: normal;
|
|
145
|
+
}
|
|
146
|
+
.gridui-u-text-foreground {
|
|
104
147
|
color: var(--gridui-foreground);
|
|
105
148
|
}
|
|
106
149
|
@media (hover: hover) {
|
|
107
|
-
.hover\:enabled\:bg-surface-hover:hover:enabled {
|
|
150
|
+
.gridui-u-hover\:enabled\:bg-surface-hover:hover:enabled {
|
|
108
151
|
background-color: var(--gridui-surface-hover);
|
|
109
152
|
}
|
|
110
153
|
}
|
|
111
|
-
.aria-invalid\:border-danger-foreground[aria-invalid="true"] {
|
|
154
|
+
.gridui-u-aria-invalid\:border-danger-foreground[aria-invalid="true"] {
|
|
112
155
|
border-color: var(--gridui-danger-foreground);
|
|
113
156
|
}
|
|
114
|
-
.data-disabled\:cursor-not-allowed[data-disabled] {
|
|
157
|
+
.gridui-u-data-disabled\:cursor-not-allowed[data-disabled] {
|
|
115
158
|
cursor: not-allowed;
|
|
116
159
|
}
|
|
117
|
-
.data-disabled\:opacity-50[data-disabled] {
|
|
160
|
+
.gridui-u-data-disabled\:opacity-50[data-disabled] {
|
|
118
161
|
opacity: 50%;
|
|
119
162
|
}
|
|
120
|
-
.data-readonly\:cursor-default[data-readonly] {
|
|
163
|
+
.gridui-u-data-readonly\:cursor-default[data-readonly] {
|
|
121
164
|
cursor: default;
|
|
122
165
|
}
|
|
123
|
-
.data-\[orientation\=
|
|
166
|
+
.gridui-u-data-\[orientation\=horizontal\]\:border-b-2[data-orientation="horizontal"] {
|
|
167
|
+
border-bottom-style: var(--tw-border-style);
|
|
168
|
+
border-bottom-width: 2px;
|
|
169
|
+
}
|
|
170
|
+
.gridui-u-data-\[orientation\=vertical\]\:grid-flow-row[data-orientation="vertical"] {
|
|
171
|
+
grid-auto-flow: row;
|
|
172
|
+
}
|
|
173
|
+
.gridui-u-data-\[orientation\=vertical\]\:auto-rows-fr[data-orientation="vertical"] {
|
|
174
|
+
grid-auto-rows: minmax(0, 1fr);
|
|
175
|
+
}
|
|
176
|
+
.gridui-u-data-\[orientation\=vertical\]\:grid-cols-1[data-orientation="vertical"] {
|
|
177
|
+
grid-template-columns: repeat(1, minmax(0, 1fr));
|
|
178
|
+
}
|
|
179
|
+
.gridui-u-data-\[orientation\=vertical\]\:flex-col[data-orientation="vertical"] {
|
|
124
180
|
flex-direction: column;
|
|
125
181
|
}
|
|
126
|
-
.data-\[
|
|
182
|
+
.gridui-u-data-\[orientation\=vertical\]\:border-r-2[data-orientation="vertical"] {
|
|
183
|
+
border-right-style: var(--tw-border-style);
|
|
184
|
+
border-right-width: 2px;
|
|
185
|
+
}
|
|
186
|
+
.gridui-u-data-\[orientation\=vertical\]\:border-b-0[data-orientation="vertical"] {
|
|
187
|
+
border-bottom-style: var(--tw-border-style);
|
|
188
|
+
border-bottom-width: 0px;
|
|
189
|
+
}
|
|
190
|
+
.gridui-u-data-\[state\=checked\]\:bg-accent-background[data-state="checked"] {
|
|
127
191
|
background-color: var(--gridui-accent-background);
|
|
128
192
|
}
|
|
129
|
-
.data-\[state\=checked\]\:text-accent-foreground[data-state="checked"] {
|
|
193
|
+
.gridui-u-data-\[state\=checked\]\:text-accent-foreground[data-state="checked"] {
|
|
130
194
|
color: var(--gridui-accent-foreground);
|
|
131
195
|
}
|
|
132
|
-
.data-\[state\=indeterminate\]\:bg-accent-background[data-state="indeterminate"] {
|
|
196
|
+
.gridui-u-data-\[state\=indeterminate\]\:bg-accent-background[data-state="indeterminate"] {
|
|
133
197
|
background-color: var(--gridui-accent-background);
|
|
134
198
|
}
|
|
135
|
-
.data-\[state\=indeterminate\]\:text-accent-foreground[data-state="indeterminate"] {
|
|
199
|
+
.gridui-u-data-\[state\=indeterminate\]\:text-accent-foreground[data-state="indeterminate"] {
|
|
136
200
|
color: var(--gridui-accent-foreground);
|
|
137
201
|
}
|
|
138
|
-
.data-\[state\=on\]\:
|
|
202
|
+
.gridui-u-data-\[state\=on\]\:border-foreground[data-state="on"] {
|
|
203
|
+
border-color: var(--gridui-foreground);
|
|
204
|
+
}
|
|
205
|
+
.gridui-u-data-\[state\=on\]\:bg-accent-background[data-state="on"] {
|
|
139
206
|
background-color: var(--gridui-accent-background);
|
|
140
207
|
}
|
|
141
|
-
.data-\[state\=on\]\:
|
|
208
|
+
.gridui-u-data-\[state\=on\]\:bg-brand-tint[data-state="on"] {
|
|
209
|
+
background-color: var(--gridui-brand-tint);
|
|
210
|
+
}
|
|
211
|
+
.gridui-u-data-\[state\=on\]\:font-medium[data-state="on"] {
|
|
212
|
+
--tw-font-weight: var(--font-weight-medium);
|
|
213
|
+
font-weight: var(--font-weight-medium);
|
|
214
|
+
}
|
|
215
|
+
.gridui-u-data-\[state\=on\]\:text-accent-foreground[data-state="on"] {
|
|
142
216
|
color: var(--gridui-accent-foreground);
|
|
143
217
|
}
|
|
218
|
+
.gridui-u-data-\[state\=on\]\:text-foreground[data-state="on"] {
|
|
219
|
+
color: var(--gridui-foreground);
|
|
220
|
+
}
|
|
144
221
|
@media (hover: hover) {
|
|
145
|
-
.data-\[state\=on\]\:hover\:enabled\:bg-accent-background[data-state="on"]:hover:enabled {
|
|
222
|
+
.gridui-u-data-\[state\=on\]\:hover\:enabled\:bg-accent-background[data-state="on"]:hover:enabled {
|
|
146
223
|
background-color: var(--gridui-accent-background);
|
|
147
224
|
}
|
|
225
|
+
.gridui-u-data-\[state\=on\]\:hover\:enabled\:bg-brand-tint[data-state="on"]:hover:enabled {
|
|
226
|
+
background-color: var(--gridui-brand-tint);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
.gridui-u-rtl\:data-\[orientation\=vertical\]\:border-r-0:where(:dir(rtl), [dir="rtl"], [dir="rtl"] *)[data-orientation="vertical"] {
|
|
230
|
+
border-right-style: var(--tw-border-style);
|
|
231
|
+
border-right-width: 0px;
|
|
232
|
+
}
|
|
233
|
+
.gridui-u-rtl\:data-\[orientation\=vertical\]\:border-l-2:where(:dir(rtl), [dir="rtl"], [dir="rtl"] *)[data-orientation="vertical"] {
|
|
234
|
+
border-left-style: var(--tw-border-style);
|
|
235
|
+
border-left-width: 2px;
|
|
148
236
|
}
|
|
149
237
|
}
|
|
150
238
|
@layer components {
|
|
@@ -174,10 +262,15 @@
|
|
|
174
262
|
inherits: false;
|
|
175
263
|
initial-value: solid;
|
|
176
264
|
}
|
|
265
|
+
@property --tw-font-weight {
|
|
266
|
+
syntax: "*";
|
|
267
|
+
inherits: false;
|
|
268
|
+
}
|
|
177
269
|
@layer properties {
|
|
178
270
|
@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
|
|
179
271
|
*, ::before, ::after, ::backdrop {
|
|
180
272
|
--tw-border-style: solid;
|
|
273
|
+
--tw-font-weight: initial;
|
|
181
274
|
}
|
|
182
275
|
}
|
|
183
276
|
}
|
|
@@ -4,4 +4,6 @@
|
|
|
4
4
|
* @namespace ToggleGroup
|
|
5
5
|
* @description Style
|
|
6
6
|
*/
|
|
7
|
-
export declare const toggleGroupStyles: (props?:
|
|
7
|
+
export declare const toggleGroupStyles: (props?: ({
|
|
8
|
+
layout?: "standard" | "cells" | null | undefined;
|
|
9
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
@@ -12,5 +12,6 @@ export type ToggleGroupProps = Omit<ComponentPropsWithRef<typeof Primitive.Root>
|
|
|
12
12
|
readonly defaultValue?: string[] | undefined;
|
|
13
13
|
readonly onValueChange?: ((value: string[]) => void) | undefined;
|
|
14
14
|
readonly loopFocus?: boolean | undefined;
|
|
15
|
+
readonly layout?: "standard" | "cells" | undefined;
|
|
15
16
|
};
|
|
16
17
|
export declare const ToggleGroup: FC<ToggleGroupProps>;
|
|
@@ -4,4 +4,6 @@
|
|
|
4
4
|
* @namespace ToggleGroupItem
|
|
5
5
|
* @description Style
|
|
6
6
|
*/
|
|
7
|
-
export declare const toggleStyles: (props?:
|
|
7
|
+
export declare const toggleStyles: (props?: ({
|
|
8
|
+
layout?: "standard" | "cells" | null | undefined;
|
|
9
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Tabs and choice controls
|
|
2
|
+
|
|
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.
|
|
5
|
+
Native refs, form ownership, and accessibility props are forwarded. Choice change
|
|
6
|
+
details expose the native `event`, `cancel()`, and `isCanceled`. GridUI accepts string class names, with semantic tokens and no required
|
|
7
|
+
animation library. Provide a visible associated label or an accessible name.
|
|
8
|
+
|
|
9
|
+
## Tabs
|
|
10
|
+
|
|
11
|
+
Compose `Tabs`, `TabsList`, `TabsTab`, and `TabsPanel`. Values are stable strings;
|
|
12
|
+
use `value`/`onValueChange` for controlled state or `defaultValue` otherwise. Use
|
|
13
|
+
`null` for no active tab. Set an explicit enabled initial value for deterministic
|
|
14
|
+
SSR. The root supplies `orientation="horizontal" | "vertical"`.
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
<Tabs defaultValue="preview">
|
|
18
|
+
<TabsList aria-label="Result views">
|
|
19
|
+
<TabsTab value="preview">Preview</TabsTab>
|
|
20
|
+
<TabsTab value="source">Source</TabsTab>
|
|
21
|
+
</TabsList>
|
|
22
|
+
<TabsPanel value="preview">Rendered result</TabsPanel>
|
|
23
|
+
<TabsPanel value="source" keepMounted>Editable source</TabsPanel>
|
|
24
|
+
</Tabs>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The list defaults to manual activation: arrow keys move focus, Enter/Space selects.
|
|
28
|
+
Use `activateOnFocus` for automatic activation. Disabled tabs remain focusable for discovery but cannot be activated. Radix owns Home/End, roving focus, and tab/panel associations.
|
|
29
|
+
GridUI preserves selection fallback when an uncontrolled selected tab disappears.
|
|
30
|
+
Fallback only considers tabs owned by that root; nested tab values are independent. Controlled consumers own that fallback.
|
|
31
|
+
`keepMounted` preserves an inactive panel's draft state while hiding it. These are
|
|
32
|
+
in-page panels, not route links. Do not put nested controls inside a tab button.
|
|
33
|
+
|
|
34
|
+
## Checkbox and Switch
|
|
35
|
+
|
|
36
|
+
`Checkbox` and `Switch` accept `checked`/`onCheckedChange` or `defaultChecked`,
|
|
37
|
+
plus `name`, `value`, `form`, `required`, `disabled`, `readOnly`, and `inputRef`.
|
|
38
|
+
Their hidden native inputs participate in form submission and uncontrolled form
|
|
39
|
+
reset. Disabled inputs are excluded; unchecked inputs are excluded unless
|
|
40
|
+
`uncheckedValue` is supplied. Controlled consumers must update their own state
|
|
41
|
+
on form reset. Do not use a switch to represent a multi-value selection.
|
|
42
|
+
|
|
43
|
+
`Checkbox indeterminate` represents mixed selection independently of `checked`.
|
|
44
|
+
The application computes and clears the mixed state. Use the callback's boolean
|
|
45
|
+
to update the child collection. A required checkbox must be checked to submit.
|
|
46
|
+
|
|
47
|
+
Required Checkbox and Switch validation focuses the first invalid visible control,
|
|
48
|
+
preserving keyboard operation. Applications own visible error messages and
|
|
49
|
+
`aria-invalid`; native form `onInvalid` handlers can provide that feedback.
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
<label><Checkbox name="consent" required /> Accept the terms</label>
|
|
53
|
+
<label><Switch name="notifications" defaultChecked /> Enable notifications</label>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## ToggleGroup
|
|
57
|
+
|
|
58
|
+
Compose `ToggleGroup` and `ToggleGroupItem value="..."`. Both controlled `value`
|
|
59
|
+
and uncontrolled `defaultValue` are arrays of strings, including single-selection
|
|
60
|
+
mode. `multiple` enables independent pressed items. An empty array means none;
|
|
61
|
+
pressing the sole selected item can request an empty selection. A controlled
|
|
62
|
+
application filter can retain its current value when that request is empty.
|
|
63
|
+
Use `RadioGroup` from `@gridui/radio-group` for an exclusive, required form choice. See the
|
|
64
|
+
[radio family contract](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/radio-group/README.md). `orientation`, `loopFocus`,
|
|
65
|
+
and `disabled` are forwarded. Items are buttons with `aria-pressed` and do not submit a surrounding
|
|
66
|
+
form. The group does not create hidden form inputs; consumers serialize values
|
|
67
|
+
explicitly. Supply an accessible group label and labels for icon-only items.
|
|
68
|
+
Selected items retain their accent foreground/background pair while hovered;
|
|
69
|
+
unselected enabled items use the neutral hover surface.
|
|
70
|
+
|
|
71
|
+
## CopyButton
|
|
72
|
+
|
|
73
|
+
`CopyButton` takes `value`, `label`, `copiedLabel`, and `failedLabel`, plus Button
|
|
74
|
+
presentation props. It waits for clipboard completion before reporting success,
|
|
75
|
+
blocks concurrent clicks, and ignores stale results after the value changes.
|
|
76
|
+
On failure it displays a read-only textarea, focuses it, and selects its text for
|
|
77
|
+
manual copying. There are no global notices or reset timers. Keep CopyPath for
|
|
78
|
+
interfaces where the value should always remain visible.
|
|
79
|
+
|
|
80
|
+
Storybook provides controlled and uncontrolled Tabs, manual/automatic and vertical
|
|
81
|
+
navigation, mixed selection, form submission/reset, read-only/disabled/invalid
|
|
82
|
+
choices, and single/multiple ToggleGroup examples. Cross-package browser tests
|
|
83
|
+
own keyboard, focus, and native form interaction checks.
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridui/choice",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "GridUI React choice",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
|
+
"docs",
|
|
9
10
|
"README.md"
|
|
10
11
|
],
|
|
11
12
|
"sideEffects": [
|
|
@@ -26,19 +27,21 @@
|
|
|
26
27
|
"react-dom": "^19.2.0"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@gridui/form": "^2.0.
|
|
30
|
-
"@gridui/interaction": "^1.1.
|
|
31
|
-
"@gridui/style-utils": "^2.1.
|
|
32
|
-
"@gridui/theme": "^2.2
|
|
30
|
+
"@gridui/form": "^2.0.2",
|
|
31
|
+
"@gridui/interaction": "^1.1.2",
|
|
32
|
+
"@gridui/style-utils": "^2.1.4",
|
|
33
|
+
"@gridui/theme": "^2.3.2",
|
|
33
34
|
"@radix-ui/react-checkbox": "1.4.1",
|
|
34
35
|
"@radix-ui/react-switch": "1.4.1",
|
|
35
36
|
"@radix-ui/react-toggle-group": "1.2.1",
|
|
36
37
|
"class-variance-authority": "0.7.1",
|
|
37
|
-
"lucide-react": "1.
|
|
38
|
+
"lucide-react": "1.65.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@gridui-internal/configuration": "0.0.0-internal",
|
|
42
|
+
"@gridui/button": "2.2.0",
|
|
41
43
|
"@jest/globals": "30.5.2",
|
|
44
|
+
"@storybook/react-vite": "10.6.5",
|
|
42
45
|
"@types/jest": "30.0.0",
|
|
43
46
|
"@types/node": "26.6.6",
|
|
44
47
|
"@types/react": "19.3.0",
|