@bspk/ui 1.1.16 → 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.
- package/dist/Avatar.d.ts +44 -10
- package/dist/Avatar.js +32 -13
- package/dist/Avatar.js.map +1 -1
- package/dist/AvatarGroup.d.ts +49 -0
- package/dist/AvatarGroup.js +18 -0
- package/dist/AvatarGroup.js.map +1 -0
- package/dist/Badge.js +1 -1
- package/dist/Button.d.ts +14 -4
- package/dist/Button.js +1 -1
- package/dist/Button.js.map +1 -1
- package/dist/Checkbox.d.ts +15 -2
- package/dist/Checkbox.js.map +1 -1
- package/dist/CheckboxGroup.d.ts +6 -3
- package/dist/CheckboxGroup.js.map +1 -1
- package/dist/CheckboxOption.d.ts +8 -1
- package/dist/CheckboxOption.js.map +1 -1
- package/dist/Chip.d.ts +3 -1
- package/dist/Chip.js.map +1 -1
- package/dist/Dialog.d.ts +3 -3
- package/dist/Dialog.js.map +1 -1
- package/dist/Divider.js +1 -1
- package/dist/Dropdown.d.ts +26 -6
- package/dist/Dropdown.js +2 -2
- package/dist/Dropdown.js.map +1 -1
- package/dist/ListItem.js +1 -1
- package/dist/Menu.d.ts +27 -15
- package/dist/Menu.js +1 -1
- package/dist/Menu.js.map +1 -1
- package/dist/NumberInput.d.ts +5 -1
- package/dist/NumberInput.js +7 -5
- package/dist/NumberInput.js.map +1 -1
- package/dist/Portal.d.ts +5 -1
- package/dist/Portal.js.map +1 -1
- package/dist/ProgressBar.d.ts +4 -0
- package/dist/ProgressBar.js.map +1 -1
- package/dist/ProgressionStepper.d.ts +9 -2
- package/dist/ProgressionStepper.js +1 -1
- package/dist/ProgressionStepper.js.map +1 -1
- package/dist/ProgressionStepperBar.d.ts +6 -0
- package/dist/ProgressionStepperBar.js.map +1 -1
- package/dist/Radio.d.ts +16 -2
- package/dist/Radio.js +2 -2
- package/dist/Radio.js.map +1 -1
- package/dist/RadioGroup.d.ts +26 -3
- package/dist/RadioGroup.js +3 -3
- package/dist/RadioGroup.js.map +1 -1
- package/dist/RadioOption.d.ts +9 -1
- package/dist/RadioOption.js.map +1 -1
- package/dist/SegmentedControl.d.ts +21 -2
- package/dist/SegmentedControl.js +1 -1
- package/dist/SegmentedControl.js.map +1 -1
- package/dist/Switch.d.ts +1 -1
- package/dist/SwitchGroup.d.ts +13 -6
- package/dist/SwitchGroup.js +1 -1
- package/dist/SwitchGroup.js.map +1 -1
- package/dist/TabGroup.d.ts +23 -5
- package/dist/TabGroup.js +1 -1
- package/dist/TabGroup.js.map +1 -1
- package/dist/Tag.d.ts +5 -2
- package/dist/Tag.js +1 -1
- package/dist/Tag.js.map +1 -1
- package/dist/TextInput.d.ts +15 -6
- package/dist/TextInput.js +11 -5
- package/dist/TextInput.js.map +1 -1
- package/dist/Textarea.d.ts +3 -3
- package/dist/avatar-group.css +1 -0
- package/dist/avatar.css +1 -1
- package/dist/badge.css +1 -1
- package/dist/button.css +1 -1
- package/dist/demo/ExampleModalRender.d.ts +7 -0
- package/dist/demo/ExampleModalRender.js +16 -0
- package/dist/demo/ExampleModalRender.js.map +1 -0
- package/dist/demo/ExamplePlaceholder.d.ts +7 -0
- package/dist/demo/ExamplePlaceholder.js +13 -0
- package/dist/demo/ExamplePlaceholder.js.map +1 -0
- package/dist/demo/examples.d.ts +101 -0
- package/dist/demo/examples.js +472 -0
- package/dist/demo/examples.js.map +1 -0
- package/dist/divider.css +1 -1
- package/dist/hooks/useOptionIconsInvalid.d.ts +10 -1
- package/dist/hooks/useOptionIconsInvalid.js.map +1 -1
- package/dist/index.d.ts +4 -26
- package/dist/index.js.map +1 -1
- package/dist/list-item.css +1 -1
- package/dist/menu.css +1 -1
- package/dist/segmented-control.css +1 -1
- package/dist/tab-group.css +1 -1
- package/dist/tag.css +1 -1
- package/dist/text-input.css +1 -1
- package/dist/utils/children.js.map +1 -1
- package/meta-types.ts +2 -0
- package/meta.ts +76 -42
- package/package.json +1 -1
- package/src/Avatar.tsx +80 -27
- package/src/AvatarGroup.tsx +71 -0
- package/src/Button.tsx +14 -4
- package/src/Checkbox.tsx +25 -11
- package/src/CheckboxGroup.tsx +6 -3
- package/src/CheckboxOption.tsx +9 -2
- package/src/Chip.tsx +3 -1
- package/src/Dialog.tsx +3 -3
- package/src/Dropdown.tsx +30 -10
- package/src/Menu.tsx +30 -18
- package/src/NumberInput.tsx +15 -6
- package/src/Portal.tsx +5 -1
- package/src/ProgressBar.tsx +4 -0
- package/src/ProgressionStepper.tsx +9 -2
- package/src/ProgressionStepperBar.tsx +6 -0
- package/src/Radio.tsx +21 -4
- package/src/RadioGroup.tsx +34 -6
- package/src/RadioOption.tsx +11 -2
- package/src/SegmentedControl.tsx +21 -2
- package/src/Switch.tsx +1 -1
- package/src/SwitchGroup.tsx +19 -7
- package/src/TabGroup.tsx +23 -5
- package/src/Tag.tsx +5 -2
- package/src/TextInput.tsx +25 -15
- package/src/Textarea.tsx +3 -3
- package/src/avatar-group.scss +17 -0
- package/src/avatar.scss +5 -2
- package/src/badge.scss +1 -0
- package/src/button.scss +1 -0
- package/src/demo/ExampleModalRender.tsx +37 -0
- package/src/demo/ExamplePlaceholder.tsx +40 -0
- package/src/demo/examples.tsx +683 -0
- package/src/divider.scss +2 -0
- package/src/dropdown.scss +1 -0
- package/src/hooks/useOptionIconsInvalid.ts +10 -1
- package/src/index.ts +5 -32
- package/src/list-item.scss +5 -1
- package/src/menu.scss +1 -1
- package/src/segmented-control.scss +1 -0
- package/src/tab-group.scss +1 -0
- package/src/tag.scss +1 -0
- package/src/text-input.scss +13 -18
- package/src/utils/children.ts +1 -1
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,
|
|
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?:
|
|
15
|
+
innerRef?: SetRef<HTMLDivElement>;
|
|
16
16
|
/**
|
|
17
17
|
* If the dialog should appear.
|
|
18
18
|
*
|
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<
|
|
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<
|
|
24
|
+
Pick<MenuProps<T>, 'isMulti' | 'itemCount' | 'renderListItem'> & {
|
|
25
25
|
/**
|
|
26
26
|
* Array of options to display in the dropdown
|
|
27
27
|
*
|
|
28
|
-
* @
|
|
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:
|
|
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
|
|
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
|
|
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={(
|
|
139
|
+
onChange={(next, event) => {
|
|
120
140
|
event?.preventDefault();
|
|
121
141
|
if (!isMulti) closeMenu();
|
|
122
|
-
onChange?.(
|
|
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,
|
|
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<
|
|
20
|
-
MenuProps<
|
|
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:
|
|
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<
|
|
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
|
-
* @
|
|
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?:
|
|
68
|
+
items?: T[];
|
|
55
69
|
/** A ref to the inner div element. */
|
|
56
|
-
innerRef?:
|
|
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<
|
|
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
|
-
* @
|
|
85
|
-
*
|
|
86
|
-
* @param {ChangeEvent} event
|
|
87
|
-
* @returns {void}
|
|
98
|
+
* @example
|
|
99
|
+
* (selectedValues, event) => setState({ selectedValues });
|
|
88
100
|
*/
|
|
89
|
-
onChange?: (selectedValues: string[], event?:
|
|
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
|
|
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
|
|
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:
|
|
179
|
+
onClick={(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
168
180
|
if (renderProps) renderProps?.onClick?.(event);
|
|
169
181
|
|
|
170
182
|
if (onChange) {
|
package/src/NumberInput.tsx
CHANGED
|
@@ -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
|
-
/**
|
|
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 = (
|
|
82
|
-
|
|
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
|
-
|
|
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
|
|
133
|
+
onChange(isNumber(event.target.value));
|
|
125
134
|
}}
|
|
126
135
|
readOnly={readOnly}
|
|
127
136
|
type="number"
|
package/src/Portal.tsx
CHANGED
package/src/ProgressBar.tsx
CHANGED
|
@@ -30,7 +30,14 @@ export type ProgressionStepperProps = {
|
|
|
30
30
|
/**
|
|
31
31
|
* The steps to display in the progress bar.
|
|
32
32
|
*
|
|
33
|
-
* @
|
|
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 {
|
|
2
|
+
import { ChangeEvent } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
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)}
|
package/src/RadioGroup.tsx
CHANGED
|
@@ -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'
|
|
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
|
-
* @
|
|
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
|
-
/**
|
|
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
|
|
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}
|
package/src/RadioOption.tsx
CHANGED
|
@@ -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' | '
|
|
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.
|
package/src/SegmentedControl.tsx
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
* @
|
|
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' | '
|
|
6
|
+
export type SwitchProps = CommonProps<'aria-label' | 'disabled' | 'name' | 'value'> & {
|
|
7
7
|
/**
|
|
8
8
|
* Marks the control as checked.
|
|
9
9
|
*
|
package/src/SwitchGroup.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Switch } from './Switch';
|
|
2
2
|
import { ToggleOptionProps, ToggleOption } from './ToggleOption';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ElementProps, CommonProps } from './';
|
|
5
5
|
|
|
6
|
-
export type SwitchGroupOption = Pick<
|
|
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
|
-
* @
|
|
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
|
-
|
|
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({
|
|
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
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* The icon to display on the left side of the tab.
|
|
38
|
+
*
|
|
39
|
+
* @type BspkIcon
|
|
40
|
+
*/
|
|
37
41
|
icon?: ReactNode;
|
|
38
|
-
/**
|
|
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
|
-
* @
|
|
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
|
|
68
|
+
* The value of the selected tab.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* 1;
|
|
54
72
|
*
|
|
55
73
|
* @required
|
|
56
74
|
*/
|