@bspk/ui 1.1.17 → 1.1.18

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 (136) hide show
  1. package/dist/Avatar.d.ts +17 -6
  2. package/dist/Avatar.js +15 -6
  3. package/dist/Avatar.js.map +1 -1
  4. package/dist/AvatarGroup.d.ts +49 -0
  5. package/dist/AvatarGroup.js +18 -0
  6. package/dist/AvatarGroup.js.map +1 -0
  7. package/dist/Badge.js +1 -1
  8. package/dist/Button.d.ts +14 -4
  9. package/dist/Button.js +1 -1
  10. package/dist/Button.js.map +1 -1
  11. package/dist/Checkbox.d.ts +15 -2
  12. package/dist/Checkbox.js.map +1 -1
  13. package/dist/CheckboxGroup.d.ts +6 -3
  14. package/dist/CheckboxGroup.js.map +1 -1
  15. package/dist/CheckboxOption.d.ts +8 -1
  16. package/dist/CheckboxOption.js.map +1 -1
  17. package/dist/Chip.d.ts +3 -1
  18. package/dist/Chip.js.map +1 -1
  19. package/dist/Dialog.d.ts +3 -3
  20. package/dist/Dialog.js.map +1 -1
  21. package/dist/Divider.js +1 -1
  22. package/dist/Dropdown.d.ts +26 -6
  23. package/dist/Dropdown.js +2 -2
  24. package/dist/Dropdown.js.map +1 -1
  25. package/dist/ListItem.js +1 -1
  26. package/dist/Menu.d.ts +27 -15
  27. package/dist/Menu.js +1 -1
  28. package/dist/Menu.js.map +1 -1
  29. package/dist/NumberInput.d.ts +5 -1
  30. package/dist/NumberInput.js +7 -5
  31. package/dist/NumberInput.js.map +1 -1
  32. package/dist/Portal.d.ts +5 -1
  33. package/dist/Portal.js.map +1 -1
  34. package/dist/ProgressBar.d.ts +4 -0
  35. package/dist/ProgressBar.js.map +1 -1
  36. package/dist/ProgressionStepper.d.ts +9 -2
  37. package/dist/ProgressionStepper.js +1 -1
  38. package/dist/ProgressionStepper.js.map +1 -1
  39. package/dist/ProgressionStepperBar.d.ts +6 -0
  40. package/dist/ProgressionStepperBar.js.map +1 -1
  41. package/dist/Radio.d.ts +16 -2
  42. package/dist/Radio.js +2 -2
  43. package/dist/Radio.js.map +1 -1
  44. package/dist/RadioGroup.d.ts +26 -3
  45. package/dist/RadioGroup.js +3 -3
  46. package/dist/RadioGroup.js.map +1 -1
  47. package/dist/RadioOption.d.ts +9 -1
  48. package/dist/RadioOption.js.map +1 -1
  49. package/dist/SegmentedControl.d.ts +21 -2
  50. package/dist/SegmentedControl.js +1 -1
  51. package/dist/SegmentedControl.js.map +1 -1
  52. package/dist/Switch.d.ts +1 -1
  53. package/dist/SwitchGroup.d.ts +13 -6
  54. package/dist/SwitchGroup.js +1 -1
  55. package/dist/SwitchGroup.js.map +1 -1
  56. package/dist/TabGroup.d.ts +23 -5
  57. package/dist/TabGroup.js +1 -1
  58. package/dist/TabGroup.js.map +1 -1
  59. package/dist/Tag.d.ts +5 -2
  60. package/dist/Tag.js +1 -1
  61. package/dist/Tag.js.map +1 -1
  62. package/dist/TextInput.d.ts +15 -6
  63. package/dist/TextInput.js +11 -5
  64. package/dist/TextInput.js.map +1 -1
  65. package/dist/Textarea.d.ts +3 -3
  66. package/dist/avatar-group.css +1 -0
  67. package/dist/avatar.css +1 -1
  68. package/dist/badge.css +1 -1
  69. package/dist/button.css +1 -1
  70. package/dist/demo/ExampleModalRender.d.ts +7 -0
  71. package/dist/demo/ExampleModalRender.js +16 -0
  72. package/dist/demo/ExampleModalRender.js.map +1 -0
  73. package/dist/demo/ExamplePlaceholder.d.ts +7 -0
  74. package/dist/demo/ExamplePlaceholder.js +13 -0
  75. package/dist/demo/ExamplePlaceholder.js.map +1 -0
  76. package/dist/demo/examples.d.ts +101 -0
  77. package/dist/demo/examples.js +472 -0
  78. package/dist/demo/examples.js.map +1 -0
  79. package/dist/divider.css +1 -1
  80. package/dist/hooks/useOptionIconsInvalid.d.ts +10 -1
  81. package/dist/hooks/useOptionIconsInvalid.js.map +1 -1
  82. package/dist/index.d.ts +4 -26
  83. package/dist/index.js.map +1 -1
  84. package/dist/list-item.css +1 -1
  85. package/dist/menu.css +1 -1
  86. package/dist/segmented-control.css +1 -1
  87. package/dist/tab-group.css +1 -1
  88. package/dist/tag.css +1 -1
  89. package/dist/text-input.css +1 -1
  90. package/dist/utils/children.js.map +1 -1
  91. package/meta-types.ts +2 -0
  92. package/meta.ts +76 -42
  93. package/package.json +1 -1
  94. package/src/Avatar.tsx +35 -8
  95. package/src/AvatarGroup.tsx +71 -0
  96. package/src/Button.tsx +14 -4
  97. package/src/Checkbox.tsx +25 -11
  98. package/src/CheckboxGroup.tsx +6 -3
  99. package/src/CheckboxOption.tsx +9 -2
  100. package/src/Chip.tsx +3 -1
  101. package/src/Dialog.tsx +3 -3
  102. package/src/Dropdown.tsx +30 -10
  103. package/src/Menu.tsx +30 -18
  104. package/src/NumberInput.tsx +15 -6
  105. package/src/Portal.tsx +5 -1
  106. package/src/ProgressBar.tsx +4 -0
  107. package/src/ProgressionStepper.tsx +9 -2
  108. package/src/ProgressionStepperBar.tsx +6 -0
  109. package/src/Radio.tsx +21 -4
  110. package/src/RadioGroup.tsx +34 -6
  111. package/src/RadioOption.tsx +11 -2
  112. package/src/SegmentedControl.tsx +21 -2
  113. package/src/Switch.tsx +1 -1
  114. package/src/SwitchGroup.tsx +19 -7
  115. package/src/TabGroup.tsx +23 -5
  116. package/src/Tag.tsx +5 -2
  117. package/src/TextInput.tsx +25 -15
  118. package/src/Textarea.tsx +3 -3
  119. package/src/avatar-group.scss +17 -0
  120. package/src/avatar.scss +5 -2
  121. package/src/badge.scss +1 -0
  122. package/src/button.scss +1 -0
  123. package/src/demo/ExampleModalRender.tsx +37 -0
  124. package/src/demo/ExamplePlaceholder.tsx +40 -0
  125. package/src/demo/examples.tsx +683 -0
  126. package/src/divider.scss +2 -0
  127. package/src/dropdown.scss +1 -0
  128. package/src/hooks/useOptionIconsInvalid.ts +10 -1
  129. package/src/index.ts +5 -32
  130. package/src/list-item.scss +5 -1
  131. package/src/menu.scss +1 -1
  132. package/src/segmented-control.scss +1 -0
  133. package/src/tab-group.scss +1 -0
  134. package/src/tag.scss +1 -0
  135. package/src/text-input.scss +13 -18
  136. package/src/utils/children.ts +1 -1
package/src/Dropdown.tsx CHANGED
@@ -10,27 +10,41 @@ import { useId } from './hooks/useId';
10
10
 
11
11
  import { CommonProps, InvalidPropsLibrary } from './';
12
12
 
13
- export type DropdownOption = {
13
+ export type DropdownOption = Record<string, unknown> & {
14
14
  /** The value of the option. */
15
15
  value: string;
16
16
  /** The label of the option. This is the text that will be displayed on the option. */
17
17
  label: string;
18
18
  };
19
19
 
20
- export type DropdownProps<O extends DropdownOption = DropdownOption> = CommonProps<
20
+ export type DropdownProps<T extends DropdownOption = DropdownOption> = CommonProps<
21
21
  'aria-label' | 'disabled' | 'id' | 'name' | 'readOnly' | 'size'
22
22
  > &
23
23
  InvalidPropsLibrary &
24
- Pick<MenuProps<O>, 'isMulti' | 'itemCount' | 'onChange' | 'renderListItem'> & {
24
+ Pick<MenuProps<T>, 'isMulti' | 'itemCount' | 'renderListItem'> & {
25
25
  /**
26
26
  * Array of options to display in the dropdown
27
27
  *
28
- * @type DropdownOption[]
28
+ * @example
29
+ * [
30
+ * { value: '1', label: 'Option 1' },
31
+ * { value: '2', label: 'Option 2' },
32
+ * { value: '3', label: 'Option 3' },
33
+ * { value: '4', label: 'Option 4' },
34
+ * { value: '5', label: 'Option 5' },
35
+ * { value: '6', label: 'Option 6' },
36
+ * { value: '7', label: 'Option 7' },
37
+ * { value: '8', label: 'Option 8' },
38
+ * { value: '9', label: 'Option 9' },
39
+ * { value: '10', label: 'Option 10' },
40
+ * ];
41
+ *
42
+ * @type Array<DropdownOption>
29
43
  * @required
30
44
  */
31
- options: O[];
45
+ options: T[];
32
46
  /**
33
- * Array of selected values!
47
+ * Array of selected values
34
48
  *
35
49
  * @type Array<string>
36
50
  */
@@ -49,6 +63,12 @@ export type DropdownProps<O extends DropdownOption = DropdownOption> = CommonPro
49
63
  placement?: Extract<Placement, 'bottom' | 'top'>;
50
64
  /** The style of the dropdown. */
51
65
  style?: React.CSSProperties;
66
+ /**
67
+ * The function to call when the selected values change.
68
+ *
69
+ * @required
70
+ */
71
+ onChange?: (value: string[], event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
52
72
  };
53
73
 
54
74
  /**
@@ -56,7 +76,7 @@ export type DropdownProps<O extends DropdownOption = DropdownOption> = CommonPro
56
76
  *
57
77
  * @name Dropdown
58
78
  */
59
- function Dropdown<O extends DropdownOption = DropdownOption>({
79
+ function Dropdown({
60
80
  options = [],
61
81
  value: selected,
62
82
  onChange,
@@ -74,7 +94,7 @@ function Dropdown<O extends DropdownOption = DropdownOption>({
74
94
  isMulti,
75
95
  renderListItem,
76
96
  style: styleProp,
77
- }: DropdownProps<O>) {
97
+ }: DropdownProps) {
78
98
  const id = useId(propId);
79
99
 
80
100
  const { triggerProps, menuProps, closeMenu } = useFloatingMenu({
@@ -116,10 +136,10 @@ function Dropdown<O extends DropdownOption = DropdownOption>({
116
136
  isMulti={isMulti}
117
137
  itemCount={itemCount}
118
138
  items={options}
119
- onChange={(selectedValues, event) => {
139
+ onChange={(next, event) => {
120
140
  event?.preventDefault();
121
141
  if (!isMulti) closeMenu();
122
- onChange?.(selectedValues);
142
+ onChange?.(next);
123
143
  }}
124
144
  renderListItem={renderListItem}
125
145
  selectedValues={selected}
package/src/Menu.tsx CHANGED
@@ -1,12 +1,12 @@
1
1
  import './menu.scss';
2
- import { ComponentProps, CSSProperties, MouseEvent as ReactMouseEvent, useMemo } from 'react';
2
+ import { ComponentProps, CSSProperties, useMemo } from 'react';
3
3
 
4
4
  import { Checkbox } from './Checkbox';
5
5
  import { ListItem } from './ListItem';
6
6
  import { Txt } from './Txt';
7
7
  import { useId } from './hooks/useId';
8
8
 
9
- import { CommonProps, ElementProps } from './';
9
+ import { CommonProps, ElementProps, SetRef } from './';
10
10
 
11
11
  export const MIN_ITEM_COUNT = 3;
12
12
  export const MAX_ITEM_COUNT = 10;
@@ -16,12 +16,12 @@ export function menuItemId(menuId: string, index: number) {
16
16
  }
17
17
 
18
18
  /** The props for the renderListItem function. Useful for customizing menu list items. */
19
- export type RenderListItemParams<M extends MenuItem> = Pick<
20
- MenuProps<M>,
19
+ export type RenderListItemParams<T extends MenuItem = MenuItem> = Pick<
20
+ MenuProps<T>,
21
21
  'activeIndex' | 'isMulti' | 'selectedValues'
22
22
  > & {
23
23
  index: number;
24
- item: M;
24
+ item: T;
25
25
  menuId: string;
26
26
  selected: boolean;
27
27
  itemId?: string;
@@ -37,7 +37,7 @@ export type MenuItem = CommonProps<'disabled'> & {
37
37
  id?: string;
38
38
  };
39
39
 
40
- export type MenuProps<Item extends MenuItem = MenuItem> = CommonProps<'disabled' | 'id'> & {
40
+ export type MenuProps<T extends MenuItem = MenuItem> = CommonProps<'disabled' | 'id'> & {
41
41
  /**
42
42
  * The number of items to display in the menu
43
43
  *
@@ -49,11 +49,25 @@ export type MenuProps<Item extends MenuItem = MenuItem> = CommonProps<'disabled'
49
49
  /**
50
50
  * Content to display in the menu.
51
51
  *
52
- * @type MenuItems
52
+ * @example
53
+ * [
54
+ * { value: '1', label: 'Option 1' },
55
+ * { value: '2', label: 'Option 2' },
56
+ * { value: '3', label: 'Option 3' },
57
+ * { value: '4', label: 'Option 4' },
58
+ * { value: '5', label: 'Option 5' },
59
+ * { value: '6', label: 'Option 6' },
60
+ * { value: '7', label: 'Option 7' },
61
+ * { value: '8', label: 'Option 8' },
62
+ * { value: '9', label: 'Option 9' },
63
+ * { value: '10', label: 'Option 10' },
64
+ * ];
65
+ *
66
+ * @type Array<MenuItem>
53
67
  */
54
- items?: Item[];
68
+ items?: T[];
55
69
  /** A ref to the inner div element. */
56
- innerRef?: (node: HTMLElement | null) => void;
70
+ innerRef?: SetRef<HTMLDivElement>;
57
71
  /**
58
72
  * Message to display when no results are found
59
73
  *
@@ -71,7 +85,7 @@ export type MenuProps<Item extends MenuItem = MenuItem> = CommonProps<'disabled'
71
85
  * @param {RenderListItemParams} props
72
86
  * @returns {ComponentProps<typeof ListItem>}
73
87
  */
74
- renderListItem?: (props: RenderListItemParams<Item>) => Partial<ComponentProps<typeof ListItem>>;
88
+ renderListItem?: (props: RenderListItemParams<T>) => Partial<ComponentProps<typeof ListItem>>;
75
89
  /**
76
90
  * Whether the menu allows multiple selections.
77
91
  *
@@ -81,12 +95,10 @@ export type MenuProps<Item extends MenuItem = MenuItem> = CommonProps<'disabled'
81
95
  /**
82
96
  * The function to call when the selected values change.
83
97
  *
84
- * @type (selectedValues: String[], event: ChangeEvent) => void
85
- * @param {string[]} selectedValues
86
- * @param {ChangeEvent} event
87
- * @returns {void}
98
+ * @example
99
+ * (selectedValues, event) => setState({ selectedValues });
88
100
  */
89
- onChange?: (selectedValues: string[], event?: ReactMouseEvent<HTMLButtonElement, MouseEvent>) => void;
101
+ onChange?: (selectedValues: string[], event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
90
102
  };
91
103
 
92
104
  /**
@@ -94,7 +106,7 @@ export type MenuProps<Item extends MenuItem = MenuItem> = CommonProps<'disabled'
94
106
  *
95
107
  * @name Menu
96
108
  */
97
- function Menu<Item extends MenuItem = MenuItem>({
109
+ function Menu({
98
110
  itemCount: itemCountProp = 5,
99
111
  items: itemsProp = [],
100
112
  noResultsMessage,
@@ -107,7 +119,7 @@ function Menu<Item extends MenuItem = MenuItem>({
107
119
  renderListItem,
108
120
  isMulti,
109
121
  ...props
110
- }: ElementProps<MenuProps<Item>, 'div'>) {
122
+ }: ElementProps<MenuProps, 'div'>) {
111
123
  const menuId = useId(idProp);
112
124
  const items = Array.isArray(itemsProp) ? itemsProp : [];
113
125
  const itemCount = useMemo(
@@ -164,7 +176,7 @@ function Menu<Item extends MenuItem = MenuItem>({
164
176
  id={itemId}
165
177
  key={itemId}
166
178
  label={renderProps?.label?.toString() || item.label?.toString()}
167
- onClick={(event: ReactMouseEvent<HTMLButtonElement, MouseEvent>) => {
179
+ onClick={(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
168
180
  if (renderProps) renderProps?.onClick?.(event);
169
181
 
170
182
  if (onChange) {
@@ -25,7 +25,11 @@ export type NumberInputProps = CommonProps<'aria-label' | 'disabled' | 'id' | 'n
25
25
  InvalidPropsLibrary & {
26
26
  /** The value of the control. */
27
27
  value?: number;
28
- /** Callback when the value changes. */
28
+ /**
29
+ * Callback when the value changes.
30
+ *
31
+ * @required
32
+ */
29
33
  onChange: (value: number | undefined) => void;
30
34
  /**
31
35
  * The alignment of the input box. Centered between the plus and minus buttons or to the left of the buttons.
@@ -78,8 +82,10 @@ function NumberInput({
78
82
  const max = isNumber(maxProp);
79
83
  const min = isNumber(minProp);
80
84
 
81
- const fix = (next: number | undefined = value) => {
82
- if (typeof next !== 'number') {
85
+ const fix = (nextValue: number | string | undefined) => {
86
+ const next = isNumber(nextValue);
87
+
88
+ if (typeof next !== 'number' || isNaN(next)) {
83
89
  onChange(undefined);
84
90
  return;
85
91
  }
@@ -116,12 +122,15 @@ function NumberInput({
116
122
  aria-label={ariaLabel}
117
123
  disabled={disabled}
118
124
  id={inputId}
125
+ max={max}
126
+ min={min}
119
127
  name={name}
120
- onBlur={() => {
121
- fix();
128
+ onBlur={(event) => {
129
+ // Fix the value on blur to ensure it is a valid number
130
+ fix(event.target.value);
122
131
  }}
123
132
  onChange={(event) => {
124
- onChange(event.target.value as unknown as number);
133
+ onChange(isNumber(event.target.value));
125
134
  }}
126
135
  readOnly={readOnly}
127
136
  type="number"
package/src/Portal.tsx CHANGED
@@ -8,7 +8,11 @@ export type PortalProps = {
8
8
  * @required
9
9
  */
10
10
  children: ReactNode;
11
- /** The container to render the portal in. */
11
+ /**
12
+ * The container to render the portal in.
13
+ *
14
+ * @optional
15
+ */
12
16
  container?: HTMLElement;
13
17
  };
14
18
 
@@ -11,9 +11,13 @@ export type ProgressBarProps = {
11
11
  /**
12
12
  * The current progress of the progressbar.
13
13
  *
14
+ * @example
15
+ * 42;
16
+ *
14
17
  * @default 0
15
18
  * @minimum 0
16
19
  * @maximum 100
20
+ *
17
21
  * @required
18
22
  */
19
23
  completion: number;
@@ -30,7 +30,14 @@ export type ProgressionStepperProps = {
30
30
  /**
31
31
  * The steps to display in the progress bar.
32
32
  *
33
- * @type ProgressionStepperItem[]
33
+ * @example
34
+ * [
35
+ * { name: '[Name of step to proceed forward 1]' },
36
+ * { name: '[Name of step to proceed forward 2]' },
37
+ * { name: '[Name of step to proceed forward 3]' },
38
+ * ];
39
+ *
40
+ * @type Array<ProgressionStepperItem>
34
41
  * @required
35
42
  */
36
43
  steps: ProgressionStepperItem[];
@@ -67,7 +74,7 @@ function ProgressionStepper({
67
74
  ...containerProps
68
75
  }: ElementProps<ProgressionStepperProps, 'div'>) {
69
76
  const currentStep = Math.max(0, Math.min(currentStepProp, steps.length + 1));
70
- return (
77
+ return !steps?.length ? null : (
71
78
  <div {...containerProps} data-bspk="progression-stepper" data-variant={variant}>
72
79
  {variant === 'widget' && (
73
80
  <label>
@@ -5,6 +5,9 @@ export type ProgressionStepperBarProps = {
5
5
  /**
6
6
  * The number of steps in the progress bar.
7
7
  *
8
+ * @example
9
+ * 5;
10
+ *
8
11
  * @minimum 2
9
12
  * @maximum 10
10
13
  * @required
@@ -13,6 +16,9 @@ export type ProgressionStepperBarProps = {
13
16
  /**
14
17
  * The last step completed.
15
18
  *
19
+ * @example
20
+ * 2;
21
+ *
16
22
  * @default 0
17
23
  * @minimum 0
18
24
  */
package/src/Radio.tsx CHANGED
@@ -1,8 +1,24 @@
1
1
  import './radio.scss';
2
- import { ToggleControlProps, ElementProps, InvalidPropsLibrary } from './';
2
+ import { ChangeEvent } from 'react';
3
3
 
4
- export type RadioProps = InvalidPropsLibrary &
5
- Pick<ToggleControlProps<HTMLInputElement>, 'aria-label' | 'checked' | 'disabled' | 'name' | 'onChange' | 'value'>;
4
+ import { ElementProps, InvalidPropsLibrary, CommonProps } from './';
5
+
6
+ export type RadioProps = CommonProps<'aria-label' | 'disabled' | 'name'> &
7
+ InvalidPropsLibrary &
8
+ Required<CommonProps<'value'>> & {
9
+ /**
10
+ * Marks the radio as checked.
11
+ *
12
+ * @default false
13
+ */
14
+ checked?: boolean;
15
+ /**
16
+ * The function to call when the radio is checked.
17
+ *
18
+ * @required
19
+ */
20
+ onChange: (checked: boolean, event: ChangeEvent<HTMLInputElement>) => void;
21
+ };
6
22
 
7
23
  /**
8
24
  * A round control that allows user to choose one option from a set. This is the base element and if used directly you
@@ -13,13 +29,14 @@ export type RadioProps = InvalidPropsLibrary &
13
29
  * @name Radio
14
30
  */
15
31
  function Radio(props: ElementProps<RadioProps, 'input'>) {
16
- const { checked = false, invalid, disabled, onChange, ...otherProps } = props;
32
+ const { checked = false, invalid, disabled, onChange, errorMessage, ...otherProps } = props;
17
33
 
18
34
  return (
19
35
  <span data-bspk="radio">
20
36
  <input
21
37
  {...otherProps}
22
38
  checked={!!checked}
39
+ data-errormessage={errorMessage || undefined}
23
40
  data-invalid={invalid || undefined}
24
41
  disabled={disabled || undefined}
25
42
  onChange={(event) => onChange(!!event.target.checked, event)}
@@ -5,21 +5,44 @@ import { ElementProps, CommonProps } from './';
5
5
 
6
6
  export type RadioGroupOption = Pick<ToggleOptionProps, 'description' | 'label'> & Required<CommonProps<'value'>>;
7
7
 
8
- export type RadioGroupProps = CommonProps<'name' | 'value'> & {
8
+ export type RadioGroupProps = CommonProps<'name'> & {
9
+ /**
10
+ * The value of the control.
11
+ *
12
+ * @example
13
+ * 1;
14
+ *
15
+ * @required
16
+ */
17
+ value: string;
9
18
  /**
10
19
  * The function to call when the radios are changed.
11
20
  *
21
+ * @example
22
+ * (value) => setState({ value }),
23
+ *
12
24
  * @required
13
25
  */
14
26
  onChange: (value: string) => void;
15
27
  /**
16
28
  * The options for the radios.
17
29
  *
18
- * @type RadioGroupOption[]
30
+ * @example
31
+ * [
32
+ * { value: '1', label: 'Option 1', description: 'Description here' },
33
+ * { value: '2', label: 'Option 2' },
34
+ * { value: '3', label: 'Option 3' },
35
+ * ];
36
+ *
37
+ * @type Array<RadioGroupOption>
19
38
  * @required
20
39
  */
21
40
  options: RadioGroupOption[];
22
- /** The size of the radio group labels. */
41
+ /**
42
+ * The size of the radio group labels.
43
+ *
44
+ * @default base
45
+ */
23
46
  size?: 'base' | 'large' | 'small';
24
47
  };
25
48
 
@@ -33,14 +56,19 @@ function RadioGroup({
33
56
  options = [],
34
57
  name,
35
58
  value: groupValue,
36
- size,
59
+ size = 'base',
37
60
  ...props
38
61
  }: ElementProps<RadioGroupProps, 'div'>) {
39
62
  return (
40
63
  <div {...props} data-bspk="radio-group" role="radiogroup" style={{ display: 'contents' }}>
41
- {options.map(({ label, description, value }) => {
64
+ {options.map(({ label, description, value }, index) => {
42
65
  return (
43
- <ToggleOption description={description} key={value} label={label} size={size}>
66
+ <ToggleOption
67
+ description={description}
68
+ key={`toggle-option-${value || index}`}
69
+ label={label}
70
+ size={size}
71
+ >
44
72
  <Radio
45
73
  aria-label={label}
46
74
  checked={groupValue === value}
@@ -1,11 +1,20 @@
1
+ import { ChangeEvent } from 'react';
2
+
1
3
  import { RadioProps, Radio } from './Radio';
2
4
  import { ToggleOptionProps, ToggleOption } from './ToggleOption';
3
5
 
4
6
  import { InvalidPropsLibrary } from '.';
5
7
 
6
8
  export type RadioOptionProps = InvalidPropsLibrary &
7
- Pick<RadioProps, 'checked' | 'disabled' | 'name' | 'onChange' | 'value'> &
8
- Pick<ToggleOptionProps, 'description' | 'label'>;
9
+ Pick<RadioProps, 'checked' | 'disabled' | 'name' | 'value'> &
10
+ Pick<ToggleOptionProps, 'description' | 'label'> & {
11
+ /**
12
+ * The function to call when the radio is checked.
13
+ *
14
+ * @required
15
+ */
16
+ onChange: (checked: boolean, event: ChangeEvent<HTMLInputElement>) => void;
17
+ };
9
18
 
10
19
  /**
11
20
  * A control that allows users to choose one or more items from a list or turn an feature on or off.
@@ -21,8 +21,17 @@ export type SegmentedControlOption = {
21
21
  disabled?: boolean;
22
22
  /** The value of the option. If not provided, the label will be used as the value. */
23
23
  value?: string;
24
- /** The the icon to display before the label. */
24
+ /**
25
+ * The the icon to display before the label.
26
+ *
27
+ * @type BspkIcon
28
+ */
25
29
  icon?: React.ReactNode;
30
+ /**
31
+ * The icon to display before the label when the option is active.
32
+ *
33
+ * @type BspkIcon
34
+ */
26
35
  iconActive?: React.ReactNode;
27
36
  };
28
37
 
@@ -30,13 +39,23 @@ export type SegmentedControlProps = {
30
39
  /**
31
40
  * The options to display. Each option has a label and an optional leading icon.
32
41
  *
33
- * @type SegmentedControlOption[]
42
+ * @example
43
+ * [
44
+ * { value: '1', label: 'Option 1' },
45
+ * { value: '2', label: 'Option 2' },
46
+ * { value: '3', label: 'Option 3' },
47
+ * ];
48
+ *
49
+ * @type Array<SegmentedControlOption>
34
50
  * @required
35
51
  */
36
52
  options: SegmentedControlOption[];
37
53
  /**
38
54
  * The id of the selected option.
39
55
  *
56
+ * @example
57
+ * 1;
58
+ *
40
59
  * @required
41
60
  */
42
61
  value: SegmentedControlOption['value'];
package/src/Switch.tsx CHANGED
@@ -3,7 +3,7 @@ import { ChangeEvent } from 'react';
3
3
 
4
4
  import { CommonProps } from './';
5
5
 
6
- export type SwitchProps = CommonProps<'aria-label' | 'disabled' | 'name' | 'onClick' | 'value'> & {
6
+ export type SwitchProps = CommonProps<'aria-label' | 'disabled' | 'name' | 'value'> & {
7
7
  /**
8
8
  * Marks the control as checked.
9
9
  *
@@ -1,10 +1,9 @@
1
1
  import { Switch } from './Switch';
2
2
  import { ToggleOptionProps, ToggleOption } from './ToggleOption';
3
3
 
4
- import { ToggleControlProps, ElementProps, CommonProps } from './';
4
+ import { ElementProps, CommonProps } from './';
5
5
 
6
- export type SwitchGroupOption = Pick<ToggleControlProps<HTMLInputElement>, 'value'> &
7
- Pick<ToggleOptionProps, 'description' | 'label'>;
6
+ export type SwitchGroupOption = Pick<ToggleOptionProps, 'description' | 'label'> & Required<CommonProps<'value'>>;
8
7
 
9
8
  export type SwitchGroupProps = CommonProps<'aria-label' | 'name'> & {
10
9
  /**
@@ -16,16 +15,23 @@ export type SwitchGroupProps = CommonProps<'aria-label' | 'name'> & {
16
15
  /**
17
16
  * The options for the switches.
18
17
  *
19
- * @type SwitchGroupOption[]
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>
20
26
  * @required
21
27
  */
22
28
  options: SwitchGroupOption[];
23
29
  /**
24
30
  * The values of the switches in the on state.
25
31
  *
26
- * @type string[]
32
+ * @type Array<string>
27
33
  */
28
- values?: SwitchGroupProps['options'][number]['value'][];
34
+ value?: SwitchGroupProps['options'][number]['value'][];
29
35
  };
30
36
 
31
37
  /**
@@ -33,7 +39,13 @@ export type SwitchGroupProps = CommonProps<'aria-label' | 'name'> & {
33
39
  *
34
40
  * @name SwitchGroup
35
41
  */
36
- function SwitchGroup({ onChange, options = [], name, values = [], ...props }: ElementProps<SwitchGroupProps, 'div'>) {
42
+ function SwitchGroup({
43
+ onChange,
44
+ options = [],
45
+ name,
46
+ value: values = [],
47
+ ...props
48
+ }: ElementProps<SwitchGroupProps, 'div'>) {
37
49
  return (
38
50
  <div {...props} data-bspk="switch-group" role="group">
39
51
  {options.map(({ label, description, value }) => (
package/src/TabGroup.tsx CHANGED
@@ -33,11 +33,19 @@ export type TabGroupOption = {
33
33
  * If not provided, the label will be used as the value.
34
34
  */
35
35
  value?: string;
36
- /** The icon to display on the left side of the tab. */
36
+ /**
37
+ * The icon to display on the left side of the tab.
38
+ *
39
+ * @type BspkIcon
40
+ */
37
41
  icon?: ReactNode;
38
- /** The icon to display on the left side of the tab when the tab is active. */
42
+ /**
43
+ * The icon to display on the left side of the tab when the tab is active.
44
+ *
45
+ * @type BspkIcon
46
+ */
39
47
  iconActive?: ReactNode;
40
- /** The badge count to display on the tab. */
48
+ /** The badge count to display on the tab */
41
49
  badge?: number;
42
50
  };
43
51
 
@@ -45,12 +53,22 @@ export type TabGroupProps = {
45
53
  /**
46
54
  * The tabs to display. Each tab has a label and an optional leading icon.
47
55
  *
48
- * @type TabGroupOption[]
56
+ * @example
57
+ * [
58
+ * { value: '1', label: 'Option 1' },
59
+ * { value: '2', label: 'Option 2' },
60
+ * { value: '3', label: 'Option 3' },
61
+ * ];
62
+ *
63
+ * @type Array<TabGroupOption>
49
64
  * @required
50
65
  */
51
66
  options: TabGroupOption[];
52
67
  /**
53
- * The id of the selected tab.
68
+ * The value of the selected tab.
69
+ *
70
+ * @example
71
+ * 1;
54
72
  *
55
73
  * @required
56
74
  */
package/src/Tag.tsx CHANGED
@@ -1,9 +1,9 @@
1
- import './tag.scss';
2
1
  import { ElementType, ReactNode } from 'react';
3
2
 
4
3
  import { ColorVariant } from './utils/colorVariants';
5
4
 
6
5
  import { ElementProps } from './';
6
+ import './tag.scss';
7
7
 
8
8
  export type TagProps<As extends ElementType = 'span'> = {
9
9
  /**
@@ -16,6 +16,9 @@ export type TagProps<As extends ElementType = 'span'> = {
16
16
  /**
17
17
  * The content of the tag.
18
18
  *
19
+ * @example
20
+ * New;
21
+ *
19
22
  * @required
20
23
  */
21
24
  children: ReactNode;
@@ -28,7 +31,7 @@ export type TagProps<As extends ElementType = 'span'> = {
28
31
  /**
29
32
  * The color of the tag.
30
33
  *
31
- * @default white
34
+ * @default grey
32
35
  */
33
36
  color?: ColorVariant;
34
37
  /**