@appdirect/design-system 0.0.23 → 0.0.25
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/Combobox/ADMultiselect.js +91 -0
- package/dist/Combobox/ADMultiselect.tsx +237 -0
- package/dist/Combobox/AutocompleteClearable.js +33 -35
- package/dist/Combobox/AutocompleteClearable.tsx +56 -121
- package/dist/Combobox/SearchableSelect.js +23 -42
- package/dist/Combobox/SearchableSelect.tsx +33 -129
- package/dist/Combobox/Select.js +13 -19
- package/dist/Combobox/Select.tsx +15 -44
- package/dist/Combobox/index.js +1 -1
- package/dist/Combobox/index.ts +2 -2
- package/dist/ComplexComponents/Utilities/CopyButton.js +15 -27
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +35 -49
- package/dist/DESIGN.md +2 -2
- package/dist/DataDisplay/Avatar.js +26 -81
- package/dist/DataDisplay/Avatar.tsx +35 -93
- package/dist/DataDisplay/Pill.js +21 -79
- package/dist/DataDisplay/Pill.tsx +34 -116
- package/dist/Inputs/ColorInput.js +12 -18
- package/dist/Inputs/ColorInput.tsx +13 -41
- package/dist/Inputs/NumberInput.js +12 -36
- package/dist/Inputs/NumberInput.tsx +13 -72
- package/dist/Inputs/TextArea.js +12 -18
- package/dist/Inputs/TextArea.tsx +13 -41
- package/dist/Inputs/TextInput.js +12 -18
- package/dist/Inputs/TextInput.tsx +13 -41
- package/dist/Inputs/inputLabel.js +35 -0
- package/dist/Inputs/inputLabel.tsx +83 -0
- package/dist/Layout/Inline.js +5 -42
- package/dist/Layout/Inline.tsx +6 -79
- package/dist/Overlays/Tooltip.js +2 -2
- package/dist/Overlays/Tooltip.tsx +4 -1
- package/dist/contracts/index.json +1 -1
- package/dist/css/mantine.css +193 -29
- package/dist/css/tokens.css +58 -18
- package/dist/index.js +3 -3
- package/dist/index.ts +4 -4
- package/dist/stories/Combobox/{Multiselect.stories.tsx → ADMultiselect.stories.tsx} +159 -53
- package/dist/stories/Combobox/SearchableSelect.stories.tsx +3 -3
- package/dist/stories/Combobox/Select.stories.tsx +1 -1
- package/dist/stories/ComplexComponents/Utilities/CopyButton.stories.tsx +4 -14
- package/dist/stories/Inputs/ColorInput.stories.tsx +12 -0
- package/dist/stories/Inputs/NumberInput.stories.tsx +12 -0
- package/dist/stories/Inputs/TextArea.stories.tsx +12 -0
- package/dist/stories/Inputs/TextInput.stories.tsx +12 -0
- package/dist/stories/index.json +42 -35
- package/package.json +2 -2
- package/dist/Combobox/Multiselect.js +0 -31
- package/dist/Combobox/Multiselect.tsx +0 -158
|
@@ -33,6 +33,8 @@ const meta: Meta<typeof ColorInput> = {
|
|
|
33
33
|
control: 'boolean',
|
|
34
34
|
description: 'Required field (shows asterisk)',
|
|
35
35
|
},
|
|
36
|
+
hasHelpIcon: { control: 'boolean' },
|
|
37
|
+
helpIconLabel: { control: 'text' },
|
|
36
38
|
showOptional: {
|
|
37
39
|
control: 'boolean',
|
|
38
40
|
description: 'Show "(Optional)" text after label',
|
|
@@ -75,6 +77,16 @@ export const Default: Story = {
|
|
|
75
77
|
},
|
|
76
78
|
};
|
|
77
79
|
|
|
80
|
+
export const WithHelpIcon: Story = {
|
|
81
|
+
args: {
|
|
82
|
+
label: 'Brand color',
|
|
83
|
+
placeholder: '#000000',
|
|
84
|
+
required: true,
|
|
85
|
+
hasHelpIcon: true,
|
|
86
|
+
helpIconLabel: 'More information about this field',
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
78
90
|
export const Sizes: Story = {
|
|
79
91
|
render: () => (
|
|
80
92
|
<Stack gap="md" w={300}>
|
|
@@ -33,6 +33,8 @@ const meta: Meta<typeof NumberInput> = {
|
|
|
33
33
|
control: 'boolean',
|
|
34
34
|
description: 'Required field (shows asterisk)',
|
|
35
35
|
},
|
|
36
|
+
hasHelpIcon: { control: 'boolean' },
|
|
37
|
+
helpIconLabel: { control: 'text' },
|
|
36
38
|
showOptional: {
|
|
37
39
|
control: 'boolean',
|
|
38
40
|
description: 'Show "(Optional)" text after label',
|
|
@@ -82,6 +84,16 @@ export const Default: Story = {
|
|
|
82
84
|
},
|
|
83
85
|
};
|
|
84
86
|
|
|
87
|
+
export const WithHelpIcon: Story = {
|
|
88
|
+
args: {
|
|
89
|
+
label: 'Quantity',
|
|
90
|
+
placeholder: 'Enter a number',
|
|
91
|
+
required: true,
|
|
92
|
+
hasHelpIcon: true,
|
|
93
|
+
helpIconLabel: 'More information about this field',
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
85
97
|
export const Sizes: Story = {
|
|
86
98
|
render: () => (
|
|
87
99
|
<Stack gap="md" w={300}>
|
|
@@ -33,6 +33,8 @@ const meta: Meta<typeof TextArea> = {
|
|
|
33
33
|
control: 'boolean',
|
|
34
34
|
description: 'Required field (shows asterisk)',
|
|
35
35
|
},
|
|
36
|
+
hasHelpIcon: { control: 'boolean' },
|
|
37
|
+
helpIconLabel: { control: 'text' },
|
|
36
38
|
showOptional: {
|
|
37
39
|
control: 'boolean',
|
|
38
40
|
description: 'Show "(Optional)" text after label',
|
|
@@ -78,6 +80,16 @@ export const Default: Story = {
|
|
|
78
80
|
},
|
|
79
81
|
};
|
|
80
82
|
|
|
83
|
+
export const WithHelpIcon: Story = {
|
|
84
|
+
args: {
|
|
85
|
+
label: 'Comments',
|
|
86
|
+
placeholder: 'Enter your comments',
|
|
87
|
+
required: true,
|
|
88
|
+
hasHelpIcon: true,
|
|
89
|
+
helpIconLabel: 'More information about this field',
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
81
93
|
export const Sizes: Story = {
|
|
82
94
|
render: () => (
|
|
83
95
|
<Stack gap="md" w={400}>
|
|
@@ -34,6 +34,8 @@ const meta: Meta<typeof TextInput> = {
|
|
|
34
34
|
control: 'boolean',
|
|
35
35
|
description: 'Required field (shows asterisk)',
|
|
36
36
|
},
|
|
37
|
+
hasHelpIcon: { control: 'boolean' },
|
|
38
|
+
helpIconLabel: { control: 'text' },
|
|
37
39
|
showOptional: {
|
|
38
40
|
control: 'boolean',
|
|
39
41
|
description: 'Show "(Optional)" text after label',
|
|
@@ -63,6 +65,16 @@ export const Default: Story = {
|
|
|
63
65
|
},
|
|
64
66
|
};
|
|
65
67
|
|
|
68
|
+
export const WithHelpIcon: Story = {
|
|
69
|
+
args: {
|
|
70
|
+
label: 'Name',
|
|
71
|
+
placeholder: 'Enter your name',
|
|
72
|
+
required: true,
|
|
73
|
+
hasHelpIcon: true,
|
|
74
|
+
helpIconLabel: 'More information about this field',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
66
78
|
export const Sizes: Story = {
|
|
67
79
|
render: () => (
|
|
68
80
|
<Stack gap="md" w={300}>
|
package/dist/stories/index.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.25",
|
|
3
3
|
"stories": [
|
|
4
4
|
{
|
|
5
5
|
"title": "Design System/Buttons/ActionIcon",
|
|
@@ -67,6 +67,40 @@
|
|
|
67
67
|
"Stack"
|
|
68
68
|
]
|
|
69
69
|
},
|
|
70
|
+
{
|
|
71
|
+
"title": "Design System/Combobox/ADMultiselect",
|
|
72
|
+
"component": "ADMultiselect",
|
|
73
|
+
"description": "Mantine MultiSelect with checkbox options and a \"+N more\" pill. Hovering \"+N more\" lists the hidden values. All core MultiSelect props (value, onChange, searchable, clearable, name, ...) are supported.",
|
|
74
|
+
"stories": [
|
|
75
|
+
"Default",
|
|
76
|
+
"WithHelpIcon",
|
|
77
|
+
"WithErrorCaption",
|
|
78
|
+
"Sizes",
|
|
79
|
+
"WithDescription",
|
|
80
|
+
"RequiredAndOptional",
|
|
81
|
+
"WithError",
|
|
82
|
+
"DisabledState",
|
|
83
|
+
"MaxDisplayedValues",
|
|
84
|
+
"DifferentDataTypes",
|
|
85
|
+
"FormIntegration",
|
|
86
|
+
"TagSelection",
|
|
87
|
+
"TeamAndPermissions",
|
|
88
|
+
"UseCases",
|
|
89
|
+
"Controlled",
|
|
90
|
+
"GroupedAndSearchable",
|
|
91
|
+
"Interactive"
|
|
92
|
+
],
|
|
93
|
+
"file": "Combobox/ADMultiselect.stories.tsx",
|
|
94
|
+
"designSystem": [
|
|
95
|
+
"ADMultiselect",
|
|
96
|
+
"Text",
|
|
97
|
+
"Title"
|
|
98
|
+
],
|
|
99
|
+
"mantine": [
|
|
100
|
+
"Box",
|
|
101
|
+
"Stack"
|
|
102
|
+
]
|
|
103
|
+
},
|
|
70
104
|
{
|
|
71
105
|
"title": "Design System/Combobox/AutocompleteClearable",
|
|
72
106
|
"component": "AutocompleteClearable",
|
|
@@ -113,40 +147,10 @@
|
|
|
113
147
|
],
|
|
114
148
|
"mantine": []
|
|
115
149
|
},
|
|
116
|
-
{
|
|
117
|
-
"title": "Design System/Combobox/Multiselect",
|
|
118
|
-
"component": "Multiselect",
|
|
119
|
-
"description": "Multi-selection input with pills display and checkbox options.",
|
|
120
|
-
"stories": [
|
|
121
|
-
"Default",
|
|
122
|
-
"Sizes",
|
|
123
|
-
"WithDescription",
|
|
124
|
-
"RequiredAndOptional",
|
|
125
|
-
"WithError",
|
|
126
|
-
"DisabledState",
|
|
127
|
-
"MaxDisplayedValues",
|
|
128
|
-
"DifferentDataTypes",
|
|
129
|
-
"FormIntegration",
|
|
130
|
-
"TagSelection",
|
|
131
|
-
"TeamAndPermissions",
|
|
132
|
-
"UseCases",
|
|
133
|
-
"Interactive"
|
|
134
|
-
],
|
|
135
|
-
"file": "Combobox/Multiselect.stories.tsx",
|
|
136
|
-
"designSystem": [
|
|
137
|
-
"Inline",
|
|
138
|
-
"Multiselect",
|
|
139
|
-
"Text",
|
|
140
|
-
"Title"
|
|
141
|
-
],
|
|
142
|
-
"mantine": [
|
|
143
|
-
"Stack"
|
|
144
|
-
]
|
|
145
|
-
},
|
|
146
150
|
{
|
|
147
151
|
"title": "Design System/Combobox/SearchableSelect",
|
|
148
152
|
"component": "SearchableSelect",
|
|
149
|
-
"description": "
|
|
153
|
+
"description": "The DS Select with `searchable` on by default. Designers use Combobox in Figma; engineering swaps in SearchableSelect for type-to-filter fields.",
|
|
150
154
|
"stories": [
|
|
151
155
|
"Default",
|
|
152
156
|
"Sizes",
|
|
@@ -164,7 +168,6 @@
|
|
|
164
168
|
],
|
|
165
169
|
"file": "Combobox/SearchableSelect.stories.tsx",
|
|
166
170
|
"designSystem": [
|
|
167
|
-
"Inline",
|
|
168
171
|
"SearchableSelect",
|
|
169
172
|
"Text",
|
|
170
173
|
"Title"
|
|
@@ -176,7 +179,7 @@
|
|
|
176
179
|
{
|
|
177
180
|
"title": "Design System/Combobox/Select",
|
|
178
181
|
"component": "Select",
|
|
179
|
-
"description": "A flexible select component built on Mantine's Select with design system defaults. **Features:** - **Regular mode**: Standard select with borders, labels, and validation - **Borderless mode**: Clean, minimal appearance for dashboard widgets - **Searchable / Clearable**: Optional search and clear functionality - **Help icon**: Tooltip-based contextual help
|
|
182
|
+
"description": "A flexible select component built on Mantine's Select with design system defaults. **Features:** - **Regular mode**: Standard select with borders, labels, and validation - **Borderless mode**: Clean, minimal appearance for dashboard widgets - **Searchable / Clearable**: Optional search and clear functionality - **Help icon**: Tooltip-based contextual help, a (?) icon to the right of the label - **Optional label**: Shows \"(Optional)\" text next to the label - **Error caption**: Separate error message prop for controlled error display",
|
|
180
183
|
"stories": [
|
|
181
184
|
"Default",
|
|
182
185
|
"WithObjectData",
|
|
@@ -413,7 +416,7 @@
|
|
|
413
416
|
{
|
|
414
417
|
"title": "Design System/Complex Components/Utilities/CopyButton",
|
|
415
418
|
"component": "CopyButton",
|
|
416
|
-
"description": "A reusable button component with copy-to-clipboard functionality and interactive tooltips.
|
|
419
|
+
"description": "A reusable button component with copy-to-clipboard functionality and interactive tooltips. Built on Mantine's CopyButton: clicking copies the value and the tooltip shows \"Copied\" briefly.",
|
|
417
420
|
"stories": [
|
|
418
421
|
"Default",
|
|
419
422
|
"BasicUsage",
|
|
@@ -767,6 +770,7 @@
|
|
|
767
770
|
"description": "ColorInput component for color selection with consistent design system styling and multiple format support.",
|
|
768
771
|
"stories": [
|
|
769
772
|
"Default",
|
|
773
|
+
"WithHelpIcon",
|
|
770
774
|
"Sizes",
|
|
771
775
|
"LabelVariants",
|
|
772
776
|
"States",
|
|
@@ -846,6 +850,7 @@
|
|
|
846
850
|
"description": "NumberInput component for numeric values with consistent design system styling and validation.",
|
|
847
851
|
"stories": [
|
|
848
852
|
"Default",
|
|
853
|
+
"WithHelpIcon",
|
|
849
854
|
"Sizes",
|
|
850
855
|
"LabelVariants",
|
|
851
856
|
"States",
|
|
@@ -1002,6 +1007,7 @@
|
|
|
1002
1007
|
"description": "TextArea component for multi-line text input with consistent design system styling and auto-sizing capabilities.",
|
|
1003
1008
|
"stories": [
|
|
1004
1009
|
"Default",
|
|
1010
|
+
"WithHelpIcon",
|
|
1005
1011
|
"Sizes",
|
|
1006
1012
|
"LabelVariants",
|
|
1007
1013
|
"States",
|
|
@@ -1028,6 +1034,7 @@
|
|
|
1028
1034
|
"description": "TextInput component with design system sizing, consistent styling, and enhanced label options.",
|
|
1029
1035
|
"stories": [
|
|
1030
1036
|
"Default",
|
|
1037
|
+
"WithHelpIcon",
|
|
1031
1038
|
"Sizes",
|
|
1032
1039
|
"LabelVariants",
|
|
1033
1040
|
"WithIcons",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appdirect/design-system",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "AppDirect Design System components. Wraps Mantine v9 with standardized props, variants, and tokens.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"prepublishOnly": "npm run build"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@appdirect/ad-design-tokens": "0.0.
|
|
52
|
+
"@appdirect/ad-design-tokens": "0.0.25",
|
|
53
53
|
"@remixicon/react": "^4.6.0",
|
|
54
54
|
"@tabler/icons-react": "^3.33.0",
|
|
55
55
|
"@tanstack/react-table": "^9.2.4",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { Checkbox, Combobox, Input, Pill as MantinePill, PillsInput, useCombobox, InputWrapper } from '@mantine/core';
|
|
5
|
-
import { Inline } from '../index.js';
|
|
6
|
-
import { Pill } from '../DataDisplay/Pill.js';
|
|
7
|
-
const technologies = ['React', 'Vue', 'Angular', 'Node.js', 'Docker', 'Kubernetes', 'AWS', 'MongoDB'];
|
|
8
|
-
const MAX_DISPLAYED_VALUES = 2;
|
|
9
|
-
export function Multiselect({ label, placeholder = "Pick one or more technologies", data = technologies, description, error, required = false, showOptional = false, disabled = false, searchable = true, size = 'md', style, maxDisplayedValues = MAX_DISPLAYED_VALUES, ...props }) {
|
|
10
|
-
const combobox = useCombobox({
|
|
11
|
-
onDropdownClose: () => combobox.resetSelectedOption(),
|
|
12
|
-
onDropdownOpen: () => combobox.updateSelectedOptionIndex('active'),
|
|
13
|
-
});
|
|
14
|
-
const [value, setValue] = useState([]);
|
|
15
|
-
const handleValueSelect = (val) => setValue((current) => current.includes(val) ? current.filter((v) => v !== val) : [...current, val]);
|
|
16
|
-
const handleValueRemove = (val) => setValue((current) => current.filter((v) => v !== val));
|
|
17
|
-
const values = value
|
|
18
|
-
.slice(0, maxDisplayedValues === value.length ? maxDisplayedValues : maxDisplayedValues - 1)
|
|
19
|
-
.map((item) => (_jsx(Pill, { withRemoveButton: true, onRemove: () => handleValueRemove(item), size: size, children: item }, item)));
|
|
20
|
-
// Convert data to consistent format
|
|
21
|
-
const normalizedData = data.map(item => typeof item === 'string' ? { value: item, label: item } : item);
|
|
22
|
-
const options = normalizedData.map((item) => (_jsx(Combobox.Option, { value: item.value, active: value.includes(item.value), children: _jsxs(Inline, { gap: "sm", children: [_jsx(Checkbox, { checked: value.includes(item.value), onChange: () => { }, "aria-hidden": true, tabIndex: -1, style: { pointerEvents: 'none' } }), _jsx("span", { children: item.label })] }) }, item.value)));
|
|
23
|
-
// Determine the display label
|
|
24
|
-
const displayLabel = showOptional && !required && label ? `${label} (optional)` : label;
|
|
25
|
-
return (_jsx("div", { style: style, children: _jsx(InputWrapper, { label: displayLabel, description: description, error: error, required: required && !showOptional, size: size, withAsterisk: required && !showOptional, children: _jsxs(Combobox, { store: combobox, onOptionSubmit: handleValueSelect, withinPortal: false, disabled: disabled, children: [_jsx(Combobox.DropdownTarget, { children: _jsx(PillsInput, { pointer: true, onClick: () => !disabled && combobox.toggleDropdown(), size: size, disabled: disabled, error: !!error, children: _jsxs(MantinePill.Group, { children: [value.length > 0 ? (_jsxs(_Fragment, { children: [values, value.length > maxDisplayedValues && (_jsxs(Pill, { size: size, children: ["+", value.length - (maxDisplayedValues - 1), " more"] }))] })) : (_jsx(Input.Placeholder, { children: placeholder })), _jsx(Combobox.EventsTarget, { children: _jsx(PillsInput.Field, { type: "hidden", onBlur: () => combobox.closeDropdown(), onKeyDown: (event) => {
|
|
26
|
-
if (event.key === 'Backspace' && !disabled) {
|
|
27
|
-
event.preventDefault();
|
|
28
|
-
handleValueRemove(value[value.length - 1]);
|
|
29
|
-
}
|
|
30
|
-
}, disabled: disabled }) })] }) }) }), _jsx(Combobox.Dropdown, { children: _jsx(Combobox.Options, { children: options }) })] }) }) }));
|
|
31
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { Checkbox, Combobox,Input, Pill as MantinePill, PillsInput, useCombobox, InputWrapper } from '@mantine/core';
|
|
5
|
-
import { Inline } from '..';
|
|
6
|
-
import { Pill } from '../DataDisplay/Pill';
|
|
7
|
-
|
|
8
|
-
const technologies = ['React', 'Vue', 'Angular', 'Node.js', 'Docker', 'Kubernetes', 'AWS', 'MongoDB'];
|
|
9
|
-
|
|
10
|
-
const MAX_DISPLAYED_VALUES = 2;
|
|
11
|
-
|
|
12
|
-
export interface DSMultiselectProps {
|
|
13
|
-
/** Label for the input */
|
|
14
|
-
label?: string;
|
|
15
|
-
/** Placeholder text */
|
|
16
|
-
placeholder?: string;
|
|
17
|
-
/** Data array for options - can be strings or objects with value/label */
|
|
18
|
-
data?: string[] | { value: string; label: string }[];
|
|
19
|
-
/** Description text displayed below the input */
|
|
20
|
-
description?: string;
|
|
21
|
-
/** Error message */
|
|
22
|
-
error?: string;
|
|
23
|
-
/** Whether the field is required */
|
|
24
|
-
required?: boolean;
|
|
25
|
-
/** Whether to show "(optional)" next to the label */
|
|
26
|
-
showOptional?: boolean;
|
|
27
|
-
/** Whether the input is disabled */
|
|
28
|
-
disabled?: boolean;
|
|
29
|
-
/** Whether the select is searchable */
|
|
30
|
-
searchable?: boolean;
|
|
31
|
-
/** Input size */
|
|
32
|
-
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
33
|
-
/** Style object for the component */
|
|
34
|
-
style?: React.CSSProperties;
|
|
35
|
-
/** Maximum number of pills to display before showing "+X more" */
|
|
36
|
-
maxDisplayedValues?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function Multiselect({
|
|
40
|
-
label,
|
|
41
|
-
placeholder = "Pick one or more technologies",
|
|
42
|
-
data = technologies,
|
|
43
|
-
description,
|
|
44
|
-
error,
|
|
45
|
-
required = false,
|
|
46
|
-
showOptional = false,
|
|
47
|
-
disabled = false,
|
|
48
|
-
searchable = true,
|
|
49
|
-
size = 'md',
|
|
50
|
-
style,
|
|
51
|
-
maxDisplayedValues = MAX_DISPLAYED_VALUES,
|
|
52
|
-
...props
|
|
53
|
-
}: DSMultiselectProps) {
|
|
54
|
-
const combobox = useCombobox({
|
|
55
|
-
onDropdownClose: () => combobox.resetSelectedOption(),
|
|
56
|
-
onDropdownOpen: () => combobox.updateSelectedOptionIndex('active'),
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const [value, setValue] = useState<string[]>([]);
|
|
60
|
-
|
|
61
|
-
const handleValueSelect = (val: string) =>
|
|
62
|
-
setValue((current) =>
|
|
63
|
-
current.includes(val) ? current.filter((v) => v !== val) : [...current, val]
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const handleValueRemove = (val: string) =>
|
|
67
|
-
setValue((current) => current.filter((v) => v !== val));
|
|
68
|
-
|
|
69
|
-
const values = value
|
|
70
|
-
.slice(
|
|
71
|
-
0,
|
|
72
|
-
maxDisplayedValues === value.length ? maxDisplayedValues : maxDisplayedValues - 1
|
|
73
|
-
)
|
|
74
|
-
.map((item) => (
|
|
75
|
-
<Pill key={item} withRemoveButton onRemove={() => handleValueRemove(item)} size={size}>
|
|
76
|
-
{item}
|
|
77
|
-
</Pill>
|
|
78
|
-
));
|
|
79
|
-
|
|
80
|
-
// Convert data to consistent format
|
|
81
|
-
const normalizedData = data.map(item =>
|
|
82
|
-
typeof item === 'string' ? { value: item, label: item } : item
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const options = normalizedData.map((item) => (
|
|
86
|
-
<Combobox.Option value={item.value} key={item.value} active={value.includes(item.value)}>
|
|
87
|
-
<Inline gap="sm">
|
|
88
|
-
<Checkbox
|
|
89
|
-
checked={value.includes(item.value)}
|
|
90
|
-
onChange={() => {}} // Handled by onOptionSubmit
|
|
91
|
-
aria-hidden
|
|
92
|
-
tabIndex={-1}
|
|
93
|
-
style={{ pointerEvents: 'none' }}
|
|
94
|
-
/>
|
|
95
|
-
<span>{item.label}</span>
|
|
96
|
-
</Inline>
|
|
97
|
-
</Combobox.Option>
|
|
98
|
-
));
|
|
99
|
-
|
|
100
|
-
// Determine the display label
|
|
101
|
-
const displayLabel = showOptional && !required && label ? `${label} (optional)` : label;
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<div style={style}>
|
|
105
|
-
<InputWrapper
|
|
106
|
-
label={displayLabel}
|
|
107
|
-
description={description}
|
|
108
|
-
error={error}
|
|
109
|
-
required={required && !showOptional}
|
|
110
|
-
size={size}
|
|
111
|
-
withAsterisk={required && !showOptional}
|
|
112
|
-
>
|
|
113
|
-
<Combobox store={combobox} onOptionSubmit={handleValueSelect} withinPortal={false} disabled={disabled}>
|
|
114
|
-
<Combobox.DropdownTarget>
|
|
115
|
-
<PillsInput
|
|
116
|
-
pointer
|
|
117
|
-
onClick={() => !disabled && combobox.toggleDropdown()}
|
|
118
|
-
size={size}
|
|
119
|
-
disabled={disabled}
|
|
120
|
-
error={!!error}
|
|
121
|
-
>
|
|
122
|
-
<MantinePill.Group>
|
|
123
|
-
{value.length > 0 ? (
|
|
124
|
-
<>
|
|
125
|
-
{values}
|
|
126
|
-
{value.length > maxDisplayedValues && (
|
|
127
|
-
<Pill size={size}>+{value.length - (maxDisplayedValues - 1)} more</Pill>
|
|
128
|
-
)}
|
|
129
|
-
</>
|
|
130
|
-
) : (
|
|
131
|
-
<Input.Placeholder>{placeholder}</Input.Placeholder>
|
|
132
|
-
)}
|
|
133
|
-
|
|
134
|
-
<Combobox.EventsTarget>
|
|
135
|
-
<PillsInput.Field
|
|
136
|
-
type="hidden"
|
|
137
|
-
onBlur={() => combobox.closeDropdown()}
|
|
138
|
-
onKeyDown={(event) => {
|
|
139
|
-
if (event.key === 'Backspace' && !disabled) {
|
|
140
|
-
event.preventDefault();
|
|
141
|
-
handleValueRemove(value[value.length - 1]);
|
|
142
|
-
}
|
|
143
|
-
}}
|
|
144
|
-
disabled={disabled}
|
|
145
|
-
/>
|
|
146
|
-
</Combobox.EventsTarget>
|
|
147
|
-
</MantinePill.Group>
|
|
148
|
-
</PillsInput>
|
|
149
|
-
</Combobox.DropdownTarget>
|
|
150
|
-
|
|
151
|
-
<Combobox.Dropdown>
|
|
152
|
-
<Combobox.Options>{options}</Combobox.Options>
|
|
153
|
-
</Combobox.Dropdown>
|
|
154
|
-
</Combobox>
|
|
155
|
-
</InputWrapper>
|
|
156
|
-
</div>
|
|
157
|
-
);
|
|
158
|
-
}
|