@cerberus-design/react 0.15.0-next-7a184be → 0.15.0-next-47ecb2e

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 (138) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.cts +319 -93
  2. package/build/legacy/components/checkbox/checkbox.cjs.map +1 -1
  3. package/build/legacy/components/checkbox/index.cjs.map +1 -1
  4. package/build/legacy/components/for.cjs.map +1 -1
  5. package/build/legacy/components/select/index.cjs +265 -0
  6. package/build/legacy/components/select/index.cjs.map +1 -0
  7. package/build/legacy/components/select/option-group.cjs +60 -0
  8. package/build/legacy/components/select/option-group.cjs.map +1 -0
  9. package/build/legacy/components/select/parts.cjs +153 -0
  10. package/build/legacy/components/select/parts.cjs.map +1 -0
  11. package/build/legacy/components/select/primitives.cjs +167 -0
  12. package/build/legacy/components/select/primitives.cjs.map +1 -0
  13. package/build/legacy/components/select/select.cjs +212 -0
  14. package/build/legacy/components/select/select.cjs.map +1 -0
  15. package/build/legacy/components/switch/index.cjs +118 -0
  16. package/build/legacy/components/switch/index.cjs.map +1 -0
  17. package/build/legacy/components/switch/parts.cjs +75 -0
  18. package/build/legacy/components/switch/parts.cjs.map +1 -0
  19. package/build/legacy/components/switch/primitives.cjs +72 -0
  20. package/build/legacy/components/switch/primitives.cjs.map +1 -0
  21. package/build/legacy/components/switch/switch-indicator.cjs +51 -0
  22. package/build/legacy/components/switch/switch-indicator.cjs.map +1 -0
  23. package/build/legacy/components/switch/switch.cjs +106 -0
  24. package/build/legacy/components/switch/switch.cjs.map +1 -0
  25. package/build/legacy/components/toggle/index.cjs +45 -0
  26. package/build/legacy/components/toggle/index.cjs.map +1 -0
  27. package/build/legacy/components/toggle/parts.cjs +41 -0
  28. package/build/legacy/components/toggle/parts.cjs.map +1 -0
  29. package/build/legacy/components/toggle/primitives.cjs +35 -0
  30. package/build/legacy/components/toggle/primitives.cjs.map +1 -0
  31. package/build/legacy/hooks/useToggle.cjs.map +1 -1
  32. package/build/legacy/index.cjs +617 -483
  33. package/build/legacy/index.cjs.map +1 -1
  34. package/build/modern/_tsup-dts-rollup.d.ts +319 -93
  35. package/build/modern/chunk-2CVGNLIM.js +15 -0
  36. package/build/modern/chunk-2CVGNLIM.js.map +1 -0
  37. package/build/modern/chunk-2LF3HPNA.js +1 -0
  38. package/build/modern/chunk-CAZ3EICD.js +16 -0
  39. package/build/modern/chunk-CAZ3EICD.js.map +1 -0
  40. package/build/modern/chunk-CIMY2U22.js +10 -0
  41. package/build/modern/chunk-CIMY2U22.js.map +1 -0
  42. package/build/modern/chunk-IASVL7CW.js +19 -0
  43. package/build/modern/chunk-IASVL7CW.js.map +1 -0
  44. package/build/modern/{chunk-REO5GUNC.js → chunk-ICTISECN.js} +1 -1
  45. package/build/modern/chunk-ICTISECN.js.map +1 -0
  46. package/build/modern/{chunk-77FJSNGD.js → chunk-IIH363FO.js} +1 -1
  47. package/build/modern/{chunk-77FJSNGD.js.map → chunk-IIH363FO.js.map} +1 -1
  48. package/build/modern/chunk-KQQPZJEI.js +21 -0
  49. package/build/modern/chunk-KQQPZJEI.js.map +1 -0
  50. package/build/modern/chunk-LZWNHXRP.js +48 -0
  51. package/build/modern/chunk-LZWNHXRP.js.map +1 -0
  52. package/build/modern/chunk-OVHCXBBI.js +22 -0
  53. package/build/modern/chunk-OVHCXBBI.js.map +1 -0
  54. package/build/modern/chunk-P3SF56LT.js +47 -0
  55. package/build/modern/chunk-P3SF56LT.js.map +1 -0
  56. package/build/modern/chunk-QCBLRACK.js +133 -0
  57. package/build/modern/chunk-QCBLRACK.js.map +1 -0
  58. package/build/modern/chunk-UDY6USHW.js +1 -0
  59. package/build/modern/chunk-V4YYGGMH.js +1 -0
  60. package/build/modern/chunk-XTNGF4D6.js +41 -0
  61. package/build/modern/chunk-XTNGF4D6.js.map +1 -0
  62. package/build/modern/{chunk-UNN4LHRS.js → chunk-Y4ZEJ2EF.js} +1 -1
  63. package/build/modern/chunk-Y4ZEJ2EF.js.map +1 -0
  64. package/build/modern/components/checkbox/checkbox.js +1 -1
  65. package/build/modern/components/checkbox/index.js +1 -1
  66. package/build/modern/components/for.js +1 -1
  67. package/build/modern/components/select/index.js +57 -0
  68. package/build/modern/components/select/index.js.map +1 -0
  69. package/build/modern/components/select/option-group.js +10 -0
  70. package/build/modern/components/select/option-group.js.map +1 -0
  71. package/build/modern/components/select/parts.js +8 -0
  72. package/build/modern/components/select/parts.js.map +1 -0
  73. package/build/modern/components/{Select.server.js → select/primitives.js} +8 -4
  74. package/build/modern/components/select/primitives.js.map +1 -0
  75. package/build/modern/components/select/select.js +15 -0
  76. package/build/modern/components/select/select.js.map +1 -0
  77. package/build/modern/components/switch/index.js +26 -0
  78. package/build/modern/components/switch/index.js.map +1 -0
  79. package/build/modern/components/switch/parts.js +8 -0
  80. package/build/modern/components/switch/parts.js.map +1 -0
  81. package/build/modern/components/switch/primitives.js +15 -0
  82. package/build/modern/components/switch/primitives.js.map +1 -0
  83. package/build/modern/components/switch/switch-indicator.js +9 -0
  84. package/build/modern/components/switch/switch-indicator.js.map +1 -0
  85. package/build/modern/components/switch/switch.js +11 -0
  86. package/build/modern/components/switch/switch.js.map +1 -0
  87. package/build/modern/components/toggle/index.js +14 -0
  88. package/build/modern/components/toggle/index.js.map +1 -0
  89. package/build/modern/components/toggle/parts.js +8 -0
  90. package/build/modern/components/toggle/parts.js.map +1 -0
  91. package/build/modern/components/toggle/primitives.js +9 -0
  92. package/build/modern/components/toggle/primitives.js.map +1 -0
  93. package/build/modern/context/confirm-modal.js +1 -1
  94. package/build/modern/context/cta-modal.js +2 -2
  95. package/build/modern/context/prompt-modal.js +1 -1
  96. package/build/modern/hooks/useToggle.js +1 -1
  97. package/build/modern/index.js +110 -72
  98. package/build/modern/index.js.map +1 -1
  99. package/package.json +3 -3
  100. package/src/components/checkbox/checkbox.tsx +4 -10
  101. package/src/components/for.tsx +1 -1
  102. package/src/components/select/index.ts +4 -0
  103. package/src/components/select/option-group.tsx +34 -0
  104. package/src/components/select/parts.ts +113 -0
  105. package/src/components/select/primitives.tsx +205 -0
  106. package/src/components/select/select.tsx +135 -0
  107. package/src/components/switch/index.ts +3 -0
  108. package/src/components/switch/parts.ts +53 -0
  109. package/src/components/switch/primitives.tsx +69 -0
  110. package/src/components/switch/switch-indicator.tsx +9 -0
  111. package/src/components/switch/switch.tsx +30 -0
  112. package/src/components/toggle/index.ts +2 -0
  113. package/src/components/toggle/parts.ts +32 -0
  114. package/src/components/toggle/primitives.tsx +17 -0
  115. package/src/hooks/useToggle.ts +1 -3
  116. package/src/index.ts +6 -6
  117. package/build/legacy/components/Select.cjs +0 -142
  118. package/build/legacy/components/Select.cjs.map +0 -1
  119. package/build/legacy/components/Select.server.cjs +0 -78
  120. package/build/legacy/components/Select.server.cjs.map +0 -1
  121. package/build/legacy/components/Toggle.cjs +0 -94
  122. package/build/legacy/components/Toggle.cjs.map +0 -1
  123. package/build/modern/chunk-GENS32QO.js +0 -61
  124. package/build/modern/chunk-GENS32QO.js.map +0 -1
  125. package/build/modern/chunk-REO5GUNC.js.map +0 -1
  126. package/build/modern/chunk-S2X5OEPK.js +0 -89
  127. package/build/modern/chunk-S2X5OEPK.js.map +0 -1
  128. package/build/modern/chunk-UNN4LHRS.js.map +0 -1
  129. package/build/modern/chunk-YWMPB2JR.js +0 -41
  130. package/build/modern/chunk-YWMPB2JR.js.map +0 -1
  131. package/build/modern/components/Select.js +0 -20
  132. package/build/modern/components/Toggle.js +0 -9
  133. package/src/components/Select.server.tsx +0 -80
  134. package/src/components/Select.tsx +0 -219
  135. package/src/components/Toggle.tsx +0 -98
  136. /package/build/modern/{components/Select.js.map → chunk-2LF3HPNA.js.map} +0 -0
  137. /package/build/modern/{components/Select.server.js.map → chunk-UDY6USHW.js.map} +0 -0
  138. /package/build/modern/{components/Toggle.js.map → chunk-V4YYGGMH.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/Select.server.tsx"],"sourcesContent":["import { Select as ArkSelect, type SelectRootProps } from '@ark-ui/react/select'\nimport type { SelectCollectionItem } from './Select'\n\n/**\n * Select Primitive: The context provider for the Select family\n */\nexport function SelectRoot(props: SelectRootProps<SelectCollectionItem>) {\n const { children, ...rootProps } = props\n return (\n <ArkSelect.Root {...rootProps}>\n {children}\n <ArkSelect.HiddenSelect />\n </ArkSelect.Root>\n )\n}\n\n/**\n * Select Primitive: The label that appears above the select input\n */\nexport const SelectLabel = ArkSelect.Label\n\n/**\n * Select Primitive: The wrapper to the select trigger that opens the dropdown\n */\nexport const SelectControl = ArkSelect.Control\n\n/**\n * Select Primitive: The trigger that opens the dropdown\n */\nexport const SelectTrigger = ArkSelect.Trigger\n\n/**\n * Select Primitive: The text that appears in the trigger\n */\nexport const SelectValueText = ArkSelect.ValueText\n\n/**\n * Select Primitive: The indicator that appears in the trigger\n */\nexport const SelectIndicator = ArkSelect.Indicator\n\n/**\n * Select Primitive: The trigger that clears the selected value\n */\nexport const SelectClearTrigger = ArkSelect.ClearTrigger\n\n/**\n * Select Primitive: The positioner that contains the dropdown\n */\nexport const SelectPositioner = ArkSelect.Positioner\n\n/**\n * Select Primitive: The content of the dropdown (i.e. the container itself)\n */\nexport const SelectContent = ArkSelect.Content\n\n/**\n * Select Primitive: The container for a group of item options\n */\nexport const SelectItemGroup = ArkSelect.ItemGroup\n\n/**\n * Select Primitive: The label for a group of item options\n */\nexport const SelectItemGroupLabel = ArkSelect.ItemGroupLabel\n\n/**\n * Select Primitive: The container for an item option\n */\nexport const SelectItem = ArkSelect.Item\n\n/**\n * Select Primitive: The text for an item option\n */\nexport const SelectItemText = ArkSelect.ItemText\n\n/**\n * Select Primitive: The indicator for an item option\n */\nexport const SelectItemIndicator = ArkSelect.ItemIndicator\n"],"mappings":";AAAA,SAAS,UAAU,iBAAuC;AAStD,SAEE,KAFF;AAHG,SAAS,WAAW,OAA8C;AACvE,QAAM,EAAE,UAAU,GAAG,UAAU,IAAI;AACnC,SACE,qBAAC,UAAU,MAAV,EAAgB,GAAG,WACjB;AAAA;AAAA,IACD,oBAAC,UAAU,cAAV,EAAuB;AAAA,KAC1B;AAEJ;AAKO,IAAM,cAAc,UAAU;AAK9B,IAAM,gBAAgB,UAAU;AAKhC,IAAM,gBAAgB,UAAU;AAKhC,IAAM,kBAAkB,UAAU;AAKlC,IAAM,kBAAkB,UAAU;AAKlC,IAAM,qBAAqB,UAAU;AAKrC,IAAM,mBAAmB,UAAU;AAKnC,IAAM,gBAAgB,UAAU;AAKhC,IAAM,kBAAkB,UAAU;AAKlC,IAAM,uBAAuB,UAAU;AAKvC,IAAM,aAAa,UAAU;AAK7B,IAAM,iBAAiB,UAAU;AAKjC,IAAM,sBAAsB,UAAU;","names":[]}
@@ -1,20 +0,0 @@
1
- "use client";
2
- import {
3
- Option,
4
- OptionGroup,
5
- OptionGroupLabel,
6
- Select,
7
- createSelectCollection
8
- } from "../chunk-S2X5OEPK.js";
9
- import "../chunk-YWMPB2JR.js";
10
- import "../chunk-IQJDVFPP.js";
11
- import "../chunk-GITT5645.js";
12
- import "../chunk-BUVVRQLZ.js";
13
- export {
14
- Option,
15
- OptionGroup,
16
- OptionGroupLabel,
17
- Select,
18
- createSelectCollection
19
- };
20
- //# sourceMappingURL=Select.js.map
@@ -1,9 +0,0 @@
1
- "use client";
2
- import {
3
- Toggle
4
- } from "../chunk-GENS32QO.js";
5
- import "../chunk-GITT5645.js";
6
- export {
7
- Toggle
8
- };
9
- //# sourceMappingURL=Toggle.js.map
@@ -1,80 +0,0 @@
1
- import { Select as ArkSelect, type SelectRootProps } from '@ark-ui/react/select'
2
- import type { SelectCollectionItem } from './Select'
3
-
4
- /**
5
- * Select Primitive: The context provider for the Select family
6
- */
7
- export function SelectRoot(props: SelectRootProps<SelectCollectionItem>) {
8
- const { children, ...rootProps } = props
9
- return (
10
- <ArkSelect.Root {...rootProps}>
11
- {children}
12
- <ArkSelect.HiddenSelect />
13
- </ArkSelect.Root>
14
- )
15
- }
16
-
17
- /**
18
- * Select Primitive: The label that appears above the select input
19
- */
20
- export const SelectLabel = ArkSelect.Label
21
-
22
- /**
23
- * Select Primitive: The wrapper to the select trigger that opens the dropdown
24
- */
25
- export const SelectControl = ArkSelect.Control
26
-
27
- /**
28
- * Select Primitive: The trigger that opens the dropdown
29
- */
30
- export const SelectTrigger = ArkSelect.Trigger
31
-
32
- /**
33
- * Select Primitive: The text that appears in the trigger
34
- */
35
- export const SelectValueText = ArkSelect.ValueText
36
-
37
- /**
38
- * Select Primitive: The indicator that appears in the trigger
39
- */
40
- export const SelectIndicator = ArkSelect.Indicator
41
-
42
- /**
43
- * Select Primitive: The trigger that clears the selected value
44
- */
45
- export const SelectClearTrigger = ArkSelect.ClearTrigger
46
-
47
- /**
48
- * Select Primitive: The positioner that contains the dropdown
49
- */
50
- export const SelectPositioner = ArkSelect.Positioner
51
-
52
- /**
53
- * Select Primitive: The content of the dropdown (i.e. the container itself)
54
- */
55
- export const SelectContent = ArkSelect.Content
56
-
57
- /**
58
- * Select Primitive: The container for a group of item options
59
- */
60
- export const SelectItemGroup = ArkSelect.ItemGroup
61
-
62
- /**
63
- * Select Primitive: The label for a group of item options
64
- */
65
- export const SelectItemGroupLabel = ArkSelect.ItemGroupLabel
66
-
67
- /**
68
- * Select Primitive: The container for an item option
69
- */
70
- export const SelectItem = ArkSelect.Item
71
-
72
- /**
73
- * Select Primitive: The text for an item option
74
- */
75
- export const SelectItemText = ArkSelect.ItemText
76
-
77
- /**
78
- * Select Primitive: The indicator for an item option
79
- */
80
- export const SelectItemIndicator = ArkSelect.ItemIndicator
@@ -1,219 +0,0 @@
1
- 'use client'
2
-
3
- import {
4
- Select as ArkSelect,
5
- createListCollection,
6
- type SelectRootProps,
7
- type SelectItemProps,
8
- type SelectItemGroupProps,
9
- type SelectItemGroupLabelProps,
10
- type ListCollection,
11
- type SelectValueChangeDetails,
12
- } from '@ark-ui/react/select'
13
- import {
14
- select,
15
- type SelectVariantProps,
16
- } from '@cerberus/styled-system/recipes'
17
- import { cx } from '@cerberus/styled-system/css'
18
- import { HStack } from '@cerberus/styled-system/jsx'
19
- import { useCerberusContext } from '../context/cerberus'
20
- import { Portal } from './Portal'
21
- import { Show } from './Show'
22
- import {
23
- SelectContent,
24
- SelectControl,
25
- SelectIndicator,
26
- SelectItem,
27
- SelectItemGroup,
28
- SelectItemGroupLabel,
29
- SelectItemIndicator,
30
- SelectItemText,
31
- SelectPositioner,
32
- SelectRoot,
33
- SelectTrigger,
34
- SelectValueText,
35
- } from './Select.server'
36
-
37
- /**
38
- * This module contains the Select components.
39
- * @module 'react/select'
40
- */
41
-
42
- export interface SelectCollectionItem {
43
- /**
44
- * What is displayed in the dropdown list.
45
- */
46
- label: string
47
- /**
48
- * The value of the selected item used in the form.
49
- */
50
- value: string
51
- /**
52
- * If the item is disabled.
53
- */
54
- disabled?: boolean
55
- }
56
-
57
- export interface SelectCollection {
58
- /**
59
- * The items to be displayed in the dropdown list.
60
- */
61
- items: SelectCollectionItem[]
62
- }
63
-
64
- export interface BaseSelectProps {
65
- /**
66
- * The placeholder text when no option is selected.
67
- */
68
- placeholder?: string
69
- }
70
-
71
- export type SelectProps = SelectRootProps<SelectCollectionItem> &
72
- BaseSelectProps &
73
- SelectVariantProps
74
-
75
- /**
76
- * The Select component is a dropdown list that allows users to select an
77
- * option from a list.
78
- * @definition [Select docs](https://cerberus.digitalu.design/react/select)
79
- * @definition [ARK docs](https://ark-ui.com/react/docs/components/select)
80
- * @example
81
- * ```tsx
82
- * import { Select, Option, createListCollection } from '@cerberus-design/react'
83
- *
84
- * export function SelectBasicPreview() {
85
- * const collection = createListCollection({
86
- * items: [
87
- * { label: 'Hades', value: 'hades' },
88
- * { label: 'Persephone', value: 'persephone' },
89
- * { label: 'Zeus', value: 'zeus', disabled: true },
90
- * ]
91
- * })
92
- *
93
- * return (
94
- * <Select
95
- * collection={collection}
96
- * label="Select Relative"
97
- * placeholder="Choose option"
98
- * >
99
- * {collection.items.map((item) => (
100
- * <Option key={item.value} item={item} />
101
- * ))}
102
- * </Select>
103
- * )
104
- * }
105
- */
106
- export function Select(props: SelectProps) {
107
- const { collection, placeholder, size, ...rootProps } = props
108
- const { icons } = useCerberusContext()
109
- const { selectArrow: SelectArrow, invalid: InvalidIcon } = icons
110
-
111
- const styles = select({ size })
112
-
113
- return (
114
- <SelectRoot className={styles.root} collection={collection} {...rootProps}>
115
- <SelectControl className={styles.control}>
116
- <SelectTrigger className={styles.trigger}>
117
- <SelectValueText placeholder={placeholder} />
118
-
119
- <HStack>
120
- <Show when={props.invalid}>
121
- <InvalidIcon data-part="invalid-icon" />
122
- </Show>
123
- <SelectIndicator className={styles.indicator}>
124
- <SelectArrow />
125
- </SelectIndicator>
126
- </HStack>
127
- </SelectTrigger>
128
- </SelectControl>
129
-
130
- <Portal>
131
- <SelectPositioner className={styles.positioner}>
132
- <SelectContent className={styles.content}>
133
- {props.children}
134
- </SelectContent>
135
- </SelectPositioner>
136
- </Portal>
137
-
138
- <ArkSelect.HiddenSelect />
139
- </SelectRoot>
140
- )
141
- }
142
-
143
- export interface OptionProps extends SelectItemProps {
144
- /**
145
- * The CollectionListItem to be displayed in the dropdown list.
146
- */
147
- item: SelectCollectionItem
148
- }
149
-
150
- export function Option(props: OptionProps) {
151
- const { item, ...itemProps } = props
152
-
153
- const { icons } = useCerberusContext()
154
- const { selectChecked: CheckedIcon } = icons
155
-
156
- const styles = select()
157
-
158
- return (
159
- <SelectItem {...itemProps} item={item} className={styles.item}>
160
- <SelectItemText className={styles.itemText}>{item?.label}</SelectItemText>
161
- <SelectItemIndicator className={styles.itemIndicator}>
162
- <CheckedIcon />
163
- </SelectItemIndicator>
164
- </SelectItem>
165
- )
166
- }
167
-
168
- /**
169
- * The OptionGroup component is a group of options in the dropdown list.
170
- * @definition [Select docs](https://cerberus.digitalu.design/react/select)
171
- * @definition [ARK docs](https://ark-ui.com/react/docs/components/select)
172
- * @example
173
- * ```tsx
174
- * <OptionGroup>
175
- * <OptionGroupLabel>Greek gods</OptionGroupLabel>
176
- * ...
177
- * </OptionGroup>
178
- * ```
179
- */
180
- export function OptionGroup(props: SelectItemGroupProps) {
181
- return <SelectItemGroup {...props} />
182
- }
183
-
184
- /**
185
- * The OptionGroupLabel component is the label of the OptionGroup.
186
- * @definition [Select docs](https://cerberus.digitalu.design/react/select)
187
- * @definition [ARK docs](https://ark-ui.com/react/docs/components/select)
188
- * @example
189
- * ```tsx
190
- * <OptionGroupLabel>Greek gods</OptionGroupLabel>
191
- * ```
192
- */
193
- export function OptionGroupLabel(props: SelectItemGroupLabelProps) {
194
- const styles = select()
195
- return (
196
- <SelectItemGroupLabel
197
- {...props}
198
- className={cx(props.className, styles.itemGroupLabel)}
199
- />
200
- )
201
- }
202
-
203
- /**
204
- * A helper function to create a SelectCollection object.
205
- * @param collection - An array of SelectCollectionItem objects that matches
206
- * the following shape:
207
- * ```ts
208
- * [{ label: 'Hades', value: 'hades', disabled?: true }]
209
- * ```
210
- */
211
- export function createSelectCollection(
212
- collection: SelectCollectionItem[],
213
- ): ListCollection<SelectCollectionItem> {
214
- return createListCollection({
215
- items: collection,
216
- })
217
- }
218
-
219
- export type { SelectValueChangeDetails, ListCollection }
@@ -1,98 +0,0 @@
1
- 'use client'
2
-
3
- import { useFieldContext } from '@ark-ui/react/field'
4
- import type { InputHTMLAttributes } from 'react'
5
- import { cx } from '@cerberus/styled-system/css'
6
- import { hstack, vstack } from '@cerberus/styled-system/patterns'
7
- import {
8
- toggle,
9
- type ToggleVariantProps,
10
- } from '@cerberus/styled-system/recipes'
11
- import { useCerberusContext } from '../context/cerberus'
12
-
13
- /**
14
- * This module provides a toggle component.
15
- * @module
16
- */
17
-
18
- export type ToggleBase = Omit<
19
- InputHTMLAttributes<HTMLInputElement>,
20
- 'size' | 'id' | 'value'
21
- > & {
22
- /**
23
- * @deprecated
24
- */
25
- describedBy?: string
26
- /**
27
- * A unique identifier for the Toggle. Required for accessibility.
28
- */
29
- id: string
30
- /**
31
- * The value of the Toggle.
32
- */
33
- value: string
34
- }
35
- export type ToggleProps = ToggleBase & ToggleVariantProps
36
-
37
- /**
38
- * The Toggle component is used to switch between two states. Optionally
39
- * combine with the `useToggle` hook.
40
- * @see https://cerberus.digitalu.design/react/toggle
41
- * @example
42
- * ```tsx
43
- * const { checked, handleChange } = useToggle({ checked: 'toggle' })
44
- *
45
- * <Hstack justify="space-between" w="full">
46
- * <Field>
47
- * <Label htmlFor="toggle">Show notifications</Label>
48
- * <Toggle
49
- * checked={checked === 'toggle'}
50
- * id="toggle"
51
- * onChange={handleChange}
52
- * value="toggle"
53
- * />
54
- * </Field>
55
- * </Hstack>
56
- * ```
57
- */
58
- export function Toggle(props: ToggleProps) {
59
- const { size, ...nativeProps } = props
60
- const styles = toggle({ size })
61
-
62
- const { invalid, disabled, readOnly, required, ariaDescribedby } =
63
- useFieldContext()
64
-
65
- const { icons } = useCerberusContext()
66
- const CheckedIcon = icons.toggleChecked
67
-
68
- return (
69
- <span
70
- className={cx('group', styles.track, hstack())}
71
- data-checked={props.checked || props.defaultChecked}
72
- >
73
- <input
74
- {...nativeProps}
75
- {...(disabled && { disabled: true })}
76
- {...(readOnly && { readOnly: true })}
77
- {...(required && { required: true })}
78
- {...(ariaDescribedby && {
79
- 'aria-describedby': ariaDescribedby,
80
- })}
81
- {...(invalid && { 'aria-invalid': true })}
82
- className={cx('peer', styles.input)}
83
- role="switch"
84
- type="checkbox"
85
- />
86
- <span
87
- className={cx(
88
- styles.thumb,
89
- vstack({
90
- justify: 'center',
91
- }),
92
- )}
93
- >
94
- <CheckedIcon />
95
- </span>
96
- </span>
97
- )
98
- }