@bspk/ui 1.1.17 → 1.1.19

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 (144) 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 +33 -7
  23. package/dist/Dropdown.js +5 -5
  24. package/dist/Dropdown.js.map +1 -1
  25. package/dist/ListItem.js +1 -1
  26. package/dist/Menu.d.ts +40 -21
  27. package/dist/Menu.js +63 -41
  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/SearchBar.d.ts +30 -4
  50. package/dist/SearchBar.js +16 -15
  51. package/dist/SearchBar.js.map +1 -1
  52. package/dist/SegmentedControl.d.ts +21 -2
  53. package/dist/SegmentedControl.js +1 -1
  54. package/dist/SegmentedControl.js.map +1 -1
  55. package/dist/Switch.d.ts +1 -1
  56. package/dist/SwitchGroup.d.ts +13 -6
  57. package/dist/SwitchGroup.js +1 -1
  58. package/dist/SwitchGroup.js.map +1 -1
  59. package/dist/TabGroup.d.ts +23 -5
  60. package/dist/TabGroup.js +1 -1
  61. package/dist/TabGroup.js.map +1 -1
  62. package/dist/Tag.d.ts +5 -2
  63. package/dist/Tag.js +1 -1
  64. package/dist/Tag.js.map +1 -1
  65. package/dist/TextInput.d.ts +15 -6
  66. package/dist/TextInput.js +11 -5
  67. package/dist/TextInput.js.map +1 -1
  68. package/dist/Textarea.d.ts +3 -3
  69. package/dist/avatar-group.css +1 -0
  70. package/dist/avatar.css +1 -1
  71. package/dist/badge.css +1 -1
  72. package/dist/button.css +1 -1
  73. package/dist/demo/ExampleModalRender.d.ts +7 -0
  74. package/dist/demo/ExampleModalRender.js +16 -0
  75. package/dist/demo/ExampleModalRender.js.map +1 -0
  76. package/dist/demo/ExamplePlaceholder.d.ts +7 -0
  77. package/dist/demo/ExamplePlaceholder.js +13 -0
  78. package/dist/demo/ExamplePlaceholder.js.map +1 -0
  79. package/dist/demo/examples.d.ts +101 -0
  80. package/dist/demo/examples.js +483 -0
  81. package/dist/demo/examples.js.map +1 -0
  82. package/dist/divider.css +1 -1
  83. package/dist/dropdown.css +1 -1
  84. package/dist/hooks/useKeyboardNavigation.js +5 -2
  85. package/dist/hooks/useKeyboardNavigation.js.map +1 -1
  86. package/dist/hooks/useOptionIconsInvalid.d.ts +10 -1
  87. package/dist/hooks/useOptionIconsInvalid.js.map +1 -1
  88. package/dist/index.d.ts +4 -26
  89. package/dist/index.js.map +1 -1
  90. package/dist/list-item.css +1 -1
  91. package/dist/menu.css +1 -1
  92. package/dist/segmented-control.css +1 -1
  93. package/dist/tab-group.css +1 -1
  94. package/dist/tag.css +1 -1
  95. package/dist/text-input.css +1 -1
  96. package/dist/utils/children.js.map +1 -1
  97. package/meta-types.ts +2 -0
  98. package/meta.ts +76 -42
  99. package/package.json +1 -1
  100. package/src/Avatar.tsx +35 -8
  101. package/src/AvatarGroup.tsx +71 -0
  102. package/src/Button.tsx +14 -4
  103. package/src/Checkbox.tsx +25 -11
  104. package/src/CheckboxGroup.tsx +6 -3
  105. package/src/CheckboxOption.tsx +9 -2
  106. package/src/Chip.tsx +3 -1
  107. package/src/Dialog.tsx +3 -3
  108. package/src/Dropdown.tsx +40 -11
  109. package/src/Menu.tsx +159 -108
  110. package/src/NumberInput.tsx +15 -6
  111. package/src/Portal.tsx +5 -1
  112. package/src/ProgressBar.tsx +4 -0
  113. package/src/ProgressionStepper.tsx +9 -2
  114. package/src/ProgressionStepperBar.tsx +6 -0
  115. package/src/Radio.tsx +21 -4
  116. package/src/RadioGroup.tsx +34 -6
  117. package/src/RadioOption.tsx +11 -2
  118. package/src/SearchBar.tsx +87 -44
  119. package/src/SegmentedControl.tsx +21 -2
  120. package/src/Switch.tsx +1 -1
  121. package/src/SwitchGroup.tsx +19 -7
  122. package/src/TabGroup.tsx +23 -5
  123. package/src/Tag.tsx +5 -2
  124. package/src/TextInput.tsx +25 -15
  125. package/src/Textarea.tsx +3 -3
  126. package/src/avatar-group.scss +17 -0
  127. package/src/avatar.scss +26 -2
  128. package/src/badge.scss +1 -0
  129. package/src/button.scss +1 -0
  130. package/src/demo/ExampleModalRender.tsx +37 -0
  131. package/src/demo/ExamplePlaceholder.tsx +40 -0
  132. package/src/demo/examples.tsx +699 -0
  133. package/src/divider.scss +2 -0
  134. package/src/dropdown.scss +5 -0
  135. package/src/hooks/useKeyboardNavigation.ts +3 -2
  136. package/src/hooks/useOptionIconsInvalid.ts +10 -1
  137. package/src/index.ts +5 -32
  138. package/src/list-item.scss +5 -1
  139. package/src/menu.scss +5 -1
  140. package/src/segmented-control.scss +1 -0
  141. package/src/tab-group.scss +1 -0
  142. package/src/tag.scss +1 -0
  143. package/src/text-input.scss +13 -18
  144. package/src/utils/children.ts +1 -1
@@ -0,0 +1,71 @@
1
+ import { Avatar, AvatarProps, SizeVariant } from './Avatar';
2
+ import './avatar-group.scss';
3
+
4
+ export type AvatarItem = Pick<AvatarProps, 'color' | 'icon' | 'image' | 'initials' | 'name'>;
5
+
6
+ export type AvatarGroupProps = {
7
+ /**
8
+ * The avatars to display in the group.
9
+ *
10
+ * @example
11
+ * [
12
+ * { name: 'Jane Doe', image: '/path/to/image.jpg' },
13
+ * { name: 'John Smith', initials: 'JS' },
14
+ * ];
15
+ *
16
+ * @type Array<AvatarItem>
17
+ * @required
18
+ */
19
+ items: AvatarItem[];
20
+ /**
21
+ * Size of the avatar group.
22
+ *
23
+ * @default small
24
+ */
25
+ size?: Extract<SizeVariant, 'large' | 'medium' | 'small' | 'x-small'>;
26
+ /**
27
+ * The maximum number of avatars to display before showing the overflowCount.
28
+ *
29
+ * This is used to limit the number of avatars displayed in the group.
30
+ *
31
+ * @minimum 3
32
+ * @maximum 5
33
+ */
34
+ max?: number;
35
+ /**
36
+ * The variant of the avatar group.
37
+ *
38
+ * @default spread
39
+ */
40
+ variant?: 'spread' | 'stacked';
41
+ };
42
+
43
+ /**
44
+ * AvatarGroup component displays a group of avatars.
45
+ *
46
+ * @name AvatarGroup
47
+ */
48
+ function AvatarGroup({ items, size = 'small', max = 5, variant }: AvatarGroupProps) {
49
+ if (!Array.isArray(items) || !items?.length) return null;
50
+
51
+ const overFlowCount = items.length - max;
52
+
53
+ return (
54
+ <div data-bspk="avatar-group" data-max={max} data-size={size} data-variant={variant}>
55
+ <div data-wrap>
56
+ {items.map((item, index) => (
57
+ <Avatar key={index} {...item} size={size} />
58
+ ))}
59
+ {overFlowCount > 0 && (
60
+ <div aria-hidden data-bspk="avatar" data-size={size}>
61
+ <span data-overflow-count>+{overFlowCount}</span>
62
+ </div>
63
+ )}
64
+ </div>
65
+ </div>
66
+ );
67
+ }
68
+
69
+ AvatarGroup.bspkName = 'AvatarGroup';
70
+
71
+ export { AvatarGroup };
package/src/Button.tsx CHANGED
@@ -9,10 +9,18 @@ import { ButtonSize, CommonProps, ElementProps } from './';
9
9
 
10
10
  export type ButtonVariant = 'primary' | 'secondary' | 'tertiary';
11
11
 
12
- export type ButtonProps<As extends ElementType = 'button'> = CommonProps<'disabled' | 'onClick'> & {
13
- /** The label of the button. */
14
- label?: string;
15
- /** The icon of the button. */
12
+ export type ButtonProps<As extends ElementType = 'button'> = CommonProps<'disabled'> & {
13
+ /**
14
+ * The label of the button.
15
+ *
16
+ * @required
17
+ */
18
+ label: string;
19
+ /**
20
+ * The icon of the button.
21
+ *
22
+ * @type BspkIcon
23
+ */
16
24
  icon?: ReactNode;
17
25
  /**
18
26
  * Shows the button label. When label isn't showing it is used in a tooltip and as the aria-label prop.
@@ -59,6 +67,8 @@ export type ButtonProps<As extends ElementType = 'button'> = CommonProps<'disabl
59
67
  children?: ReactNode;
60
68
  /** The tool tip text that appears when hovered. */
61
69
  toolTip?: string;
70
+ /** The function to call when the button is clicked. */
71
+ onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
62
72
  };
63
73
 
64
74
  /**
package/src/Checkbox.tsx CHANGED
@@ -1,17 +1,31 @@
1
1
  import './checkbox.scss';
2
- import { useEffect, useRef } from 'react';
2
+ import { ChangeEvent, useEffect, useRef } from 'react';
3
3
 
4
- import { ToggleControlProps, ElementProps } from './';
4
+ import { CommonProps, ElementProps, InvalidPropsLibrary } from './';
5
5
 
6
- export type CheckboxProps = ToggleControlProps<HTMLInputElement> & {
7
- /**
8
- * If the checkbox is partially checked or
9
- * [indeterminate](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate_state_checkboxes).
10
- *
11
- * @default false
12
- */
13
- indeterminate?: boolean;
14
- };
6
+ export type CheckboxProps = CommonProps<'aria-label' | 'disabled' | 'name'> &
7
+ InvalidPropsLibrary &
8
+ Required<CommonProps<'value'>> & {
9
+ /**
10
+ * If the checkbox is partially checked or
11
+ * [indeterminate](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate_state_checkboxes).
12
+ *
13
+ * @default false
14
+ */
15
+ indeterminate?: boolean;
16
+ /**
17
+ * Marks the checkbox as checked.
18
+ *
19
+ * @default false
20
+ */
21
+ checked?: boolean;
22
+ /**
23
+ * The function to call when the checkbox is checked or unchecked.
24
+ *
25
+ * @required
26
+ */
27
+ onChange: (checked: boolean, event: ChangeEvent<HTMLInputElement>) => void;
28
+ };
15
29
 
16
30
  /**
17
31
  * A control that allows users to choose one or more items from a list or turn an feature on or off. This is the base
@@ -9,9 +9,12 @@ export type CheckboxGroupProps = CommonProps<'aria-label'> & {
9
9
  /**
10
10
  * The function to call when the checkboxes are changed.
11
11
  *
12
+ * @example
13
+ * (values) => setState({ values });
14
+ *
12
15
  * @required
13
16
  */
14
- onChange: (value: string[]) => void;
17
+ onChange: (values: string[]) => void;
15
18
  /**
16
19
  * The input control name of the checkboxes.
17
20
  *
@@ -21,14 +24,14 @@ export type CheckboxGroupProps = CommonProps<'aria-label'> & {
21
24
  /**
22
25
  * The options for the checkboxes.
23
26
  *
24
- * @type CheckboxGroupOption[]
27
+ * @type Array<CheckboxGroupOption>
25
28
  * @required
26
29
  */
27
30
  options: CheckboxGroupOption[];
28
31
  /**
29
32
  * The values of the checked checkboxes.
30
33
  *
31
- * @type string[]
34
+ * @type Array<string>
32
35
  */
33
36
  values?: CheckboxGroupProps['options'][number]['value'][];
34
37
  /**
@@ -4,8 +4,15 @@ import { ToggleOptionProps, ToggleOption } from './ToggleOption';
4
4
  import { InvalidPropsLibrary } from '.';
5
5
 
6
6
  export type CheckboxOptionProps = InvalidPropsLibrary &
7
- Pick<CheckboxProps, 'checked' | 'disabled' | 'indeterminate' | 'name' | 'onChange' | 'value'> &
8
- Pick<ToggleOptionProps, 'description' | 'label'>;
7
+ Pick<CheckboxProps, 'checked' | 'disabled' | 'indeterminate' | 'name' | 'value'> &
8
+ Pick<ToggleOptionProps, 'description' | 'label'> & {
9
+ /**
10
+ * The function to call when the checkbox is checked or unchecked.
11
+ *
12
+ * @required
13
+ */
14
+ onChange: (checked: boolean, event: React.ChangeEvent<HTMLInputElement>) => void;
15
+ };
9
16
 
10
17
  /**
11
18
  * A control that allows users to choose one or more items from a list or turn an feature on or off.
package/src/Chip.tsx CHANGED
@@ -3,7 +3,7 @@ import { CSSProperties, ReactNode } from 'react';
3
3
 
4
4
  import { CommonProps } from '.';
5
5
 
6
- export type ChipProps = CommonProps<'disabled' | 'onClick'> & {
6
+ export type ChipProps = CommonProps<'disabled'> & {
7
7
  /**
8
8
  * The content of the chip.
9
9
  *
@@ -39,6 +39,8 @@ export type ChipProps = CommonProps<'disabled' | 'onClick'> & {
39
39
  selected?: boolean;
40
40
  /** The style of the chip. */
41
41
  style?: CSSProperties;
42
+ /** The function to call when the chip is clicked. */
43
+ onClick?: (event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void;
42
44
  };
43
45
 
44
46
  /**
package/src/Dialog.tsx CHANGED
@@ -1,18 +1,18 @@
1
1
  import './dialog.scss';
2
2
  import { FocusTrap } from 'focus-trap-react';
3
- import { ReactNode, Ref, useCallback, useEffect, useRef, useState } from 'react';
3
+ import { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
4
4
 
5
5
  import { Portal } from './Portal';
6
6
  import { useId } from './hooks/useId';
7
7
  import { useOutsideClick } from './hooks/useOutsideClick';
8
8
 
9
- import { CommonProps, ElementProps } from './';
9
+ import { CommonProps, ElementProps, SetRef } from './';
10
10
 
11
11
  export type DialogProps = CommonProps<'id'> & {
12
12
  /** The content of the dialog. */
13
13
  children?: ReactNode;
14
14
  /** A ref to the dialog element. */
15
- innerRef?: Ref<HTMLDivElement>;
15
+ innerRef?: SetRef<HTMLDivElement>;
16
16
  /**
17
17
  * If the dialog should appear.
18
18
  *
package/src/Dropdown.tsx CHANGED
@@ -10,27 +10,48 @@ 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 DropdownOptionAll = {
21
+ /** The label of the option. This is the text that will be displayed on the option. */
22
+ label: string;
23
+ /** Whether the option is selected. */
24
+ selected?: boolean;
25
+ };
26
+
27
+ export type DropdownProps<T extends DropdownOption = DropdownOption> = CommonProps<
21
28
  'aria-label' | 'disabled' | 'id' | 'name' | 'readOnly' | 'size'
22
29
  > &
23
30
  InvalidPropsLibrary &
24
- Pick<MenuProps<O>, 'isMulti' | 'itemCount' | 'onChange' | 'renderListItem'> & {
31
+ Pick<MenuProps<T>, 'isMulti' | 'itemCount' | 'renderListItem' | 'selectAll'> & {
25
32
  /**
26
33
  * Array of options to display in the dropdown
27
34
  *
28
- * @type DropdownOption[]
35
+ * @example
36
+ * [
37
+ * { value: '1', label: 'Option 1' },
38
+ * { value: '2', label: 'Option 2' },
39
+ * { value: '3', label: 'Option 3' },
40
+ * { value: '4', label: 'Option 4' },
41
+ * { value: '5', label: 'Option 5' },
42
+ * { value: '6', label: 'Option 6' },
43
+ * { value: '7', label: 'Option 7' },
44
+ * { value: '8', label: 'Option 8' },
45
+ * { value: '9', label: 'Option 9' },
46
+ * { value: '10', label: 'Option 10' },
47
+ * ];
48
+ *
49
+ * @type Array<DropdownOption>
29
50
  * @required
30
51
  */
31
- options: O[];
52
+ options: T[];
32
53
  /**
33
- * Array of selected values!
54
+ * Array of selected values
34
55
  *
35
56
  * @type Array<string>
36
57
  */
@@ -38,7 +59,7 @@ export type DropdownProps<O extends DropdownOption = DropdownOption> = CommonPro
38
59
  /**
39
60
  * Placeholder for the dropdown
40
61
  *
41
- * @default Select...
62
+ * @default Select one...
42
63
  */
43
64
  placeholder?: string;
44
65
  /**
@@ -49,6 +70,12 @@ export type DropdownProps<O extends DropdownOption = DropdownOption> = CommonPro
49
70
  placement?: Extract<Placement, 'bottom' | 'top'>;
50
71
  /** The style of the dropdown. */
51
72
  style?: React.CSSProperties;
73
+ /**
74
+ * The function to call when the selected values change.
75
+ *
76
+ * @required
77
+ */
78
+ onChange?: (value: string[], event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
52
79
  };
53
80
 
54
81
  /**
@@ -56,7 +83,7 @@ export type DropdownProps<O extends DropdownOption = DropdownOption> = CommonPro
56
83
  *
57
84
  * @name Dropdown
58
85
  */
59
- function Dropdown<O extends DropdownOption = DropdownOption>({
86
+ function Dropdown({
60
87
  options = [],
61
88
  value: selected,
62
89
  onChange,
@@ -74,7 +101,8 @@ function Dropdown<O extends DropdownOption = DropdownOption>({
74
101
  isMulti,
75
102
  renderListItem,
76
103
  style: styleProp,
77
- }: DropdownProps<O>) {
104
+ selectAll,
105
+ }: DropdownProps) {
78
106
  const id = useId(propId);
79
107
 
80
108
  const { triggerProps, menuProps, closeMenu } = useFloatingMenu({
@@ -116,12 +144,13 @@ function Dropdown<O extends DropdownOption = DropdownOption>({
116
144
  isMulti={isMulti}
117
145
  itemCount={itemCount}
118
146
  items={options}
119
- onChange={(selectedValues, event) => {
147
+ onChange={(next, event) => {
120
148
  event?.preventDefault();
121
149
  if (!isMulti) closeMenu();
122
- onChange?.(selectedValues);
150
+ onChange?.(next);
123
151
  }}
124
152
  renderListItem={renderListItem}
153
+ selectAll={selectAll}
125
154
  selectedValues={selected}
126
155
  {...menuProps}
127
156
  />