@bspk/ui 1.1.21 → 1.1.22

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 (211) hide show
  1. package/dist/Avatar.d.ts +18 -2
  2. package/dist/Avatar.js +18 -2
  3. package/dist/Avatar.js.map +1 -1
  4. package/dist/AvatarGroup.d.ts +14 -0
  5. package/dist/AvatarGroup.js +14 -0
  6. package/dist/AvatarGroup.js.map +1 -1
  7. package/dist/Badge.d.ts +23 -2
  8. package/dist/Badge.js +12 -3
  9. package/dist/Badge.js.map +1 -1
  10. package/dist/BannerAlert.d.ts +17 -0
  11. package/dist/BannerAlert.js +17 -0
  12. package/dist/BannerAlert.js.map +1 -1
  13. package/dist/Button.d.ts +16 -0
  14. package/dist/Button.js +16 -0
  15. package/dist/Button.js.map +1 -1
  16. package/dist/Card.d.ts +12 -0
  17. package/dist/Card.js +12 -0
  18. package/dist/Card.js.map +1 -1
  19. package/dist/Checkbox.d.ts +21 -0
  20. package/dist/Checkbox.js +21 -0
  21. package/dist/Checkbox.js.map +1 -1
  22. package/dist/CheckboxGroup.d.ts +30 -0
  23. package/dist/CheckboxGroup.js +23 -0
  24. package/dist/CheckboxGroup.js.map +1 -1
  25. package/dist/CheckboxOption.d.ts +23 -1
  26. package/dist/CheckboxOption.js +25 -2
  27. package/dist/CheckboxOption.js.map +1 -1
  28. package/dist/Chip.d.ts +11 -0
  29. package/dist/Chip.js +11 -0
  30. package/dist/Chip.js.map +1 -1
  31. package/dist/Dialog.d.ts +19 -0
  32. package/dist/Dialog.js +19 -0
  33. package/dist/Dialog.js.map +1 -1
  34. package/dist/Divider.d.ts +13 -0
  35. package/dist/Divider.js +13 -0
  36. package/dist/Divider.js.map +1 -1
  37. package/dist/Dropdown.d.ts +30 -0
  38. package/dist/Dropdown.js +30 -0
  39. package/dist/Dropdown.js.map +1 -1
  40. package/dist/DropdownField.d.ts +22 -0
  41. package/dist/DropdownField.js +22 -0
  42. package/dist/DropdownField.js.map +1 -1
  43. package/dist/EmptyState.d.ts +11 -0
  44. package/dist/EmptyState.js +11 -0
  45. package/dist/EmptyState.js.map +1 -1
  46. package/dist/Fab.d.ts +8 -0
  47. package/dist/Fab.js +8 -0
  48. package/dist/Fab.js.map +1 -1
  49. package/dist/FormField.d.ts +25 -0
  50. package/dist/FormField.js +25 -0
  51. package/dist/FormField.js.map +1 -1
  52. package/dist/Img.d.ts +7 -0
  53. package/dist/Img.js +7 -0
  54. package/dist/Img.js.map +1 -1
  55. package/dist/InlineAlert.d.ts +7 -0
  56. package/dist/InlineAlert.js +7 -0
  57. package/dist/InlineAlert.js.map +1 -1
  58. package/dist/Layout.d.ts +7 -0
  59. package/dist/Layout.js +7 -0
  60. package/dist/Layout.js.map +1 -1
  61. package/dist/Link.d.ts +7 -0
  62. package/dist/Link.js +7 -0
  63. package/dist/Link.js.map +1 -1
  64. package/dist/ListItem.d.ts +15 -0
  65. package/dist/ListItem.js +15 -0
  66. package/dist/ListItem.js.map +1 -1
  67. package/dist/Menu.d.ts +28 -0
  68. package/dist/Menu.js +29 -1
  69. package/dist/Menu.js.map +1 -1
  70. package/dist/MenuButton.d.ts +7 -0
  71. package/dist/MenuButton.js +7 -0
  72. package/dist/MenuButton.js.map +1 -1
  73. package/dist/Modal.d.ts +23 -1
  74. package/dist/Modal.js +23 -1
  75. package/dist/Modal.js.map +1 -1
  76. package/dist/NumberField.d.ts +19 -0
  77. package/dist/NumberField.js +19 -0
  78. package/dist/NumberField.js.map +1 -1
  79. package/dist/NumberInput.d.ts +16 -0
  80. package/dist/NumberInput.js +16 -0
  81. package/dist/NumberInput.js.map +1 -1
  82. package/dist/Popover.d.ts +29 -2
  83. package/dist/Popover.js +30 -3
  84. package/dist/Popover.js.map +1 -1
  85. package/dist/ProgressBar.d.ts +8 -0
  86. package/dist/ProgressBar.js +9 -1
  87. package/dist/ProgressBar.js.map +1 -1
  88. package/dist/ProgressCircle.d.ts +8 -0
  89. package/dist/ProgressCircle.js +8 -0
  90. package/dist/ProgressCircle.js.map +1 -1
  91. package/dist/ProgressionStepper.d.ts +12 -0
  92. package/dist/ProgressionStepper.js +12 -0
  93. package/dist/ProgressionStepper.js.map +1 -1
  94. package/dist/RadioGroup.d.ts +38 -6
  95. package/dist/RadioGroup.js +34 -5
  96. package/dist/RadioGroup.js.map +1 -1
  97. package/dist/RadioOption.d.ts +3 -1
  98. package/dist/RadioOption.js +5 -2
  99. package/dist/RadioOption.js.map +1 -1
  100. package/dist/SearchBar.d.ts +34 -0
  101. package/dist/SearchBar.js +34 -0
  102. package/dist/SearchBar.js.map +1 -1
  103. package/dist/SegmentedControl.d.ts +35 -8
  104. package/dist/SegmentedControl.js +24 -2
  105. package/dist/SegmentedControl.js.map +1 -1
  106. package/dist/Skeleton.d.ts +3 -1
  107. package/dist/Skeleton.js +3 -1
  108. package/dist/Skeleton.js.map +1 -1
  109. package/dist/Switch.d.ts +18 -1
  110. package/dist/Switch.js +18 -1
  111. package/dist/Switch.js.map +1 -1
  112. package/dist/SwitchOption.d.ts +4 -2
  113. package/dist/SwitchOption.js +5 -2
  114. package/dist/SwitchOption.js.map +1 -1
  115. package/dist/TabGroup.d.ts +26 -5
  116. package/dist/TabGroup.js +20 -0
  117. package/dist/TabGroup.js.map +1 -1
  118. package/dist/Tag.d.ts +13 -1
  119. package/dist/Tag.js +13 -1
  120. package/dist/Tag.js.map +1 -1
  121. package/dist/TextField.d.ts +21 -2
  122. package/dist/TextField.js +22 -2
  123. package/dist/TextField.js.map +1 -1
  124. package/dist/TextInput.d.ts +22 -3
  125. package/dist/TextInput.js +20 -2
  126. package/dist/TextInput.js.map +1 -1
  127. package/dist/Textarea.d.ts +23 -4
  128. package/dist/Textarea.js +27 -7
  129. package/dist/Textarea.js.map +1 -1
  130. package/dist/TextareaField.d.ts +21 -1
  131. package/dist/TextareaField.js +24 -2
  132. package/dist/TextareaField.js.map +1 -1
  133. package/dist/ToggleOption.d.ts +8 -5
  134. package/dist/ToggleOption.js +3 -3
  135. package/dist/ToggleOption.js.map +1 -1
  136. package/dist/Tooltip.d.ts +15 -3
  137. package/dist/Tooltip.js +20 -3
  138. package/dist/Tooltip.js.map +1 -1
  139. package/dist/Txt.d.ts +9 -1
  140. package/dist/Txt.js +9 -1
  141. package/dist/Txt.js.map +1 -1
  142. package/dist/badge.css +1 -1
  143. package/dist/demo/examples.js +3 -0
  144. package/dist/demo/examples.js.map +1 -1
  145. package/dist/progress-bar.css +1 -1
  146. package/dist/radio-group.css +1 -0
  147. package/dist/textarea.css +1 -1
  148. package/dist/toggle-option.css +1 -1
  149. package/meta.ts +8 -6
  150. package/package.json +1 -1
  151. package/src/Avatar.tsx +18 -2
  152. package/src/AvatarGroup.tsx +14 -0
  153. package/src/Badge.tsx +30 -4
  154. package/src/BannerAlert.tsx +17 -0
  155. package/src/Button.tsx +16 -0
  156. package/src/Card.tsx +12 -0
  157. package/src/Checkbox.tsx +21 -0
  158. package/src/CheckboxGroup.tsx +30 -0
  159. package/src/CheckboxOption.tsx +29 -4
  160. package/src/Chip.tsx +11 -0
  161. package/src/Dialog.tsx +19 -0
  162. package/src/Divider.tsx +13 -0
  163. package/src/Dropdown.tsx +30 -0
  164. package/src/DropdownField.tsx +22 -0
  165. package/src/EmptyState.tsx +11 -0
  166. package/src/Fab.tsx +8 -0
  167. package/src/FormField.tsx +25 -0
  168. package/src/Img.tsx +7 -0
  169. package/src/InlineAlert.tsx +7 -0
  170. package/src/Layout.tsx +7 -0
  171. package/src/Link.tsx +7 -0
  172. package/src/ListItem.tsx +15 -0
  173. package/src/Menu.tsx +29 -0
  174. package/src/MenuButton.tsx +7 -0
  175. package/src/Modal.tsx +23 -1
  176. package/src/NumberField.tsx +19 -0
  177. package/src/NumberInput.tsx +16 -0
  178. package/src/Popover.tsx +53 -5
  179. package/src/ProgressBar.tsx +8 -0
  180. package/src/ProgressCircle.tsx +8 -0
  181. package/src/ProgressionStepper.tsx +12 -0
  182. package/src/RadioGroup.tsx +68 -25
  183. package/src/RadioOption.tsx +9 -4
  184. package/src/SearchBar.tsx +47 -3
  185. package/src/SegmentedControl.tsx +57 -14
  186. package/src/Skeleton.tsx +3 -1
  187. package/src/Switch.tsx +18 -1
  188. package/src/SwitchOption.tsx +11 -6
  189. package/src/TabGroup.tsx +30 -6
  190. package/src/Tag.tsx +13 -1
  191. package/src/TextField.tsx +37 -6
  192. package/src/TextInput.tsx +36 -5
  193. package/src/Textarea.tsx +41 -9
  194. package/src/TextareaField.tsx +33 -4
  195. package/src/ToggleOption.tsx +9 -6
  196. package/src/Tooltip.tsx +29 -5
  197. package/src/Txt.tsx +14 -2
  198. package/src/badge.scss +17 -4
  199. package/src/demo/examples.tsx +3 -0
  200. package/src/progress-bar.scss +0 -2
  201. package/src/radio-group.scss +5 -0
  202. package/src/textarea.scss +4 -0
  203. package/src/toggle-option.scss +1 -20
  204. package/dist/SwitchGroup.d.ts +0 -42
  205. package/dist/SwitchGroup.js +0 -16
  206. package/dist/SwitchGroup.js.map +0 -1
  207. package/dist/hooks/useSwitchGroupState.d.ts +0 -37
  208. package/dist/hooks/useSwitchGroupState.js +0 -57
  209. package/dist/hooks/useSwitchGroupState.js.map +0 -1
  210. package/src/SwitchGroup.tsx +0 -72
  211. package/src/hooks/useSwitchGroupState.ts +0 -75
package/src/Tooltip.tsx CHANGED
@@ -4,13 +4,19 @@ import { ReactElement, cloneElement, useId, useMemo, useRef, useState } from 're
4
4
  import { Portal } from './Portal';
5
5
  import { Placement, useFloating } from './hooks/useFloating';
6
6
 
7
+ const DEFAULT = {
8
+ placement: 'top',
9
+ showTail: true,
10
+ disabled: false,
11
+ } as const;
12
+
7
13
  export type TooltipProps = {
8
14
  /**
9
15
  * The placement of the tooltip.
10
16
  *
11
17
  * @default top
12
18
  */
13
- placement?: Placement;
19
+ placement?: Extract<Placement, 'bottom' | 'left' | 'right' | 'top'>;
14
20
  /** The tooltip content. */
15
21
  label: string;
16
22
  /**
@@ -27,15 +33,33 @@ export type TooltipProps = {
27
33
  *
28
34
  * @default true
29
35
  */
30
- tail?: boolean;
36
+ showTail?: boolean;
31
37
  };
32
38
 
33
39
  /**
34
40
  * Brief message that provide additional guidance and helps users perform an action if needed.
35
41
  *
42
+ * @example
43
+ * import { Tooltip } from '@bspk/ui/Tooltip';
44
+ * import { Button } from '@bspk/ui/Button';
45
+ *
46
+ * export function Example() {
47
+ * return (
48
+ * <Tooltip label="I explain what this button does" placement="top">
49
+ * <Button>Click me</Button>
50
+ * </Tooltip>
51
+ * );
52
+ * }
53
+ *
36
54
  * @name Tooltip
37
55
  */
38
- function Tooltip({ placement = 'top', label, children, disabled = false, tail = true }: TooltipProps) {
56
+ function Tooltip({
57
+ placement = DEFAULT.placement,
58
+ label,
59
+ children,
60
+ disabled = DEFAULT.disabled,
61
+ showTail = DEFAULT.showTail,
62
+ }: TooltipProps) {
39
63
  const id = useId();
40
64
  const [show, setShow] = useState(false);
41
65
 
@@ -56,7 +80,7 @@ function Tooltip({ placement = 'top', label, children, disabled = false, tail =
56
80
  const { floatingStyles, middlewareData, elements } = useFloating({
57
81
  placement: placement,
58
82
  strategy: 'fixed',
59
- offsetOptions: 8,
83
+ offsetOptions: 4,
60
84
  arrowRef,
61
85
  hide: !show,
62
86
  });
@@ -80,7 +104,7 @@ function Tooltip({ placement = 'top', label, children, disabled = false, tail =
80
104
  style={floatingStyles}
81
105
  >
82
106
  <span data-text>{label}</span>
83
- {tail !== false && (
107
+ {showTail !== false && (
84
108
  <span
85
109
  aria-hidden
86
110
  data-arrow
package/src/Txt.tsx CHANGED
@@ -30,7 +30,15 @@ export type TxtProps<As extends ElementType = 'span'> = {
30
30
  };
31
31
 
32
32
  /**
33
- * A text component that applies the correct font styles based on the variant and size. variant
33
+ * A text component that applies the correct font styles based on the variant
34
+ * and size. variant
35
+ *
36
+ * @example
37
+ * import { Txt } from '@bspk/ui/Txt';
38
+ *
39
+ * export function Example() {
40
+ * return <Txt>Example Txt</Txt>;
41
+ * }
34
42
  *
35
43
  * @name Txt
36
44
  */
@@ -48,7 +56,11 @@ function Txt<As extends ElementType = 'span'>({
48
56
  const As: ElementType = as || 'span';
49
57
 
50
58
  return (
51
- <As {...containerProps} data-bspk="txt" style={{ ...styleProp, font: `var(--${variant})` }}>
59
+ <As
60
+ {...containerProps}
61
+ data-bspk="txt"
62
+ style={{ ...styleProp, font: `var(--${variant})` }}
63
+ >
52
64
  {content}
53
65
  </As>
54
66
  );
package/src/badge.scss CHANGED
@@ -9,6 +9,9 @@
9
9
  width: fit-content;
10
10
  min-width: var(--size);
11
11
  padding: 0 var(--spacing-sizing-02);
12
+ font: var(--labels-x-small);
13
+ color: var(--foreground-brand-on-primary);
14
+ background: var(--surface-brand-primary);
12
15
 
13
16
  &[data-size='x-small'] {
14
17
  --size: var(--spacing-sizing-05);
@@ -16,14 +19,24 @@
16
19
  padding: 2px var(--spacing-sizing-01);
17
20
  }
18
21
 
19
- font: var(--labels-x-small);
20
- color: var(--foreground-brand-on-primary);
21
- background: var(--surface-brand-primary);
22
-
23
22
  &[data-variant='secondary'] {
24
23
  color: var(--foreground-brand-on-secondary);
25
24
  background: var(--surface-brand-secondary);
26
25
  }
26
+
27
+ &[data-surface-border] {
28
+ position: relative;
29
+
30
+ &::after {
31
+ display: block;
32
+ content: ' ';
33
+ position: absolute;
34
+ inset: 0;
35
+ border-radius: var(--radius-circular);
36
+ border: 2px solid var(--surface-neutral-t1-base);
37
+ z-index: 1;
38
+ }
39
+ }
27
40
  }
28
41
 
29
42
  /** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
@@ -478,6 +478,9 @@ export const examples: (setState: DemoSetState, action: DemoAction) => Record<st
478
478
  );
479
479
  },
480
480
  },
481
+ ProgressBar: {
482
+ containerStyle: { width: '80%' },
483
+ },
481
484
  ProgressionStepper: {
482
485
  presets: setPresets<ProgressionStepperProps>([
483
486
  {
@@ -29,8 +29,6 @@
29
29
  }
30
30
 
31
31
  &[data-size='small'] {
32
- max-width: 248px;
33
-
34
32
  [data-bar] {
35
33
  height: var(--spacing-sizing-01);
36
34
  }
@@ -0,0 +1,5 @@
1
+ [data-bspk='radio-group'] {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: var(--spacing-sizing-01);
5
+ }
package/src/textarea.scss CHANGED
@@ -27,6 +27,7 @@
27
27
  [data-replicated-value] {
28
28
  white-space: pre-wrap;
29
29
  visibility: hidden;
30
+ overflow-y: hidden;
30
31
  }
31
32
 
32
33
  textarea,
@@ -38,11 +39,14 @@
38
39
  grid-area: 1 / 1 / 2 / 2;
39
40
  min-height: calc((var(--line-height) * var(--min-rows)) + (var(--padding) * 2));
40
41
  max-height: calc((var(--line-height) * var(--max-rows)) + (var(--padding) * 2));
42
+ max-width: 100%;
41
43
  }
42
44
 
43
45
  textarea {
44
46
  --border-color: var(--stroke-neutral-base);
45
47
 
48
+ text-wrap: break-word;
49
+
46
50
  &::placeholder {
47
51
  color: var(--foreground-neutral-on-surface-variant-03);
48
52
  }
@@ -16,6 +16,7 @@
16
16
  align-items: unset;
17
17
  }
18
18
 
19
+ // this media query targets touch devices
19
20
  @media (any-pointer: coarse) {
20
21
  min-height: var(--spacing-sizing-12);
21
22
  }
@@ -36,26 +37,6 @@
36
37
  color: var(--foreground-neutral-on-surface-variant-01);
37
38
  }
38
39
 
39
- &[data-size='small'] {
40
- [data-label] {
41
- font: var(--labels-small);
42
- }
43
-
44
- [data-description] {
45
- font: var(--body-x-small);
46
- }
47
- }
48
-
49
- &[data-size='large'] {
50
- [data-label] {
51
- font: var(--labels-large);
52
- }
53
-
54
- [data-description] {
55
- font: var(--body-base);
56
- }
57
- }
58
-
59
40
  &:not(:has(:disabled)) {
60
41
  [data-pseudo='focus'] &,
61
42
  &:focus-visible,
@@ -1,42 +0,0 @@
1
- import { ToggleOptionProps } from './ToggleOption';
2
- import { ElementProps, CommonProps } from './';
3
- export type SwitchGroupOption = Pick<ToggleOptionProps, 'description' | 'label'> & Required<CommonProps<'value'>>;
4
- export type SwitchGroupProps = CommonProps<'aria-label' | 'name'> & {
5
- /**
6
- * The function to call when the switches are changed.
7
- *
8
- * @required
9
- */
10
- onChange: (value: string[]) => void;
11
- /**
12
- * The options for the switches.
13
- *
14
- * @example
15
- * [
16
- * { value: '1', label: 'Option 1' },
17
- * { value: '2', label: 'Option 2' },
18
- * { value: '3', label: 'Option 3' },
19
- * ];
20
- *
21
- * @type Array<SwitchGroupOption>
22
- * @required
23
- */
24
- options: SwitchGroupOption[];
25
- /**
26
- * The values of the switches in the on state.
27
- *
28
- * @type Array<string>
29
- */
30
- value?: SwitchGroupProps['options'][number]['value'][];
31
- };
32
- /**
33
- * A group of switches that allows users to choose one or more items from a list or turn an feature on or off.
34
- *
35
- * @name SwitchGroup
36
- */
37
- declare function SwitchGroup({ onChange, options, name, value: values, ...props }: ElementProps<SwitchGroupProps, 'div'>): import("react/jsx-runtime").JSX.Element;
38
- declare namespace SwitchGroup {
39
- var bspkName: string;
40
- }
41
- export { SwitchGroup };
42
- /** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
@@ -1,16 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Switch } from './Switch';
3
- import { ToggleOption } from './ToggleOption';
4
- /**
5
- * A group of switches that allows users to choose one or more items from a list or turn an feature on or off.
6
- *
7
- * @name SwitchGroup
8
- */
9
- function SwitchGroup({ onChange, options = [], name, value: values = [], ...props }) {
10
- return (_jsx("div", { ...props, "data-bspk": "switch-group", role: "group", children: options.map(({ label, description, value }) => (_jsx(ToggleOption, { description: description, label: label, children: _jsx(Switch, { "aria-label": label, checked: values.includes(value), name: name, onChange: (checked) => {
11
- onChange(checked ? [...values, value] : values.filter((v) => v !== value));
12
- }, value: value }) }, value))) }));
13
- }
14
- SwitchGroup.bspkName = 'SwitchGroup';
15
- export { SwitchGroup };
16
- //# sourceMappingURL=SwitchGroup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SwitchGroup.js","sourceRoot":"","sources":["../src/SwitchGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAqB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAmCjE;;;;GAIG;AACH,SAAS,WAAW,CAAC,EACjB,QAAQ,EACR,OAAO,GAAG,EAAE,EACZ,IAAI,EACJ,KAAK,EAAE,MAAM,GAAG,EAAE,EAClB,GAAG,KAAK,EAC4B;IACpC,OAAO,CACH,iBAAS,KAAK,eAAY,cAAc,EAAC,IAAI,EAAC,OAAO,YAChD,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAC5C,KAAC,YAAY,IAAC,WAAW,EAAE,WAAW,EAAc,KAAK,EAAE,KAAK,YAC5D,KAAC,MAAM,kBACS,KAAK,EACjB,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC/B,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE;oBAClB,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;gBAC/E,CAAC,EACD,KAAK,EAAE,KAAK,GACd,IATuC,KAAK,CAUnC,CAClB,CAAC,GACA,CACT,CAAC;AACN,CAAC;AAED,WAAW,CAAC,QAAQ,GAAG,aAAa,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,37 +0,0 @@
1
- import { SwitchProps } from '../Switch';
2
- /**
3
- * A hook to manage the state of a group of switches. Used alongside the SwitchGroup component.
4
- *
5
- * @example
6
- * import { Switch } from '@bspk/ui/Switch';
7
- * import { useSwitchGroupState } from '@bspk/ui/hooks/useSwitchGroupState';
8
- *
9
- * export function Example() {
10
- * const allValues = ['Red', 'Orange', 'Yellow', 'Green'];
11
- *
12
- * const { allSwitchProps, switchProps, values } = useSwitchGroupState(allValues, 'fruits');
13
- *
14
- * return (
15
- * <>
16
- * <pre>Selected Values: {values.join(', ')}</pre>
17
- * <Switch aria-label="All" {...allSwitchProps} />
18
- * {allValues.map((value) => (
19
- * <Switch key={value} aria-label={value} {...switchProps(value)} />
20
- * ))}
21
- * </>
22
- * );
23
- * }
24
- *
25
- * @param allValues - The values of the switches.
26
- * @param name - The name of the switches.
27
- * @param externalState - The externally managed state of the switches.
28
- * @returns Properties to pass to the switch, other helper functions, and the state of the switch.
29
- */
30
- export declare function useSwitchGroupState(allValues: string[], name: string, externalState?: [values: string[], setValues: (next: string[]) => void]): {
31
- toggleValue: (itemValue: string, checked: boolean) => void;
32
- allSwitchProps: Pick<SwitchProps, "name" | "value" | "onChange" | "checked">;
33
- switchProps: (value: string) => Pick<SwitchProps, "checked" | "name" | "onChange" | "value">;
34
- values: string[];
35
- setValues: import("react").Dispatch<import("react").SetStateAction<string[]>>;
36
- };
37
- /** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
@@ -1,57 +0,0 @@
1
- import { useCallback, useMemo, useState } from 'react';
2
- /**
3
- * A hook to manage the state of a group of switches. Used alongside the SwitchGroup component.
4
- *
5
- * @example
6
- * import { Switch } from '@bspk/ui/Switch';
7
- * import { useSwitchGroupState } from '@bspk/ui/hooks/useSwitchGroupState';
8
- *
9
- * export function Example() {
10
- * const allValues = ['Red', 'Orange', 'Yellow', 'Green'];
11
- *
12
- * const { allSwitchProps, switchProps, values } = useSwitchGroupState(allValues, 'fruits');
13
- *
14
- * return (
15
- * <>
16
- * <pre>Selected Values: {values.join(', ')}</pre>
17
- * <Switch aria-label="All" {...allSwitchProps} />
18
- * {allValues.map((value) => (
19
- * <Switch key={value} aria-label={value} {...switchProps(value)} />
20
- * ))}
21
- * </>
22
- * );
23
- * }
24
- *
25
- * @param allValues - The values of the switches.
26
- * @param name - The name of the switches.
27
- * @param externalState - The externally managed state of the switches.
28
- * @returns Properties to pass to the switch, other helper functions, and the state of the switch.
29
- */
30
- export function useSwitchGroupState(allValues, name, externalState) {
31
- const localState = useState([]);
32
- const [values, setValues] = externalState || localState;
33
- const toggleValue = useCallback((itemValue, checked) => {
34
- setValues(allValues.flatMap((value) => {
35
- if (value === itemValue)
36
- return checked ? value : [];
37
- return values.includes(value) ? value : [];
38
- }));
39
- }, [allValues, setValues, values]);
40
- const switchProps = useCallback((value) => ({
41
- checked: values.includes(value),
42
- name,
43
- onChange: (checked) => toggleValue(value, checked),
44
- value,
45
- }), [values, name, toggleValue]);
46
- const allSwitchProps = useMemo(() => {
47
- return {
48
- checked: allValues.length === values.length,
49
- name,
50
- onChange: () => setValues(allValues.length === values.length ? [] : allValues),
51
- value: 'all',
52
- };
53
- }, [allValues, values.length, name, setValues]);
54
- return { toggleValue, allSwitchProps, switchProps, values, setValues };
55
- }
56
- /** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
57
- //# sourceMappingURL=useSwitchGroupState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSwitchGroupState.js","sourceRoot":"","sources":["../../src/hooks/useSwitchGroupState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB,CAC/B,SAAmB,EACnB,IAAY,EACZ,aAAuE;IAEvE,MAAM,UAAU,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAC1C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,aAAa,IAAI,UAAU,CAAC;IAExD,MAAM,WAAW,GAAG,WAAW,CAC3B,CAAC,SAAiB,EAAE,OAAgB,EAAE,EAAE;QACpC,SAAS,CACL,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACrD,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,CAAC,CAAC,CACL,CAAC;IACN,CAAC,EACD,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CACjC,CAAC;IAEF,MAAM,WAAW,GAAG,WAAW,CAC3B,CAAC,KAAa,EAAgE,EAAE,CAAC,CAAC;QAC9E,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC/B,IAAI;QACJ,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC;QAClD,KAAK;KACR,CAAC,EACF,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAC9B,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAAC,GAAiE,EAAE;QAC9F,OAAO;YACH,OAAO,EAAE,SAAS,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;YAC3C,IAAI;YACJ,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YAC9E,KAAK,EAAE,KAAK;SACf,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAEhD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC3E,CAAC;AAED,sDAAsD"}
@@ -1,72 +0,0 @@
1
- import { Switch } from './Switch';
2
- import { ToggleOptionProps, ToggleOption } from './ToggleOption';
3
-
4
- import { ElementProps, CommonProps } from './';
5
-
6
- export type SwitchGroupOption = Pick<ToggleOptionProps, 'description' | 'label'> & Required<CommonProps<'value'>>;
7
-
8
- export type SwitchGroupProps = CommonProps<'aria-label' | 'name'> & {
9
- /**
10
- * The function to call when the switches are changed.
11
- *
12
- * @required
13
- */
14
- onChange: (value: string[]) => void;
15
- /**
16
- * The options for the switches.
17
- *
18
- * @example
19
- * [
20
- * { value: '1', label: 'Option 1' },
21
- * { value: '2', label: 'Option 2' },
22
- * { value: '3', label: 'Option 3' },
23
- * ];
24
- *
25
- * @type Array<SwitchGroupOption>
26
- * @required
27
- */
28
- options: SwitchGroupOption[];
29
- /**
30
- * The values of the switches in the on state.
31
- *
32
- * @type Array<string>
33
- */
34
- value?: SwitchGroupProps['options'][number]['value'][];
35
- };
36
-
37
- /**
38
- * A group of switches that allows users to choose one or more items from a list or turn an feature on or off.
39
- *
40
- * @name SwitchGroup
41
- */
42
- function SwitchGroup({
43
- onChange,
44
- options = [],
45
- name,
46
- value: values = [],
47
- ...props
48
- }: ElementProps<SwitchGroupProps, 'div'>) {
49
- return (
50
- <div {...props} data-bspk="switch-group" role="group">
51
- {options.map(({ label, description, value }) => (
52
- <ToggleOption description={description} key={value} label={label}>
53
- <Switch
54
- aria-label={label}
55
- checked={values.includes(value)}
56
- name={name}
57
- onChange={(checked) => {
58
- onChange(checked ? [...values, value] : values.filter((v) => v !== value));
59
- }}
60
- value={value}
61
- />
62
- </ToggleOption>
63
- ))}
64
- </div>
65
- );
66
- }
67
-
68
- SwitchGroup.bspkName = 'SwitchGroup';
69
-
70
- export { SwitchGroup };
71
-
72
- /** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
@@ -1,75 +0,0 @@
1
- import { useCallback, useMemo, useState } from 'react';
2
-
3
- import { SwitchProps } from '../Switch';
4
-
5
- /**
6
- * A hook to manage the state of a group of switches. Used alongside the SwitchGroup component.
7
- *
8
- * @example
9
- * import { Switch } from '@bspk/ui/Switch';
10
- * import { useSwitchGroupState } from '@bspk/ui/hooks/useSwitchGroupState';
11
- *
12
- * export function Example() {
13
- * const allValues = ['Red', 'Orange', 'Yellow', 'Green'];
14
- *
15
- * const { allSwitchProps, switchProps, values } = useSwitchGroupState(allValues, 'fruits');
16
- *
17
- * return (
18
- * <>
19
- * <pre>Selected Values: {values.join(', ')}</pre>
20
- * <Switch aria-label="All" {...allSwitchProps} />
21
- * {allValues.map((value) => (
22
- * <Switch key={value} aria-label={value} {...switchProps(value)} />
23
- * ))}
24
- * </>
25
- * );
26
- * }
27
- *
28
- * @param allValues - The values of the switches.
29
- * @param name - The name of the switches.
30
- * @param externalState - The externally managed state of the switches.
31
- * @returns Properties to pass to the switch, other helper functions, and the state of the switch.
32
- */
33
- export function useSwitchGroupState(
34
- allValues: string[],
35
- name: string,
36
- externalState?: [values: string[], setValues: (next: string[]) => void],
37
- ) {
38
- const localState = useState<string[]>([]);
39
- const [values, setValues] = externalState || localState;
40
-
41
- const toggleValue = useCallback(
42
- (itemValue: string, checked: boolean) => {
43
- setValues(
44
- allValues.flatMap((value) => {
45
- if (value === itemValue) return checked ? value : [];
46
- return values.includes(value) ? value : [];
47
- }),
48
- );
49
- },
50
- [allValues, setValues, values],
51
- );
52
-
53
- const switchProps = useCallback(
54
- (value: string): Pick<SwitchProps, 'checked' | 'name' | 'onChange' | 'value'> => ({
55
- checked: values.includes(value),
56
- name,
57
- onChange: (checked) => toggleValue(value, checked),
58
- value,
59
- }),
60
- [values, name, toggleValue],
61
- );
62
-
63
- const allSwitchProps = useMemo((): Pick<SwitchProps, 'checked' | 'name' | 'onChange' | 'value'> => {
64
- return {
65
- checked: allValues.length === values.length,
66
- name,
67
- onChange: () => setValues(allValues.length === values.length ? [] : allValues),
68
- value: 'all',
69
- };
70
- }, [allValues, values.length, name, setValues]);
71
-
72
- return { toggleValue, allSwitchProps, switchProps, values, setValues };
73
- }
74
-
75
- /** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */