@plexui/ui 0.38.0 → 0.39.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/dist/es/components/ToggleGroup/ToggleGroup.js +38 -0
- package/dist/es/components/ToggleGroup/ToggleGroup.js.map +1 -0
- package/dist/es/components/ToggleGroup/index.js +2 -0
- package/dist/es/components/ToggleGroup/index.js.map +1 -0
- package/dist/types/components/ToggleGroup/ToggleGroup.d.ts +80 -0
- package/dist/types/components/ToggleGroup/index.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { ToggleGroup as RadixToggleGroup } from "radix-ui";
|
|
5
|
+
import { createContext, useContext, useState } from "react";
|
|
6
|
+
import s from "@plexui/styles/components/ToggleGroup/ToggleGroup.module.css";
|
|
7
|
+
import {} from "../../types.js";
|
|
8
|
+
import { Button } from "../Button/index.js";
|
|
9
|
+
const ToggleGroupContext = createContext(null);
|
|
10
|
+
const NO_VALUE = [];
|
|
11
|
+
/**
|
|
12
|
+
* A row of buttons that each stay pressed or not, any number at a time, such as the days an alarm repeats on.
|
|
13
|
+
* For one choice out of several, use SegmentedControl or RadioGroup.
|
|
14
|
+
*/
|
|
15
|
+
const ToggleGroupRoot = (props) => {
|
|
16
|
+
const { value: valueProp, defaultValue = NO_VALUE, onChange, color = "primary", size = "md", pill = false, uniform = false, block = false, disabled = false, className, children, ...restProps } = props;
|
|
17
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
18
|
+
const value = valueProp ?? internalValue;
|
|
19
|
+
const handleValueChange = (next) => {
|
|
20
|
+
if (valueProp === undefined)
|
|
21
|
+
setInternalValue(next);
|
|
22
|
+
onChange?.(next);
|
|
23
|
+
};
|
|
24
|
+
return (_jsx(RadixToggleGroup.Root, { type: "multiple", className: clsx(s.ToggleGroup, className), value: value, onValueChange: handleValueChange, disabled: disabled, "data-slot": "toggle-group", "data-block": block ? "" : undefined, ...restProps, children: _jsx(ToggleGroupContext.Provider, { value: { value, color, size, pill, uniform, disabled }, children: children }) }));
|
|
25
|
+
};
|
|
26
|
+
const ToggleGroupItem = (props) => {
|
|
27
|
+
const { value, disabled, className, children, ...restProps } = props;
|
|
28
|
+
const group = useContext(ToggleGroupContext);
|
|
29
|
+
if (!group)
|
|
30
|
+
throw new Error("ToggleGroup.Item must be rendered inside a ToggleGroup");
|
|
31
|
+
const pressed = group.value.includes(value);
|
|
32
|
+
return (_jsx(RadixToggleGroup.Item, { value: value, disabled: disabled, asChild: true, children: _jsx(Button, { className: clsx(s.Item, className), color: pressed ? group.color : "secondary", variant: pressed ? "solid" : "soft", size: group.size, pill: group.pill, uniform: group.uniform,
|
|
33
|
+
// Inert rather than Button's disabled look, which paints a pressed and a released item alike: a disabled
|
|
34
|
+
// item keeps its state at half opacity (ToggleGroup.module.css). Radix Toggle's own two attributes give way.
|
|
35
|
+
disabled: undefined, "data-disabled": undefined, inert: group.disabled || !!disabled, ...restProps, children: children }) }));
|
|
36
|
+
};
|
|
37
|
+
export const ToggleGroup = Object.assign(ToggleGroupRoot, { Item: ToggleGroupItem });
|
|
38
|
+
//# sourceMappingURL=ToggleGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToggleGroup.js","sourceRoot":"","sources":["../../../../src/components/ToggleGroup/ToggleGroup.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAmC,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC5F,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAyC,MAAM,aAAa,CAAA;AACnE,OAAO,EAAE,M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radix-ui\"\nimport { createContext, type MouseEvent, type ReactNode, useContext, useState } from \"react\"\nimport s from \"@plexui/styles/components/ToggleGroup/ToggleGroup.module.css\"\nimport { type ControlSize, type SemanticColors } from \"../../types\"\nimport { Button } from \"../Button\"\n\ntype ToggleGroupColor = SemanticColors<\n \"primary\" | \"secondary\" | \"danger\" | \"success\" | \"info\" | \"discovery\" | \"caution\" | \"warning\"\n>\n\ntype ToggleGroupContextValue = {\n value: readonly string[]\n color: ToggleGroupColor\n size: ControlSize\n pill: boolean\n uniform: boolean\n disabled: boolean\n}\n\nconst ToggleGroupContext = createContext<ToggleGroupContextValue | null>(null)\n\nexport type ToggleGroupProps = {\n /** The values of the pressed items (controlled). */\n value?: string[]\n /**\n * The values of the items pressed when the group is first rendered (uncontrolled).\n * @default []\n */\n defaultValue?: string[]\n /** Called with the values of the pressed items when one is pressed or released, a newly pressed one last. */\n onChange?: (value: string[]) => void\n /**\n * The fill of a pressed item, a solid button in this color. An item that is not pressed is a soft secondary button.\n * @default primary\n */\n color?: ToggleGroupColor\n /**\n * The size of the items, as the Button sizes.\n * @default md\n */\n size?: ControlSize\n /**\n * Fully rounded items. With `uniform`, each item is a circle.\n * @default false\n */\n pill?: boolean\n /**\n * Items as wide as they are tall, for a letter or an icon.\n * @default false\n */\n uniform?: boolean\n /**\n * Fills the width of its container and spreads the items across it, the first and the last at the edges.\n * @default false\n */\n block?: boolean\n /**\n * Disables every item.\n * @default false\n */\n disabled?: boolean\n /**\n * The reading direction of the items, which the arrow keys follow.\n * @default \"ltr\"\n */\n dir?: \"ltr\" | \"rtl\"\n /** Accessible name of the group, when no visible label names it. */\n \"aria-label\"?: string\n /** The id of the visible label of the group. */\n \"aria-labelledby\"?: string\n /** The id of the group. */\n id?: string\n /** CSS classes applied to the group. */\n className?: string\n /** The items, each a `ToggleGroup.Item`. */\n children: ReactNode\n}\n\nconst NO_VALUE: string[] = []\n\n/**\n * A row of buttons that each stay pressed or not, any number at a time, such as the days an alarm repeats on.\n * For one choice out of several, use SegmentedControl or RadioGroup.\n */\nconst ToggleGroupRoot = (props: ToggleGroupProps) => {\n const {\n value: valueProp,\n defaultValue = NO_VALUE,\n onChange,\n color = \"primary\",\n size = \"md\",\n pill = false,\n uniform = false,\n block = false,\n disabled = false,\n className,\n children,\n ...restProps\n } = props\n const [internalValue, setInternalValue] = useState(defaultValue)\n const value = valueProp ?? internalValue\n\n const handleValueChange = (next: string[]) => {\n if (valueProp === undefined) setInternalValue(next)\n onChange?.(next)\n }\n\n return (\n <RadixToggleGroup.Root\n type=\"multiple\"\n className={clsx(s.ToggleGroup, className)}\n value={value}\n onValueChange={handleValueChange}\n disabled={disabled}\n data-slot=\"toggle-group\"\n data-block={block ? \"\" : undefined}\n {...restProps}\n >\n <ToggleGroupContext.Provider value={{ value, color, size, pill, uniform, disabled }}>{children}</ToggleGroupContext.Provider>\n </RadixToggleGroup.Root>\n )\n}\n\nexport type ToggleGroupItemProps = {\n /** The value of the item, in the group's `value` while it is pressed. */\n value: string\n /**\n * Disables the item.\n * @default false\n */\n disabled?: boolean\n /** Accessible name of the item, when its content does not say it in full, such as a weekday's letter. */\n \"aria-label\"?: string\n /** Called on a click before the item is pressed or released; `event.preventDefault()` keeps it as it is. */\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void\n /** CSS classes applied to the item. */\n className?: string\n /** The content of the item: a label, a letter or an icon. */\n children: ReactNode\n}\n\nconst ToggleGroupItem = (props: ToggleGroupItemProps) => {\n const { value, disabled, className, children, ...restProps } = props\n const group = useContext(ToggleGroupContext)\n if (!group) throw new Error(\"ToggleGroup.Item must be rendered inside a ToggleGroup\")\n const pressed = group.value.includes(value)\n return (\n <RadixToggleGroup.Item value={value} disabled={disabled} asChild>\n <Button\n className={clsx(s.Item, className)}\n color={pressed ? group.color : \"secondary\"}\n variant={pressed ? \"solid\" : \"soft\"}\n size={group.size}\n pill={group.pill}\n uniform={group.uniform}\n // Inert rather than Button's disabled look, which paints a pressed and a released item alike: a disabled\n // item keeps its state at half opacity (ToggleGroup.module.css). Radix Toggle's own two attributes give way.\n disabled={undefined}\n data-disabled={undefined}\n inert={group.disabled || !!disabled}\n {...restProps}\n >\n {children}\n </Button>\n </RadixToggleGroup.Item>\n )\n}\n\nexport const ToggleGroup = Object.assign(ToggleGroupRoot, { Item: ToggleGroupItem })\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ToggleGroup/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoD,MAAM,eAAe,CAAA","sourcesContent":["export { ToggleGroup, type ToggleGroupItemProps, type ToggleGroupProps } from \"./ToggleGroup\"\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type MouseEvent, type ReactNode } from "react";
|
|
2
|
+
import { type ControlSize, type SemanticColors } from "../../types.js";
|
|
3
|
+
type ToggleGroupColor = SemanticColors<"primary" | "secondary" | "danger" | "success" | "info" | "discovery" | "caution" | "warning">;
|
|
4
|
+
export type ToggleGroupProps = {
|
|
5
|
+
/** The values of the pressed items (controlled). */
|
|
6
|
+
value?: string[];
|
|
7
|
+
/**
|
|
8
|
+
* The values of the items pressed when the group is first rendered (uncontrolled).
|
|
9
|
+
* @default []
|
|
10
|
+
*/
|
|
11
|
+
defaultValue?: string[];
|
|
12
|
+
/** Called with the values of the pressed items when one is pressed or released, a newly pressed one last. */
|
|
13
|
+
onChange?: (value: string[]) => void;
|
|
14
|
+
/**
|
|
15
|
+
* The fill of a pressed item, a solid button in this color. An item that is not pressed is a soft secondary button.
|
|
16
|
+
* @default primary
|
|
17
|
+
*/
|
|
18
|
+
color?: ToggleGroupColor;
|
|
19
|
+
/**
|
|
20
|
+
* The size of the items, as the Button sizes.
|
|
21
|
+
* @default md
|
|
22
|
+
*/
|
|
23
|
+
size?: ControlSize;
|
|
24
|
+
/**
|
|
25
|
+
* Fully rounded items. With `uniform`, each item is a circle.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
pill?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Items as wide as they are tall, for a letter or an icon.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
uniform?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Fills the width of its container and spreads the items across it, the first and the last at the edges.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
block?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Disables every item.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The reading direction of the items, which the arrow keys follow.
|
|
46
|
+
* @default "ltr"
|
|
47
|
+
*/
|
|
48
|
+
dir?: "ltr" | "rtl";
|
|
49
|
+
/** Accessible name of the group, when no visible label names it. */
|
|
50
|
+
"aria-label"?: string;
|
|
51
|
+
/** The id of the visible label of the group. */
|
|
52
|
+
"aria-labelledby"?: string;
|
|
53
|
+
/** The id of the group. */
|
|
54
|
+
id?: string;
|
|
55
|
+
/** CSS classes applied to the group. */
|
|
56
|
+
className?: string;
|
|
57
|
+
/** The items, each a `ToggleGroup.Item`. */
|
|
58
|
+
children: ReactNode;
|
|
59
|
+
};
|
|
60
|
+
export type ToggleGroupItemProps = {
|
|
61
|
+
/** The value of the item, in the group's `value` while it is pressed. */
|
|
62
|
+
value: string;
|
|
63
|
+
/**
|
|
64
|
+
* Disables the item.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
/** Accessible name of the item, when its content does not say it in full, such as a weekday's letter. */
|
|
69
|
+
"aria-label"?: string;
|
|
70
|
+
/** Called on a click before the item is pressed or released; `event.preventDefault()` keeps it as it is. */
|
|
71
|
+
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
72
|
+
/** CSS classes applied to the item. */
|
|
73
|
+
className?: string;
|
|
74
|
+
/** The content of the item: a label, a letter or an icon. */
|
|
75
|
+
children: ReactNode;
|
|
76
|
+
};
|
|
77
|
+
export declare const ToggleGroup: ((props: ToggleGroupProps) => import("react/jsx-runtime").JSX.Element) & {
|
|
78
|
+
Item: (props: ToggleGroupItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToggleGroup, type ToggleGroupItemProps, type ToggleGroupProps } from "./ToggleGroup.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Modern design system for building high-quality applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@maskito/core": "^5.2.2",
|
|
100
100
|
"@maskito/kit": "^5.2.2",
|
|
101
101
|
"@maskito/react": "^5.2.2",
|
|
102
|
-
"@plexui/styles": "^0.1.
|
|
102
|
+
"@plexui/styles": "^0.1.44",
|
|
103
103
|
"@radix-ui/react-dismissable-layer": "1.2.1",
|
|
104
104
|
"@radix-ui/react-focus-guards": "1.2.0",
|
|
105
105
|
"@radix-ui/react-focus-scope": "1.3.1",
|