@parallelworks/ui 0.41.0 → 0.42.0
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/README.md +25 -0
- package/dist/ai/components/AllocationSelector.d.ts +3 -4
- package/dist/ai/components/AllocationSelector.js +37 -33
- package/dist/ai/components/AttachmentManager.js +7 -7
- package/dist/ai/components/AttachmentUpload.js +5 -5
- package/dist/ai/components/BranchNavigator.js +1 -1
- package/dist/ai/components/ChatEmptyState.js +2 -2
- package/dist/ai/components/ChatInput.js +10 -8
- package/dist/ai/components/ChatLayout.js +4 -5
- package/dist/ai/components/ChatMessage.js +12 -12
- package/dist/ai/components/ChatMessageList.js +9 -9
- package/dist/ai/components/ChatSidebar.js +8 -9
- package/dist/ai/components/ChatThread.js +4 -4
- package/dist/ai/components/ComposerChrome.d.ts +2 -2
- package/dist/ai/components/ComposerChrome.js +3 -6
- package/dist/ai/components/DragOverlay.js +2 -2
- package/dist/ai/components/ModelSelector.d.ts +5 -3
- package/dist/ai/components/ModelSelector.js +102 -339
- package/dist/ai/components/PastedText.js +11 -11
- package/dist/ai/components/ProviderIssueBanner.d.ts +2 -0
- package/dist/ai/components/ProviderIssueBanner.js +34 -16
- package/dist/ai/components/Reasoning.js +4 -4
- package/dist/ai/components/ShareDialog.js +43 -35
- package/dist/ai/components/SlashMenu.d.ts +12 -2
- package/dist/ai/components/SlashMenu.js +29 -13
- package/dist/ai/components/agent/ActivityLine.js +3 -3
- package/dist/ai/components/agent/AgentMessageParts.js +20 -20
- package/dist/ai/components/agent/PermissionPicker.js +13 -11
- package/dist/ai/components/conversationActions.d.ts +4 -6
- package/dist/ai/components/conversationActions.js +9 -13
- package/dist/ai/core/ChatProvider.js +1 -1
- package/dist/ai/core/config.js +1 -1
- package/dist/ai/core/providerIssues.d.ts +7 -0
- package/dist/ai/core/providerIssues.js +9 -1
- package/dist/ai/core/useKeyboardShortcuts.d.ts +4 -0
- package/dist/ai/core/useKeyboardShortcuts.js +8 -2
- package/dist/ai/index.d.ts +0 -1
- package/dist/ai/index.js +1 -2
- package/dist/ai/strings.d.ts +19 -0
- package/dist/ai/strings.js +18 -1
- package/dist/ai/ui/Avatar.js +5 -5
- package/dist/ai/ui/ConversationSidebar.d.ts +0 -1
- package/dist/ai/ui/ConversationSidebar.js +6 -7
- package/dist/ai/ui/Markdown.js +3 -3
- package/dist/ai/ui/Notice.js +6 -6
- package/dist/ai/ui/chip.d.ts +4 -0
- package/dist/ai/ui/chip.js +8 -0
- package/dist/ai/ui/sidebar.d.ts +6 -5
- package/dist/ai/ui/sidebar.js +39 -43
- package/dist/components/ActionMenu.d.ts +13 -0
- package/dist/components/ActionMenu.js +30 -0
- package/dist/components/Avatar.js +6 -6
- package/dist/components/Breadcrumbs.js +1 -1
- package/dist/components/Button.js +10 -10
- package/dist/components/Callout.js +2 -2
- package/dist/components/Card.js +3 -3
- package/dist/components/Combobox.d.ts +66 -0
- package/dist/components/Combobox.js +393 -0
- package/dist/components/ConfirmModal.js +11 -11
- package/dist/components/ContextMenu.d.ts +23 -0
- package/dist/components/ContextMenu.js +89 -0
- package/dist/components/CopyToClipboard.js +2 -2
- package/dist/components/CreateModal.d.ts +17 -36
- package/dist/components/CreateModal.js +97 -259
- package/dist/components/DescriptionList.js +8 -8
- package/dist/components/Filter.js +2 -2
- package/dist/components/FilterPill.js +2 -2
- package/dist/components/HoverCard.d.ts +14 -0
- package/dist/components/HoverCard.js +33 -0
- package/dist/components/IconButton.d.ts +5 -5
- package/dist/components/IconButton.js +18 -22
- package/dist/components/InfoTip.d.ts +15 -0
- package/dist/components/InfoTip.js +60 -0
- package/dist/components/Input.js +5 -5
- package/dist/components/LetterBadge.js +2 -2
- package/dist/components/Loader.js +3 -3
- package/dist/components/Markdown.js +1 -1
- package/dist/components/MarkdownImpl.js +2 -2
- package/dist/components/Menu.d.ts +33 -0
- package/dist/components/Menu.js +86 -0
- package/dist/components/MenuEntries.d.ts +56 -0
- package/dist/components/MenuEntries.js +123 -0
- package/dist/components/Modal.d.ts +29 -0
- package/dist/components/Modal.js +47 -0
- package/dist/components/Overview.js +11 -10
- package/dist/components/PageHeader.d.ts +10 -16
- package/dist/components/PageHeader.js +69 -95
- package/dist/components/Pagination.js +5 -5
- package/dist/components/Provider.d.ts +5 -11
- package/dist/components/Provider.js +11 -14
- package/dist/components/Radio.d.ts +8 -0
- package/dist/components/Radio.js +16 -0
- package/dist/components/SectionHeader.js +2 -2
- package/dist/components/SegmentedControl.d.ts +6 -5
- package/dist/components/SegmentedControl.js +34 -30
- package/dist/components/Select.d.ts +27 -0
- package/dist/components/Select.js +78 -0
- package/dist/components/SettingModeOption.d.ts +5 -8
- package/dist/components/SettingModeOption.js +10 -12
- package/dist/components/SettingRow.js +4 -4
- package/dist/components/SettingsCard.js +4 -4
- package/dist/components/SettingsGroup.js +2 -2
- package/dist/components/Sort.js +1 -1
- package/dist/components/StatusBadge.js +7 -7
- package/dist/components/StatusIcons.js +4 -4
- package/dist/components/Switch.d.ts +22 -0
- package/dist/components/Switch.js +28 -0
- package/dist/components/Table.js +11 -11
- package/dist/components/Tooltip.d.ts +24 -20
- package/dist/components/Tooltip.js +58 -76
- package/dist/components/floating.d.ts +14 -0
- package/dist/components/floating.js +21 -0
- package/dist/components/search.d.ts +2 -0
- package/dist/components/search.js +14 -0
- package/dist/editor/Editor.js +1 -1
- package/dist/editor/EditorField.js +16 -21
- package/dist/editor/FormCodePanel.js +19 -19
- package/dist/editor/Monaco.js +3 -3
- package/dist/file-explorer/FileExplorer.js +77 -81
- package/dist/file-explorer/FileExplorerContext.js +2 -2
- package/dist/file-explorer/FilePreview/CodePreviewEditor.js +1 -1
- package/dist/file-explorer/FilePreview/Inline.js +1 -1
- package/dist/file-explorer/FilePreview/StreamedBadge.js +5 -6
- package/dist/file-explorer/FilePreview/Viewer.js +8 -8
- package/dist/file-explorer/FilePreview/index.d.ts +1 -1
- package/dist/file-explorer/FilePreview/index.js +49 -83
- package/dist/file-explorer/FileRow.d.ts +4 -3
- package/dist/file-explorer/FileRow.js +32 -38
- package/dist/file-explorer/FileRowsWindow.d.ts +3 -2
- package/dist/file-explorer/FileRowsWindow.js +4 -4
- package/dist/file-explorer/FileTable.d.ts +3 -2
- package/dist/file-explorer/FileTable.js +3 -3
- package/dist/file-explorer/LoadMoreRow.js +1 -1
- package/dist/file-explorer/TreeView.js +11 -16
- package/dist/file-explorer/helpers.js +11 -12
- package/dist/file-explorer/toasts.js +11 -11
- package/dist/form/FieldGroup.d.ts +11 -0
- package/dist/form/FieldGroup.js +36 -0
- package/dist/form/FieldWrapper.js +4 -4
- package/dist/form/Fields/BooleanField.js +23 -33
- package/dist/form/Fields/CheckboxGroupField.d.ts +1 -1
- package/dist/form/Fields/CheckboxGroupField.js +9 -13
- package/dist/form/Fields/ColorField.d.ts +1 -2
- package/dist/form/Fields/ColorField.js +6 -11
- package/dist/form/Fields/DropdownField.d.ts +3 -13
- package/dist/form/Fields/DropdownField.js +40 -27
- package/dist/form/Fields/DurationField.d.ts +1 -2
- package/dist/form/Fields/DurationField.js +25 -32
- package/dist/form/Fields/LabelField.js +2 -2
- package/dist/form/Fields/MultiDropdownField.d.ts +6 -12
- package/dist/form/Fields/MultiDropdownField.js +31 -22
- package/dist/form/Fields/NumberField.d.ts +1 -1
- package/dist/form/Fields/NumberField.js +65 -35
- package/dist/form/Fields/ObjectField.d.ts +1 -1
- package/dist/form/Fields/ObjectField.js +12 -43
- package/dist/form/Fields/RadioField.d.ts +1 -1
- package/dist/form/Fields/RadioField.js +30 -41
- package/dist/form/Fields/RangeField.d.ts +1 -2
- package/dist/form/Fields/RangeField.js +23 -16
- package/dist/form/Fields/StringField.d.ts +1 -2
- package/dist/form/Fields/StringField.js +58 -26
- package/dist/form/Fields/TextAreaField.js +12 -10
- package/dist/form/Form.d.ts +30 -48
- package/dist/form/Form.js +306 -412
- package/dist/form/FormLayout.js +9 -9
- package/dist/form/Wizard/WizardContainer.d.ts +1 -4
- package/dist/form/Wizard/WizardContainer.js +40 -56
- package/dist/form/Wizard/WizardNavigation.js +1 -1
- package/dist/form/Wizard/WizardStepContent.d.ts +1 -5
- package/dist/form/Wizard/WizardStepContent.js +11 -16
- package/dist/form/Wizard/WizardStepIndicator.js +6 -6
- package/dist/form/Wizard/types.d.ts +0 -14
- package/dist/form/fieldRegistry.d.ts +1 -1
- package/dist/form/fieldRegistry.js +6 -6
- package/dist/form/formEditing.js +1 -1
- package/dist/form/index.d.ts +5 -4
- package/dist/form/index.js +6 -7
- package/dist/form/types/fieldComponentTypes.d.ts +8 -10
- package/dist/form/useChoiceField.d.ts +20 -0
- package/dist/form/useChoiceField.js +49 -0
- package/dist/form/useFieldValue.d.ts +7 -0
- package/dist/form/useFieldValue.js +20 -0
- package/dist/form/useParsedOpts.d.ts +3 -1
- package/dist/form/useParsedOpts.js +12 -17
- package/dist/form/utils/dependentOptions.d.ts +8 -4
- package/dist/form/utils/dependentOptions.js +25 -17
- package/dist/form/utils/fieldItems.d.ts +10 -0
- package/dist/form/utils/fieldItems.js +11 -0
- package/dist/form/utils/fieldPath.d.ts +10 -0
- package/dist/form/utils/fieldPath.js +20 -0
- package/dist/form/utils/shareEqual.d.ts +6 -0
- package/dist/form/utils/shareEqual.js +38 -0
- package/dist/graph/AnnotationBanner.js +8 -8
- package/dist/graph/Collapse.d.ts +1 -0
- package/dist/graph/Collapse.js +6 -27
- package/dist/graph/Connectors.js +5 -5
- package/dist/graph/DependencyGraph.js +20 -19
- package/dist/graph/GraphEditor.js +30 -41
- package/dist/graph/GraphEditorDialogs.js +17 -17
- package/dist/graph/GraphNode.js +1 -1
- package/dist/graph/InputDialog.js +19 -22
- package/dist/graph/InputsEditor.js +58 -66
- package/dist/graph/JobSummary.js +42 -39
- package/dist/graph/MatrixGroup.js +1 -1
- package/dist/graph/ProblemsButton.js +18 -19
- package/dist/graph/Reveal.js +1 -1
- package/dist/graph/ShortcutsButton.js +15 -18
- package/dist/graph/SuggestionInput.d.ts +5 -10
- package/dist/graph/SuggestionInput.js +14 -18
- package/dist/graph/ToolbarPopover.d.ts +11 -6
- package/dist/graph/ToolbarPopover.js +35 -67
- package/dist/graph/TreeView.js +24 -37
- package/dist/graph/WorkflowSettingsDialog.js +4 -4
- package/dist/graph/editorChrome.js +13 -12
- package/dist/graph/editorFields.js +29 -29
- package/dist/graph/editorPrimitives.d.ts +1 -1
- package/dist/graph/editorPrimitives.js +10 -7
- package/dist/graph/editorRows.js +103 -97
- package/dist/graph/fieldProblems.js +2 -2
- package/dist/graph/graphEditorState.d.ts +4 -3
- package/dist/graph/inputRefs.js +9 -9
- package/dist/graph/settingsViews.js +6 -7
- package/dist/graph/stepWith.js +6 -6
- package/dist/index.d.ts +14 -15
- package/dist/index.js +15 -14
- package/dist/list/ActionToolbar.d.ts +6 -14
- package/dist/list/ActionToolbar.js +48 -96
- package/dist/list/ListPage.d.ts +6 -12
- package/dist/list/ListPage.js +46 -29
- package/dist/list/ListPager.js +4 -4
- package/dist/list/ListTable.js +5 -5
- package/dist/list/ListViewControls.d.ts +5 -4
- package/dist/list/ListViewControls.js +177 -267
- package/dist/list/UserHoverCard.d.ts +3 -17
- package/dist/list/UserHoverCard.js +21 -45
- package/dist/list/index.d.ts +3 -4
- package/dist/list/index.js +3 -4
- package/dist/list/listSearch.js +12 -11
- package/dist/list/rowMenu.d.ts +63 -0
- package/dist/list/rowMenu.js +134 -0
- package/dist/logviewer/LogViewer.js +26 -26
- package/dist/styles.css +1 -1
- package/package.json +7 -13
- package/dist/ai/ui/Dropdown.d.ts +0 -31
- package/dist/ai/ui/Dropdown.js +0 -110
- package/dist/components/AddMenu.d.ts +0 -18
- package/dist/components/AddMenu.js +0 -46
- package/dist/components/BareModal.d.ts +0 -17
- package/dist/components/BareModal.js +0 -77
- package/dist/components/CollapsiblePanel.d.ts +0 -27
- package/dist/components/CollapsiblePanel.js +0 -77
- package/dist/components/Dropdown.d.ts +0 -28
- package/dist/components/Dropdown.js +0 -355
- package/dist/components/Listbox.d.ts +0 -21
- package/dist/components/Listbox.js +0 -119
- package/dist/components/MultiSelect.d.ts +0 -22
- package/dist/components/MultiSelect.js +0 -168
- package/dist/components/SwitchToggle.d.ts +0 -15
- package/dist/components/SwitchToggle.js +0 -57
- package/dist/components/SwitchToggleSmall.d.ts +0 -6
- package/dist/components/SwitchToggleSmall.js +0 -14
- package/dist/components/Toggle.d.ts +0 -6
- package/dist/components/Toggle.js +0 -20
- package/dist/components/dropdownUtils.d.ts +0 -37
- package/dist/components/dropdownUtils.js +0 -99
- package/dist/form/SpecialTypes/DropdownWrapper.d.ts +0 -25
- package/dist/form/SpecialTypes/DropdownWrapper.js +0 -28
- package/dist/form/SpecialTypes/FormikCustomDropdown.d.ts +0 -51
- package/dist/form/SpecialTypes/FormikCustomDropdown.js +0 -119
- package/dist/form/SpecialTypes/FormikCustomInput.d.ts +0 -19
- package/dist/form/SpecialTypes/FormikCustomInput.js +0 -121
- package/dist/form/SpecialTypes/FormikMultiSelectDropdown.d.ts +0 -13
- package/dist/form/SpecialTypes/FormikMultiSelectDropdown.js +0 -31
- package/dist/form/SpecialTypes/FormikNumericInput.d.ts +0 -9
- package/dist/form/SpecialTypes/FormikNumericInput.js +0 -60
- package/dist/form/SpecialTypes/index.d.ts +0 -3
- package/dist/list/HoverCard.d.ts +0 -24
- package/dist/list/HoverCard.js +0 -73
- package/dist/list/RowContextMenu.d.ts +0 -127
- package/dist/list/RowContextMenu.js +0 -515
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import { useStrings } from "./Provider.js";
|
|
2
|
-
import { FaCaretDown } from "../icons/fa/FaCaretDown.js";
|
|
3
|
-
import { truncationTooltipProps } from "./Tooltip.js";
|
|
4
|
-
import { DropdownCaret, flattenDisplayOptions, isCategory, toggleSetMember } from "./dropdownUtils.js";
|
|
5
|
-
import { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions } from "@headlessui/react";
|
|
6
|
-
import cx from "classnames";
|
|
7
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import { createPortal } from "react-dom";
|
|
10
|
-
import deepEqual from "fast-deep-equal";
|
|
11
|
-
import { usePopper } from "react-popper";
|
|
12
|
-
//#region src/components/Dropdown.tsx
|
|
13
|
-
var defaultCollapsedLabel = (count) => `${count} more`;
|
|
14
|
-
function isNamedValue(value) {
|
|
15
|
-
return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string";
|
|
16
|
-
}
|
|
17
|
-
var checkEquals = (val, opt) => {
|
|
18
|
-
if (typeof val === "object" && !Array.isArray(val)) return deepEqual(val, opt);
|
|
19
|
-
return val === opt;
|
|
20
|
-
};
|
|
21
|
-
function getOptionFromValue(value, options) {
|
|
22
|
-
if (value === void 0) return {
|
|
23
|
-
label: "",
|
|
24
|
-
value: ""
|
|
25
|
-
};
|
|
26
|
-
const found = options.find((option) => {
|
|
27
|
-
if (typeof option === "string") return checkEquals(value, option);
|
|
28
|
-
else if (isCategory(option)) return option.options.find((opt) => checkEquals(value, opt.value));
|
|
29
|
-
else return checkEquals(value, option.value);
|
|
30
|
-
});
|
|
31
|
-
if (found) {
|
|
32
|
-
if (typeof found === "string") return {
|
|
33
|
-
label: found,
|
|
34
|
-
value: found
|
|
35
|
-
};
|
|
36
|
-
else if (isCategory(found)) return found.options.find((opt) => checkEquals(value, opt.value)) || {
|
|
37
|
-
label: JSON.stringify(value),
|
|
38
|
-
value
|
|
39
|
-
};
|
|
40
|
-
else return found;
|
|
41
|
-
}
|
|
42
|
-
const isNamedObject = isNamedValue(value);
|
|
43
|
-
const fallbackLabel = typeof value === "string" ? value : isNamedObject ? value.name : JSON.stringify(value);
|
|
44
|
-
return {
|
|
45
|
-
label: fallbackLabel,
|
|
46
|
-
value: isNamedObject ? value : fallbackLabel
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function Dropdown(props) {
|
|
50
|
-
const { onChange, value, options, ...others } = props;
|
|
51
|
-
const val = useMemo(() => {
|
|
52
|
-
return getOptionFromValue(value, options);
|
|
53
|
-
}, [value, options]);
|
|
54
|
-
const wrapperOnchange = (value) => {
|
|
55
|
-
onChange(value?.value);
|
|
56
|
-
};
|
|
57
|
-
const transformedOptions = useMemo(() => {
|
|
58
|
-
return options.map((item) => {
|
|
59
|
-
if (isCategory(item)) return {
|
|
60
|
-
...item,
|
|
61
|
-
options: item.options.map((opt) => {
|
|
62
|
-
if (typeof opt === "string") return {
|
|
63
|
-
label: opt,
|
|
64
|
-
value: opt
|
|
65
|
-
};
|
|
66
|
-
return opt;
|
|
67
|
-
})
|
|
68
|
-
};
|
|
69
|
-
else if (typeof item === "string") return {
|
|
70
|
-
label: item,
|
|
71
|
-
value: item
|
|
72
|
-
};
|
|
73
|
-
return item;
|
|
74
|
-
});
|
|
75
|
-
}, [options]);
|
|
76
|
-
return /* @__PURE__ */ jsx(DropdownHelper, {
|
|
77
|
-
value: val,
|
|
78
|
-
onChange: wrapperOnchange,
|
|
79
|
-
options: transformedOptions,
|
|
80
|
-
...others
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function ActiveWatcher({ active, onChange }) {
|
|
84
|
-
const prev = useRef(null);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (prev.current !== active) {
|
|
87
|
-
onChange?.(active?.value);
|
|
88
|
-
prev.current = active;
|
|
89
|
-
}
|
|
90
|
-
}, [active, onChange]);
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
function OptionContent({ label, description, icon }) {
|
|
94
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
95
|
-
className: cx("flex gap-1.5", description ? "items-start min-w-0" : "items-center truncate"),
|
|
96
|
-
...truncationTooltipProps(label, (anchor) => anchor.lastElementChild),
|
|
97
|
-
children: [icon, description ? /* @__PURE__ */ jsxs("span", {
|
|
98
|
-
className: "flex flex-col min-w-0",
|
|
99
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
100
|
-
className: "truncate",
|
|
101
|
-
children: label
|
|
102
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
103
|
-
className: "text-(--theme-muted-text-color) text-xs leading-snug",
|
|
104
|
-
children: description
|
|
105
|
-
})]
|
|
106
|
-
}) : /* @__PURE__ */ jsx("span", {
|
|
107
|
-
className: "truncate",
|
|
108
|
-
children: label
|
|
109
|
-
})]
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function ToggleOption({ option, category, expanded, onToggle, ...virtualRowProps }) {
|
|
113
|
-
return /* @__PURE__ */ jsx(ComboboxOption, {
|
|
114
|
-
...virtualRowProps,
|
|
115
|
-
"data-testid": "combobox-toggle",
|
|
116
|
-
value: option,
|
|
117
|
-
className: "w-full h-10 flex items-center pl-3",
|
|
118
|
-
children: /* @__PURE__ */ jsxs("button", {
|
|
119
|
-
type: "button",
|
|
120
|
-
"aria-expanded": expanded,
|
|
121
|
-
className: "flex items-center gap-1.5 cursor-pointer text-(--theme-muted-text-color) hover:text-(--theme-app)",
|
|
122
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
123
|
-
onClick: (e) => {
|
|
124
|
-
e.preventDefault();
|
|
125
|
-
e.stopPropagation();
|
|
126
|
-
onToggle(category);
|
|
127
|
-
},
|
|
128
|
-
children: [/* @__PURE__ */ jsx(FaCaretDown, { className: cx("w-3 h-3", !expanded && "-rotate-90") }), option.label]
|
|
129
|
-
})
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function DropdownHelper({ wrapperClassName = "w-full", className, textBoxClassName = "w-full", options = [], onChange, onActiveChange, value, id, ariaLabel, "aria-describedby": describedBy, required, disabled = false, placeholder = "", loading = false, allowCustomValue = false, customValueLabel = "Use", collapsedLabel = defaultCollapsedLabel, portalEl, compact = false, showCaret = true }) {
|
|
133
|
-
const DEBOUNCE_MS = 500;
|
|
134
|
-
const t = useStrings().dropdown;
|
|
135
|
-
const [query, setQuery] = useState("");
|
|
136
|
-
const [selectedIconWidth, setSelectedIconWidth] = useState(0);
|
|
137
|
-
const selectedIconRef = useCallback((node) => {
|
|
138
|
-
setSelectedIconWidth(node?.offsetWidth ?? 0);
|
|
139
|
-
}, []);
|
|
140
|
-
const selectedIcon = query === "" ? value?.icon : void 0;
|
|
141
|
-
const [referenceElement, setReferenceElement] = useState(null);
|
|
142
|
-
const [popperElement, setPopperElement] = useState(null);
|
|
143
|
-
const [boundaryEl, setBoundaryEl] = useState(null);
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
if (!referenceElement) {
|
|
146
|
-
setBoundaryEl(null);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const ref = referenceElement;
|
|
150
|
-
const dialog = ref.closest("[role=\"dialog\"]");
|
|
151
|
-
if (!dialog) {
|
|
152
|
-
setBoundaryEl(null);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
let node = ref.parentElement;
|
|
156
|
-
while (node) {
|
|
157
|
-
const style = getComputedStyle(node);
|
|
158
|
-
if (/(auto|scroll|hidden)/.test(`${style.overflowX} ${style.overflowY}`)) {
|
|
159
|
-
setBoundaryEl(node);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (node === dialog) break;
|
|
163
|
-
node = node.parentElement;
|
|
164
|
-
}
|
|
165
|
-
setBoundaryEl(dialog);
|
|
166
|
-
}, [referenceElement]);
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
if (!referenceElement) return;
|
|
169
|
-
if (describedBy) referenceElement.setAttribute("aria-describedby", describedBy);
|
|
170
|
-
else referenceElement.removeAttribute("aria-describedby");
|
|
171
|
-
}, [referenceElement, describedBy]);
|
|
172
|
-
const sameWidthModifier = useMemo(() => ({
|
|
173
|
-
name: "sameWidth",
|
|
174
|
-
enabled: true,
|
|
175
|
-
phase: "beforeWrite",
|
|
176
|
-
requires: ["computeStyles"],
|
|
177
|
-
fn: ({ state }) => {
|
|
178
|
-
const popperStyles = state.styles["popper"];
|
|
179
|
-
if (popperStyles) popperStyles.width = `${state.rects.reference.width}px`;
|
|
180
|
-
},
|
|
181
|
-
effect: ({ state }) => {
|
|
182
|
-
const { popper, reference } = state.elements;
|
|
183
|
-
if (reference instanceof HTMLElement) popper.style.width = `${reference.offsetWidth}px`;
|
|
184
|
-
}
|
|
185
|
-
}), []);
|
|
186
|
-
const popperModifiers = useMemo(() => boundaryEl ? [
|
|
187
|
-
sameWidthModifier,
|
|
188
|
-
{
|
|
189
|
-
name: "flip",
|
|
190
|
-
options: { boundary: boundaryEl }
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
name: "preventOverflow",
|
|
194
|
-
options: { boundary: boundaryEl }
|
|
195
|
-
}
|
|
196
|
-
] : [sameWidthModifier], [boundaryEl, sameWidthModifier]);
|
|
197
|
-
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
|
198
|
-
strategy: "fixed",
|
|
199
|
-
modifiers: popperModifiers
|
|
200
|
-
});
|
|
201
|
-
const debounceRef = useRef(null);
|
|
202
|
-
const typedRef = useRef("");
|
|
203
|
-
const buttonRef = useRef(null);
|
|
204
|
-
const [expandedCategories, setExpandedCategories] = useState(/* @__PURE__ */ new Set());
|
|
205
|
-
const selectedCategory = useMemo(() => options.find((o) => isCategory(o) && o.options.some((opt) => checkEquals(value.value, opt.value)))?.category, [options, value]);
|
|
206
|
-
const lastAutoExpandedValue = useRef(void 0);
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
if (!selectedCategory || checkEquals(lastAutoExpandedValue.current, value.value)) return;
|
|
209
|
-
lastAutoExpandedValue.current = value.value;
|
|
210
|
-
setExpandedCategories((prev) => prev.size === 1 && prev.has(selectedCategory) ? prev : /* @__PURE__ */ new Set([selectedCategory]));
|
|
211
|
-
}, [selectedCategory, value]);
|
|
212
|
-
const toggleCategory = (category) => setExpandedCategories((prev) => toggleSetMember(prev, category));
|
|
213
|
-
const flushCustomValue = useCallback((val) => {
|
|
214
|
-
onChange({
|
|
215
|
-
label: val,
|
|
216
|
-
value: val
|
|
217
|
-
});
|
|
218
|
-
}, [onChange]);
|
|
219
|
-
const onQueryChange = (val) => {
|
|
220
|
-
setQuery(val);
|
|
221
|
-
if (allowCustomValue) {
|
|
222
|
-
typedRef.current = val;
|
|
223
|
-
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
224
|
-
debounceRef.current = setTimeout(() => {
|
|
225
|
-
flushCustomValue(val);
|
|
226
|
-
debounceRef.current = null;
|
|
227
|
-
}, DEBOUNCE_MS);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
const onInputBlur = () => {
|
|
231
|
-
if (allowCustomValue && debounceRef.current) {
|
|
232
|
-
clearTimeout(debounceRef.current);
|
|
233
|
-
debounceRef.current = null;
|
|
234
|
-
flushCustomValue(typedRef.current);
|
|
235
|
-
}
|
|
236
|
-
setQuery("");
|
|
237
|
-
};
|
|
238
|
-
const onComboboxChange = (val) => {
|
|
239
|
-
if (debounceRef.current) {
|
|
240
|
-
clearTimeout(debounceRef.current);
|
|
241
|
-
debounceRef.current = null;
|
|
242
|
-
}
|
|
243
|
-
onChange(val);
|
|
244
|
-
};
|
|
245
|
-
const flattenedOptions = useMemo(() => flattenDisplayOptions({
|
|
246
|
-
options,
|
|
247
|
-
query,
|
|
248
|
-
expandedCategories,
|
|
249
|
-
collapsedLabel,
|
|
250
|
-
selectedValue: value?.value,
|
|
251
|
-
allowCustomValue,
|
|
252
|
-
customValueLabel
|
|
253
|
-
}), [
|
|
254
|
-
options,
|
|
255
|
-
query,
|
|
256
|
-
expandedCategories,
|
|
257
|
-
collapsedLabel,
|
|
258
|
-
value,
|
|
259
|
-
allowCustomValue,
|
|
260
|
-
customValueLabel
|
|
261
|
-
]);
|
|
262
|
-
const comboOptions = /* @__PURE__ */ jsx(ComboboxOptions, {
|
|
263
|
-
modal: false,
|
|
264
|
-
ref: setPopperElement,
|
|
265
|
-
style: styles["popper"],
|
|
266
|
-
className: cx("bg-(--theme-input-bg) border-(--theme-border) text-(--theme-app) max-h-60! empty:invisible border overflow-auto rounded-md shadow-lg focus:outline-hidden z-9999 data-[popper-reference-hidden=true]:invisible data-[popper-reference-hidden=true]:pointer-events-none", compact ? "text-xs" : "sm:text-sm"),
|
|
267
|
-
...attributes["popper"],
|
|
268
|
-
children: ({ option }) => {
|
|
269
|
-
const optionLabel = typeof option === "string" ? option : option.label;
|
|
270
|
-
const optionDescription = typeof option !== "string" ? option.description : void 0;
|
|
271
|
-
const isCategoryRow = typeof option !== "string" && Boolean(option.category);
|
|
272
|
-
const toggleTarget = typeof option !== "string" ? option.toggle : void 0;
|
|
273
|
-
const isPinned = typeof option !== "string" && Boolean(option.pinned);
|
|
274
|
-
if (toggleTarget !== void 0) return /* @__PURE__ */ jsx(ToggleOption, {
|
|
275
|
-
option,
|
|
276
|
-
category: toggleTarget,
|
|
277
|
-
expanded: expandedCategories.has(toggleTarget),
|
|
278
|
-
onToggle: toggleCategory
|
|
279
|
-
});
|
|
280
|
-
return /* @__PURE__ */ jsx(ComboboxOption, {
|
|
281
|
-
"data-testid": "combobox-option",
|
|
282
|
-
value: option,
|
|
283
|
-
className: cx("w-full group relative flex", optionDescription ? "min-h-10 py-2" : compact ? "h-8" : "h-10", isCategoryRow ? "text-[14px] font-bold pl-1 items-center" : "data-disabled:text-(--theme-muted-text-color) data-disabled:bg-(--theme-muted-panel-bg) data-disabled:cursor-not-allowed cursor-pointer items-center pr-9 pl-3 leading-5 data-focus:bg-(--theme-muted-panel-bg) data-focus:text-(--theme-app) data-focus:outline-hidden", "data-selected:border-l-2 data-selected:border-(--theme-link) data-selected:bg-(--theme-muted-panel-bg) data-selected:text-(--theme-app)", isPinned && "border-t border-(--theme-border) font-medium"),
|
|
284
|
-
children: /* @__PURE__ */ jsx(OptionContent, {
|
|
285
|
-
label: optionLabel,
|
|
286
|
-
description: optionDescription,
|
|
287
|
-
icon: typeof option !== "string" && option.icon
|
|
288
|
-
})
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
return /* @__PURE__ */ jsx("div", {
|
|
293
|
-
className: cx("relative rounded-md flex items-center", wrapperClassName),
|
|
294
|
-
children: /* @__PURE__ */ jsx(Combobox, {
|
|
295
|
-
"data-testid": "combobox",
|
|
296
|
-
className: cx("relative w-full", className),
|
|
297
|
-
as: "div",
|
|
298
|
-
by: checkEquals,
|
|
299
|
-
value,
|
|
300
|
-
onChange: onComboboxChange,
|
|
301
|
-
onClose: () => {
|
|
302
|
-
setQuery("");
|
|
303
|
-
setExpandedCategories(new Set(selectedCategory ? [selectedCategory] : []));
|
|
304
|
-
},
|
|
305
|
-
immediate: true,
|
|
306
|
-
virtual: {
|
|
307
|
-
options: flattenedOptions,
|
|
308
|
-
disabled: (option) => Boolean(option.disabled)
|
|
309
|
-
},
|
|
310
|
-
disabled,
|
|
311
|
-
children: ({ activeOption, open }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
312
|
-
onActiveChange && /* @__PURE__ */ jsx(ActiveWatcher, {
|
|
313
|
-
active: activeOption,
|
|
314
|
-
onChange: onActiveChange
|
|
315
|
-
}),
|
|
316
|
-
selectedIcon && /* @__PURE__ */ jsx("span", {
|
|
317
|
-
ref: selectedIconRef,
|
|
318
|
-
className: "pointer-events-none absolute inset-y-0 left-3 z-10 flex items-center",
|
|
319
|
-
children: selectedIcon
|
|
320
|
-
}, value.label),
|
|
321
|
-
/* @__PURE__ */ jsx(ComboboxInput, {
|
|
322
|
-
id,
|
|
323
|
-
"aria-label": ariaLabel || void 0,
|
|
324
|
-
"aria-describedby": describedBy,
|
|
325
|
-
"aria-required": required || void 0,
|
|
326
|
-
placeholder: loading ? "Loading..." : placeholder,
|
|
327
|
-
onBlur: onInputBlur,
|
|
328
|
-
ref: setReferenceElement,
|
|
329
|
-
onClick: () => {
|
|
330
|
-
if (!open) buttonRef.current?.click();
|
|
331
|
-
},
|
|
332
|
-
style: selectedIcon && selectedIconWidth > 0 ? { paddingLeft: selectedIconWidth + 18 } : void 0,
|
|
333
|
-
className: cx("placeholder:text-xs bg-(--theme-input-bg) border-(--theme-border) text-(--theme-app) focus:border-(--theme-element) focus:outline-none focus:ring-1 focus:ring-(--theme-element) w-full h-full text-ellipsis pr-8", "disabled:bg-(--theme-input-disabled-bg) disabled:text-(--theme-input-disabled-text) disabled:cursor-not-allowed", textBoxClassName),
|
|
334
|
-
autoComplete: "off",
|
|
335
|
-
onChange: (event) => onQueryChange(event.target.value),
|
|
336
|
-
displayValue: (opt) => {
|
|
337
|
-
return opt?.label?.replaceAll("\"", "") || query || "";
|
|
338
|
-
},
|
|
339
|
-
disabled
|
|
340
|
-
}),
|
|
341
|
-
/* @__PURE__ */ jsx(ComboboxButton, {
|
|
342
|
-
ref: buttonRef,
|
|
343
|
-
"aria-label": t.showOptions,
|
|
344
|
-
className: cx("absolute inset-y-0 right-0 flex items-center pr-3 disabled:cursor-not-allowed", !showCaret && "hidden"),
|
|
345
|
-
"data-testid": "combobox-button",
|
|
346
|
-
disabled,
|
|
347
|
-
children: /* @__PURE__ */ jsx(DropdownCaret, {})
|
|
348
|
-
}),
|
|
349
|
-
typeof document !== "undefined" && createPortal(comboOptions, portalEl ?? document.querySelector(".ds-root") ?? document.body)
|
|
350
|
-
] })
|
|
351
|
-
})
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
//#endregion
|
|
355
|
-
export { Dropdown as default };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
interface ICustomListboxProps<T> {
|
|
2
|
-
/** Only used visually to inform what you're selecting */
|
|
3
|
-
type: string;
|
|
4
|
-
options: {
|
|
5
|
-
label: string;
|
|
6
|
-
secondaryLabel?: string;
|
|
7
|
-
icon?: React.ReactNode;
|
|
8
|
-
value: T;
|
|
9
|
-
selected: boolean;
|
|
10
|
-
}[];
|
|
11
|
-
closeOnSelect?: boolean;
|
|
12
|
-
allowSearch?: boolean;
|
|
13
|
-
handleOptionSelected: (value: T) => void;
|
|
14
|
-
className?: string;
|
|
15
|
-
invalid?: boolean;
|
|
16
|
-
required?: boolean;
|
|
17
|
-
id?: string | undefined;
|
|
18
|
-
'aria-describedby'?: string | undefined;
|
|
19
|
-
}
|
|
20
|
-
export default function CustomListbox<T>({ options, handleOptionSelected, type, allowSearch, closeOnSelect, className, invalid, required, id, 'aria-describedby': describedBy, }: ICustomListboxProps<T>): import("react").JSX.Element;
|
|
21
|
-
export {};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { useStrings } from "./Provider.js";
|
|
2
|
-
import { FaAngleDown } from "../icons/fa/FaAngleDown.js";
|
|
3
|
-
import { keyedByContent } from "./keys.js";
|
|
4
|
-
import { focusOnMount } from "./focus.js";
|
|
5
|
-
import { Listbox, ListboxButton, ListboxOption, ListboxOptions, Transition } from "@headlessui/react";
|
|
6
|
-
import cx from "classnames";
|
|
7
|
-
import { useEffect, useRef, useState } from "react";
|
|
8
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
//#region src/components/Listbox.tsx
|
|
10
|
-
function CustomListbox({ options = [], handleOptionSelected, type, allowSearch = false, closeOnSelect = true, className = "", invalid = false, required = false, id, "aria-describedby": describedBy }) {
|
|
11
|
-
const { dropdown: strings } = useStrings();
|
|
12
|
-
const [filter, setFilter] = useState("");
|
|
13
|
-
const [controlledOpen, setControlledOpen] = useState(false);
|
|
14
|
-
const optionsToShow = options.filter((option) => !option.selected && option.label && option.label.toLowerCase().includes(filter.toLowerCase()));
|
|
15
|
-
const wrapperRef = useRef(null);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
function handleClickOutside(event) {
|
|
18
|
-
const wrapper = wrapperRef.current;
|
|
19
|
-
if (wrapper && event.target instanceof Node && !wrapper.contains(event.target)) {
|
|
20
|
-
setControlledOpen(false);
|
|
21
|
-
setFilter("");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
25
|
-
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
26
|
-
}, []);
|
|
27
|
-
const optionsElement = /* @__PURE__ */ jsxs(ListboxOptions, {
|
|
28
|
-
modal: false,
|
|
29
|
-
static: true,
|
|
30
|
-
className: "absolute w-full py-1 z-50 theme-input rounded-md",
|
|
31
|
-
children: [allowSearch && /* @__PURE__ */ jsx("div", {
|
|
32
|
-
className: "pl-2 pr-4 mb-1",
|
|
33
|
-
children: /* @__PURE__ */ jsx("input", {
|
|
34
|
-
autoComplete: "off",
|
|
35
|
-
type: "search",
|
|
36
|
-
ref: focusOnMount,
|
|
37
|
-
onChange: (e) => setFilter(e.target.value),
|
|
38
|
-
value: filter,
|
|
39
|
-
className: "w-full p-1 theme-input",
|
|
40
|
-
onKeyDown: (e) => {
|
|
41
|
-
if (![
|
|
42
|
-
"ArrowUp",
|
|
43
|
-
"ArrowDown",
|
|
44
|
-
"Enter",
|
|
45
|
-
"Home",
|
|
46
|
-
"End",
|
|
47
|
-
"Escape"
|
|
48
|
-
].includes(e.key)) e.stopPropagation();
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
52
|
-
className: "overflow-auto max-h-60 theme-panel",
|
|
53
|
-
children: optionsToShow.length > 0 ? keyedByContent(optionsToShow, (o) => String(o.value)).map(({ key, item: option }) => /* @__PURE__ */ jsx(ListboxOption, {
|
|
54
|
-
className: "relative hover:theme-hover select-none pl-2 pr-4",
|
|
55
|
-
value: option.value,
|
|
56
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
57
|
-
className: "w-full flex flex-row",
|
|
58
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
59
|
-
className: "w-3/4 py-2 flex items-center",
|
|
60
|
-
children: [
|
|
61
|
-
/* @__PURE__ */ jsx("div", {
|
|
62
|
-
className: "w-4 h-6 btn btn-info text-xl line-height-0 mr-2",
|
|
63
|
-
children: "+"
|
|
64
|
-
}),
|
|
65
|
-
option.icon && /* @__PURE__ */ jsx("span", {
|
|
66
|
-
className: "mr-2 flex items-center",
|
|
67
|
-
children: option.icon
|
|
68
|
-
}),
|
|
69
|
-
/* @__PURE__ */ jsx("span", {
|
|
70
|
-
className: "mr-2",
|
|
71
|
-
children: option.label
|
|
72
|
-
}),
|
|
73
|
-
/* @__PURE__ */ jsx("span", {
|
|
74
|
-
className: "italic",
|
|
75
|
-
children: option.secondaryLabel
|
|
76
|
-
})
|
|
77
|
-
]
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
}, key)) : /* @__PURE__ */ jsx("div", {
|
|
81
|
-
className: "w-full flex flex-row",
|
|
82
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
83
|
-
className: "w-3/4 py-2 pl-2 capitalize flex items-center",
|
|
84
|
-
children: filter === "" ? `All ${type} Added` : `No ${type} Found`
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
})]
|
|
88
|
-
});
|
|
89
|
-
return /* @__PURE__ */ jsxs(Listbox, {
|
|
90
|
-
as: "div",
|
|
91
|
-
className: cx("relative mt-1 theme-input border theme-border rounded-md", className),
|
|
92
|
-
ref: wrapperRef,
|
|
93
|
-
onChange: handleOptionSelected,
|
|
94
|
-
children: [/* @__PURE__ */ jsxs(ListboxButton, {
|
|
95
|
-
id,
|
|
96
|
-
"aria-describedby": describedBy,
|
|
97
|
-
"aria-required": required || void 0,
|
|
98
|
-
onClick: () => setControlledOpen((prev) => !prev),
|
|
99
|
-
className: cx("relative w-full py-2 pl-3 text-left", invalid && "border-red-600 focus:border-red-600 focus:ring-red-500"),
|
|
100
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
101
|
-
className: "block truncate",
|
|
102
|
-
children: strings.select(type)
|
|
103
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
104
|
-
className: "pointer-events-none absolute inset-y-0 right-0 flex items-center justify-items-center",
|
|
105
|
-
children: /* @__PURE__ */ jsx(FaAngleDown, {
|
|
106
|
-
className: "h-5 w-8",
|
|
107
|
-
"aria-hidden": "true"
|
|
108
|
-
})
|
|
109
|
-
})]
|
|
110
|
-
}), closeOnSelect ? /* @__PURE__ */ jsx(Transition, {
|
|
111
|
-
leave: "transition ease-in duration-100",
|
|
112
|
-
leaveFrom: "opacity-100",
|
|
113
|
-
leaveTo: "opacity-0",
|
|
114
|
-
children: optionsElement
|
|
115
|
-
}) : controlledOpen && optionsElement]
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
//#endregion
|
|
119
|
-
export { CustomListbox as default };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type ICategory, type IOptions } from './dropdownUtils.js';
|
|
2
|
-
type MultiSelectDropdownProps<T = string> = {
|
|
3
|
-
options: (ICategory<T> | IOptions<T> | string)[];
|
|
4
|
-
value: T[];
|
|
5
|
-
onChange: (next: T[]) => void;
|
|
6
|
-
id?: string | undefined;
|
|
7
|
-
'aria-labelledby'?: string | undefined;
|
|
8
|
-
'aria-describedby'?: string | undefined;
|
|
9
|
-
required?: boolean;
|
|
10
|
-
className?: string;
|
|
11
|
-
wrapperClassName?: string;
|
|
12
|
-
textBoxClassName?: string | undefined;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
placeholder?: string | undefined;
|
|
15
|
-
loading?: boolean;
|
|
16
|
-
searchable?: boolean;
|
|
17
|
-
maxTagCount?: number;
|
|
18
|
-
/** Custom comparator for object values. Defaults to strict equality. */
|
|
19
|
-
compareBy?: ((a: T, b: T) => boolean) | undefined;
|
|
20
|
-
};
|
|
21
|
-
export default function MultiSelectDropdown<T = string>({ options, value, onChange, id, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, required, className, wrapperClassName, textBoxClassName, disabled, placeholder, loading, searchable, maxTagCount, compareBy, }: MultiSelectDropdownProps<T>): import("react").JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { useStrings } from "./Provider.js";
|
|
2
|
-
import { keyedByContent } from "./keys.js";
|
|
3
|
-
import { DropdownCaret, filterOption, flattenOptions, isCategory, isOption } from "./dropdownUtils.js";
|
|
4
|
-
import { focusOnMount } from "./focus.js";
|
|
5
|
-
import { Combobox, ComboboxButton, ComboboxOption, ComboboxOptions } from "@headlessui/react";
|
|
6
|
-
import cx from "classnames";
|
|
7
|
-
import { useMemo, useState } from "react";
|
|
8
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import { usePopper } from "react-popper";
|
|
10
|
-
//#region src/components/MultiSelect.tsx
|
|
11
|
-
var strictEqual = (a, b) => a === b;
|
|
12
|
-
function MultiSelectDropdown({ options, value, onChange, id, "aria-labelledby": labelledBy, "aria-describedby": describedBy, required, className, wrapperClassName = "w-full", textBoxClassName, disabled = false, placeholder, loading = false, searchable = true, maxTagCount = 2, compareBy }) {
|
|
13
|
-
const strings = useStrings();
|
|
14
|
-
const [query, setQuery] = useState("");
|
|
15
|
-
const [referenceEl, setReferenceEl] = useState(null);
|
|
16
|
-
const [popperEl, setPopperEl] = useState(null);
|
|
17
|
-
const { styles, attributes } = usePopper(referenceEl, popperEl, {
|
|
18
|
-
placement: "bottom-start",
|
|
19
|
-
modifiers: [{
|
|
20
|
-
name: "offset",
|
|
21
|
-
options: { offset: [0, 4] }
|
|
22
|
-
}]
|
|
23
|
-
});
|
|
24
|
-
const allOptions = useMemo(() => flattenOptions(options), [options]);
|
|
25
|
-
const compare = compareBy ?? strictEqual;
|
|
26
|
-
const selectedOptions = useMemo(() => {
|
|
27
|
-
const result = [];
|
|
28
|
-
for (const val of value) {
|
|
29
|
-
const found = allOptions.find((opt) => isOption(opt) && compare(opt.value, val));
|
|
30
|
-
if (found) result.push(found);
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}, [
|
|
34
|
-
value,
|
|
35
|
-
allOptions,
|
|
36
|
-
compare
|
|
37
|
-
]);
|
|
38
|
-
const filteredOptions = useMemo(() => {
|
|
39
|
-
if (!searchable || query.trim() === "") return allOptions;
|
|
40
|
-
const result = [];
|
|
41
|
-
for (const opt of allOptions) if (isCategory(opt)) {
|
|
42
|
-
const matchedChildren = opt.options.filter((o) => filterOption(o, query));
|
|
43
|
-
if (matchedChildren.length > 0) result.push(opt, ...matchedChildren);
|
|
44
|
-
} else if (isOption(opt) && filterOption(opt, query)) result.push(opt);
|
|
45
|
-
return result;
|
|
46
|
-
}, [
|
|
47
|
-
allOptions,
|
|
48
|
-
query,
|
|
49
|
-
searchable
|
|
50
|
-
]);
|
|
51
|
-
const display = useMemo(() => {
|
|
52
|
-
const shown = selectedOptions.slice(0, maxTagCount);
|
|
53
|
-
return {
|
|
54
|
-
label: shown.map((o) => o.label).join(", "),
|
|
55
|
-
overflow: selectedOptions.length - shown.length
|
|
56
|
-
};
|
|
57
|
-
}, [selectedOptions, maxTagCount]);
|
|
58
|
-
const isDisabled = disabled || loading;
|
|
59
|
-
const isEmpty = filteredOptions.length === 0;
|
|
60
|
-
return /* @__PURE__ */ jsx(Combobox, {
|
|
61
|
-
multiple: true,
|
|
62
|
-
value: Array.isArray(value) ? value : [],
|
|
63
|
-
onChange,
|
|
64
|
-
disabled: isDisabled,
|
|
65
|
-
onClose: () => setQuery(""),
|
|
66
|
-
by: compare,
|
|
67
|
-
children: ({ open }) => /* @__PURE__ */ jsxs("div", {
|
|
68
|
-
ref: setReferenceEl,
|
|
69
|
-
className: cx("relative", wrapperClassName),
|
|
70
|
-
children: [
|
|
71
|
-
/* @__PURE__ */ jsx(ComboboxButton, {
|
|
72
|
-
as: "div",
|
|
73
|
-
id,
|
|
74
|
-
"aria-labelledby": labelledBy,
|
|
75
|
-
"aria-describedby": describedBy,
|
|
76
|
-
"aria-required": required || void 0,
|
|
77
|
-
className: cx("theme-input flex items-center cursor-pointer rounded border text-[14px] w-full px-2 pr-8 py-1 min-h-[30px] overflow-hidden", isDisabled && "opacity-50 cursor-not-allowed", textBoxClassName, className),
|
|
78
|
-
children: loading ? /* @__PURE__ */ jsx("span", {
|
|
79
|
-
className: "theme-muted-text",
|
|
80
|
-
children: strings.loading
|
|
81
|
-
}) : selectedOptions.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
82
|
-
className: "min-w-0 truncate",
|
|
83
|
-
children: display.label
|
|
84
|
-
}), display.overflow > 0 && /* @__PURE__ */ jsxs("span", {
|
|
85
|
-
className: "ml-1 shrink-0 theme-muted-text",
|
|
86
|
-
children: ["+", display.overflow]
|
|
87
|
-
})] }) : /* @__PURE__ */ jsx("span", {
|
|
88
|
-
className: "theme-muted-text truncate",
|
|
89
|
-
children: placeholder
|
|
90
|
-
})
|
|
91
|
-
}),
|
|
92
|
-
/* @__PURE__ */ jsx(DropdownCaret, {}),
|
|
93
|
-
open && /* @__PURE__ */ jsxs(ComboboxOptions, {
|
|
94
|
-
modal: false,
|
|
95
|
-
ref: setPopperEl,
|
|
96
|
-
static: true,
|
|
97
|
-
"data-testid": "msd-list",
|
|
98
|
-
style: styles["popper"],
|
|
99
|
-
...attributes["popper"],
|
|
100
|
-
className: "theme-panel z-10 max-h-60 w-full overflow-auto rounded-md shadow-lg focus:outline-none",
|
|
101
|
-
children: [searchable && /* @__PURE__ */ jsx("div", {
|
|
102
|
-
className: "sticky top-0 theme-panel p-2 border-b z-10",
|
|
103
|
-
children: /* @__PURE__ */ jsx("input", {
|
|
104
|
-
placeholder,
|
|
105
|
-
"data-1p-ignore": true,
|
|
106
|
-
autoComplete: "off",
|
|
107
|
-
type: "text",
|
|
108
|
-
className: "theme-input w-full",
|
|
109
|
-
value: query,
|
|
110
|
-
onChange: (e) => setQuery(e.target.value),
|
|
111
|
-
onKeyDown: (e) => e.stopPropagation(),
|
|
112
|
-
ref: focusOnMount
|
|
113
|
-
})
|
|
114
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
115
|
-
className: "py-1",
|
|
116
|
-
children: isEmpty ? /* @__PURE__ */ jsx("div", {
|
|
117
|
-
className: "px-4 py-2 text-sm theme-muted-text",
|
|
118
|
-
children: strings.dropdown.noOptionsFound
|
|
119
|
-
}) : keyedByContent(filteredOptions, (o) => isCategory(o) ? `category-${o.category ?? "uncat"}` : `option-${String(o.value)}`).map(({ key, item: opt }) => {
|
|
120
|
-
if (isCategory(opt)) return /* @__PURE__ */ jsx("li", {
|
|
121
|
-
role: "presentation",
|
|
122
|
-
className: "px-4 py-2 text-sm font-bold theme-muted-text",
|
|
123
|
-
children: opt.category
|
|
124
|
-
}, key);
|
|
125
|
-
const option = opt;
|
|
126
|
-
return /* @__PURE__ */ jsx(ComboboxOption, {
|
|
127
|
-
value: option.value,
|
|
128
|
-
disabled: option.disabled ?? false,
|
|
129
|
-
"data-testid": `msd-option-${String(option.value)}`,
|
|
130
|
-
className: ({ focus }) => cx("relative cursor-pointer select-none py-2 pl-10 pr-4 text-sm", focus && "theme-hover", option.disabled && "cursor-not-allowed opacity-50"),
|
|
131
|
-
children: ({ selected }) => /* @__PURE__ */ jsxs("div", {
|
|
132
|
-
className: "flex items-center",
|
|
133
|
-
children: [
|
|
134
|
-
/* @__PURE__ */ jsx("span", {
|
|
135
|
-
className: "absolute inset-y-0 left-0 flex items-center pl-3",
|
|
136
|
-
children: /* @__PURE__ */ jsx("input", {
|
|
137
|
-
autoComplete: "off",
|
|
138
|
-
type: "checkbox",
|
|
139
|
-
checked: selected,
|
|
140
|
-
readOnly: true,
|
|
141
|
-
tabIndex: -1,
|
|
142
|
-
className: "h-4 w-4 cursor-pointer",
|
|
143
|
-
"aria-hidden": "true"
|
|
144
|
-
})
|
|
145
|
-
}),
|
|
146
|
-
option.icon && /* @__PURE__ */ jsx("span", {
|
|
147
|
-
className: "mr-2 flex items-center",
|
|
148
|
-
children: option.icon
|
|
149
|
-
}),
|
|
150
|
-
/* @__PURE__ */ jsx("div", {
|
|
151
|
-
className: "flex flex-col",
|
|
152
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
153
|
-
className: "block truncate",
|
|
154
|
-
children: option.label
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
]
|
|
158
|
-
})
|
|
159
|
-
}, key);
|
|
160
|
-
})
|
|
161
|
-
})]
|
|
162
|
-
})
|
|
163
|
-
]
|
|
164
|
-
})
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
//#endregion
|
|
168
|
-
export { MultiSelectDropdown as default };
|