@cerberus-design/react 0.5.2-next-b5db70c → 0.5.2-next-7d39ff1

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.
Files changed (53) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.ts +37 -0
  2. package/build/legacy/{chunk-LQD23PG3.js → chunk-3CBN7U25.js} +2 -2
  3. package/build/legacy/chunk-5MNCW677.js +11 -0
  4. package/build/legacy/chunk-5MNCW677.js.map +1 -0
  5. package/build/legacy/chunk-734PGVLT.js +58 -0
  6. package/build/legacy/chunk-734PGVLT.js.map +1 -0
  7. package/build/{modern/chunk-MYDNNVMZ.js → legacy/chunk-HE3HFKYU.js} +4 -4
  8. package/build/legacy/chunk-SCQVXJBT.js +22 -0
  9. package/build/legacy/chunk-SCQVXJBT.js.map +1 -0
  10. package/build/legacy/{chunk-SZ2JQBP4.js → chunk-X4YQ27D5.js} +5 -5
  11. package/build/legacy/components/Input.js +4 -4
  12. package/build/legacy/components/Label.js +2 -2
  13. package/build/legacy/components/Toggle.js +11 -0
  14. package/build/legacy/components/Toggle.js.map +1 -0
  15. package/build/legacy/config/cerbIcons.js +1 -1
  16. package/build/legacy/config/defineIcons.js +2 -2
  17. package/build/legacy/hooks/useToggle.js +8 -0
  18. package/build/legacy/hooks/useToggle.js.map +1 -0
  19. package/build/legacy/index.js +22 -14
  20. package/build/modern/_tsup-dts-rollup.d.ts +37 -0
  21. package/build/modern/{chunk-LQD23PG3.js → chunk-3CBN7U25.js} +2 -2
  22. package/build/modern/chunk-5MNCW677.js +11 -0
  23. package/build/modern/chunk-5MNCW677.js.map +1 -0
  24. package/build/modern/chunk-734PGVLT.js +58 -0
  25. package/build/modern/chunk-734PGVLT.js.map +1 -0
  26. package/build/{legacy/chunk-MYDNNVMZ.js → modern/chunk-HE3HFKYU.js} +4 -4
  27. package/build/modern/chunk-QEA6N6TN.js +22 -0
  28. package/build/modern/chunk-QEA6N6TN.js.map +1 -0
  29. package/build/modern/{chunk-SZ2JQBP4.js → chunk-X4YQ27D5.js} +5 -5
  30. package/build/modern/components/Input.js +4 -4
  31. package/build/modern/components/Label.js +2 -2
  32. package/build/modern/components/Toggle.js +11 -0
  33. package/build/modern/components/Toggle.js.map +1 -0
  34. package/build/modern/config/cerbIcons.js +1 -1
  35. package/build/modern/config/defineIcons.js +2 -2
  36. package/build/modern/hooks/useToggle.js +8 -0
  37. package/build/modern/hooks/useToggle.js.map +1 -0
  38. package/build/modern/index.js +22 -14
  39. package/package.json +2 -2
  40. package/src/components/Toggle.tsx +55 -0
  41. package/src/config/cerbIcons.ts +3 -1
  42. package/src/hooks/useToggle.ts +30 -0
  43. package/src/index.ts +2 -0
  44. package/build/legacy/chunk-RK5HK6UU.js +0 -10
  45. package/build/legacy/chunk-RK5HK6UU.js.map +0 -1
  46. package/build/modern/chunk-RK5HK6UU.js +0 -10
  47. package/build/modern/chunk-RK5HK6UU.js.map +0 -1
  48. /package/build/legacy/{chunk-LQD23PG3.js.map → chunk-3CBN7U25.js.map} +0 -0
  49. /package/build/legacy/{chunk-MYDNNVMZ.js.map → chunk-HE3HFKYU.js.map} +0 -0
  50. /package/build/legacy/{chunk-SZ2JQBP4.js.map → chunk-X4YQ27D5.js.map} +0 -0
  51. /package/build/modern/{chunk-LQD23PG3.js.map → chunk-3CBN7U25.js.map} +0 -0
  52. /package/build/modern/{chunk-MYDNNVMZ.js.map → chunk-HE3HFKYU.js.map} +0 -0
  53. /package/build/modern/{chunk-SZ2JQBP4.js.map → chunk-X4YQ27D5.js.map} +0 -0
@@ -2,6 +2,7 @@ import type { AnchorHTMLAttributes } from 'react';
2
2
  import { button } from '@cerberus/styled-system/recipes';
3
3
  import { ButtonHTMLAttributes } from 'react';
4
4
  import { CarbonIconType } from '@cerberus/icons';
5
+ import { ChangeEvent } from 'react';
5
6
  import { Context } from 'react';
6
7
  import { ElementType } from 'react';
7
8
  import { fieldMessage } from '@cerberus/styled-system/recipes';
@@ -21,6 +22,7 @@ import type { RecipeVariantProps as RecipeVariantProps_3 } from '@cerberus/style
21
22
  import { RefObject } from 'react';
22
23
  import { tag } from '@cerberus/styled-system/recipes';
23
24
  import type { TextareaHTMLAttributes } from 'react';
25
+ import { ToggleVariantProps } from '@cerberus-design/styled-system/recipes';
24
26
 
25
27
  declare let $cerberusIcons: DefinedIcons;
26
28
  export { $cerberusIcons }
@@ -72,6 +74,7 @@ export { DefaultThemes as DefaultThemes_alias_1 }
72
74
 
73
75
  export declare interface DefinedIcons {
74
76
  invalid: CarbonIconType | ElementType;
77
+ toggleChecked: CarbonIconType | ElementType;
75
78
  }
76
79
 
77
80
  declare function defineIcons(icons: DefinedIcons): DefinedIcons;
@@ -557,6 +560,29 @@ declare function ThemeProvider(props: PropsWithChildren<unknown>): JSX.Element;
557
560
  export { ThemeProvider }
558
561
  export { ThemeProvider as ThemeProvider_alias_1 }
559
562
 
563
+ declare function Toggle(props: ToggleProps): JSX_2.Element;
564
+ export { Toggle }
565
+ export { Toggle as Toggle_alias_1 }
566
+
567
+ declare type ToggleBase = Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'id' | 'value'> & {
568
+ describedBy?: string;
569
+ id: string;
570
+ value: string;
571
+ };
572
+ export { ToggleBase }
573
+ export { ToggleBase as ToggleBase_alias_1 }
574
+
575
+ declare interface ToggleHookReturn {
576
+ checked: string;
577
+ handleChange: (e: ChangeEvent<HTMLInputElement>) => void;
578
+ }
579
+ export { ToggleHookReturn }
580
+ export { ToggleHookReturn as ToggleHookReturn_alias_1 }
581
+
582
+ declare type ToggleProps = ToggleBase & ToggleVariantProps;
583
+ export { ToggleProps }
584
+ export { ToggleProps as ToggleProps_alias_1 }
585
+
560
586
  declare function useFieldContext(): FieldContextValue;
561
587
  export { useFieldContext }
562
588
  export { useFieldContext as useFieldContext_alias_1 }
@@ -583,4 +609,15 @@ declare function useThemeContext(): ThemeContextValue<DefaultThemes>;
583
609
  export { useThemeContext }
584
610
  export { useThemeContext as useThemeContext_alias_1 }
585
611
 
612
+ declare function useToggle(options?: UseToggleOptions): ToggleHookReturn;
613
+ export { useToggle }
614
+ export { useToggle as useToggle_alias_1 }
615
+
616
+ declare interface UseToggleOptions {
617
+ checked?: string;
618
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
619
+ }
620
+ export { UseToggleOptions }
621
+ export { UseToggleOptions as UseToggleOptions_alias_1 }
622
+
586
623
  export { }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "./chunk-RK5HK6UU.js";
3
+ } from "./chunk-5MNCW677.js";
4
4
 
5
5
  // src/config/defineIcons.ts
6
6
  function _validateIconsProperties(icons) {
@@ -21,4 +21,4 @@ export {
21
21
  defineIcons,
22
22
  $cerberusIcons
23
23
  };
24
- //# sourceMappingURL=chunk-LQD23PG3.js.map
24
+ //# sourceMappingURL=chunk-3CBN7U25.js.map
@@ -0,0 +1,11 @@
1
+ // src/config/cerbIcons.ts
2
+ import { Checkmark, WarningFilled } from "@cerberus/icons";
3
+ var defaultIcons = {
4
+ invalid: WarningFilled,
5
+ toggleChecked: Checkmark
6
+ };
7
+
8
+ export {
9
+ defaultIcons
10
+ };
11
+ //# sourceMappingURL=chunk-5MNCW677.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import { Checkmark, WarningFilled, type CarbonIconType } from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n invalid: CarbonIconType | ElementType\n toggleChecked: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n invalid: WarningFilled,\n toggleChecked: Checkmark,\n}\n"],"mappings":";AAAA,SAAS,WAAW,qBAA0C;AAQvD,IAAM,eAA6B;AAAA,EACxC,SAAS;AAAA,EACT,eAAe;AACjB;","names":[]}
@@ -0,0 +1,58 @@
1
+ import {
2
+ useFieldContext
3
+ } from "./chunk-ZAU4JVLL.js";
4
+ import {
5
+ $cerberusIcons
6
+ } from "./chunk-3CBN7U25.js";
7
+
8
+ // src/components/Toggle.tsx
9
+ import { cx } from "@cerberus-design/styled-system/css";
10
+ import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
11
+ import {
12
+ toggle
13
+ } from "@cerberus-design/styled-system/recipes";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ function Toggle(props) {
16
+ const { size, describedBy, ...nativeProps } = props;
17
+ const styles = toggle({ size });
18
+ const { invalid, ...state } = useFieldContext();
19
+ const Icon = $cerberusIcons.toggleChecked;
20
+ return /* @__PURE__ */ jsxs(
21
+ "span",
22
+ {
23
+ className: cx("group", styles.track, hstack()),
24
+ "data-checked": props.checked || props.defaultChecked,
25
+ children: [
26
+ /* @__PURE__ */ jsx(
27
+ "input",
28
+ {
29
+ ...nativeProps,
30
+ ...state,
31
+ ...describedBy && { "aria-describedby": describedBy },
32
+ ...invalid && { "aria-invalid": true },
33
+ className: cx("peer", styles.input),
34
+ role: "switch",
35
+ type: "checkbox"
36
+ }
37
+ ),
38
+ /* @__PURE__ */ jsx(
39
+ "span",
40
+ {
41
+ className: cx(
42
+ styles.thumb,
43
+ vstack({
44
+ justify: "center"
45
+ })
46
+ ),
47
+ children: /* @__PURE__ */ jsx(Icon, {})
48
+ }
49
+ )
50
+ ]
51
+ }
52
+ );
53
+ }
54
+
55
+ export {
56
+ Toggle
57
+ };
58
+ //# sourceMappingURL=chunk-734PGVLT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/Toggle.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus-design/styled-system/css'\nimport { hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport {\n toggle,\n type ToggleVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport type { InputHTMLAttributes } from 'react'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { useFieldContext } from '../context/field'\n\nexport type ToggleBase = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'size' | 'id' | 'value'\n> & {\n describedBy?: string\n id: string\n value: string\n}\nexport type ToggleProps = ToggleBase & ToggleVariantProps\n\nexport function Toggle(props: ToggleProps) {\n const { size, describedBy, ...nativeProps } = props\n const styles = toggle({ size })\n const { invalid, ...state } = useFieldContext()\n const Icon = $cerberusIcons.toggleChecked\n\n return (\n <span\n className={cx('group', styles.track, hstack())}\n data-checked={props.checked || props.defaultChecked}\n >\n <input\n {...nativeProps}\n {...state}\n {...(describedBy && { 'aria-describedby': describedBy })}\n {...(invalid && { 'aria-invalid': true })}\n className={cx('peer', styles.input)}\n role=\"switch\"\n type=\"checkbox\"\n />\n <span\n className={cx(\n styles.thumb,\n vstack({\n justify: 'center',\n }),\n )}\n >\n <Icon />\n </span>\n </span>\n )\n}\n"],"mappings":";;;;;;;;AAEA,SAAS,UAAU;AACnB,SAAS,QAAQ,cAAc;AAC/B;AAAA,EACE;AAAA,OAEK;AAsBH,SAIE,KAJF;AAPG,SAAS,OAAO,OAAoB;AACzC,QAAM,EAAE,MAAM,aAAa,GAAG,YAAY,IAAI;AAC9C,QAAM,SAAS,OAAO,EAAE,KAAK,CAAC;AAC9B,QAAM,EAAE,SAAS,GAAG,MAAM,IAAI,gBAAgB;AAC9C,QAAM,OAAO,eAAe;AAE5B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,GAAG,SAAS,OAAO,OAAO,OAAO,CAAC;AAAA,MAC7C,gBAAc,MAAM,WAAW,MAAM;AAAA,MAErC;AAAA;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,YACH,GAAG;AAAA,YACH,GAAI,eAAe,EAAE,oBAAoB,YAAY;AAAA,YACrD,GAAI,WAAW,EAAE,gBAAgB,KAAK;AAAA,YACvC,WAAW,GAAG,QAAQ,OAAO,KAAK;AAAA,YAClC,MAAK;AAAA,YACL,MAAK;AAAA;AAAA,QACP;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,WAAW;AAAA,cACT,OAAO;AAAA,cACP,OAAO;AAAA,gBACL,SAAS;AAAA,cACX,CAAC;AAAA,YACH;AAAA,YAEA,8BAAC,QAAK;AAAA;AAAA,QACR;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -1,9 +1,9 @@
1
- import {
2
- Show
3
- } from "./chunk-4O4QFF4S.js";
4
1
  import {
5
2
  useFieldContext
6
3
  } from "./chunk-ZAU4JVLL.js";
4
+ import {
5
+ Show
6
+ } from "./chunk-4O4QFF4S.js";
7
7
 
8
8
  // src/components/Label.tsx
9
9
  import { label } from "@cerberus/styled-system/recipes";
@@ -46,4 +46,4 @@ function Label(props) {
46
46
  export {
47
47
  Label
48
48
  };
49
- //# sourceMappingURL=chunk-MYDNNVMZ.js.map
49
+ //# sourceMappingURL=chunk-HE3HFKYU.js.map
@@ -0,0 +1,22 @@
1
+ // src/hooks/useToggle.ts
2
+ import { useCallback, useMemo, useState } from "react";
3
+ function useToggle(options) {
4
+ const [checked, setChecked] = useState((options == null ? void 0 : options.checked) ?? "");
5
+ const onChange = options == null ? void 0 : options.onChange;
6
+ const handleChange = useCallback(
7
+ (e) => {
8
+ const target = e.currentTarget;
9
+ setChecked((prev) => {
10
+ return prev === target.value ? "" : target.value;
11
+ });
12
+ onChange == null ? void 0 : onChange(e);
13
+ },
14
+ [onChange]
15
+ );
16
+ return useMemo(() => ({ checked, handleChange }), [checked, handleChange]);
17
+ }
18
+
19
+ export {
20
+ useToggle
21
+ };
22
+ //# sourceMappingURL=chunk-SCQVXJBT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useToggle.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useMemo, useState, type ChangeEvent } from 'react'\n\nexport interface UseToggleOptions {\n checked?: string\n onChange?: (e: ChangeEvent<HTMLInputElement>) => void\n}\nexport interface ToggleHookReturn {\n checked: string\n handleChange: (e: ChangeEvent<HTMLInputElement>) => void\n}\n\nexport function useToggle(options?: UseToggleOptions): ToggleHookReturn {\n const [checked, setChecked] = useState<string>(options?.checked ?? '')\n const onChange = options?.onChange\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n const target = e.currentTarget as HTMLInputElement\n setChecked((prev) => {\n return prev === target.value ? '' : target.value\n })\n onChange?.(e)\n },\n [onChange],\n )\n\n return useMemo(() => ({ checked, handleChange }), [checked, handleChange])\n}\n"],"mappings":";AAEA,SAAS,aAAa,SAAS,gBAAkC;AAW1D,SAAS,UAAU,SAA8C;AACtE,QAAM,CAAC,SAAS,UAAU,IAAI,UAAiB,mCAAS,YAAW,EAAE;AACrE,QAAM,WAAW,mCAAS;AAE1B,QAAM,eAAe;AAAA,IACnB,CAAC,MAAqC;AACpC,YAAM,SAAS,EAAE;AACjB,iBAAW,CAAC,SAAS;AACnB,eAAO,SAAS,OAAO,QAAQ,KAAK,OAAO;AAAA,MAC7C,CAAC;AACD,2CAAW;AAAA,IACb;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,SAAO,QAAQ,OAAO,EAAE,SAAS,aAAa,IAAI,CAAC,SAAS,YAAY,CAAC;AAC3E;","names":[]}
@@ -1,12 +1,12 @@
1
- import {
2
- Show
3
- } from "./chunk-4O4QFF4S.js";
4
1
  import {
5
2
  useFieldContext
6
3
  } from "./chunk-ZAU4JVLL.js";
4
+ import {
5
+ Show
6
+ } from "./chunk-4O4QFF4S.js";
7
7
  import {
8
8
  $cerberusIcons
9
- } from "./chunk-LQD23PG3.js";
9
+ } from "./chunk-3CBN7U25.js";
10
10
 
11
11
  // src/components/Input.tsx
12
12
  import { input } from "@cerberus/styled-system/recipes";
@@ -39,4 +39,4 @@ function Input(props) {
39
39
  export {
40
40
  Input
41
41
  };
42
- //# sourceMappingURL=chunk-SZ2JQBP4.js.map
42
+ //# sourceMappingURL=chunk-X4YQ27D5.js.map
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Input
4
- } from "../chunk-SZ2JQBP4.js";
5
- import "../chunk-4O4QFF4S.js";
4
+ } from "../chunk-X4YQ27D5.js";
6
5
  import "../chunk-ZAU4JVLL.js";
7
- import "../chunk-LQD23PG3.js";
8
- import "../chunk-RK5HK6UU.js";
6
+ import "../chunk-4O4QFF4S.js";
7
+ import "../chunk-3CBN7U25.js";
8
+ import "../chunk-5MNCW677.js";
9
9
  export {
10
10
  Input
11
11
  };
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import {
3
3
  Label
4
- } from "../chunk-MYDNNVMZ.js";
5
- import "../chunk-4O4QFF4S.js";
4
+ } from "../chunk-HE3HFKYU.js";
6
5
  import "../chunk-ZAU4JVLL.js";
6
+ import "../chunk-4O4QFF4S.js";
7
7
  export {
8
8
  Label
9
9
  };
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import {
3
+ Toggle
4
+ } from "../chunk-734PGVLT.js";
5
+ import "../chunk-ZAU4JVLL.js";
6
+ import "../chunk-3CBN7U25.js";
7
+ import "../chunk-5MNCW677.js";
8
+ export {
9
+ Toggle
10
+ };
11
+ //# sourceMappingURL=Toggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "../chunk-RK5HK6UU.js";
3
+ } from "../chunk-5MNCW677.js";
4
4
  export {
5
5
  defaultIcons
6
6
  };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  $cerberusIcons,
3
3
  defineIcons
4
- } from "../chunk-LQD23PG3.js";
5
- import "../chunk-RK5HK6UU.js";
4
+ } from "../chunk-3CBN7U25.js";
5
+ import "../chunk-5MNCW677.js";
6
6
  export {
7
7
  $cerberusIcons,
8
8
  defineIcons
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import {
3
+ useToggle
4
+ } from "../chunk-SCQVXJBT.js";
5
+ export {
6
+ useToggle
7
+ };
8
+ //# sourceMappingURL=useToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1,6 @@
1
+ import {
2
+ Radio
3
+ } from "./chunk-WE3JNSNO.js";
1
4
  import {
2
5
  Tab
3
6
  } from "./chunk-YA2UV2AB.js";
@@ -13,6 +16,12 @@ import {
13
16
  import {
14
17
  Textarea
15
18
  } from "./chunk-TCO46FK7.js";
19
+ import {
20
+ Toggle
21
+ } from "./chunk-734PGVLT.js";
22
+ import {
23
+ Button
24
+ } from "./chunk-2ATICEW3.js";
16
25
  import {
17
26
  FieldMessage
18
27
  } from "./chunk-VGHVH2T3.js";
@@ -21,10 +30,14 @@ import {
21
30
  } from "./chunk-SLHX5K6I.js";
22
31
  import {
23
32
  Input
24
- } from "./chunk-SZ2JQBP4.js";
33
+ } from "./chunk-X4YQ27D5.js";
25
34
  import {
26
35
  Label
27
- } from "./chunk-MYDNNVMZ.js";
36
+ } from "./chunk-HE3HFKYU.js";
37
+ import {
38
+ Field,
39
+ useFieldContext
40
+ } from "./chunk-ZAU4JVLL.js";
28
41
  import {
29
42
  NavMenuLink
30
43
  } from "./chunk-6DIGPXAD.js";
@@ -42,13 +55,6 @@ import {
42
55
  import {
43
56
  Show
44
57
  } from "./chunk-4O4QFF4S.js";
45
- import {
46
- Radio
47
- } from "./chunk-WE3JNSNO.js";
48
- import {
49
- Field,
50
- useFieldContext
51
- } from "./chunk-ZAU4JVLL.js";
52
58
  import "./chunk-55J6XMHW.js";
53
59
  import {
54
60
  createNavTriggerProps
@@ -64,8 +70,8 @@ import {
64
70
  import {
65
71
  $cerberusIcons,
66
72
  defineIcons
67
- } from "./chunk-LQD23PG3.js";
68
- import "./chunk-RK5HK6UU.js";
73
+ } from "./chunk-3CBN7U25.js";
74
+ import "./chunk-5MNCW677.js";
69
75
  import {
70
76
  MODE_KEY,
71
77
  THEME_KEY,
@@ -74,8 +80,8 @@ import {
74
80
  useThemeContext
75
81
  } from "./chunk-SXXWC6UD.js";
76
82
  import {
77
- Button
78
- } from "./chunk-2ATICEW3.js";
83
+ useToggle
84
+ } from "./chunk-SCQVXJBT.js";
79
85
  export {
80
86
  $cerberusIcons,
81
87
  Button,
@@ -100,6 +106,7 @@ export {
100
106
  Tag,
101
107
  Textarea,
102
108
  ThemeProvider,
109
+ Toggle,
103
110
  createNavTriggerProps,
104
111
  defineIcons,
105
112
  getPosition,
@@ -108,6 +115,7 @@ export {
108
115
  useTabsContext,
109
116
  useTabsKeyboardNavigation,
110
117
  useTheme,
111
- useThemeContext
118
+ useThemeContext,
119
+ useToggle
112
120
  };
113
121
  //# sourceMappingURL=index.js.map
@@ -2,6 +2,7 @@ import type { AnchorHTMLAttributes } from 'react';
2
2
  import { button } from '@cerberus/styled-system/recipes';
3
3
  import { ButtonHTMLAttributes } from 'react';
4
4
  import { CarbonIconType } from '@cerberus/icons';
5
+ import { ChangeEvent } from 'react';
5
6
  import { Context } from 'react';
6
7
  import { ElementType } from 'react';
7
8
  import { fieldMessage } from '@cerberus/styled-system/recipes';
@@ -21,6 +22,7 @@ import type { RecipeVariantProps as RecipeVariantProps_3 } from '@cerberus/style
21
22
  import { RefObject } from 'react';
22
23
  import { tag } from '@cerberus/styled-system/recipes';
23
24
  import type { TextareaHTMLAttributes } from 'react';
25
+ import { ToggleVariantProps } from '@cerberus-design/styled-system/recipes';
24
26
 
25
27
  declare let $cerberusIcons: DefinedIcons;
26
28
  export { $cerberusIcons }
@@ -72,6 +74,7 @@ export { DefaultThemes as DefaultThemes_alias_1 }
72
74
 
73
75
  export declare interface DefinedIcons {
74
76
  invalid: CarbonIconType | ElementType;
77
+ toggleChecked: CarbonIconType | ElementType;
75
78
  }
76
79
 
77
80
  declare function defineIcons(icons: DefinedIcons): DefinedIcons;
@@ -557,6 +560,29 @@ declare function ThemeProvider(props: PropsWithChildren<unknown>): JSX.Element;
557
560
  export { ThemeProvider }
558
561
  export { ThemeProvider as ThemeProvider_alias_1 }
559
562
 
563
+ declare function Toggle(props: ToggleProps): JSX_2.Element;
564
+ export { Toggle }
565
+ export { Toggle as Toggle_alias_1 }
566
+
567
+ declare type ToggleBase = Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'id' | 'value'> & {
568
+ describedBy?: string;
569
+ id: string;
570
+ value: string;
571
+ };
572
+ export { ToggleBase }
573
+ export { ToggleBase as ToggleBase_alias_1 }
574
+
575
+ declare interface ToggleHookReturn {
576
+ checked: string;
577
+ handleChange: (e: ChangeEvent<HTMLInputElement>) => void;
578
+ }
579
+ export { ToggleHookReturn }
580
+ export { ToggleHookReturn as ToggleHookReturn_alias_1 }
581
+
582
+ declare type ToggleProps = ToggleBase & ToggleVariantProps;
583
+ export { ToggleProps }
584
+ export { ToggleProps as ToggleProps_alias_1 }
585
+
560
586
  declare function useFieldContext(): FieldContextValue;
561
587
  export { useFieldContext }
562
588
  export { useFieldContext as useFieldContext_alias_1 }
@@ -583,4 +609,15 @@ declare function useThemeContext(): ThemeContextValue<DefaultThemes>;
583
609
  export { useThemeContext }
584
610
  export { useThemeContext as useThemeContext_alias_1 }
585
611
 
612
+ declare function useToggle(options?: UseToggleOptions): ToggleHookReturn;
613
+ export { useToggle }
614
+ export { useToggle as useToggle_alias_1 }
615
+
616
+ declare interface UseToggleOptions {
617
+ checked?: string;
618
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
619
+ }
620
+ export { UseToggleOptions }
621
+ export { UseToggleOptions as UseToggleOptions_alias_1 }
622
+
586
623
  export { }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "./chunk-RK5HK6UU.js";
3
+ } from "./chunk-5MNCW677.js";
4
4
 
5
5
  // src/config/defineIcons.ts
6
6
  function _validateIconsProperties(icons) {
@@ -21,4 +21,4 @@ export {
21
21
  defineIcons,
22
22
  $cerberusIcons
23
23
  };
24
- //# sourceMappingURL=chunk-LQD23PG3.js.map
24
+ //# sourceMappingURL=chunk-3CBN7U25.js.map
@@ -0,0 +1,11 @@
1
+ // src/config/cerbIcons.ts
2
+ import { Checkmark, WarningFilled } from "@cerberus/icons";
3
+ var defaultIcons = {
4
+ invalid: WarningFilled,
5
+ toggleChecked: Checkmark
6
+ };
7
+
8
+ export {
9
+ defaultIcons
10
+ };
11
+ //# sourceMappingURL=chunk-5MNCW677.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import { Checkmark, WarningFilled, type CarbonIconType } from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n invalid: CarbonIconType | ElementType\n toggleChecked: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n invalid: WarningFilled,\n toggleChecked: Checkmark,\n}\n"],"mappings":";AAAA,SAAS,WAAW,qBAA0C;AAQvD,IAAM,eAA6B;AAAA,EACxC,SAAS;AAAA,EACT,eAAe;AACjB;","names":[]}
@@ -0,0 +1,58 @@
1
+ import {
2
+ useFieldContext
3
+ } from "./chunk-ZAU4JVLL.js";
4
+ import {
5
+ $cerberusIcons
6
+ } from "./chunk-3CBN7U25.js";
7
+
8
+ // src/components/Toggle.tsx
9
+ import { cx } from "@cerberus-design/styled-system/css";
10
+ import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
11
+ import {
12
+ toggle
13
+ } from "@cerberus-design/styled-system/recipes";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ function Toggle(props) {
16
+ const { size, describedBy, ...nativeProps } = props;
17
+ const styles = toggle({ size });
18
+ const { invalid, ...state } = useFieldContext();
19
+ const Icon = $cerberusIcons.toggleChecked;
20
+ return /* @__PURE__ */ jsxs(
21
+ "span",
22
+ {
23
+ className: cx("group", styles.track, hstack()),
24
+ "data-checked": props.checked || props.defaultChecked,
25
+ children: [
26
+ /* @__PURE__ */ jsx(
27
+ "input",
28
+ {
29
+ ...nativeProps,
30
+ ...state,
31
+ ...describedBy && { "aria-describedby": describedBy },
32
+ ...invalid && { "aria-invalid": true },
33
+ className: cx("peer", styles.input),
34
+ role: "switch",
35
+ type: "checkbox"
36
+ }
37
+ ),
38
+ /* @__PURE__ */ jsx(
39
+ "span",
40
+ {
41
+ className: cx(
42
+ styles.thumb,
43
+ vstack({
44
+ justify: "center"
45
+ })
46
+ ),
47
+ children: /* @__PURE__ */ jsx(Icon, {})
48
+ }
49
+ )
50
+ ]
51
+ }
52
+ );
53
+ }
54
+
55
+ export {
56
+ Toggle
57
+ };
58
+ //# sourceMappingURL=chunk-734PGVLT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/Toggle.tsx"],"sourcesContent":["'use client'\n\nimport { cx } from '@cerberus-design/styled-system/css'\nimport { hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport {\n toggle,\n type ToggleVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport type { InputHTMLAttributes } from 'react'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { useFieldContext } from '../context/field'\n\nexport type ToggleBase = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n 'size' | 'id' | 'value'\n> & {\n describedBy?: string\n id: string\n value: string\n}\nexport type ToggleProps = ToggleBase & ToggleVariantProps\n\nexport function Toggle(props: ToggleProps) {\n const { size, describedBy, ...nativeProps } = props\n const styles = toggle({ size })\n const { invalid, ...state } = useFieldContext()\n const Icon = $cerberusIcons.toggleChecked\n\n return (\n <span\n className={cx('group', styles.track, hstack())}\n data-checked={props.checked || props.defaultChecked}\n >\n <input\n {...nativeProps}\n {...state}\n {...(describedBy && { 'aria-describedby': describedBy })}\n {...(invalid && { 'aria-invalid': true })}\n className={cx('peer', styles.input)}\n role=\"switch\"\n type=\"checkbox\"\n />\n <span\n className={cx(\n styles.thumb,\n vstack({\n justify: 'center',\n }),\n )}\n >\n <Icon />\n </span>\n </span>\n )\n}\n"],"mappings":";;;;;;;;AAEA,SAAS,UAAU;AACnB,SAAS,QAAQ,cAAc;AAC/B;AAAA,EACE;AAAA,OAEK;AAsBH,SAIE,KAJF;AAPG,SAAS,OAAO,OAAoB;AACzC,QAAM,EAAE,MAAM,aAAa,GAAG,YAAY,IAAI;AAC9C,QAAM,SAAS,OAAO,EAAE,KAAK,CAAC;AAC9B,QAAM,EAAE,SAAS,GAAG,MAAM,IAAI,gBAAgB;AAC9C,QAAM,OAAO,eAAe;AAE5B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,GAAG,SAAS,OAAO,OAAO,OAAO,CAAC;AAAA,MAC7C,gBAAc,MAAM,WAAW,MAAM;AAAA,MAErC;AAAA;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,YACH,GAAG;AAAA,YACH,GAAI,eAAe,EAAE,oBAAoB,YAAY;AAAA,YACrD,GAAI,WAAW,EAAE,gBAAgB,KAAK;AAAA,YACvC,WAAW,GAAG,QAAQ,OAAO,KAAK;AAAA,YAClC,MAAK;AAAA,YACL,MAAK;AAAA;AAAA,QACP;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,WAAW;AAAA,cACT,OAAO;AAAA,cACP,OAAO;AAAA,gBACL,SAAS;AAAA,cACX,CAAC;AAAA,YACH;AAAA,YAEA,8BAAC,QAAK;AAAA;AAAA,QACR;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -1,9 +1,9 @@
1
- import {
2
- Show
3
- } from "./chunk-4O4QFF4S.js";
4
1
  import {
5
2
  useFieldContext
6
3
  } from "./chunk-ZAU4JVLL.js";
4
+ import {
5
+ Show
6
+ } from "./chunk-4O4QFF4S.js";
7
7
 
8
8
  // src/components/Label.tsx
9
9
  import { label } from "@cerberus/styled-system/recipes";
@@ -46,4 +46,4 @@ function Label(props) {
46
46
  export {
47
47
  Label
48
48
  };
49
- //# sourceMappingURL=chunk-MYDNNVMZ.js.map
49
+ //# sourceMappingURL=chunk-HE3HFKYU.js.map
@@ -0,0 +1,22 @@
1
+ // src/hooks/useToggle.ts
2
+ import { useCallback, useMemo, useState } from "react";
3
+ function useToggle(options) {
4
+ const [checked, setChecked] = useState(options?.checked ?? "");
5
+ const onChange = options?.onChange;
6
+ const handleChange = useCallback(
7
+ (e) => {
8
+ const target = e.currentTarget;
9
+ setChecked((prev) => {
10
+ return prev === target.value ? "" : target.value;
11
+ });
12
+ onChange?.(e);
13
+ },
14
+ [onChange]
15
+ );
16
+ return useMemo(() => ({ checked, handleChange }), [checked, handleChange]);
17
+ }
18
+
19
+ export {
20
+ useToggle
21
+ };
22
+ //# sourceMappingURL=chunk-QEA6N6TN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useToggle.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useMemo, useState, type ChangeEvent } from 'react'\n\nexport interface UseToggleOptions {\n checked?: string\n onChange?: (e: ChangeEvent<HTMLInputElement>) => void\n}\nexport interface ToggleHookReturn {\n checked: string\n handleChange: (e: ChangeEvent<HTMLInputElement>) => void\n}\n\nexport function useToggle(options?: UseToggleOptions): ToggleHookReturn {\n const [checked, setChecked] = useState<string>(options?.checked ?? '')\n const onChange = options?.onChange\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n const target = e.currentTarget as HTMLInputElement\n setChecked((prev) => {\n return prev === target.value ? '' : target.value\n })\n onChange?.(e)\n },\n [onChange],\n )\n\n return useMemo(() => ({ checked, handleChange }), [checked, handleChange])\n}\n"],"mappings":";AAEA,SAAS,aAAa,SAAS,gBAAkC;AAW1D,SAAS,UAAU,SAA8C;AACtE,QAAM,CAAC,SAAS,UAAU,IAAI,SAAiB,SAAS,WAAW,EAAE;AACrE,QAAM,WAAW,SAAS;AAE1B,QAAM,eAAe;AAAA,IACnB,CAAC,MAAqC;AACpC,YAAM,SAAS,EAAE;AACjB,iBAAW,CAAC,SAAS;AACnB,eAAO,SAAS,OAAO,QAAQ,KAAK,OAAO;AAAA,MAC7C,CAAC;AACD,iBAAW,CAAC;AAAA,IACd;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AAEA,SAAO,QAAQ,OAAO,EAAE,SAAS,aAAa,IAAI,CAAC,SAAS,YAAY,CAAC;AAC3E;","names":[]}
@@ -1,12 +1,12 @@
1
- import {
2
- Show
3
- } from "./chunk-4O4QFF4S.js";
4
1
  import {
5
2
  useFieldContext
6
3
  } from "./chunk-ZAU4JVLL.js";
4
+ import {
5
+ Show
6
+ } from "./chunk-4O4QFF4S.js";
7
7
  import {
8
8
  $cerberusIcons
9
- } from "./chunk-LQD23PG3.js";
9
+ } from "./chunk-3CBN7U25.js";
10
10
 
11
11
  // src/components/Input.tsx
12
12
  import { input } from "@cerberus/styled-system/recipes";
@@ -39,4 +39,4 @@ function Input(props) {
39
39
  export {
40
40
  Input
41
41
  };
42
- //# sourceMappingURL=chunk-SZ2JQBP4.js.map
42
+ //# sourceMappingURL=chunk-X4YQ27D5.js.map
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Input
4
- } from "../chunk-SZ2JQBP4.js";
5
- import "../chunk-4O4QFF4S.js";
4
+ } from "../chunk-X4YQ27D5.js";
6
5
  import "../chunk-ZAU4JVLL.js";
7
- import "../chunk-LQD23PG3.js";
8
- import "../chunk-RK5HK6UU.js";
6
+ import "../chunk-4O4QFF4S.js";
7
+ import "../chunk-3CBN7U25.js";
8
+ import "../chunk-5MNCW677.js";
9
9
  export {
10
10
  Input
11
11
  };
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import {
3
3
  Label
4
- } from "../chunk-MYDNNVMZ.js";
5
- import "../chunk-4O4QFF4S.js";
4
+ } from "../chunk-HE3HFKYU.js";
6
5
  import "../chunk-ZAU4JVLL.js";
6
+ import "../chunk-4O4QFF4S.js";
7
7
  export {
8
8
  Label
9
9
  };
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import {
3
+ Toggle
4
+ } from "../chunk-734PGVLT.js";
5
+ import "../chunk-ZAU4JVLL.js";
6
+ import "../chunk-3CBN7U25.js";
7
+ import "../chunk-5MNCW677.js";
8
+ export {
9
+ Toggle
10
+ };
11
+ //# sourceMappingURL=Toggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "../chunk-RK5HK6UU.js";
3
+ } from "../chunk-5MNCW677.js";
4
4
  export {
5
5
  defaultIcons
6
6
  };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  $cerberusIcons,
3
3
  defineIcons
4
- } from "../chunk-LQD23PG3.js";
5
- import "../chunk-RK5HK6UU.js";
4
+ } from "../chunk-3CBN7U25.js";
5
+ import "../chunk-5MNCW677.js";
6
6
  export {
7
7
  $cerberusIcons,
8
8
  defineIcons
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import {
3
+ useToggle
4
+ } from "../chunk-QEA6N6TN.js";
5
+ export {
6
+ useToggle
7
+ };
8
+ //# sourceMappingURL=useToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1,6 @@
1
+ import {
2
+ Radio
3
+ } from "./chunk-WE3JNSNO.js";
1
4
  import {
2
5
  Tab
3
6
  } from "./chunk-SUP7U42W.js";
@@ -13,6 +16,12 @@ import {
13
16
  import {
14
17
  Textarea
15
18
  } from "./chunk-TCO46FK7.js";
19
+ import {
20
+ Toggle
21
+ } from "./chunk-734PGVLT.js";
22
+ import {
23
+ Button
24
+ } from "./chunk-2ATICEW3.js";
16
25
  import {
17
26
  FieldMessage
18
27
  } from "./chunk-VGHVH2T3.js";
@@ -21,10 +30,14 @@ import {
21
30
  } from "./chunk-SLHX5K6I.js";
22
31
  import {
23
32
  Input
24
- } from "./chunk-SZ2JQBP4.js";
33
+ } from "./chunk-X4YQ27D5.js";
25
34
  import {
26
35
  Label
27
- } from "./chunk-MYDNNVMZ.js";
36
+ } from "./chunk-HE3HFKYU.js";
37
+ import {
38
+ Field,
39
+ useFieldContext
40
+ } from "./chunk-ZAU4JVLL.js";
28
41
  import {
29
42
  NavMenuLink
30
43
  } from "./chunk-6DIGPXAD.js";
@@ -42,13 +55,6 @@ import {
42
55
  import {
43
56
  Show
44
57
  } from "./chunk-4O4QFF4S.js";
45
- import {
46
- Radio
47
- } from "./chunk-WE3JNSNO.js";
48
- import {
49
- Field,
50
- useFieldContext
51
- } from "./chunk-ZAU4JVLL.js";
52
58
  import "./chunk-55J6XMHW.js";
53
59
  import {
54
60
  createNavTriggerProps
@@ -64,8 +70,8 @@ import {
64
70
  import {
65
71
  $cerberusIcons,
66
72
  defineIcons
67
- } from "./chunk-LQD23PG3.js";
68
- import "./chunk-RK5HK6UU.js";
73
+ } from "./chunk-3CBN7U25.js";
74
+ import "./chunk-5MNCW677.js";
69
75
  import {
70
76
  MODE_KEY,
71
77
  THEME_KEY,
@@ -74,8 +80,8 @@ import {
74
80
  useThemeContext
75
81
  } from "./chunk-SXXWC6UD.js";
76
82
  import {
77
- Button
78
- } from "./chunk-2ATICEW3.js";
83
+ useToggle
84
+ } from "./chunk-QEA6N6TN.js";
79
85
  export {
80
86
  $cerberusIcons,
81
87
  Button,
@@ -100,6 +106,7 @@ export {
100
106
  Tag,
101
107
  Textarea,
102
108
  ThemeProvider,
109
+ Toggle,
103
110
  createNavTriggerProps,
104
111
  defineIcons,
105
112
  getPosition,
@@ -108,6 +115,7 @@ export {
108
115
  useTabsContext,
109
116
  useTabsKeyboardNavigation,
110
117
  useTheme,
111
- useThemeContext
118
+ useThemeContext,
119
+ useToggle
112
120
  };
113
121
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerberus-design/react",
3
- "version": "0.5.2-next-b5db70c",
3
+ "version": "0.5.2-next-7d39ff1",
4
4
  "description": "The Cerberus Design React component library.",
5
5
  "browserslist": "> 0.25%, not dead",
6
6
  "sideEffects": false,
@@ -22,7 +22,7 @@
22
22
  "react-dom": "^18",
23
23
  "tsup": "^8.1.0",
24
24
  "@cerberus-design/configs": "0.0.0",
25
- "@cerberus-design/styled-system": "0.5.2-next-b5db70c"
25
+ "@cerberus-design/styled-system": "0.5.2-next-7d39ff1"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
@@ -0,0 +1,55 @@
1
+ 'use client'
2
+
3
+ import { cx } from '@cerberus-design/styled-system/css'
4
+ import { hstack, vstack } from '@cerberus-design/styled-system/patterns'
5
+ import {
6
+ toggle,
7
+ type ToggleVariantProps,
8
+ } from '@cerberus-design/styled-system/recipes'
9
+ import type { InputHTMLAttributes } from 'react'
10
+ import { $cerberusIcons } from '../config/defineIcons'
11
+ import { useFieldContext } from '../context/field'
12
+
13
+ export type ToggleBase = Omit<
14
+ InputHTMLAttributes<HTMLInputElement>,
15
+ 'size' | 'id' | 'value'
16
+ > & {
17
+ describedBy?: string
18
+ id: string
19
+ value: string
20
+ }
21
+ export type ToggleProps = ToggleBase & ToggleVariantProps
22
+
23
+ export function Toggle(props: ToggleProps) {
24
+ const { size, describedBy, ...nativeProps } = props
25
+ const styles = toggle({ size })
26
+ const { invalid, ...state } = useFieldContext()
27
+ const Icon = $cerberusIcons.toggleChecked
28
+
29
+ return (
30
+ <span
31
+ className={cx('group', styles.track, hstack())}
32
+ data-checked={props.checked || props.defaultChecked}
33
+ >
34
+ <input
35
+ {...nativeProps}
36
+ {...state}
37
+ {...(describedBy && { 'aria-describedby': describedBy })}
38
+ {...(invalid && { 'aria-invalid': true })}
39
+ className={cx('peer', styles.input)}
40
+ role="switch"
41
+ type="checkbox"
42
+ />
43
+ <span
44
+ className={cx(
45
+ styles.thumb,
46
+ vstack({
47
+ justify: 'center',
48
+ }),
49
+ )}
50
+ >
51
+ <Icon />
52
+ </span>
53
+ </span>
54
+ )
55
+ }
@@ -1,10 +1,12 @@
1
- import { WarningFilled, type CarbonIconType } from '@cerberus/icons'
1
+ import { Checkmark, WarningFilled, type CarbonIconType } from '@cerberus/icons'
2
2
  import type { ElementType } from 'react'
3
3
 
4
4
  export interface DefinedIcons {
5
5
  invalid: CarbonIconType | ElementType
6
+ toggleChecked: CarbonIconType | ElementType
6
7
  }
7
8
 
8
9
  export const defaultIcons: DefinedIcons = {
9
10
  invalid: WarningFilled,
11
+ toggleChecked: Checkmark,
10
12
  }
@@ -0,0 +1,30 @@
1
+ 'use client'
2
+
3
+ import { useCallback, useMemo, useState, type ChangeEvent } from 'react'
4
+
5
+ export interface UseToggleOptions {
6
+ checked?: string
7
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void
8
+ }
9
+ export interface ToggleHookReturn {
10
+ checked: string
11
+ handleChange: (e: ChangeEvent<HTMLInputElement>) => void
12
+ }
13
+
14
+ export function useToggle(options?: UseToggleOptions): ToggleHookReturn {
15
+ const [checked, setChecked] = useState<string>(options?.checked ?? '')
16
+ const onChange = options?.onChange
17
+
18
+ const handleChange = useCallback(
19
+ (e: ChangeEvent<HTMLInputElement>) => {
20
+ const target = e.currentTarget as HTMLInputElement
21
+ setChecked((prev) => {
22
+ return prev === target.value ? '' : target.value
23
+ })
24
+ onChange?.(e)
25
+ },
26
+ [onChange],
27
+ )
28
+
29
+ return useMemo(() => ({ checked, handleChange }), [checked, handleChange])
30
+ }
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ export * from './components/TabList'
19
19
  export * from './components/TabPanel'
20
20
  export * from './components/Tag'
21
21
  export * from './components/Textarea'
22
+ export * from './components/Toggle'
22
23
  export * from './components/Show'
23
24
 
24
25
  // context
@@ -31,6 +32,7 @@ export * from './context/theme'
31
32
  // hooks
32
33
 
33
34
  export * from './hooks/useTheme'
35
+ export * from './hooks/useToggle'
34
36
 
35
37
  // aria-helpers
36
38
 
@@ -1,10 +0,0 @@
1
- // src/config/cerbIcons.ts
2
- import { WarningFilled } from "@cerberus/icons";
3
- var defaultIcons = {
4
- invalid: WarningFilled
5
- };
6
-
7
- export {
8
- defaultIcons
9
- };
10
- //# sourceMappingURL=chunk-RK5HK6UU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import { WarningFilled, type CarbonIconType } from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n invalid: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n invalid: WarningFilled,\n}\n"],"mappings":";AAAA,SAAS,qBAA0C;AAO5C,IAAM,eAA6B;AAAA,EACxC,SAAS;AACX;","names":[]}
@@ -1,10 +0,0 @@
1
- // src/config/cerbIcons.ts
2
- import { WarningFilled } from "@cerberus/icons";
3
- var defaultIcons = {
4
- invalid: WarningFilled
5
- };
6
-
7
- export {
8
- defaultIcons
9
- };
10
- //# sourceMappingURL=chunk-RK5HK6UU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import { WarningFilled, type CarbonIconType } from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n invalid: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n invalid: WarningFilled,\n}\n"],"mappings":";AAAA,SAAS,qBAA0C;AAO5C,IAAM,eAA6B;AAAA,EACxC,SAAS;AACX;","names":[]}