colibri-ui 0.8.76 → 0.8.78
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/Autocomplete/Autocomplete.d.ts +6 -0
- package/Autocomplete/Autocomplete.js +298 -0
- package/Autocomplete/Autocomplete.module.css +147 -0
- package/Autocomplete/index.d.ts +2 -0
- package/Autocomplete/index.js +7 -0
- package/Autocomplete/index.props.d.ts +39 -0
- package/Autocomplete/package.json +9 -0
- package/Button/tokens.d.ts +78 -0
- package/Button/tokens.js +84 -0
- package/Calendar/Calendar.js +3 -1
- package/Input/index.d.ts +1 -1
- package/Input/index.js +20 -14
- package/Input/index.props.d.ts +4 -1
- package/List/List.d.ts +5 -0
- package/List/List.js +161 -0
- package/List/List.module.css +185 -0
- package/List/index.d.ts +2 -0
- package/List/index.js +9 -0
- package/List/index.props.d.ts +43 -0
- package/List/package.json +9 -0
- package/Modal/Modal.module.css +14 -7
- package/Modal/components/Body/Body.module.css +12 -0
- package/Modal/components/Body/index.d.ts +3 -0
- package/Modal/components/Body/index.js +27 -0
- package/Modal/components/Body/index.props.d.ts +1 -0
- package/Modal/components/Close/index.js +5 -2
- package/Modal/components/Close/index.props.d.ts +1 -0
- package/Modal/components/Footer/Footer.module.css +10 -0
- package/Modal/components/Footer/index.d.ts +3 -0
- package/Modal/components/Footer/index.js +23 -0
- package/Modal/components/Footer/index.props.d.ts +1 -0
- package/Modal/components/Header/Header.module.css +32 -0
- package/Modal/components/Header/index.d.ts +3 -0
- package/Modal/components/Header/index.js +37 -0
- package/Modal/components/Header/index.props.d.ts +1 -0
- package/Modal/components/Title/index.js +20 -7
- package/Modal/components/Title/index.props.d.ts +1 -2
- package/Modal/context.d.ts +9 -0
- package/Modal/context.js +15 -0
- package/Modal/index.d.ts +12 -2
- package/Modal/index.js +103 -31
- package/Modal/index.props.d.ts +25 -0
- package/Modal/useModalStack.d.ts +2 -0
- package/Modal/useModalStack.js +20 -0
- package/README.md +59 -0
- package/Theme/breakpoints.d.ts +20 -16
- package/Theme/breakpoints.js +21 -32
- package/Theme/colors/index.d.ts +4 -0
- package/Theme/colors/theme_buenos_aires.d.ts +4 -0
- package/Theme/colors/theme_buenos_aires.js +2 -0
- package/Theme/colors/theme_jaipur.d.ts +4 -0
- package/Theme/colors/theme_jaipur.js +2 -0
- package/Theme/index.d.ts +300 -152
- package/Theme/index.js +6 -2
- package/Theme/themes/buenos_aires.d.ts +73 -76
- package/Theme/themes/buenos_aires.js +73 -76
- package/Theme/themes/jaipur.d.ts +73 -76
- package/Theme/themes/jaipur.js +73 -76
- package/esm/Autocomplete/Autocomplete.d.ts +6 -0
- package/esm/Autocomplete/Autocomplete.js +288 -0
- package/esm/Autocomplete/Autocomplete.module.css +147 -0
- package/esm/Autocomplete/index.d.ts +2 -0
- package/esm/Autocomplete/index.props.d.ts +39 -0
- package/esm/Button/tokens.d.ts +78 -0
- package/esm/Button/tokens.js +82 -0
- package/esm/Calendar/Calendar.js +3 -1
- package/esm/Input/index.d.ts +1 -1
- package/esm/Input/index.js +16 -10
- package/esm/Input/index.props.d.ts +4 -1
- package/esm/List/List.d.ts +5 -0
- package/esm/List/List.js +150 -0
- package/esm/List/List.module.css +185 -0
- package/esm/List/index.d.ts +2 -0
- package/esm/List/index.props.d.ts +43 -0
- package/esm/Modal/Modal.module.css +14 -7
- package/esm/Modal/components/Body/Body.module.css +12 -0
- package/esm/Modal/components/Body/index.d.ts +3 -0
- package/esm/Modal/components/Body/index.js +18 -0
- package/esm/Modal/components/Body/index.props.d.ts +1 -0
- package/esm/Modal/components/Close/index.js +4 -2
- package/esm/Modal/components/Close/index.props.d.ts +1 -0
- package/esm/Modal/components/Footer/Footer.module.css +10 -0
- package/esm/Modal/components/Footer/index.d.ts +3 -0
- package/esm/Modal/components/Footer/index.js +15 -0
- package/esm/Modal/components/Footer/index.props.d.ts +1 -0
- package/esm/Modal/components/Header/Header.module.css +32 -0
- package/esm/Modal/components/Header/index.d.ts +3 -0
- package/esm/Modal/components/Header/index.js +28 -0
- package/esm/Modal/components/Header/index.props.d.ts +1 -0
- package/esm/Modal/components/Title/index.js +20 -8
- package/esm/Modal/components/Title/index.props.d.ts +1 -2
- package/esm/Modal/context.d.ts +9 -0
- package/esm/Modal/context.js +12 -0
- package/esm/Modal/index.d.ts +12 -2
- package/esm/Modal/index.js +92 -25
- package/esm/Modal/index.props.d.ts +25 -0
- package/esm/Modal/useModalStack.d.ts +2 -0
- package/esm/Modal/useModalStack.js +18 -0
- package/esm/Theme/breakpoints.d.ts +20 -16
- package/esm/Theme/breakpoints.js +20 -26
- package/esm/Theme/colors/index.d.ts +4 -0
- package/esm/Theme/colors/theme_buenos_aires.d.ts +4 -0
- package/esm/Theme/colors/theme_buenos_aires.js +2 -0
- package/esm/Theme/colors/theme_jaipur.d.ts +4 -0
- package/esm/Theme/colors/theme_jaipur.js +2 -0
- package/esm/Theme/index.d.ts +300 -152
- package/esm/Theme/index.js +3 -2
- package/esm/Theme/themes/buenos_aires.d.ts +73 -76
- package/esm/Theme/themes/buenos_aires.js +73 -76
- package/esm/Theme/themes/jaipur.d.ts +73 -76
- package/esm/Theme/themes/jaipur.js +73 -76
- package/esm/hooks/useMediaSizes/index.d.ts +2 -2
- package/esm/hooks/useMediaSizes/index.js +2 -2
- package/esm/hooks/useTrapFocus/index.d.ts +1 -1
- package/esm/hooks/useTrapFocus/index.js +3 -2
- package/esm/index.d.ts +8 -3
- package/esm/index.js +7 -0
- package/esm/theme_ba_variables.css +149 -76
- package/esm/theme_jaipur_variables.css +149 -76
- package/hooks/useMediaSizes/index.d.ts +2 -2
- package/hooks/useMediaSizes/index.js +1 -1
- package/hooks/useTrapFocus/index.d.ts +1 -1
- package/hooks/useTrapFocus/index.js +3 -2
- package/index.d.ts +8 -3
- package/index.js +54 -35
- package/package.json +1 -1
- package/theme_ba_variables.css +149 -76
- package/theme_jaipur_variables.css +149 -76
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ForwardedRef } from "react";
|
|
3
|
+
import type { AutocompleteOption, AutocompleteProps } from "./index.props";
|
|
4
|
+
export declare const Autocomplete: <T extends AutocompleteOption = AutocompleteOption>(props: AutocompleteProps<T> & {
|
|
5
|
+
ref?: ForwardedRef<HTMLInputElement>;
|
|
6
|
+
}) => React.ReactElement;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var clsx = require('clsx');
|
|
8
|
+
var index = require('../Input/index.js');
|
|
9
|
+
var Chevron = require('../Icons/Chevron.js');
|
|
10
|
+
var Cross = require('../Icons/Cross.js');
|
|
11
|
+
var styles = require('./Autocomplete.module.css');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
|
|
16
|
+
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
|
|
17
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
18
|
+
var clsx__default = /*#__PURE__*/_interopDefault(clsx);
|
|
19
|
+
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
20
|
+
|
|
21
|
+
var AutocompleteInner = function AutocompleteInner(props, forwardedRef) {
|
|
22
|
+
var options = props.options,
|
|
23
|
+
value = props.value,
|
|
24
|
+
_props$defaultValue = props.defaultValue,
|
|
25
|
+
defaultValue = _props$defaultValue === void 0 ? "" : _props$defaultValue,
|
|
26
|
+
onValueChange = props.onValueChange,
|
|
27
|
+
onOptionSelect = props.onOptionSelect,
|
|
28
|
+
filterOption = props.filterOption,
|
|
29
|
+
renderOption = props.renderOption,
|
|
30
|
+
_props$getOptionKey = props.getOptionKey,
|
|
31
|
+
getOptionKey = _props$getOptionKey === void 0 ? function (option) {
|
|
32
|
+
return option.value;
|
|
33
|
+
} : _props$getOptionKey,
|
|
34
|
+
_props$minQueryLength = props.minQueryLength,
|
|
35
|
+
minQueryLength = _props$minQueryLength === void 0 ? 0 : _props$minQueryLength,
|
|
36
|
+
open = props.open,
|
|
37
|
+
_props$defaultOpen = props.defaultOpen,
|
|
38
|
+
defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
|
|
39
|
+
onOpenChange = props.onOpenChange,
|
|
40
|
+
_props$openOnFocus = props.openOnFocus,
|
|
41
|
+
openOnFocus = _props$openOnFocus === void 0 ? true : _props$openOnFocus,
|
|
42
|
+
_props$loading = props.loading,
|
|
43
|
+
loading = _props$loading === void 0 ? false : _props$loading,
|
|
44
|
+
_props$loadingText = props.loadingText,
|
|
45
|
+
loadingText = _props$loadingText === void 0 ? "Loading..." : _props$loadingText,
|
|
46
|
+
_props$emptyText = props.emptyText,
|
|
47
|
+
emptyText = _props$emptyText === void 0 ? "No results found" : _props$emptyText,
|
|
48
|
+
label = props.label,
|
|
49
|
+
hint = props.hint,
|
|
50
|
+
hasError = props.hasError,
|
|
51
|
+
success = props.success,
|
|
52
|
+
_props$clearable = props.clearable,
|
|
53
|
+
clearable = _props$clearable === void 0 ? true : _props$clearable,
|
|
54
|
+
_props$clearLabel = props.clearLabel,
|
|
55
|
+
clearLabel = _props$clearLabel === void 0 ? "Clear value" : _props$clearLabel,
|
|
56
|
+
_props$size = props.size,
|
|
57
|
+
size = _props$size === void 0 ? "m" : _props$size,
|
|
58
|
+
_props$listMaxHeight = props.listMaxHeight,
|
|
59
|
+
listMaxHeight = _props$listMaxHeight === void 0 ? "var(--component-autocomplete-list-max-height)" : _props$listMaxHeight,
|
|
60
|
+
containerClassName = props.containerClassName,
|
|
61
|
+
className = props.className,
|
|
62
|
+
disabled = props.disabled,
|
|
63
|
+
readOnly = props.readOnly,
|
|
64
|
+
required = props.required,
|
|
65
|
+
id = props.id,
|
|
66
|
+
_onFocus = props.onFocus,
|
|
67
|
+
onBlur = props.onBlur,
|
|
68
|
+
onKeyDown = props.onKeyDown,
|
|
69
|
+
inputProps = tslib.__rest(props, ["options", "value", "defaultValue", "onValueChange", "onOptionSelect", "filterOption", "renderOption", "getOptionKey", "minQueryLength", "open", "defaultOpen", "onOpenChange", "openOnFocus", "loading", "loadingText", "emptyText", "label", "hint", "hasError", "success", "clearable", "clearLabel", "size", "listMaxHeight", "containerClassName", "className", "disabled", "readOnly", "required", "id", "onFocus", "onBlur", "onKeyDown"]);
|
|
70
|
+
var generatedId = React.useId();
|
|
71
|
+
var inputId = id !== null && id !== void 0 ? id : generatedId;
|
|
72
|
+
var listId = "".concat(inputId, "-listbox");
|
|
73
|
+
var controlled = value !== undefined;
|
|
74
|
+
var _useState = React.useState(defaultValue),
|
|
75
|
+
_useState2 = _slicedToArray__default.default(_useState, 2),
|
|
76
|
+
internalValue = _useState2[0],
|
|
77
|
+
setInternalValue = _useState2[1];
|
|
78
|
+
var _useState3 = React.useState(defaultOpen),
|
|
79
|
+
_useState4 = _slicedToArray__default.default(_useState3, 2),
|
|
80
|
+
internalOpen = _useState4[0],
|
|
81
|
+
setInternalOpen = _useState4[1];
|
|
82
|
+
var _useState5 = React.useState(-1),
|
|
83
|
+
_useState6 = _slicedToArray__default.default(_useState5, 2),
|
|
84
|
+
activeIndex = _useState6[0],
|
|
85
|
+
setActiveIndex = _useState6[1];
|
|
86
|
+
var rootRef = React.useRef(null);
|
|
87
|
+
var controlRef = React.useRef(null);
|
|
88
|
+
var inputRef = React.useRef(null);
|
|
89
|
+
var optionRefs = React.useRef([]);
|
|
90
|
+
var query = controlled ? value : internalValue;
|
|
91
|
+
var isOpen = open !== null && open !== void 0 ? open : internalOpen;
|
|
92
|
+
var setInputRef = function setInputRef(node) {
|
|
93
|
+
inputRef.current = node;
|
|
94
|
+
if (typeof forwardedRef === "function") forwardedRef(node);else if (forwardedRef) forwardedRef.current = node;
|
|
95
|
+
};
|
|
96
|
+
var setOpen = React.useCallback(function (next) {
|
|
97
|
+
if (open === undefined) setInternalOpen(next);
|
|
98
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(next);
|
|
99
|
+
if (!next) setActiveIndex(-1);
|
|
100
|
+
}, [onOpenChange, open]);
|
|
101
|
+
var filteredOptions = React.useMemo(function () {
|
|
102
|
+
if (query.length < minQueryLength) return [];
|
|
103
|
+
var normalized = query.trim().toLocaleLowerCase();
|
|
104
|
+
var predicate = filterOption !== null && filterOption !== void 0 ? filterOption : function (option) {
|
|
105
|
+
return option.label.toLocaleLowerCase().includes(normalized);
|
|
106
|
+
};
|
|
107
|
+
return options.filter(function (option) {
|
|
108
|
+
return predicate(option, query);
|
|
109
|
+
});
|
|
110
|
+
}, [filterOption, minQueryLength, options, query]);
|
|
111
|
+
var showPopup = isOpen && !disabled && !readOnly && query.length >= minQueryLength;
|
|
112
|
+
React.useEffect(function () {
|
|
113
|
+
if (!showPopup) return undefined;
|
|
114
|
+
var closeOutside = function closeOutside(event) {
|
|
115
|
+
var _a;
|
|
116
|
+
if (!((_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) setOpen(false);
|
|
117
|
+
};
|
|
118
|
+
document.addEventListener("mousedown", closeOutside);
|
|
119
|
+
return function () {
|
|
120
|
+
return document.removeEventListener("mousedown", closeOutside);
|
|
121
|
+
};
|
|
122
|
+
}, [setOpen, showPopup]);
|
|
123
|
+
React.useEffect(function () {
|
|
124
|
+
setActiveIndex(-1);
|
|
125
|
+
}, [query]);
|
|
126
|
+
React.useEffect(function () {
|
|
127
|
+
var _a;
|
|
128
|
+
if (activeIndex >= 0) {
|
|
129
|
+
(_a = optionRefs.current[activeIndex]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
130
|
+
block: "nearest"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}, [activeIndex]);
|
|
134
|
+
var changeValue = function changeValue(next) {
|
|
135
|
+
if (!controlled) setInternalValue(next);
|
|
136
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(next);
|
|
137
|
+
};
|
|
138
|
+
var selectOption = function selectOption(option) {
|
|
139
|
+
var _a;
|
|
140
|
+
if (option.disabled) return;
|
|
141
|
+
changeValue(option.label);
|
|
142
|
+
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(option);
|
|
143
|
+
setOpen(false);
|
|
144
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
145
|
+
};
|
|
146
|
+
var moveActive = function moveActive(direction) {
|
|
147
|
+
if (!showPopup) setOpen(true);
|
|
148
|
+
if (!filteredOptions.length) return;
|
|
149
|
+
var next = activeIndex;
|
|
150
|
+
for (var attempts = 0; attempts < filteredOptions.length; attempts += 1) {
|
|
151
|
+
next = (next + direction + filteredOptions.length) % filteredOptions.length;
|
|
152
|
+
if (!filteredOptions[next].disabled) break;
|
|
153
|
+
}
|
|
154
|
+
setActiveIndex(next);
|
|
155
|
+
};
|
|
156
|
+
var handleChange = function handleChange(_event, next) {
|
|
157
|
+
changeValue(next);
|
|
158
|
+
setOpen(next.length >= minQueryLength);
|
|
159
|
+
};
|
|
160
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
161
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
162
|
+
if (event.defaultPrevented) return;
|
|
163
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
166
|
+
} else if (event.key === "Enter" && showPopup && activeIndex >= 0) {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
selectOption(filteredOptions[activeIndex]);
|
|
169
|
+
} else if (event.key === "Escape") {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
setOpen(false);
|
|
172
|
+
} else if (event.key === "Home" && showPopup) {
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
var first = filteredOptions.findIndex(function (option) {
|
|
175
|
+
return !option.disabled;
|
|
176
|
+
});
|
|
177
|
+
setActiveIndex(first);
|
|
178
|
+
} else if (event.key === "End" && showPopup) {
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
var last = filteredOptions.length - 1;
|
|
181
|
+
while (last >= 0 && filteredOptions[last].disabled) last -= 1;
|
|
182
|
+
setActiveIndex(last);
|
|
183
|
+
} else if (event.key === "Tab") {
|
|
184
|
+
setOpen(false);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var clearButton = clearable && query && !disabled && !readOnly && (/*#__PURE__*/React__default.default.createElement("button", {
|
|
188
|
+
type: "button",
|
|
189
|
+
className: styles__default.default.clear,
|
|
190
|
+
"aria-label": clearLabel,
|
|
191
|
+
onMouseDown: function onMouseDown(event) {
|
|
192
|
+
return event.preventDefault();
|
|
193
|
+
},
|
|
194
|
+
onClick: function onClick() {
|
|
195
|
+
var _a;
|
|
196
|
+
changeValue("");
|
|
197
|
+
setOpen(openOnFocus && minQueryLength === 0);
|
|
198
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
199
|
+
}
|
|
200
|
+
}, /*#__PURE__*/React__default.default.createElement(Cross.Cross, null)));
|
|
201
|
+
var endIcon = /*#__PURE__*/React__default.default.createElement("span", {
|
|
202
|
+
className: styles__default.default["end-icons"]
|
|
203
|
+
}, clearButton, /*#__PURE__*/React__default.default.createElement(Chevron.Chevron, {
|
|
204
|
+
className: clsx__default.default(styles__default.default.chevron, _defineProperty__default.default({}, styles__default.default["chevron_open"], showPopup)),
|
|
205
|
+
"aria-hidden": "true"
|
|
206
|
+
}));
|
|
207
|
+
var popup = showPopup && (/*#__PURE__*/React__default.default.createElement("div", {
|
|
208
|
+
className: styles__default.default.popup
|
|
209
|
+
}, /*#__PURE__*/React__default.default.createElement("ul", {
|
|
210
|
+
id: listId,
|
|
211
|
+
role: "listbox",
|
|
212
|
+
"aria-label": typeof label === "string" ? label : undefined,
|
|
213
|
+
className: styles__default.default.list,
|
|
214
|
+
style: {
|
|
215
|
+
maxHeight: listMaxHeight
|
|
216
|
+
}
|
|
217
|
+
}, loading ? (/*#__PURE__*/React__default.default.createElement("li", {
|
|
218
|
+
className: styles__default.default.message
|
|
219
|
+
}, loadingText)) : filteredOptions.length === 0 ? (/*#__PURE__*/React__default.default.createElement("li", {
|
|
220
|
+
className: styles__default.default.message
|
|
221
|
+
}, emptyText)) : filteredOptions.map(function (option, index) {
|
|
222
|
+
var active = index === activeIndex;
|
|
223
|
+
var selected = option.label === query;
|
|
224
|
+
return /*#__PURE__*/React__default.default.createElement("li", {
|
|
225
|
+
ref: function ref(node) {
|
|
226
|
+
optionRefs.current[index] = node;
|
|
227
|
+
},
|
|
228
|
+
id: "".concat(listId, "-").concat(index),
|
|
229
|
+
key: getOptionKey(option),
|
|
230
|
+
role: "option",
|
|
231
|
+
"aria-selected": selected,
|
|
232
|
+
"aria-disabled": option.disabled || undefined,
|
|
233
|
+
className: clsx__default.default(styles__default.default.option, _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, styles__default.default.active, active), styles__default.default.selected, selected), styles__default.default["option_disabled"], option.disabled)),
|
|
234
|
+
onMouseDown: function onMouseDown(event) {
|
|
235
|
+
return event.preventDefault();
|
|
236
|
+
},
|
|
237
|
+
onMouseEnter: function onMouseEnter() {
|
|
238
|
+
if (!option.disabled) setActiveIndex(index);
|
|
239
|
+
},
|
|
240
|
+
onKeyDown: function onKeyDown(event) {
|
|
241
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
selectOption(option);
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
onClick: function onClick() {
|
|
247
|
+
return selectOption(option);
|
|
248
|
+
}
|
|
249
|
+
}, renderOption ? renderOption(option, {
|
|
250
|
+
active: active,
|
|
251
|
+
selected: selected
|
|
252
|
+
}) : (/*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, option.contentLeft && (/*#__PURE__*/React__default.default.createElement("span", {
|
|
253
|
+
className: styles__default.default.side
|
|
254
|
+
}, option.contentLeft)), /*#__PURE__*/React__default.default.createElement("span", {
|
|
255
|
+
className: styles__default.default["option-text"]
|
|
256
|
+
}, /*#__PURE__*/React__default.default.createElement("span", null, option.label), option.description && (/*#__PURE__*/React__default.default.createElement("small", null, option.description))), option.contentRight && (/*#__PURE__*/React__default.default.createElement("span", {
|
|
257
|
+
className: styles__default.default.side
|
|
258
|
+
}, option.contentRight)))));
|
|
259
|
+
}))));
|
|
260
|
+
return /*#__PURE__*/React__default.default.createElement("div", {
|
|
261
|
+
ref: rootRef,
|
|
262
|
+
className: clsx__default.default(styles__default.default.root, styles__default.default["size_".concat(size)], _defineProperty__default.default({}, styles__default.default.success, success), containerClassName)
|
|
263
|
+
}, /*#__PURE__*/React__default.default.createElement(index.Input, Object.assign({}, inputProps, {
|
|
264
|
+
id: inputId,
|
|
265
|
+
type: "text",
|
|
266
|
+
role: "combobox",
|
|
267
|
+
"aria-autocomplete": "list",
|
|
268
|
+
"aria-expanded": showPopup,
|
|
269
|
+
"aria-controls": showPopup ? listId : undefined,
|
|
270
|
+
"aria-activedescendant": activeIndex >= 0 ? "".concat(listId, "-").concat(activeIndex) : undefined,
|
|
271
|
+
"aria-invalid": hasError || undefined,
|
|
272
|
+
autoComplete: "off",
|
|
273
|
+
className: clsx__default.default(styles__default.default.field, className),
|
|
274
|
+
controlAfter: popup,
|
|
275
|
+
controlClassName: styles__default.default.control,
|
|
276
|
+
controlRef: controlRef,
|
|
277
|
+
disabled: disabled,
|
|
278
|
+
endIcon: endIcon,
|
|
279
|
+
hasError: hasError,
|
|
280
|
+
hint: hint,
|
|
281
|
+
inputRef: setInputRef,
|
|
282
|
+
label: label,
|
|
283
|
+
readOnly: readOnly,
|
|
284
|
+
required: required,
|
|
285
|
+
size: size,
|
|
286
|
+
value: query,
|
|
287
|
+
onBlur: onBlur,
|
|
288
|
+
onChange: handleChange,
|
|
289
|
+
onFocus: function onFocus(event) {
|
|
290
|
+
_onFocus === null || _onFocus === void 0 ? void 0 : _onFocus(event);
|
|
291
|
+
if (openOnFocus && query.length >= minQueryLength) setOpen(true);
|
|
292
|
+
},
|
|
293
|
+
onKeyDown: handleKeyDown
|
|
294
|
+
})));
|
|
295
|
+
};
|
|
296
|
+
var Autocomplete = /*#__PURE__*/React.forwardRef(AutocompleteInner);
|
|
297
|
+
|
|
298
|
+
exports.Autocomplete = Autocomplete;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
width: var(--component-autocomplete-inline-size);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.field {
|
|
8
|
+
width: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.control {
|
|
12
|
+
position: relative;
|
|
13
|
+
width: 100%;
|
|
14
|
+
}
|
|
15
|
+
.control > div {
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.success {
|
|
20
|
+
--component-input-border: var(--component-autocomplete-border-success);
|
|
21
|
+
--component-input-border-focus: var(--component-autocomplete-border-success);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.end-icons {
|
|
25
|
+
align-items: center;
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
gap: var(--component-autocomplete-end-icon-gap);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.clear {
|
|
31
|
+
align-items: center;
|
|
32
|
+
background: transparent;
|
|
33
|
+
border: 0;
|
|
34
|
+
border-radius: var(--component-autocomplete-clear-radius);
|
|
35
|
+
color: var(--component-autocomplete-clear-icon);
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
display: inline-flex;
|
|
38
|
+
flex: none;
|
|
39
|
+
height: var(--component-autocomplete-clear-size);
|
|
40
|
+
justify-content: center;
|
|
41
|
+
padding: var(--space-0);
|
|
42
|
+
width: var(--component-autocomplete-clear-size);
|
|
43
|
+
}
|
|
44
|
+
.clear:hover {
|
|
45
|
+
background: var(--component-autocomplete-clear-bg-hover);
|
|
46
|
+
}
|
|
47
|
+
.clear svg {
|
|
48
|
+
height: var(--component-autocomplete-icon-size);
|
|
49
|
+
width: var(--component-autocomplete-icon-size);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.chevron {
|
|
53
|
+
color: var(--component-autocomplete-chevron);
|
|
54
|
+
flex: none;
|
|
55
|
+
height: var(--component-autocomplete-icon-size);
|
|
56
|
+
transition: transform 0.16s ease-in;
|
|
57
|
+
width: var(--component-autocomplete-icon-size);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.chevron_open {
|
|
61
|
+
transform: rotate(180deg);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.popup {
|
|
65
|
+
background: var(--component-autocomplete-popup-bg);
|
|
66
|
+
border-color: var(--component-autocomplete-popup-border);
|
|
67
|
+
border-radius: var(--component-autocomplete-popup-radius);
|
|
68
|
+
border-style: solid;
|
|
69
|
+
border-width: var(--border-width-hairline);
|
|
70
|
+
box-shadow: var(--component-autocomplete-popup-shadow);
|
|
71
|
+
left: 0;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
position: absolute;
|
|
74
|
+
right: 0;
|
|
75
|
+
top: calc(100% + var(--component-autocomplete-popup-offset));
|
|
76
|
+
z-index: var(--component-autocomplete-popup-z-index);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.list {
|
|
80
|
+
box-sizing: border-box;
|
|
81
|
+
list-style: none;
|
|
82
|
+
margin: var(--space-0);
|
|
83
|
+
overflow: auto;
|
|
84
|
+
padding: var(--component-autocomplete-list-padding);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.option {
|
|
88
|
+
align-items: center;
|
|
89
|
+
border-radius: var(--component-autocomplete-option-radius);
|
|
90
|
+
color: var(--component-autocomplete-option-text);
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
display: flex;
|
|
93
|
+
gap: var(--component-autocomplete-option-gap);
|
|
94
|
+
min-height: var(--component-autocomplete-option-min-height);
|
|
95
|
+
padding: var(--component-autocomplete-option-padding-block) var(--component-autocomplete-option-padding-inline);
|
|
96
|
+
}
|
|
97
|
+
.option:hover {
|
|
98
|
+
background: var(--component-autocomplete-option-bg-hover);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.active {
|
|
102
|
+
background: var(--component-autocomplete-option-bg-hover);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.selected {
|
|
106
|
+
color: var(--component-autocomplete-option-text-selected);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.option_disabled {
|
|
110
|
+
color: var(--component-autocomplete-option-text-disabled);
|
|
111
|
+
cursor: not-allowed;
|
|
112
|
+
}
|
|
113
|
+
.option_disabled:hover {
|
|
114
|
+
background: transparent;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.option-text {
|
|
118
|
+
display: flex;
|
|
119
|
+
flex: 1;
|
|
120
|
+
flex-direction: column;
|
|
121
|
+
min-width: 0;
|
|
122
|
+
}
|
|
123
|
+
.option-text > span {
|
|
124
|
+
overflow: hidden;
|
|
125
|
+
text-overflow: ellipsis;
|
|
126
|
+
white-space: nowrap;
|
|
127
|
+
}
|
|
128
|
+
.option-text small {
|
|
129
|
+
color: var(--component-autocomplete-option-description);
|
|
130
|
+
font-size: var(--font-size-text-xs);
|
|
131
|
+
line-height: var(--line-height-text-xs);
|
|
132
|
+
margin-top: var(--component-autocomplete-description-offset);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.side {
|
|
136
|
+
align-items: center;
|
|
137
|
+
display: inline-flex;
|
|
138
|
+
flex: none;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.message {
|
|
142
|
+
color: var(--component-autocomplete-message-text);
|
|
143
|
+
font-size: var(--font-size-text-sm);
|
|
144
|
+
line-height: var(--line-height-text-sm);
|
|
145
|
+
padding: var(--component-autocomplete-message-padding);
|
|
146
|
+
text-align: center;
|
|
147
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
import type { InputProps } from "../Input/index.props";
|
|
3
|
+
export interface AutocompleteOption {
|
|
4
|
+
contentLeft?: ReactNode;
|
|
5
|
+
contentRight?: ReactNode;
|
|
6
|
+
description?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
label: string;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
export type AutocompleteSize = "s" | "m" | "l";
|
|
12
|
+
export interface AutocompleteOptionState {
|
|
13
|
+
active: boolean;
|
|
14
|
+
selected: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface AutocompleteProps<T extends AutocompleteOption = AutocompleteOption> extends Omit<InputProps, "controlAfter" | "controlClassName" | "controlRef" | "defaultValue" | "endIcon" | "inputRef" | "onChange" | "size" | "value"> {
|
|
17
|
+
clearLabel?: string;
|
|
18
|
+
clearable?: boolean;
|
|
19
|
+
containerClassName?: string;
|
|
20
|
+
defaultOpen?: boolean;
|
|
21
|
+
defaultValue?: string;
|
|
22
|
+
emptyText?: ReactNode;
|
|
23
|
+
filterOption?: (option: T, query: string) => boolean;
|
|
24
|
+
getOptionKey?: (option: T) => string;
|
|
25
|
+
listMaxHeight?: CSSProperties["maxHeight"];
|
|
26
|
+
loading?: boolean;
|
|
27
|
+
loadingText?: ReactNode;
|
|
28
|
+
minQueryLength?: number;
|
|
29
|
+
onOpenChange?: (open: boolean) => void;
|
|
30
|
+
onOptionSelect?: (option: T) => void;
|
|
31
|
+
onValueChange?: (value: string) => void;
|
|
32
|
+
open?: boolean;
|
|
33
|
+
openOnFocus?: boolean;
|
|
34
|
+
options: T[];
|
|
35
|
+
renderOption?: (option: T, state: AutocompleteOptionState) => ReactNode;
|
|
36
|
+
size?: AutocompleteSize;
|
|
37
|
+
success?: boolean;
|
|
38
|
+
value?: string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const BUTTON_TOKENS: {
|
|
2
|
+
readonly "component-button-primary-bg": "var(--color-action-primary)";
|
|
3
|
+
readonly "component-button-primary-border": "var(--color-action-primary)";
|
|
4
|
+
readonly "component-button-primary-text": "var(--color-action-secondary)";
|
|
5
|
+
readonly "component-button-primary-bg-hover": "var(--color-action-primary-hover)";
|
|
6
|
+
readonly "component-button-primary-border-hover": "var(--color-action-primary-hover)";
|
|
7
|
+
readonly "component-button-primary-text-hover": "var(--color-action-secondary)";
|
|
8
|
+
readonly "component-button-primary-bg-pressed": "var(--color-action-secondary)";
|
|
9
|
+
readonly "component-button-primary-border-pressed": "var(--color-action-secondary)";
|
|
10
|
+
readonly "component-button-primary-text-pressed": "var(--color-text-on-brand)";
|
|
11
|
+
readonly "component-button-secondary-bg": "var(--color-bg-surface-strong)";
|
|
12
|
+
readonly "component-button-secondary-border": "var(--color-border-default)";
|
|
13
|
+
readonly "component-button-secondary-text": "var(--color-text-primary)";
|
|
14
|
+
readonly "component-button-secondary-bg-hover": "var(--color-neutral-300)";
|
|
15
|
+
readonly "component-button-secondary-border-hover": "var(--color-border-strong)";
|
|
16
|
+
readonly "component-button-secondary-text-hover": "var(--color-text-primary)";
|
|
17
|
+
readonly "component-button-secondary-bg-pressed": "var(--color-action-primary)";
|
|
18
|
+
readonly "component-button-secondary-border-pressed": "var(--color-action-primary)";
|
|
19
|
+
readonly "component-button-secondary-text-pressed": "var(--color-action-secondary)";
|
|
20
|
+
readonly "component-button-outline-bg": "var(--color-bg-surface)";
|
|
21
|
+
readonly "component-button-outline-border": "var(--color-border-default)";
|
|
22
|
+
readonly "component-button-outline-text": "var(--color-text-primary)";
|
|
23
|
+
readonly "component-button-outline-bg-hover": "var(--color-bg-surface-subtle)";
|
|
24
|
+
readonly "component-button-outline-border-hover": "var(--color-border-strong)";
|
|
25
|
+
readonly "component-button-outline-text-hover": "var(--color-text-primary)";
|
|
26
|
+
readonly "component-button-outline-bg-pressed": "var(--color-bg-surface-strong)";
|
|
27
|
+
readonly "component-button-outline-border-pressed": "var(--color-action-primary)";
|
|
28
|
+
readonly "component-button-outline-text-pressed": "var(--color-action-primary-pressed)";
|
|
29
|
+
readonly "component-button-pseudo-bg": "var(--color-bg-canvas)";
|
|
30
|
+
readonly "component-button-pseudo-border": "var(--color-bg-canvas)";
|
|
31
|
+
readonly "component-button-pseudo-text": "var(--color-text-primary)";
|
|
32
|
+
readonly "component-button-pseudo-bg-hover": "var(--color-bg-surface-subtle)";
|
|
33
|
+
readonly "component-button-pseudo-border-hover": "var(--color-bg-surface-subtle)";
|
|
34
|
+
readonly "component-button-pseudo-text-hover": "var(--color-text-primary)";
|
|
35
|
+
readonly "component-button-pseudo-bg-pressed": "var(--color-bg-surface-strong)";
|
|
36
|
+
readonly "component-button-pseudo-border-pressed": "var(--color-bg-surface-strong)";
|
|
37
|
+
readonly "component-button-pseudo-text-pressed": "var(--color-text-primary)";
|
|
38
|
+
readonly "component-button-clear-bg": "transparent";
|
|
39
|
+
readonly "component-button-clear-border": "transparent";
|
|
40
|
+
readonly "component-button-clear-text": "var(--color-text-primary)";
|
|
41
|
+
readonly "component-button-clear-bg-hover": "transparent";
|
|
42
|
+
readonly "component-button-clear-border-hover": "transparent";
|
|
43
|
+
readonly "component-button-clear-text-hover": "var(--color-action-clear-text-hover)";
|
|
44
|
+
readonly "component-button-clear-bg-pressed": "transparent";
|
|
45
|
+
readonly "component-button-clear-border-pressed": "transparent";
|
|
46
|
+
readonly "component-button-clear-text-pressed": "var(--color-action-primary-pressed)";
|
|
47
|
+
readonly "component-button-alert-bg": "var(--color-status-error)";
|
|
48
|
+
readonly "component-button-alert-border": "var(--color-status-error)";
|
|
49
|
+
readonly "component-button-alert-text": "var(--color-brand-white)";
|
|
50
|
+
readonly "component-button-alert-bg-hover": "var(--color-status-error-hover)";
|
|
51
|
+
readonly "component-button-alert-border-hover": "var(--color-status-error-hover)";
|
|
52
|
+
readonly "component-button-alert-text-hover": "var(--color-brand-white)";
|
|
53
|
+
readonly "component-button-alert-bg-pressed": "var(--color-status-error-accent)";
|
|
54
|
+
readonly "component-button-alert-border-pressed": "var(--color-status-error-accent)";
|
|
55
|
+
readonly "component-button-alert-text-pressed": "var(--color-brand-white)";
|
|
56
|
+
readonly "component-button-success-bg": "var(--color-status-success-bg)";
|
|
57
|
+
readonly "component-button-success-border": "var(--color-status-success-bg)";
|
|
58
|
+
readonly "component-button-success-text": "var(--color-text-primary)";
|
|
59
|
+
readonly "component-button-success-bg-hover": "var(--color-status-success-bg-hover)";
|
|
60
|
+
readonly "component-button-success-border-hover": "var(--color-status-success-bg-hover)";
|
|
61
|
+
readonly "component-button-success-text-hover": "var(--color-text-primary)";
|
|
62
|
+
readonly "component-button-success-bg-pressed": "var(--color-status-success)";
|
|
63
|
+
readonly "component-button-success-border-pressed": "var(--color-status-success)";
|
|
64
|
+
readonly "component-button-success-text-pressed": "var(--color-brand-white)";
|
|
65
|
+
readonly "component-button-bg-disabled": "var(--color-action-disabled)";
|
|
66
|
+
readonly "component-button-border-disabled": "var(--color-action-disabled)";
|
|
67
|
+
readonly "component-button-text-disabled": "var(--color-action-disabled-text)";
|
|
68
|
+
readonly "component-button-font-size-xs": string;
|
|
69
|
+
readonly "component-button-font-size-s": string;
|
|
70
|
+
readonly "component-button-font-size-m": string;
|
|
71
|
+
readonly "component-button-font-size-l": string;
|
|
72
|
+
readonly "component-button-height-xs": string;
|
|
73
|
+
readonly "component-button-height-s": string;
|
|
74
|
+
readonly "component-button-height-m": string;
|
|
75
|
+
readonly "component-button-height-l": string;
|
|
76
|
+
readonly "component-button-radius": string;
|
|
77
|
+
readonly "component-button-radius-lg": string;
|
|
78
|
+
};
|