agroptima-design-system 0.25.1 → 0.25.2
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/package.json
CHANGED
|
@@ -7,8 +7,12 @@ import { buildHelpText } from '../utils/buildHelpText'
|
|
|
7
7
|
export type Variant = 'primary'
|
|
8
8
|
export type Option = { id: string; label: string }
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
type InputPropsWithoutOnChange = Omit<
|
|
11
|
+
React.ComponentPropsWithoutRef<'input'>,
|
|
12
|
+
'onChange'
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
export interface MultiselectProps extends InputPropsWithoutOnChange {
|
|
12
16
|
placeholder?: string
|
|
13
17
|
helpText?: string
|
|
14
18
|
variant?: Variant
|
|
@@ -19,6 +23,7 @@ export interface MultiselectProps
|
|
|
19
23
|
selectedLabel?: string
|
|
20
24
|
hideLabel?: boolean
|
|
21
25
|
defaultValue?: string[]
|
|
26
|
+
onChange?: (value: string[]) => void
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export function Multiselect({
|
|
@@ -31,6 +36,7 @@ export function Multiselect({
|
|
|
31
36
|
options,
|
|
32
37
|
label,
|
|
33
38
|
accessibilityLabel,
|
|
39
|
+
onChange,
|
|
34
40
|
variant = 'primary',
|
|
35
41
|
selectedLabel = 'items selected',
|
|
36
42
|
hideLabel = false,
|
|
@@ -53,12 +59,12 @@ export function Multiselect({
|
|
|
53
59
|
|
|
54
60
|
function selectOption(id: string) {
|
|
55
61
|
const isOptionSelected = selectedOptions.includes(id)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
const options = isOptionSelected
|
|
63
|
+
? selectedOptions.filter((optionId) => optionId !== id)
|
|
64
|
+
: [...selectedOptions, id]
|
|
65
|
+
|
|
66
|
+
setSelectedOptions(options)
|
|
67
|
+
if (onChange !== undefined) onChange(options)
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
function handleBlur(event: React.FocusEvent<HTMLDivElement>) {
|