@ultraviolet/ui 3.0.0-beta.17 → 3.0.0-beta.19

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.
Files changed (149) hide show
  1. package/README.md +23 -11
  2. package/dist/components/ActionBar/styles.css.cjs +0 -1
  3. package/dist/components/ActionBar/styles.css.js +0 -1
  4. package/dist/components/Alert/styles.css.cjs +1 -0
  5. package/dist/components/Alert/styles.css.js +1 -0
  6. package/dist/components/Avatar/styles.css.cjs +0 -1
  7. package/dist/components/Avatar/styles.css.js +0 -1
  8. package/dist/components/Avatar/variables.css.cjs +1 -0
  9. package/dist/components/Avatar/variables.css.js +1 -0
  10. package/dist/components/Checkbox/index.cjs +1 -1
  11. package/dist/components/Checkbox/index.js +1 -1
  12. package/dist/components/Chip/index.d.ts +1 -1
  13. package/dist/components/DateInput/components/CalendarContent.cjs +2 -20
  14. package/dist/components/DateInput/components/CalendarContent.js +2 -18
  15. package/dist/components/DateInput/components/CalendarDaily.cjs +3 -43
  16. package/dist/components/DateInput/components/CalendarDaily.js +3 -41
  17. package/dist/components/DateInput/components/CalendarMonthly.cjs +2 -24
  18. package/dist/components/DateInput/components/CalendarMonthly.js +2 -22
  19. package/dist/components/DateInput/components/Popup.cjs +2 -15
  20. package/dist/components/DateInput/components/Popup.js +2 -13
  21. package/dist/components/DateInput/components/styles.css.cjs +12 -0
  22. package/dist/components/DateInput/components/styles.css.d.ts +4 -0
  23. package/dist/components/DateInput/components/styles.css.js +12 -0
  24. package/dist/components/DateInput/helpers.cjs +0 -8
  25. package/dist/components/DateInput/helpers.d.ts +0 -2
  26. package/dist/components/DateInput/helpers.js +1 -9
  27. package/dist/components/DateInput/index.cjs +10 -30
  28. package/dist/components/DateInput/index.js +11 -29
  29. package/dist/components/DateInput/styles.css.cjs +8 -0
  30. package/dist/components/DateInput/styles.css.d.ts +8 -0
  31. package/dist/components/DateInput/styles.css.js +8 -0
  32. package/dist/components/EmptyState/index.cjs +11 -74
  33. package/dist/components/EmptyState/index.d.ts +1 -6
  34. package/dist/components/EmptyState/index.js +8 -69
  35. package/dist/components/EmptyState/styles.css.cjs +10 -0
  36. package/dist/components/EmptyState/styles.css.d.ts +29 -0
  37. package/dist/components/EmptyState/styles.css.js +10 -0
  38. package/dist/components/Popup/helpers.cjs +8 -4
  39. package/dist/components/Popup/helpers.js +8 -4
  40. package/dist/components/Popup/styles.css.cjs +1 -0
  41. package/dist/components/Popup/styles.css.js +1 -0
  42. package/dist/components/Popup/variables.css.cjs +0 -1
  43. package/dist/components/Popup/variables.css.js +0 -1
  44. package/dist/components/ProgressBar/styles.css.cjs +1 -0
  45. package/dist/components/ProgressBar/styles.css.js +1 -0
  46. package/dist/components/ProgressBar/variables.css.cjs +0 -1
  47. package/dist/components/ProgressBar/variables.css.js +0 -1
  48. package/dist/components/SearchInput/KeyGroup.cjs +4 -22
  49. package/dist/components/SearchInput/KeyGroup.js +2 -18
  50. package/dist/components/SearchInput/index.cjs +2 -38
  51. package/dist/components/SearchInput/index.js +3 -37
  52. package/dist/components/SearchInput/styles.css.cjs +10 -0
  53. package/dist/components/SearchInput/styles.css.d.ts +3 -0
  54. package/dist/components/SearchInput/styles.css.js +10 -0
  55. package/dist/components/SelectInput/components/Dropdown.cjs +342 -0
  56. package/dist/components/SelectInput/{Dropdown.d.ts → components/Dropdown.d.ts} +1 -1
  57. package/dist/components/SelectInput/components/Dropdown.js +342 -0
  58. package/dist/components/SelectInput/components/DropdownOption.cjs +47 -0
  59. package/dist/components/SelectInput/{DropdownOption.d.ts → components/DropdownOption.d.ts} +1 -1
  60. package/dist/components/SelectInput/components/DropdownOption.js +47 -0
  61. package/dist/components/SelectInput/components/SearchBarDropdown.cjs +117 -0
  62. package/dist/components/SelectInput/{SearchBarDropdown.d.ts → components/SearchBarDropdown.d.ts} +1 -1
  63. package/dist/components/SelectInput/components/SearchBarDropdown.js +117 -0
  64. package/dist/components/SelectInput/components/SelectBar.cjs +237 -0
  65. package/dist/components/SelectInput/{SelectBar.d.ts → components/SelectBar.d.ts} +1 -12
  66. package/dist/components/SelectInput/components/SelectBar.js +237 -0
  67. package/dist/components/SelectInput/components/dropdown.css.cjs +34 -0
  68. package/dist/components/SelectInput/components/dropdown.css.d.ts +35 -0
  69. package/dist/components/SelectInput/components/dropdown.css.js +34 -0
  70. package/dist/components/SelectInput/components/selectBar.css.cjs +24 -0
  71. package/dist/components/SelectInput/components/selectBar.css.d.ts +108 -0
  72. package/dist/components/SelectInput/components/selectBar.css.js +24 -0
  73. package/dist/components/SelectInput/index.cjs +8 -33
  74. package/dist/components/SelectInput/index.d.ts +2 -2
  75. package/dist/components/SelectInput/index.js +8 -31
  76. package/dist/components/SelectInput/styles.css.cjs +7 -0
  77. package/dist/components/SelectInput/styles.css.d.ts +2 -0
  78. package/dist/components/SelectInput/styles.css.js +7 -0
  79. package/dist/components/SelectableCard/styles.css.cjs +1 -0
  80. package/dist/components/SelectableCard/styles.css.js +1 -0
  81. package/dist/components/SelectableCard/variables.css.cjs +0 -1
  82. package/dist/components/SelectableCard/variables.css.js +0 -1
  83. package/dist/components/SelectableCardOptionGroup/components/Option.cjs +7 -7
  84. package/dist/components/SelectableCardOptionGroup/components/Option.js +7 -7
  85. package/dist/components/Skeleton/index.cjs +3 -2
  86. package/dist/components/Skeleton/index.d.ts +3 -1
  87. package/dist/components/Skeleton/index.js +3 -2
  88. package/dist/components/SwitchButton/FocusOverlay.cjs +2 -18
  89. package/dist/components/SwitchButton/FocusOverlay.js +2 -16
  90. package/dist/components/SwitchButton/Option.cjs +2 -45
  91. package/dist/components/SwitchButton/Option.js +2 -43
  92. package/dist/components/SwitchButton/index.cjs +2 -27
  93. package/dist/components/SwitchButton/index.js +2 -25
  94. package/dist/components/SwitchButton/styles.css.cjs +9 -0
  95. package/dist/components/SwitchButton/styles.css.d.ts +7 -0
  96. package/dist/components/SwitchButton/styles.css.js +9 -0
  97. package/dist/components/Tag/index.cjs +2 -1
  98. package/dist/components/Tag/index.d.ts +3 -2
  99. package/dist/components/Tag/index.js +2 -1
  100. package/dist/components/TagInput/index.cjs +11 -88
  101. package/dist/components/TagInput/index.d.ts +1 -5
  102. package/dist/components/TagInput/index.js +11 -86
  103. package/dist/components/TagInput/styles.css.cjs +12 -0
  104. package/dist/components/TagInput/styles.css.d.ts +21 -0
  105. package/dist/components/TagInput/styles.css.js +12 -0
  106. package/dist/components/TagList/constant.cjs +5 -0
  107. package/dist/components/TagList/constant.d.ts +1 -0
  108. package/dist/components/TagList/constant.js +5 -0
  109. package/dist/components/TagList/index.cjs +21 -66
  110. package/dist/components/TagList/index.js +19 -62
  111. package/dist/components/TagList/styles.css.cjs +14 -0
  112. package/dist/components/TagList/styles.css.d.ts +11 -0
  113. package/dist/components/TagList/styles.css.js +14 -0
  114. package/dist/components/TextInput/constants.d.ts +5 -0
  115. package/dist/components/TextInput/index.cjs +8 -113
  116. package/dist/components/TextInput/index.d.ts +2 -88
  117. package/dist/components/TextInput/index.js +8 -111
  118. package/dist/components/TextInput/styles.css.cjs +17 -0
  119. package/dist/components/TextInput/styles.css.d.ts +8 -0
  120. package/dist/components/TextInput/styles.css.js +17 -0
  121. package/dist/components/TimeInput/constants.cjs +0 -6
  122. package/dist/components/TimeInput/constants.js +0 -6
  123. package/dist/components/TimeInput/index.cjs +16 -96
  124. package/dist/components/TimeInput/index.d.ts +0 -7
  125. package/dist/components/TimeInput/index.js +13 -91
  126. package/dist/components/TimeInput/styles.css.cjs +10 -0
  127. package/dist/components/TimeInput/styles.css.d.ts +82 -0
  128. package/dist/components/TimeInput/styles.css.js +10 -0
  129. package/dist/components/Toggle/index.cjs +10 -108
  130. package/dist/components/Toggle/index.d.ts +0 -18
  131. package/dist/components/Toggle/index.js +13 -109
  132. package/dist/components/Toggle/styles.css.cjs +10 -0
  133. package/dist/components/Toggle/styles.css.d.ts +108 -0
  134. package/dist/components/Toggle/styles.css.js +10 -0
  135. package/dist/components/UnitInput/index.cjs +28 -122
  136. package/dist/components/UnitInput/index.js +24 -116
  137. package/dist/components/UnitInput/styles.css.cjs +17 -0
  138. package/dist/components/UnitInput/styles.css.d.ts +7 -0
  139. package/dist/components/UnitInput/styles.css.js +17 -0
  140. package/dist/ui.css +1 -1
  141. package/package.json +2 -2
  142. package/dist/components/SelectInput/Dropdown.cjs +0 -488
  143. package/dist/components/SelectInput/Dropdown.js +0 -486
  144. package/dist/components/SelectInput/DropdownOption.cjs +0 -91
  145. package/dist/components/SelectInput/DropdownOption.js +0 -89
  146. package/dist/components/SelectInput/SearchBarDropdown.cjs +0 -133
  147. package/dist/components/SelectInput/SearchBarDropdown.js +0 -131
  148. package/dist/components/SelectInput/SelectBar.cjs +0 -366
  149. package/dist/components/SelectInput/SelectBar.js +0 -364
@@ -0,0 +1,117 @@
1
+ "use client";
2
+ import { jsx } from "@emotion/react/jsx-runtime";
3
+ import { SearchIcon } from "@ultraviolet/icons";
4
+ import { useRef, useEffect } from "react";
5
+ import { isFuzzyMatch, normalizeString } from "../../../utils/searchAlgorithm.js";
6
+ import { TextInput } from "../../TextInput/index.js";
7
+ import { useSelectInput } from "../SelectInputProvider.js";
8
+ import { searchBar } from "./dropdown.css.js";
9
+ const getReferenceText = (option) => {
10
+ if (option.searchText) {
11
+ return normalizeString(option.searchText);
12
+ }
13
+ if (typeof option.label === "string") {
14
+ return normalizeString(option.label);
15
+ }
16
+ return "";
17
+ };
18
+ const searchRegex = (data, query) => data.filter((option) => {
19
+ const referenceText = getReferenceText(option);
20
+ const regex = new RegExp(query, "i");
21
+ return (query.length > 2 ? isFuzzyMatch(query, referenceText) : referenceText.match(regex)) || typeof option.description === "string" && option.description.match(regex) || option.value.match(regex);
22
+ });
23
+ const findClosestOption = (options, searchInput) => {
24
+ if (searchInput) {
25
+ if (!Array.isArray(options)) {
26
+ const possibleOptions = {
27
+ ...options
28
+ };
29
+ Object.keys(possibleOptions).map((group) => {
30
+ possibleOptions[group] = possibleOptions[group].filter((option) => !option.disabled);
31
+ return null;
32
+ });
33
+ if (Object.keys(possibleOptions).some((group) => possibleOptions[group].length > 0)) {
34
+ const firstFit = Object.keys(possibleOptions).map((group) => possibleOptions[group][0]).find((value) => !!value);
35
+ return firstFit;
36
+ }
37
+ } else {
38
+ const possibleOption = [...options].find((option) => !option.disabled);
39
+ if (possibleOption) {
40
+ return possibleOption;
41
+ }
42
+ }
43
+ }
44
+ return null;
45
+ };
46
+ const escapeRegExp = (string) => string.replace(/[.*+?^{}()|[\]\\]/g, String.raw`\$&`);
47
+ const SearchBarDropdown = ({
48
+ placeholder,
49
+ displayedOptions,
50
+ setSearchBarActive
51
+ }) => {
52
+ const searchInputRef = useRef(null);
53
+ const {
54
+ onChange,
55
+ onSearch,
56
+ setSearchInput,
57
+ searchInput,
58
+ options,
59
+ multiselect,
60
+ setSelectedData,
61
+ selectedData
62
+ } = useSelectInput();
63
+ const handleChange = (search) => {
64
+ if (search.length > 0) {
65
+ if (!Array.isArray(options)) {
66
+ const filteredOptions = {
67
+ ...options
68
+ };
69
+ Object.keys(filteredOptions).map((group) => {
70
+ filteredOptions[group] = searchRegex(filteredOptions[group], escapeRegExp(search.toString()));
71
+ return null;
72
+ });
73
+ onSearch(filteredOptions);
74
+ } else {
75
+ const filteredOptions = searchRegex([...options], escapeRegExp(search.toString()));
76
+ onSearch(filteredOptions);
77
+ }
78
+ } else {
79
+ onSearch(options);
80
+ }
81
+ setSearchInput(search);
82
+ };
83
+ const handleKeyDown = (key, search) => {
84
+ if (key === "Enter") {
85
+ const closestOption = findClosestOption(displayedOptions, search);
86
+ if (closestOption) {
87
+ if (multiselect) {
88
+ setSelectedData({
89
+ clickedOption: closestOption,
90
+ group: !Array.isArray(options) ? Object.keys(options).find((group) => options[group].includes(closestOption)) : void 0,
91
+ type: "selectOption"
92
+ });
93
+ onChange?.(selectedData.selectedValues.includes(closestOption.value) ? selectedData.selectedValues : [...selectedData.selectedValues, closestOption.value]);
94
+ } else {
95
+ setSelectedData({
96
+ clickedOption: closestOption,
97
+ type: "selectOption"
98
+ });
99
+ onChange?.(selectedData.selectedValues[0] ?? "");
100
+ }
101
+ }
102
+ } else if (key === "Tab") {
103
+ searchInputRef.current?.blur();
104
+ }
105
+ };
106
+ useEffect(() => {
107
+ setTimeout(() => {
108
+ searchInputRef.current?.focus();
109
+ }, 50);
110
+ }, []);
111
+ return /* @__PURE__ */ jsx(TextInput, { "aria-label": "search-bar", className: searchBar, "data-testid": "search-bar", onBlur: () => setSearchBarActive(false), onChange: (event) => handleChange(event.target.value), onFocus: () => setSearchBarActive(true), onKeyDown: (event) => handleKeyDown(event.key, searchInput), placeholder, prefix: /* @__PURE__ */ jsx(SearchIcon, { sentiment: "neutral", size: "small" }), ref: searchInputRef, size: "medium", value: searchInput });
112
+ };
113
+ export {
114
+ SearchBarDropdown,
115
+ getReferenceText,
116
+ searchRegex
117
+ };
@@ -0,0 +1,237 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const jsxRuntime = require("@emotion/react/jsx-runtime");
5
+ const Icon = require("@ultraviolet/icons");
6
+ const dynamic = require("@vanilla-extract/dynamic");
7
+ const react = require("react");
8
+ const index$3 = require("../../Button/index.cjs");
9
+ const index$2 = require("../../Stack/index.cjs");
10
+ const index$4 = require("../../Tag/index.cjs");
11
+ const index$1 = require("../../Text/index.cjs");
12
+ const index = require("../../Tooltip/index.cjs");
13
+ const findOptionInOptions = require("../findOptionInOptions.cjs");
14
+ const SelectInputProvider = require("../SelectInputProvider.cjs");
15
+ const selectBar_css = require("./selectBar.css.cjs");
16
+ const SIZES_TAG = {
17
+ gap: 8,
18
+ paddings: 16
19
+ };
20
+ const DisplayValues = ({
21
+ refTag,
22
+ nonOverflowedValues,
23
+ potentiallyNonOverflowedValues,
24
+ disabled,
25
+ readOnly,
26
+ overflowed,
27
+ overflowAmount,
28
+ size,
29
+ measureRef,
30
+ lastElementMaxWidth,
31
+ overflow,
32
+ refPlusTag,
33
+ displayShadowCopy
34
+ }) => {
35
+ const {
36
+ multiselect,
37
+ selectedData,
38
+ setSelectedData,
39
+ options,
40
+ onChange
41
+ } = SelectInputProvider.useSelectInput();
42
+ return multiselect ? /* @__PURE__ */ jsxRuntime.jsxs(index$2.Stack, { alignItems: "center", className: selectBar_css.multiselectStack, direction: "row", gap: "1", ref: refTag, wrap: "nowrap", children: [
43
+ displayShadowCopy ? /* @__PURE__ */ jsxRuntime.jsx("div", { ref: measureRef, style: {
44
+ position: "absolute"
45
+ }, children: potentiallyNonOverflowedValues.map((option) => /* @__PURE__ */ jsxRuntime.jsx(index$4.Tag, { className: `${option.value} ${selectBar_css.selectBarTags.hidden}`, onClose: () => {
46
+ }, children: option?.label }, option.value)) }) : null,
47
+ nonOverflowedValues.map((option, index2) => /* @__PURE__ */ jsxRuntime.jsx(index$4.Tag, { className: selectBar_css.selectBarTags.visible, "data-testid": "selected-options-tags", disabled, onClose: !readOnly ? (event) => {
48
+ event.stopPropagation();
49
+ setSelectedData({
50
+ clickedOption: option,
51
+ type: "selectOption"
52
+ });
53
+ const newSelectedValues = selectedData.selectedValues?.filter((val) => val !== option.value);
54
+ onChange?.(newSelectedValues);
55
+ } : void 0, sentiment: "neutral", style: index2 === nonOverflowedValues.length - 1 && overflow ? dynamic.assignInlineVars({
56
+ [selectBar_css.minWidthTag]: "auto",
57
+ [selectBar_css.maxWidthTag]: `${lastElementMaxWidth}px`
58
+ }) : void 0, children: option?.label }, option?.value)),
59
+ overflowed ? /* @__PURE__ */ jsxRuntime.jsx(index$2.Stack, { justifyContent: "center", ref: refPlusTag, children: /* @__PURE__ */ jsxRuntime.jsxs(index$4.Tag, { "aria-label": "Plus tag", className: selectBar_css.plusTag, "data-testid": "plus-tag", disabled, sentiment: "neutral", children: [
60
+ /* @__PURE__ */ jsxRuntime.jsx(Icon.PlusIcon, { size: "xsmall" }),
61
+ overflowAmount
62
+ ] }, "+") }) : null
63
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(index$1.Text, { as: "span", className: selectBar_css.selectedValues, disabled, prominence: "default", sentiment: "neutral", variant: size === "large" ? "body" : "bodySmall", children: selectedData.selectedValues[0] ? findOptionInOptions.findOptionInOptions(options, selectedData.selectedValues[0])?.label : null });
64
+ };
65
+ const SelectBar = ({
66
+ size,
67
+ clearable,
68
+ disabled,
69
+ readOnly,
70
+ placeholder,
71
+ success,
72
+ error,
73
+ autoFocus,
74
+ tooltip,
75
+ innerRef,
76
+ id,
77
+ "data-testid": dataTestId,
78
+ label,
79
+ dropdownId
80
+ }) => {
81
+ const {
82
+ isDropdownVisible,
83
+ onChange,
84
+ setIsDropdownVisible,
85
+ options,
86
+ selectedData,
87
+ setSelectedData,
88
+ multiselect
89
+ } = SelectInputProvider.useSelectInput();
90
+ const openable = !(readOnly || disabled);
91
+ const [displayShadowCopy, setDisplayShadowCopy] = react.useState(false);
92
+ const refTag = react.useRef(null);
93
+ const measureRef = react.useRef(null);
94
+ const arrowRef = react.useRef(null);
95
+ const refPlusTag = react.useRef(null);
96
+ const [overflowAmount, setOverflowAmount] = react.useState(0);
97
+ const [overflow, setOverflow] = react.useState(false);
98
+ const [lastElementMaxWidth, setLastElementMaxWidth] = react.useState(0);
99
+ const [nonOverflowedValues, setNonOverFlowedValues] = react.useState(() => {
100
+ if (selectedData.selectedValues[0]) {
101
+ const firstSelectOption = findOptionInOptions.findOptionInOptions(options, selectedData.selectedValues[0]);
102
+ return firstSelectOption ? [firstSelectOption] : [];
103
+ }
104
+ return [];
105
+ });
106
+ const potentiallyNonOverflowedValues = react.useMemo(() => selectedData.selectedValues.map((selectedValue) => findOptionInOptions.findOptionInOptions(options, selectedValue)).filter((option) => !!option), [options, selectedData.selectedValues]);
107
+ const state = react.useMemo(() => {
108
+ if (error) {
109
+ return "danger";
110
+ }
111
+ if (success) {
112
+ return "success";
113
+ }
114
+ return "neutral";
115
+ }, [error, success]);
116
+ react.useEffect(() => {
117
+ setDisplayShadowCopy(true);
118
+ }, [selectedData.selectedValues.length]);
119
+ const getWidth = react.useCallback(() => {
120
+ if (refTag.current) {
121
+ return refTag.current.offsetWidth;
122
+ }
123
+ return innerRef.current?.offsetWidth ?? 0 - (arrowRef.current?.offsetWidth ?? 0) - SIZES_TAG.paddings;
124
+ }, [innerRef.current?.offsetWidth]);
125
+ react.useLayoutEffect(() => {
126
+ if (selectedData.selectedValues.length === 0) {
127
+ setOverflowAmount(0);
128
+ setNonOverFlowedValues([]);
129
+ }
130
+ if (measureRef.current && selectedData.selectedValues.length > 0) {
131
+ const toMeasureElements = measureRef.current.children;
132
+ const toMeasureElementsArray = [...toMeasureElements];
133
+ const innerWidth = getWidth();
134
+ const {
135
+ measuredVisibleTags,
136
+ measuredHiddenTags,
137
+ accumulatedWidth,
138
+ lastVisibleElementWidth,
139
+ lastVisibleLabel
140
+ } = toMeasureElementsArray.reduce((accumulator, currentValue, index2) => {
141
+ const elementWidth = currentValue.offsetWidth;
142
+ const newAccumulatedWidth = accumulator.accumulatedWidth + elementWidth + SIZES_TAG.gap;
143
+ const canBeVisible = newAccumulatedWidth <= innerWidth;
144
+ return {
145
+ accumulatedWidth: !canBeVisible ? accumulator.accumulatedWidth : newAccumulatedWidth,
146
+ lastVisibleElementWidth: canBeVisible ? elementWidth : accumulator.lastVisibleElementWidth,
147
+ lastVisibleLabel: canBeVisible ? potentiallyNonOverflowedValues[index2].label : accumulator.lastVisibleLabel,
148
+ measuredHiddenTags: accumulator.measuredHiddenTags + (!canBeVisible ? 1 : 0),
149
+ measuredVisibleTags: [...accumulator.measuredVisibleTags, canBeVisible && potentiallyNonOverflowedValues[index2]].filter(Boolean)
150
+ };
151
+ }, {
152
+ accumulatedWidth: 0,
153
+ lastVisibleElementWidth: 0,
154
+ lastVisibleLabel: "",
155
+ measuredHiddenTags: 0,
156
+ measuredVisibleTags: []
157
+ });
158
+ const additionnalElementsWidth = SIZES_TAG.paddings + (refPlusTag.current?.offsetWidth ?? 0);
159
+ const finalWidth = accumulatedWidth + (measuredHiddenTags ? additionnalElementsWidth : 0);
160
+ const overflowPx = finalWidth - innerWidth;
161
+ const hasOverflow = overflowPx > 0;
162
+ const hasHiddenTags = measuredHiddenTags > 0;
163
+ const lastVisibleElementMaxSize = lastVisibleElementWidth - overflowPx;
164
+ if (measuredHiddenTags === 1 && measuredVisibleTags.length === 0) {
165
+ setOverflowAmount(0);
166
+ setNonOverFlowedValues([potentiallyNonOverflowedValues[0]]);
167
+ const newOverflowPx = lastVisibleElementWidth + (measuredHiddenTags > 1 ? additionnalElementsWidth : 0) - innerWidth;
168
+ setLastElementMaxWidth(lastVisibleElementWidth - newOverflowPx);
169
+ setOverflow(true);
170
+ } else if (hasOverflow && hasHiddenTags && (lastVisibleElementMaxSize > 65 || measuredVisibleTags.length === 1 && lastVisibleElementMaxSize > 65) && typeof lastVisibleLabel === "string") {
171
+ setLastElementMaxWidth(lastVisibleElementMaxSize);
172
+ setOverflow(true);
173
+ setOverflowAmount(measuredHiddenTags);
174
+ setNonOverFlowedValues(measuredVisibleTags);
175
+ } else if (hasOverflow && hasHiddenTags) {
176
+ setLastElementMaxWidth(0);
177
+ setOverflow(false);
178
+ setOverflowAmount(measuredHiddenTags + 1);
179
+ setNonOverFlowedValues(measuredVisibleTags.slice(0, -1));
180
+ } else {
181
+ setOverflow(false);
182
+ setOverflowAmount(measuredHiddenTags);
183
+ setNonOverFlowedValues(measuredVisibleTags);
184
+ }
185
+ }
186
+ setDisplayShadowCopy(false);
187
+ }, [displayShadowCopy, potentiallyNonOverflowedValues, selectedData.selectedValues.length, getWidth]);
188
+ react.useEffect(() => {
189
+ setSelectedData({
190
+ type: "update"
191
+ });
192
+ }, [setSelectedData, options]);
193
+ const shouldDisplayValues = react.useMemo(() => {
194
+ if (multiselect) {
195
+ return potentiallyNonOverflowedValues.length > 0 || selectedData.selectedValues.some((selectedValue) => findOptionInOptions.findOptionInOptions(options, selectedValue) !== void 0);
196
+ }
197
+ return selectedData.selectedValues[0] !== void 0 && findOptionInOptions.findOptionInOptions(options, selectedData.selectedValues[0]) !== void 0;
198
+ }, [multiselect, options, potentiallyNonOverflowedValues.length, selectedData.selectedValues]);
199
+ return /* @__PURE__ */ jsxRuntime.jsx(index.Tooltip, { text: tooltip, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { "aria-controls": dropdownId, "aria-expanded": isDropdownVisible, "aria-label": label, autoFocus, className: selectBar_css.selectBar({
200
+ disabled,
201
+ dropdownVisible: isDropdownVisible,
202
+ readOnly,
203
+ size,
204
+ state
205
+ }), "data-disabled": disabled, "data-readonly": readOnly, "data-testid": dataTestId, id, onClick: openable ? () => setIsDropdownVisible(!isDropdownVisible) : void 0, onKeyDown: (event) => {
206
+ if (event.key === "ArrowDown") {
207
+ if (!isDropdownVisible) {
208
+ setIsDropdownVisible(true);
209
+ } else {
210
+ document.getElementById(`option-0`)?.focus();
211
+ }
212
+ }
213
+ if (event.key === " ") {
214
+ event.preventDefault();
215
+ }
216
+ return ["Enter", " "].includes(event.key) && openable ? setIsDropdownVisible(!isDropdownVisible) : null;
217
+ }, ref: innerRef, role: "combobox", tabIndex: 0, children: [
218
+ shouldDisplayValues ? /* @__PURE__ */ jsxRuntime.jsx(DisplayValues, { disabled, displayShadowCopy, lastElementMaxWidth, measureRef, nonOverflowedValues, overflow, overflowAmount, overflowed: !!overflowAmount, potentiallyNonOverflowedValues, readOnly, refPlusTag, refTag, size }) : /* @__PURE__ */ jsxRuntime.jsx(index$1.Text, { as: "span", className: selectBar_css.selectinputPlaceholder, disabled, prominence: "weak", sentiment: "neutral", variant: size === "large" ? "body" : "bodySmall", children: placeholder }),
219
+ /* @__PURE__ */ jsxRuntime.jsxs(index$2.Stack, { alignItems: "center", className: selectBar_css.selectbarState, direction: "row", gap: 1, ref: arrowRef, children: [
220
+ error ? /* @__PURE__ */ jsxRuntime.jsx(Icon.AlertCircleIcon, { sentiment: "danger" }) : null,
221
+ success && !error ? /* @__PURE__ */ jsxRuntime.jsx(Icon.CheckCircleIcon, { sentiment: "success" }) : null,
222
+ clearable && selectedData.selectedValues.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(index$3.Button, { "aria-label": "clear value", "data-testid": "clear-all", disabled: disabled || !selectedData.selectedValues[0] || readOnly, onClick: (event) => {
223
+ event.stopPropagation();
224
+ setSelectedData({
225
+ type: "clearAll"
226
+ });
227
+ if (multiselect) {
228
+ onChange?.([]);
229
+ } else {
230
+ onChange?.("");
231
+ }
232
+ }, sentiment: "neutral", size: "small", variant: "ghost", children: /* @__PURE__ */ jsxRuntime.jsx(Icon.CloseIcon, {}) }) : null,
233
+ /* @__PURE__ */ jsxRuntime.jsx(Icon.ArrowDownIcon, { "aria-label": "show dropdown", disabled: disabled || readOnly, sentiment: "neutral", size: "small" })
234
+ ] })
235
+ ] }) });
236
+ };
237
+ exports.SelectBar = SelectBar;
@@ -15,16 +15,5 @@ type SelectBarProps = {
15
15
  tooltip?: string;
16
16
  dropdownId?: string;
17
17
  };
18
- declare const StyledInputWrapper: import("@emotion/styled").StyledComponent<{
19
- theme?: import("@emotion/react").Theme;
20
- as?: React.ElementType;
21
- } & {
22
- 'data-readonly': boolean;
23
- 'data-disabled': boolean;
24
- 'data-size': "small" | "medium" | "large";
25
- 'data-state': "neutral" | "success" | "danger";
26
- 'data-dropdownvisible': boolean;
27
- 'aria-label'?: string;
28
- }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
29
18
  declare const SelectBar: ({ size, clearable, disabled, readOnly, placeholder, success, error, autoFocus, tooltip, innerRef, id, "data-testid": dataTestId, label, dropdownId, }: SelectBarProps) => import("@emotion/react/jsx-runtime").JSX.Element;
30
- export { SelectBar, StyledInputWrapper };
19
+ export { SelectBar };
@@ -0,0 +1,237 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
3
+ import { AlertCircleIcon, CheckCircleIcon, CloseIcon, ArrowDownIcon, PlusIcon } from "@ultraviolet/icons";
4
+ import { assignInlineVars } from "@vanilla-extract/dynamic";
5
+ import { useState, useRef, useMemo, useEffect, useCallback, useLayoutEffect } from "react";
6
+ import { Button } from "../../Button/index.js";
7
+ import { Stack } from "../../Stack/index.js";
8
+ import { Tag } from "../../Tag/index.js";
9
+ import { Text } from "../../Text/index.js";
10
+ import { Tooltip } from "../../Tooltip/index.js";
11
+ import { findOptionInOptions } from "../findOptionInOptions.js";
12
+ import { useSelectInput } from "../SelectInputProvider.js";
13
+ import { selectBar, selectinputPlaceholder, selectbarState, multiselectStack, selectBarTags, maxWidthTag, minWidthTag, plusTag, selectedValues } from "./selectBar.css.js";
14
+ const SIZES_TAG = {
15
+ gap: 8,
16
+ paddings: 16
17
+ };
18
+ const DisplayValues = ({
19
+ refTag,
20
+ nonOverflowedValues,
21
+ potentiallyNonOverflowedValues,
22
+ disabled,
23
+ readOnly,
24
+ overflowed,
25
+ overflowAmount,
26
+ size,
27
+ measureRef,
28
+ lastElementMaxWidth,
29
+ overflow,
30
+ refPlusTag,
31
+ displayShadowCopy
32
+ }) => {
33
+ const {
34
+ multiselect,
35
+ selectedData,
36
+ setSelectedData,
37
+ options,
38
+ onChange
39
+ } = useSelectInput();
40
+ return multiselect ? /* @__PURE__ */ jsxs(Stack, { alignItems: "center", className: multiselectStack, direction: "row", gap: "1", ref: refTag, wrap: "nowrap", children: [
41
+ displayShadowCopy ? /* @__PURE__ */ jsx("div", { ref: measureRef, style: {
42
+ position: "absolute"
43
+ }, children: potentiallyNonOverflowedValues.map((option) => /* @__PURE__ */ jsx(Tag, { className: `${option.value} ${selectBarTags.hidden}`, onClose: () => {
44
+ }, children: option?.label }, option.value)) }) : null,
45
+ nonOverflowedValues.map((option, index) => /* @__PURE__ */ jsx(Tag, { className: selectBarTags.visible, "data-testid": "selected-options-tags", disabled, onClose: !readOnly ? (event) => {
46
+ event.stopPropagation();
47
+ setSelectedData({
48
+ clickedOption: option,
49
+ type: "selectOption"
50
+ });
51
+ const newSelectedValues = selectedData.selectedValues?.filter((val) => val !== option.value);
52
+ onChange?.(newSelectedValues);
53
+ } : void 0, sentiment: "neutral", style: index === nonOverflowedValues.length - 1 && overflow ? assignInlineVars({
54
+ [minWidthTag]: "auto",
55
+ [maxWidthTag]: `${lastElementMaxWidth}px`
56
+ }) : void 0, children: option?.label }, option?.value)),
57
+ overflowed ? /* @__PURE__ */ jsx(Stack, { justifyContent: "center", ref: refPlusTag, children: /* @__PURE__ */ jsxs(Tag, { "aria-label": "Plus tag", className: plusTag, "data-testid": "plus-tag", disabled, sentiment: "neutral", children: [
58
+ /* @__PURE__ */ jsx(PlusIcon, { size: "xsmall" }),
59
+ overflowAmount
60
+ ] }, "+") }) : null
61
+ ] }) : /* @__PURE__ */ jsx(Text, { as: "span", className: selectedValues, disabled, prominence: "default", sentiment: "neutral", variant: size === "large" ? "body" : "bodySmall", children: selectedData.selectedValues[0] ? findOptionInOptions(options, selectedData.selectedValues[0])?.label : null });
62
+ };
63
+ const SelectBar = ({
64
+ size,
65
+ clearable,
66
+ disabled,
67
+ readOnly,
68
+ placeholder,
69
+ success,
70
+ error,
71
+ autoFocus,
72
+ tooltip,
73
+ innerRef,
74
+ id,
75
+ "data-testid": dataTestId,
76
+ label,
77
+ dropdownId
78
+ }) => {
79
+ const {
80
+ isDropdownVisible,
81
+ onChange,
82
+ setIsDropdownVisible,
83
+ options,
84
+ selectedData,
85
+ setSelectedData,
86
+ multiselect
87
+ } = useSelectInput();
88
+ const openable = !(readOnly || disabled);
89
+ const [displayShadowCopy, setDisplayShadowCopy] = useState(false);
90
+ const refTag = useRef(null);
91
+ const measureRef = useRef(null);
92
+ const arrowRef = useRef(null);
93
+ const refPlusTag = useRef(null);
94
+ const [overflowAmount, setOverflowAmount] = useState(0);
95
+ const [overflow, setOverflow] = useState(false);
96
+ const [lastElementMaxWidth, setLastElementMaxWidth] = useState(0);
97
+ const [nonOverflowedValues, setNonOverFlowedValues] = useState(() => {
98
+ if (selectedData.selectedValues[0]) {
99
+ const firstSelectOption = findOptionInOptions(options, selectedData.selectedValues[0]);
100
+ return firstSelectOption ? [firstSelectOption] : [];
101
+ }
102
+ return [];
103
+ });
104
+ const potentiallyNonOverflowedValues = useMemo(() => selectedData.selectedValues.map((selectedValue) => findOptionInOptions(options, selectedValue)).filter((option) => !!option), [options, selectedData.selectedValues]);
105
+ const state = useMemo(() => {
106
+ if (error) {
107
+ return "danger";
108
+ }
109
+ if (success) {
110
+ return "success";
111
+ }
112
+ return "neutral";
113
+ }, [error, success]);
114
+ useEffect(() => {
115
+ setDisplayShadowCopy(true);
116
+ }, [selectedData.selectedValues.length]);
117
+ const getWidth = useCallback(() => {
118
+ if (refTag.current) {
119
+ return refTag.current.offsetWidth;
120
+ }
121
+ return innerRef.current?.offsetWidth ?? 0 - (arrowRef.current?.offsetWidth ?? 0) - SIZES_TAG.paddings;
122
+ }, [innerRef.current?.offsetWidth]);
123
+ useLayoutEffect(() => {
124
+ if (selectedData.selectedValues.length === 0) {
125
+ setOverflowAmount(0);
126
+ setNonOverFlowedValues([]);
127
+ }
128
+ if (measureRef.current && selectedData.selectedValues.length > 0) {
129
+ const toMeasureElements = measureRef.current.children;
130
+ const toMeasureElementsArray = [...toMeasureElements];
131
+ const innerWidth = getWidth();
132
+ const {
133
+ measuredVisibleTags,
134
+ measuredHiddenTags,
135
+ accumulatedWidth,
136
+ lastVisibleElementWidth,
137
+ lastVisibleLabel
138
+ } = toMeasureElementsArray.reduce((accumulator, currentValue, index) => {
139
+ const elementWidth = currentValue.offsetWidth;
140
+ const newAccumulatedWidth = accumulator.accumulatedWidth + elementWidth + SIZES_TAG.gap;
141
+ const canBeVisible = newAccumulatedWidth <= innerWidth;
142
+ return {
143
+ accumulatedWidth: !canBeVisible ? accumulator.accumulatedWidth : newAccumulatedWidth,
144
+ lastVisibleElementWidth: canBeVisible ? elementWidth : accumulator.lastVisibleElementWidth,
145
+ lastVisibleLabel: canBeVisible ? potentiallyNonOverflowedValues[index].label : accumulator.lastVisibleLabel,
146
+ measuredHiddenTags: accumulator.measuredHiddenTags + (!canBeVisible ? 1 : 0),
147
+ measuredVisibleTags: [...accumulator.measuredVisibleTags, canBeVisible && potentiallyNonOverflowedValues[index]].filter(Boolean)
148
+ };
149
+ }, {
150
+ accumulatedWidth: 0,
151
+ lastVisibleElementWidth: 0,
152
+ lastVisibleLabel: "",
153
+ measuredHiddenTags: 0,
154
+ measuredVisibleTags: []
155
+ });
156
+ const additionnalElementsWidth = SIZES_TAG.paddings + (refPlusTag.current?.offsetWidth ?? 0);
157
+ const finalWidth = accumulatedWidth + (measuredHiddenTags ? additionnalElementsWidth : 0);
158
+ const overflowPx = finalWidth - innerWidth;
159
+ const hasOverflow = overflowPx > 0;
160
+ const hasHiddenTags = measuredHiddenTags > 0;
161
+ const lastVisibleElementMaxSize = lastVisibleElementWidth - overflowPx;
162
+ if (measuredHiddenTags === 1 && measuredVisibleTags.length === 0) {
163
+ setOverflowAmount(0);
164
+ setNonOverFlowedValues([potentiallyNonOverflowedValues[0]]);
165
+ const newOverflowPx = lastVisibleElementWidth + (measuredHiddenTags > 1 ? additionnalElementsWidth : 0) - innerWidth;
166
+ setLastElementMaxWidth(lastVisibleElementWidth - newOverflowPx);
167
+ setOverflow(true);
168
+ } else if (hasOverflow && hasHiddenTags && (lastVisibleElementMaxSize > 65 || measuredVisibleTags.length === 1 && lastVisibleElementMaxSize > 65) && typeof lastVisibleLabel === "string") {
169
+ setLastElementMaxWidth(lastVisibleElementMaxSize);
170
+ setOverflow(true);
171
+ setOverflowAmount(measuredHiddenTags);
172
+ setNonOverFlowedValues(measuredVisibleTags);
173
+ } else if (hasOverflow && hasHiddenTags) {
174
+ setLastElementMaxWidth(0);
175
+ setOverflow(false);
176
+ setOverflowAmount(measuredHiddenTags + 1);
177
+ setNonOverFlowedValues(measuredVisibleTags.slice(0, -1));
178
+ } else {
179
+ setOverflow(false);
180
+ setOverflowAmount(measuredHiddenTags);
181
+ setNonOverFlowedValues(measuredVisibleTags);
182
+ }
183
+ }
184
+ setDisplayShadowCopy(false);
185
+ }, [displayShadowCopy, potentiallyNonOverflowedValues, selectedData.selectedValues.length, getWidth]);
186
+ useEffect(() => {
187
+ setSelectedData({
188
+ type: "update"
189
+ });
190
+ }, [setSelectedData, options]);
191
+ const shouldDisplayValues = useMemo(() => {
192
+ if (multiselect) {
193
+ return potentiallyNonOverflowedValues.length > 0 || selectedData.selectedValues.some((selectedValue) => findOptionInOptions(options, selectedValue) !== void 0);
194
+ }
195
+ return selectedData.selectedValues[0] !== void 0 && findOptionInOptions(options, selectedData.selectedValues[0]) !== void 0;
196
+ }, [multiselect, options, potentiallyNonOverflowedValues.length, selectedData.selectedValues]);
197
+ return /* @__PURE__ */ jsx(Tooltip, { text: tooltip, children: /* @__PURE__ */ jsxs("div", { "aria-controls": dropdownId, "aria-expanded": isDropdownVisible, "aria-label": label, autoFocus, className: selectBar({
198
+ disabled,
199
+ dropdownVisible: isDropdownVisible,
200
+ readOnly,
201
+ size,
202
+ state
203
+ }), "data-disabled": disabled, "data-readonly": readOnly, "data-testid": dataTestId, id, onClick: openable ? () => setIsDropdownVisible(!isDropdownVisible) : void 0, onKeyDown: (event) => {
204
+ if (event.key === "ArrowDown") {
205
+ if (!isDropdownVisible) {
206
+ setIsDropdownVisible(true);
207
+ } else {
208
+ document.getElementById(`option-0`)?.focus();
209
+ }
210
+ }
211
+ if (event.key === " ") {
212
+ event.preventDefault();
213
+ }
214
+ return ["Enter", " "].includes(event.key) && openable ? setIsDropdownVisible(!isDropdownVisible) : null;
215
+ }, ref: innerRef, role: "combobox", tabIndex: 0, children: [
216
+ shouldDisplayValues ? /* @__PURE__ */ jsx(DisplayValues, { disabled, displayShadowCopy, lastElementMaxWidth, measureRef, nonOverflowedValues, overflow, overflowAmount, overflowed: !!overflowAmount, potentiallyNonOverflowedValues, readOnly, refPlusTag, refTag, size }) : /* @__PURE__ */ jsx(Text, { as: "span", className: selectinputPlaceholder, disabled, prominence: "weak", sentiment: "neutral", variant: size === "large" ? "body" : "bodySmall", children: placeholder }),
217
+ /* @__PURE__ */ jsxs(Stack, { alignItems: "center", className: selectbarState, direction: "row", gap: 1, ref: arrowRef, children: [
218
+ error ? /* @__PURE__ */ jsx(AlertCircleIcon, { sentiment: "danger" }) : null,
219
+ success && !error ? /* @__PURE__ */ jsx(CheckCircleIcon, { sentiment: "success" }) : null,
220
+ clearable && selectedData.selectedValues.length > 0 ? /* @__PURE__ */ jsx(Button, { "aria-label": "clear value", "data-testid": "clear-all", disabled: disabled || !selectedData.selectedValues[0] || readOnly, onClick: (event) => {
221
+ event.stopPropagation();
222
+ setSelectedData({
223
+ type: "clearAll"
224
+ });
225
+ if (multiselect) {
226
+ onChange?.([]);
227
+ } else {
228
+ onChange?.("");
229
+ }
230
+ }, sentiment: "neutral", size: "small", variant: "ghost", children: /* @__PURE__ */ jsx(CloseIcon, {}) }) : null,
231
+ /* @__PURE__ */ jsx(ArrowDownIcon, { "aria-label": "show dropdown", disabled: disabled || readOnly, sentiment: "neutral", size: "small" })
232
+ ] })
233
+ ] }) });
234
+ };
235
+ export {
236
+ SelectBar
237
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ ;/* empty css */
4
+ const createRuntimeFn = require("@vanilla-extract/recipes/createRuntimeFn");
5
+ var dropdown = "uv_5kpm8k0";
6
+ var dropdownContainer = "uv_5kpm8k1";
7
+ var dropdownContainerUnGrouped = "uv_5kpm8k2";
8
+ var dropdownGroup = "uv_5kpm8k3";
9
+ var dropdownGroupSelectable = "uv_5kpm8k4";
10
+ var dropdownGroupWrapper = "uv_5kpm8k5";
11
+ var dropdownItem = createRuntimeFn.createRuntimeFn({ defaultClassName: "uv_5kpm8k6", variantClassNames: { selected: { true: "uv_5kpm8k7" }, disabled: { true: "uv_5kpm8k8" } }, defaultVariants: { disabled: false, selected: false }, compoundVariants: [] });
12
+ var footer = "uv_5kpm8k9";
13
+ var dropdownCheckbox = "uv_5kpm8ka";
14
+ var dropdownEmptyState = "uv_5kpm8kb";
15
+ var dropdownLoadMore = "uv_5kpm8kc";
16
+ var dropdownInfo = "uv_5kpm8kd";
17
+ var dropdownInfoTextItem = "uv_5kpm8ke";
18
+ var dropdownInfoContainer = "uv_5kpm8kf";
19
+ var searchBar = "uv_5kpm8kg";
20
+ exports.dropdown = dropdown;
21
+ exports.dropdownCheckbox = dropdownCheckbox;
22
+ exports.dropdownContainer = dropdownContainer;
23
+ exports.dropdownContainerUnGrouped = dropdownContainerUnGrouped;
24
+ exports.dropdownEmptyState = dropdownEmptyState;
25
+ exports.dropdownGroup = dropdownGroup;
26
+ exports.dropdownGroupSelectable = dropdownGroupSelectable;
27
+ exports.dropdownGroupWrapper = dropdownGroupWrapper;
28
+ exports.dropdownInfo = dropdownInfo;
29
+ exports.dropdownInfoContainer = dropdownInfoContainer;
30
+ exports.dropdownInfoTextItem = dropdownInfoTextItem;
31
+ exports.dropdownItem = dropdownItem;
32
+ exports.dropdownLoadMore = dropdownLoadMore;
33
+ exports.footer = footer;
34
+ exports.searchBar = searchBar;