@bspk/ui 1.1.26 → 1.1.28
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 +2 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/Button.js +1 -1
- package/dist/Button.js.map +1 -1
- package/dist/FormField.d.ts +2 -2
- package/dist/FormField.js +1 -1
- package/dist/Popover.d.ts +2 -3
- package/dist/Popover.js +3 -4
- package/dist/Popover.js.map +1 -1
- package/dist/ProgressBar.d.ts +6 -7
- package/dist/ProgressBar.js +6 -7
- package/dist/ProgressBar.js.map +1 -1
- package/dist/ProgressCircle.d.ts +6 -7
- package/dist/ProgressCircle.js +6 -7
- package/dist/ProgressCircle.js.map +1 -1
- package/dist/ProgressionStepper.d.ts +3 -8
- package/dist/ProgressionStepper.js +3 -8
- package/dist/ProgressionStepper.js.map +1 -1
- package/dist/RadioGroup.d.ts +9 -2
- package/dist/RadioGroup.js.map +1 -1
- package/dist/SearchBar.d.ts +1 -2
- package/dist/SearchBar.js +5 -6
- package/dist/SearchBar.js.map +1 -1
- package/dist/SegmentedControl.d.ts +8 -15
- package/dist/SegmentedControl.js +2 -4
- package/dist/SegmentedControl.js.map +1 -1
- package/dist/{Dropdown.d.ts → Select.d.ts} +15 -15
- package/dist/Select.js +67 -0
- package/dist/Select.js.map +1 -0
- package/dist/{DropdownField.d.ts → SelectField.d.ts} +9 -9
- package/dist/SelectField.js +39 -0
- package/dist/SelectField.js.map +1 -0
- package/dist/StylesProviderAnywhere.js +1 -1
- package/dist/StylesProviderBetterHomesGardens.js +1 -1
- package/dist/StylesProviderCartus.js +1 -1
- package/dist/StylesProviderCentury21.js +1 -1
- package/dist/StylesProviderColdwellBanker.js +1 -1
- package/dist/StylesProviderCorcoran.js +1 -1
- package/dist/StylesProviderDenaliBoss.js +1 -1
- package/dist/StylesProviderEra.js +1 -1
- package/dist/StylesProviderSothebys.js +1 -1
- package/dist/TabGroup.d.ts +5 -6
- package/dist/TabGroup.js.map +1 -1
- package/dist/Tag.d.ts +1 -2
- package/dist/Tag.js +1 -2
- package/dist/Tag.js.map +1 -1
- package/dist/TextField.d.ts +2 -3
- package/dist/TextField.js +2 -4
- package/dist/TextField.js.map +1 -1
- package/dist/TextInput.d.ts +4 -13
- package/dist/TextInput.js +3 -11
- package/dist/TextInput.js.map +1 -1
- package/dist/Textarea.d.ts +5 -14
- package/dist/Textarea.js +6 -16
- package/dist/Textarea.js.map +1 -1
- package/dist/TextareaField.d.ts +1 -2
- package/dist/TextareaField.js +1 -2
- package/dist/TextareaField.js.map +1 -1
- package/dist/Txt.d.ts +1 -2
- package/dist/Txt.js +1 -2
- package/dist/Txt.js.map +1 -1
- package/dist/base.css +1 -1
- package/dist/demo/ExamplePlaceholder.js.map +1 -1
- package/dist/demo/examples.js +84 -15
- package/dist/demo/examples.js.map +1 -1
- package/dist/hooks/useCombobox.d.ts +45 -0
- package/dist/hooks/{useFloatingMenu.js → useCombobox.js} +17 -8
- package/dist/hooks/useCombobox.js.map +1 -0
- package/dist/hooks/useFloating.d.ts +39 -8
- package/dist/hooks/useFloating.js +2 -13
- package/dist/hooks/useFloating.js.map +1 -1
- package/dist/hooks/useKeyboardNavigation.d.ts +1 -1
- package/dist/hooks/useKeyboardNavigation.js +1 -1
- package/dist/hooks/useOutsideClick.d.ts +2 -2
- package/dist/hooks/useOutsideClick.js +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/select.css +1 -0
- package/package.json +3 -2
- package/src/Avatar.tsx +2 -1
- package/src/Button.tsx +2 -2
- package/src/FormField.tsx +2 -2
- package/src/Popover.tsx +5 -27
- package/src/ProgressBar.tsx +6 -7
- package/src/ProgressCircle.tsx +6 -7
- package/src/ProgressionStepper.tsx +3 -8
- package/src/RadioGroup.tsx +9 -2
- package/src/SearchBar.tsx +8 -20
- package/src/SegmentedControl.tsx +14 -37
- package/src/{Dropdown.tsx → Select.tsx} +30 -32
- package/src/{DropdownField.tsx → SelectField.tsx} +15 -15
- package/src/TabGroup.tsx +6 -10
- package/src/Tag.tsx +1 -2
- package/src/TextField.tsx +6 -19
- package/src/TextInput.tsx +6 -27
- package/src/Textarea.tsx +10 -31
- package/src/TextareaField.tsx +3 -8
- package/src/Txt.tsx +2 -7
- package/src/base.scss +53 -70
- package/src/demo/ExamplePlaceholder.tsx +6 -1
- package/src/demo/examples.tsx +99 -21
- package/src/hooks/{useFloatingMenu.ts → useCombobox.ts} +28 -40
- package/src/hooks/useFloating.ts +45 -24
- package/src/hooks/useKeyboardNavigation.ts +1 -1
- package/src/hooks/useOutsideClick.ts +2 -2
- package/src/index.ts +3 -1
- package/src/{dropdown.scss → select.scss} +36 -36
- package/dist/Dropdown.js +0 -68
- package/dist/Dropdown.js.map +0 -1
- package/dist/DropdownField.js +0 -39
- package/dist/DropdownField.js.map +0 -1
- package/dist/dropdown.css +0 -1
- package/dist/hooks/useFloatingMenu.d.ts +0 -36
- package/dist/hooks/useFloatingMenu.js.map +0 -1
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { SvgChevronRight } from '@bspk/icons/ChevronRight';
|
|
2
2
|
|
|
3
|
-
import './
|
|
3
|
+
import './select.scss';
|
|
4
4
|
import { ListItem } from './ListItem';
|
|
5
5
|
import { Menu, MenuProps } from './Menu';
|
|
6
6
|
import { Portal } from './Portal';
|
|
7
|
+
import { useCombobox } from './hooks/useCombobox';
|
|
7
8
|
import { Placement } from './hooks/useFloating';
|
|
8
|
-
import { useFloatingMenu } from './hooks/useFloatingMenu';
|
|
9
9
|
import { useId } from './hooks/useId';
|
|
10
10
|
|
|
11
11
|
import { CommonProps, InvalidPropsLibrary } from './';
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type SelectOption = 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
|
|
20
|
+
export type SelectProps<T extends SelectOption = SelectOption> = CommonProps<
|
|
21
21
|
'aria-label' | 'disabled' | 'id' | 'name' | 'readOnly' | 'size'
|
|
22
22
|
> &
|
|
23
23
|
InvalidPropsLibrary &
|
|
24
24
|
Pick<MenuProps<T>, 'isMulti' | 'itemCount' | 'renderListItem' | 'selectAll'> & {
|
|
25
25
|
/**
|
|
26
|
-
* Array of options to display in the
|
|
26
|
+
* Array of options to display in the select
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* [
|
|
@@ -39,7 +39,7 @@ export type DropdownProps<T extends DropdownOption = DropdownOption> = CommonPro
|
|
|
39
39
|
* { value: '10', label: 'Option 10' },
|
|
40
40
|
* ];
|
|
41
41
|
*
|
|
42
|
-
* @type Array<
|
|
42
|
+
* @type Array<SelectOption>
|
|
43
43
|
* @required
|
|
44
44
|
*/
|
|
45
45
|
options: T[];
|
|
@@ -50,18 +50,18 @@ export type DropdownProps<T extends DropdownOption = DropdownOption> = CommonPro
|
|
|
50
50
|
*/
|
|
51
51
|
value?: Array<string>;
|
|
52
52
|
/**
|
|
53
|
-
* Placeholder for the
|
|
53
|
+
* Placeholder for the select
|
|
54
54
|
*
|
|
55
55
|
* @default Select one...
|
|
56
56
|
*/
|
|
57
57
|
placeholder?: string;
|
|
58
58
|
/**
|
|
59
|
-
* The placement of the
|
|
59
|
+
* The placement of the select menu. Will be ignored if the menu is too close to the edge of the screen.
|
|
60
60
|
*
|
|
61
61
|
* @default bottom
|
|
62
62
|
*/
|
|
63
63
|
placement?: Extract<Placement, 'bottom' | 'top'>;
|
|
64
|
-
/** The style of the
|
|
64
|
+
/** The style of the select. */
|
|
65
65
|
style?: React.CSSProperties;
|
|
66
66
|
/**
|
|
67
67
|
* The function to call when the selected values change.
|
|
@@ -75,15 +75,15 @@ export type DropdownProps<T extends DropdownOption = DropdownOption> = CommonPro
|
|
|
75
75
|
* A field element that allows users to select one option from a list of available choices. *
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
78
|
-
* import {
|
|
78
|
+
* import { Select } from '@bspk/ui/Select';
|
|
79
79
|
*
|
|
80
80
|
* export function Example() {
|
|
81
81
|
* const [selected, setSelected] = React.useState<string[]>([]);
|
|
82
82
|
* return (
|
|
83
|
-
* <
|
|
83
|
+
* <Select
|
|
84
84
|
* aria-label="Select an option"
|
|
85
85
|
* itemCount={5}
|
|
86
|
-
* name="example-
|
|
86
|
+
* name="example-select"
|
|
87
87
|
* onChange={setSelected}
|
|
88
88
|
* options={[
|
|
89
89
|
* { value: '1', label: 'Option 1' },
|
|
@@ -104,9 +104,9 @@ export type DropdownProps<T extends DropdownOption = DropdownOption> = CommonPro
|
|
|
104
104
|
* );
|
|
105
105
|
* }
|
|
106
106
|
*
|
|
107
|
-
* @name
|
|
107
|
+
* @name Select
|
|
108
108
|
*/
|
|
109
|
-
function
|
|
109
|
+
function Select({
|
|
110
110
|
options = [],
|
|
111
111
|
value: selected,
|
|
112
112
|
onChange,
|
|
@@ -119,26 +119,24 @@ function Dropdown({
|
|
|
119
119
|
invalid,
|
|
120
120
|
errorMessage,
|
|
121
121
|
readOnly,
|
|
122
|
-
placement = 'bottom',
|
|
123
122
|
name,
|
|
124
123
|
isMulti,
|
|
125
124
|
renderListItem,
|
|
126
125
|
style: styleProp,
|
|
127
126
|
selectAll,
|
|
128
|
-
}:
|
|
127
|
+
}: SelectProps) {
|
|
129
128
|
const id = useId(propId);
|
|
130
129
|
|
|
131
|
-
const {
|
|
132
|
-
placement,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
130
|
+
const { toggleProps, menuProps, closeMenu } = useCombobox({
|
|
131
|
+
placement: 'bottom',
|
|
132
|
+
disabled,
|
|
133
|
+
invalid,
|
|
134
|
+
readOnly,
|
|
135
|
+
errorMessage,
|
|
136
|
+
offsetOptions: 4,
|
|
139
137
|
});
|
|
140
138
|
|
|
141
|
-
const
|
|
139
|
+
const selectLabel = isMulti
|
|
142
140
|
? `${selected?.length || 0} option${selected?.length !== 1 ? 's' : ''} selected`
|
|
143
141
|
: options.find((o) => o.value === selected?.[0])?.label;
|
|
144
142
|
|
|
@@ -147,17 +145,17 @@ function Dropdown({
|
|
|
147
145
|
<input defaultValue={selected} name={name} type="hidden" />
|
|
148
146
|
<button
|
|
149
147
|
aria-label={ariaLabel}
|
|
150
|
-
data-bspk="
|
|
151
|
-
data-empty={
|
|
148
|
+
data-bspk="select"
|
|
149
|
+
data-empty={selectLabel ? undefined : ''}
|
|
152
150
|
data-invalid={invalid || undefined}
|
|
153
151
|
data-size={size}
|
|
154
152
|
disabled={disabled || readOnly}
|
|
155
153
|
id={id}
|
|
156
154
|
style={styleProp}
|
|
157
|
-
{...
|
|
155
|
+
{...toggleProps}
|
|
158
156
|
>
|
|
159
|
-
<ListItem data-placeholder="" label={
|
|
160
|
-
<span data-
|
|
157
|
+
<ListItem data-placeholder="" label={selectLabel || placeholder} readOnly />
|
|
158
|
+
<span data-icon>
|
|
161
159
|
<SvgChevronRight />
|
|
162
160
|
</span>
|
|
163
161
|
</button>
|
|
@@ -182,8 +180,8 @@ function Dropdown({
|
|
|
182
180
|
);
|
|
183
181
|
}
|
|
184
182
|
|
|
185
|
-
|
|
183
|
+
Select.bspkName = 'Select';
|
|
186
184
|
|
|
187
|
-
export {
|
|
185
|
+
export { Select };
|
|
188
186
|
|
|
189
187
|
/** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DropdownProps, Dropdown } from './Dropdown';
|
|
2
1
|
import { FormFieldProps, FormField } from './FormField';
|
|
2
|
+
import { SelectProps, Select } from './Select';
|
|
3
3
|
|
|
4
|
-
export type
|
|
5
|
-
|
|
4
|
+
export type SelectFieldProps = Pick<
|
|
5
|
+
SelectProps,
|
|
6
6
|
| 'disabled'
|
|
7
7
|
| 'itemCount'
|
|
8
8
|
| 'name'
|
|
@@ -19,15 +19,15 @@ export type DropdownFieldProps = Pick<
|
|
|
19
19
|
/**
|
|
20
20
|
* A component that allows users to input large amounts of text that could span multiple lines.
|
|
21
21
|
*
|
|
22
|
-
* This component takes properties from the FormField and
|
|
22
|
+
* This component takes properties from the FormField and Select components.
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
|
-
* import {
|
|
25
|
+
* import { SelectField } from '@bspk/ui/SelectField';
|
|
26
26
|
*
|
|
27
27
|
* export function Example() {
|
|
28
28
|
* const [state, setState] = React.useState(['option1']);
|
|
29
29
|
* return (
|
|
30
|
-
* <
|
|
30
|
+
* <SelectField
|
|
31
31
|
* controlId="Example controlId"
|
|
32
32
|
* label="Example label"
|
|
33
33
|
* name="Example name"
|
|
@@ -43,23 +43,23 @@ export type DropdownFieldProps = Pick<
|
|
|
43
43
|
* );
|
|
44
44
|
* }
|
|
45
45
|
*
|
|
46
|
-
* @name
|
|
46
|
+
* @name SelectField
|
|
47
47
|
*/
|
|
48
|
-
function
|
|
48
|
+
function SelectField({
|
|
49
49
|
label,
|
|
50
50
|
errorMessage: errorMessageProp,
|
|
51
51
|
helperText,
|
|
52
52
|
controlId: id,
|
|
53
53
|
labelTrailing,
|
|
54
54
|
required,
|
|
55
|
-
...
|
|
56
|
-
}:
|
|
57
|
-
const errorMessage = (!
|
|
55
|
+
...selectProps
|
|
56
|
+
}: SelectFieldProps) {
|
|
57
|
+
const errorMessage = (!selectProps.readOnly && !selectProps.disabled && errorMessageProp) || undefined;
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<FormField
|
|
61
61
|
controlId={id}
|
|
62
|
-
data-bspk="
|
|
62
|
+
data-bspk="select-field"
|
|
63
63
|
errorMessage={errorMessage}
|
|
64
64
|
helperText={helperText}
|
|
65
65
|
label={label}
|
|
@@ -67,14 +67,14 @@ function DropdownField({
|
|
|
67
67
|
required={required}
|
|
68
68
|
>
|
|
69
69
|
{(fieldProps) => (
|
|
70
|
-
<
|
|
70
|
+
<Select {...selectProps} {...fieldProps} aria-label={label} id={id} invalid={!!errorMessage} />
|
|
71
71
|
)}
|
|
72
72
|
</FormField>
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
SelectField.bspkName = 'SelectField';
|
|
77
77
|
|
|
78
|
-
export {
|
|
78
|
+
export { SelectField };
|
|
79
79
|
|
|
80
80
|
/** Copyright 2025 Anywhere Real Estate - CC BY 4.0 */
|
package/src/TabGroup.tsx
CHANGED
|
@@ -22,8 +22,7 @@ export type TabGroupOption = {
|
|
|
22
22
|
*/
|
|
23
23
|
label: string;
|
|
24
24
|
/**
|
|
25
|
-
* Determines if the element is
|
|
26
|
-
* [disabled](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled).
|
|
25
|
+
* Determines if the element is [disabled](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled).
|
|
27
26
|
*
|
|
28
27
|
* @default false
|
|
29
28
|
*/
|
|
@@ -87,15 +86,15 @@ export type TabGroupProps = {
|
|
|
87
86
|
*/
|
|
88
87
|
size?: TabGroupSize;
|
|
89
88
|
/**
|
|
90
|
-
* When 'fill' the options will fill the width of the container. When 'hug',
|
|
91
|
-
*
|
|
89
|
+
* When 'fill' the options will fill the width of the container. When 'hug', the options will be as wide as their
|
|
90
|
+
* content.
|
|
92
91
|
*
|
|
93
92
|
* @default hug
|
|
94
93
|
*/
|
|
95
94
|
width?: 'fill' | 'hug';
|
|
96
95
|
/**
|
|
97
|
-
* When width is 'hug' this determines if the trailing underline should be
|
|
98
|
-
*
|
|
96
|
+
* When width is 'hug' this determines if the trailing underline should be showing. When width is 'fill' this
|
|
97
|
+
* property isn't applicable.
|
|
99
98
|
*
|
|
100
99
|
* @default false
|
|
101
100
|
*/
|
|
@@ -164,10 +163,7 @@ function TabGroup({
|
|
|
164
163
|
{(isActive && item.iconActive) || item.icon}
|
|
165
164
|
{item.label}
|
|
166
165
|
{item.badge && !item.disabled && !isActive && (
|
|
167
|
-
<Badge
|
|
168
|
-
count={item.badge}
|
|
169
|
-
size={TAB_BADGE_SIZES[size]}
|
|
170
|
-
/>
|
|
166
|
+
<Badge count={item.badge} size={TAB_BADGE_SIZES[size]} />
|
|
171
167
|
)}
|
|
172
168
|
</span>
|
|
173
169
|
</button>
|
package/src/Tag.tsx
CHANGED
|
@@ -51,8 +51,7 @@ export type TagProps<As extends ElementType = 'span'> = {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* A non-interactive visual indicators to draw attention or categorization of a
|
|
55
|
-
* component.
|
|
54
|
+
* A non-interactive visual indicators to draw attention or categorization of a component.
|
|
56
55
|
*
|
|
57
56
|
* @example
|
|
58
57
|
* import { Tag } from '@bspk/ui/Tag';
|
package/src/TextField.tsx
CHANGED
|
@@ -3,12 +3,7 @@ import { TextInputProps, TextInput } from './TextInput';
|
|
|
3
3
|
|
|
4
4
|
import { InvalidPropsLibrary } from '.';
|
|
5
5
|
|
|
6
|
-
export type TextFieldProps =
|
|
7
|
-
InvalidPropsLibrary &
|
|
8
|
-
Pick<
|
|
9
|
-
FormFieldProps,
|
|
10
|
-
'controlId' | 'errorMessage' | 'helperText' | 'label' | 'labelTrailing'
|
|
11
|
-
> &
|
|
6
|
+
export type TextFieldProps = InvalidPropsLibrary &
|
|
12
7
|
Pick<
|
|
13
8
|
TextInputProps,
|
|
14
9
|
| 'autoComplete'
|
|
@@ -24,11 +19,11 @@ export type TextFieldProps =
|
|
|
24
19
|
| 'trailing'
|
|
25
20
|
| 'type'
|
|
26
21
|
| 'value'
|
|
27
|
-
|
|
22
|
+
> &
|
|
23
|
+
Pick<FormFieldProps, 'controlId' | 'errorMessage' | 'helperText' | 'label' | 'labelTrailing'>;
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
|
-
* A text input that allows users to enter text, numbers or symbols in a
|
|
31
|
-
* singular line.
|
|
26
|
+
* A text input that allows users to enter text, numbers or symbols in a singular line.
|
|
32
27
|
*
|
|
33
28
|
* This component takes properties from the FormField and TextInput components.
|
|
34
29
|
*
|
|
@@ -61,9 +56,7 @@ function TextField({
|
|
|
61
56
|
required,
|
|
62
57
|
...inputProps
|
|
63
58
|
}: TextFieldProps) {
|
|
64
|
-
const errorMessage =
|
|
65
|
-
(!inputProps.readOnly && !inputProps.disabled && errorMessageProp) ||
|
|
66
|
-
undefined;
|
|
59
|
+
const errorMessage = (!inputProps.readOnly && !inputProps.disabled && errorMessageProp) || undefined;
|
|
67
60
|
|
|
68
61
|
return (
|
|
69
62
|
<FormField
|
|
@@ -76,13 +69,7 @@ function TextField({
|
|
|
76
69
|
required={required}
|
|
77
70
|
>
|
|
78
71
|
{(fieldProps) => (
|
|
79
|
-
<TextInput
|
|
80
|
-
{...inputProps}
|
|
81
|
-
{...fieldProps}
|
|
82
|
-
aria-label={label}
|
|
83
|
-
id={controlId}
|
|
84
|
-
required={required}
|
|
85
|
-
/>
|
|
72
|
+
<TextInput {...inputProps} {...fieldProps} aria-label={label} id={controlId} required={required} />
|
|
86
73
|
)}
|
|
87
74
|
</FormField>
|
|
88
75
|
);
|
package/src/TextInput.tsx
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { SvgCancel } from '@bspk/icons/Cancel';
|
|
2
|
-
import {
|
|
3
|
-
ChangeEvent,
|
|
4
|
-
HTMLInputAutoCompleteAttribute,
|
|
5
|
-
HTMLInputTypeAttribute,
|
|
6
|
-
ReactNode,
|
|
7
|
-
} from 'react';
|
|
2
|
+
import { ChangeEvent, HTMLInputAutoCompleteAttribute, HTMLInputTypeAttribute, ReactNode } from 'react';
|
|
8
3
|
|
|
9
4
|
import { useId } from './hooks/useId';
|
|
10
5
|
|
|
@@ -20,14 +15,7 @@ export const DEFAULT = {
|
|
|
20
15
|
} as const;
|
|
21
16
|
|
|
22
17
|
export type TextInputProps = CommonProps<
|
|
23
|
-
|
|
24
|
-
| 'disabled'
|
|
25
|
-
| 'id'
|
|
26
|
-
| 'name'
|
|
27
|
-
| 'readOnly'
|
|
28
|
-
| 'required'
|
|
29
|
-
| 'size'
|
|
30
|
-
| 'value'
|
|
18
|
+
'aria-label' | 'disabled' | 'id' | 'name' | 'readOnly' | 'required' | 'size' | 'value'
|
|
31
19
|
> &
|
|
32
20
|
InvalidPropsLibrary & {
|
|
33
21
|
/**
|
|
@@ -53,8 +41,7 @@ export type TextInputProps = CommonProps<
|
|
|
53
41
|
*/
|
|
54
42
|
type?: Extract<HTMLInputTypeAttribute, 'number' | 'text'>;
|
|
55
43
|
/**
|
|
56
|
-
* Specifies if user agent has any permission to provide automated
|
|
57
|
-
* assistance in filling out form field values.
|
|
44
|
+
* Specifies if user agent has any permission to provide automated assistance in filling out form field values.
|
|
58
45
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
|
59
46
|
*
|
|
60
47
|
* @default off
|
|
@@ -63,9 +50,8 @@ export type TextInputProps = CommonProps<
|
|
|
63
50
|
};
|
|
64
51
|
|
|
65
52
|
/**
|
|
66
|
-
* A text input that allows users to enter text, numbers or symbols in a
|
|
67
|
-
*
|
|
68
|
-
* directly. Use the TextField component.
|
|
53
|
+
* A text input that allows users to enter text, numbers or symbols in a singular line. This is the base element and is
|
|
54
|
+
* not intended to be used directly. Use the TextField component.
|
|
69
55
|
*
|
|
70
56
|
* @example
|
|
71
57
|
* import { useState } from 'react';
|
|
@@ -74,14 +60,7 @@ export type TextInputProps = CommonProps<
|
|
|
74
60
|
* export function Example() {
|
|
75
61
|
* const [value, setValue] = useState<string>('');
|
|
76
62
|
*
|
|
77
|
-
* return
|
|
78
|
-
* <TextInput
|
|
79
|
-
* aria-label="Example aria-label"
|
|
80
|
-
* name="Example name"
|
|
81
|
-
* onChange={setValue}
|
|
82
|
-
* value={value}
|
|
83
|
-
* />
|
|
84
|
-
* );
|
|
63
|
+
* return <TextInput aria-label="Example aria-label" name="Example name" onChange={setValue} value={value} />;
|
|
85
64
|
* }
|
|
86
65
|
*
|
|
87
66
|
* @element
|
package/src/Textarea.tsx
CHANGED
|
@@ -11,9 +11,7 @@ const DEFAULT = {
|
|
|
11
11
|
textSize: 'medium',
|
|
12
12
|
} as const;
|
|
13
13
|
|
|
14
|
-
export type TextareaProps = CommonProps<
|
|
15
|
-
'aria-label' | 'disabled' | 'id' | 'readOnly' | 'required'
|
|
16
|
-
> &
|
|
14
|
+
export type TextareaProps = CommonProps<'aria-label' | 'disabled' | 'id' | 'readOnly' | 'required'> &
|
|
17
15
|
InvalidPropsLibrary & {
|
|
18
16
|
/**
|
|
19
17
|
* Callback when the value of the field changes.
|
|
@@ -21,10 +19,7 @@ export type TextareaProps = CommonProps<
|
|
|
21
19
|
* @type (next: String, Event) => void
|
|
22
20
|
* @required
|
|
23
21
|
*/
|
|
24
|
-
onChange: (
|
|
25
|
-
next: string,
|
|
26
|
-
event?: ChangeEvent<HTMLTextAreaElement>,
|
|
27
|
-
) => void;
|
|
22
|
+
onChange: (next: string, event?: ChangeEvent<HTMLTextAreaElement>) => void;
|
|
28
23
|
/**
|
|
29
24
|
* The text size of the field.
|
|
30
25
|
*
|
|
@@ -72,13 +67,11 @@ export type TextareaProps = CommonProps<
|
|
|
72
67
|
};
|
|
73
68
|
|
|
74
69
|
/**
|
|
75
|
-
* A component that allows users to input large amounts of text that could span
|
|
76
|
-
* multiple lines.
|
|
70
|
+
* A component that allows users to input large amounts of text that could span multiple lines.
|
|
77
71
|
*
|
|
78
|
-
* This component gives you a textarea HTML element that automatically adjusts
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* characters remaining below the limit.
|
|
72
|
+
* This component gives you a textarea HTML element that automatically adjusts its height to match the length of the
|
|
73
|
+
* content within maximum and minimum rows. A character counter when a maxLength is set to show the number of characters
|
|
74
|
+
* remaining below the limit.
|
|
82
75
|
*
|
|
83
76
|
* @example
|
|
84
77
|
* import { useState } from 'react';
|
|
@@ -87,14 +80,7 @@ export type TextareaProps = CommonProps<
|
|
|
87
80
|
* export function Example() {
|
|
88
81
|
* const [value, setValue] = useState<string>('');
|
|
89
82
|
*
|
|
90
|
-
* return
|
|
91
|
-
* <Textarea
|
|
92
|
-
* aria-label="Example aria-label"
|
|
93
|
-
* name="Example name"
|
|
94
|
-
* onChange={setValue}
|
|
95
|
-
* value={value}
|
|
96
|
-
* />
|
|
97
|
-
* );
|
|
83
|
+
* return <Textarea aria-label="Example aria-label" name="Example name" onChange={setValue} value={value} />;
|
|
98
84
|
* }
|
|
99
85
|
*
|
|
100
86
|
* @element
|
|
@@ -119,14 +105,8 @@ function Textarea({
|
|
|
119
105
|
const id = useId(idProp);
|
|
120
106
|
const invalid = !otherProps.readOnly && !otherProps.disabled && invalidProp;
|
|
121
107
|
// ensure minRows and maxRows are within bounds
|
|
122
|
-
const minRows = Math.min(
|
|
123
|
-
|
|
124
|
-
Math.max(minRowsProp, DEFAULT.minRows),
|
|
125
|
-
);
|
|
126
|
-
const maxRows = Math.max(
|
|
127
|
-
DEFAULT.minRows,
|
|
128
|
-
Math.min(maxRowsProp, DEFAULT.maxRows),
|
|
129
|
-
);
|
|
108
|
+
const minRows = Math.min(DEFAULT.maxRows, Math.max(minRowsProp, DEFAULT.minRows));
|
|
109
|
+
const maxRows = Math.max(DEFAULT.minRows, Math.min(maxRowsProp, DEFAULT.maxRows));
|
|
130
110
|
|
|
131
111
|
return (
|
|
132
112
|
<div
|
|
@@ -155,8 +135,7 @@ function Textarea({
|
|
|
155
135
|
const target = event.target as HTMLTextAreaElement;
|
|
156
136
|
// we know the textarea was resized, so we don't want to auto-size it
|
|
157
137
|
if (target.style.height) return;
|
|
158
|
-
(target.nextSibling as HTMLElement).innerText =
|
|
159
|
-
`${target.value}\n`;
|
|
138
|
+
(target.nextSibling as HTMLElement).innerText = `${target.value}\n`;
|
|
160
139
|
}}
|
|
161
140
|
placeholder={placeholder}
|
|
162
141
|
ref={innerRef}
|
package/src/TextareaField.tsx
CHANGED
|
@@ -3,14 +3,10 @@ import { TextareaProps, Textarea } from './Textarea';
|
|
|
3
3
|
import { Txt } from './Txt';
|
|
4
4
|
import { tryIntParse } from './utils/tryIntPsrse';
|
|
5
5
|
|
|
6
|
-
export type TextareaFieldProps = Pick<
|
|
7
|
-
FormFieldProps,
|
|
8
|
-
'controlId' | 'errorMessage' | 'helperText' | 'label'
|
|
9
|
-
> &
|
|
6
|
+
export type TextareaFieldProps = Pick<FormFieldProps, 'controlId' | 'errorMessage' | 'helperText' | 'label'> &
|
|
10
7
|
TextareaProps;
|
|
11
8
|
/**
|
|
12
|
-
* A component that allows users to input large amounts of text that could span
|
|
13
|
-
* multiple lines.
|
|
9
|
+
* A component that allows users to input large amounts of text that could span multiple lines.
|
|
14
10
|
*
|
|
15
11
|
* This component takes properties from the FormField and Textarea components.
|
|
16
12
|
*
|
|
@@ -49,8 +45,7 @@ function TextareaField({
|
|
|
49
45
|
...textareaProps
|
|
50
46
|
}: TextareaFieldProps) {
|
|
51
47
|
const maxLength = tryIntParse(maxLengthProp) || -1;
|
|
52
|
-
const errorMessage =
|
|
53
|
-
(!readOnly && !disabled && errorMessageProp) || undefined;
|
|
48
|
+
const errorMessage = (!readOnly && !disabled && errorMessageProp) || undefined;
|
|
54
49
|
|
|
55
50
|
if (typeof onChange !== 'function') return null;
|
|
56
51
|
|
package/src/Txt.tsx
CHANGED
|
@@ -30,8 +30,7 @@ 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
|
|
34
|
-
* and size. variant
|
|
33
|
+
* A text component that applies the correct font styles based on the variant and size. variant
|
|
35
34
|
*
|
|
36
35
|
* @example
|
|
37
36
|
* import { Txt } from '@bspk/ui/Txt';
|
|
@@ -56,11 +55,7 @@ function Txt<As extends ElementType = 'span'>({
|
|
|
56
55
|
const As: ElementType = as || 'span';
|
|
57
56
|
|
|
58
57
|
return (
|
|
59
|
-
<As
|
|
60
|
-
{...containerProps}
|
|
61
|
-
data-bspk="txt"
|
|
62
|
-
style={{ ...styleProp, font: `var(--${variant})` }}
|
|
63
|
-
>
|
|
58
|
+
<As {...containerProps} data-bspk="txt" style={{ ...styleProp, font: `var(--${variant})` }}>
|
|
64
59
|
{content}
|
|
65
60
|
</As>
|
|
66
61
|
);
|