@uxf/ui 11.34.0 → 11.34.1
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/combobox/combobox.js
CHANGED
|
@@ -57,28 +57,30 @@ function Options(props) {
|
|
|
57
57
|
})) : (react_3.default.createElement("div", { className: "uxf-dropdown__empty-wrapper" }, props.emptyMessage))));
|
|
58
58
|
}
|
|
59
59
|
Options.displayName = "UxfUiComboboxOptions";
|
|
60
|
+
// eslint-disable-next-line complexity
|
|
60
61
|
function Combobox(props) {
|
|
61
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
62
63
|
const isAsync = (0, is_not_nil_1.isNotNil)(props.loadOptions);
|
|
63
64
|
const [query, setQuery] = (0, react_3.useState)("");
|
|
64
|
-
const
|
|
65
|
+
const asyncOptions = (0, use_async_loading_1.useAsyncLoading)(query, (_a = props.options) !== null && _a !== void 0 ? _a : empty_array_1.EMPTY_ARRAY, props.loadOptions);
|
|
66
|
+
const options = isAsync ? asyncOptions : ((_b = props.options) !== null && _b !== void 0 ? _b : empty_array_1.EMPTY_ARRAY);
|
|
65
67
|
const filteredData = (0, is_empty_1.isEmpty)(query) || isAsync ? options : options.filter((item) => (0, slugify_1.slugify)(item.label).includes((0, slugify_1.slugify)(query)));
|
|
66
68
|
const emptyMessage = (0, is_empty_1.isEmpty)(query)
|
|
67
|
-
? ((
|
|
69
|
+
? ((_c = props.noQueryMessage) !== null && _c !== void 0 ? _c : "Pro zobrazení možností začněte psát")
|
|
68
70
|
: (0, is_empty_1.isEmpty)(options)
|
|
69
|
-
? ((
|
|
70
|
-
: ((
|
|
71
|
+
? ((_d = props.noOptionsMessage) !== null && _d !== void 0 ? _d : "Nabídka neosahuje žádné položky")
|
|
72
|
+
: ((_e = props.notFoundMessage) !== null && _e !== void 0 ? _e : "Nic nenalezeno");
|
|
71
73
|
const clearQuery = () => setQuery("");
|
|
72
74
|
const onChange = (v) => props.onChange(v);
|
|
73
75
|
const onInputChange = (event) => setQuery(event.target.value);
|
|
74
76
|
const displayValue = (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.label) !== null && _a !== void 0 ? _a : ""; };
|
|
75
|
-
const selectedOption = (
|
|
77
|
+
const selectedOption = (_f = props.value) !== null && _f !== void 0 ? _f : null;
|
|
76
78
|
const generatedId = (0, react_3.useId)();
|
|
77
|
-
const id = (
|
|
79
|
+
const id = (_g = props.id) !== null && _g !== void 0 ? _g : generatedId;
|
|
78
80
|
const innerRef = (0, react_3.useRef)(null);
|
|
79
81
|
const errorId = props.isInvalid ? `${id}--error-message` : undefined;
|
|
80
82
|
const input = (0, use_input_focus_1.useInputFocus)(innerRef, props.onBlur, props.onFocus);
|
|
81
|
-
const dropdown = (0, use_dropdown_1.useDropdown)((
|
|
83
|
+
const dropdown = (0, use_dropdown_1.useDropdown)((_h = props.dropdownPlacement) !== null && _h !== void 0 ? _h : "bottom", (_j = props.dropdownMatchesInputWidth) !== null && _j !== void 0 ? _j : true, props.dropdownMaxHeight, props.dropdownStrategy);
|
|
82
84
|
const stableRef = (0, react_3.useMemo)(() => (0, compose_refs_1.composeRefs)(innerRef, props.inputGroupRef, dropdown.refs.setReference), [dropdown.refs.setReference, props.inputGroupRef]);
|
|
83
85
|
const isNotInteractive = props.isDisabled || props.isReadOnly;
|
|
84
86
|
return (react_3.default.createElement(react_2.Combobox, { as: "div", by: "id", className: (0, cx_1.cx)("uxf-form-component uxf-combobox", props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isRequired && classes_1.CLASSES.IS_REQUIRED, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.className), "data-name": props.name, disabled: isNotInteractive, form: props.form, name: props.name, onChange: onChange, style: props.style, value: selectedOption }, (renderProps) => (react_3.default.createElement(react_3.default.Fragment, null,
|
|
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
7
|
const snap_test_1 = require("../utils/snap-test");
|
|
8
8
|
const combobox_stories_1 = require("./combobox.stories");
|
|
9
|
-
(0, snap_test_1.snapTest)("render default stories", react_1.default.createElement(combobox_stories_1.
|
|
10
|
-
(0, snap_test_1.snapTest)("render async stories", react_1.default.createElement(combobox_stories_1.
|
|
9
|
+
(0, snap_test_1.snapTest)("render default stories", react_1.default.createElement(combobox_stories_1.SynchronousOptions, null));
|
|
10
|
+
(0, snap_test_1.snapTest)("render async stories", react_1.default.createElement(combobox_stories_1.AsynchronousOptions, null));
|
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
title: string;
|
|
5
|
-
component: typeof Combobox;
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|
|
8
|
-
export declare function Default(): React.JSX.Element;
|
|
9
|
-
export declare function Async(): React.JSX.Element;
|
|
10
|
-
export declare function ComponentStructure(): React.JSX.Element;
|
|
2
|
+
export declare function SynchronousOptions(): React.JSX.Element;
|
|
3
|
+
export declare function AsynchronousOptions(): React.JSX.Element;
|
|
@@ -22,61 +22,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.ComponentStructure = ComponentStructure;
|
|
26
|
+
exports.SynchronousOptions = SynchronousOptions;
|
|
27
|
+
exports.AsynchronousOptions = AsynchronousOptions;
|
|
32
28
|
const react_1 = __importStar(require("react"));
|
|
33
29
|
const action_1 = require("../utils/action");
|
|
34
|
-
const component_structure_analyzer_1 = __importDefault(require("../utils/component-structure-analyzer"));
|
|
35
30
|
const index_1 = require("./index");
|
|
36
|
-
|
|
37
|
-
title: "UI/Combobox",
|
|
38
|
-
component: index_1.Combobox,
|
|
39
|
-
};
|
|
40
|
-
const options = [
|
|
31
|
+
const OPTIONS = [
|
|
41
32
|
{ id: "one", label: "Option one" },
|
|
42
33
|
{ id: "two", label: "Option two disabled", disabled: true },
|
|
43
34
|
{ id: "three", label: "Option three" },
|
|
44
35
|
{ id: "four", label: "Option with diacritics (ěščřžýáíé)" },
|
|
45
36
|
];
|
|
46
|
-
function
|
|
37
|
+
function SynchronousOptions() {
|
|
47
38
|
const [value, setValue] = (0, react_1.useState)(null);
|
|
48
|
-
const onChange = (0, action_1.action)("onChange",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
react_1.default.createElement(index_1.Combobox, { id: "combobox-1", label: "Combobox", name: "combobox", onChange: onChange, options: options, placeholder: "Vyberte...", value: value }),
|
|
55
|
-
react_1.default.createElement(index_1.Combobox, { helperText: "Start typing to see options...", id: "combobox-1", label: "Combobox with helper text", name: "combobox", onChange: onChange, options: options, placeholder: "Vyberte...", value: value }),
|
|
56
|
-
react_1.default.createElement(index_1.Combobox, { helperText: "Error message", id: "combobox-1", isInvalid: true, isRequired: true, label: "Combobox invalid", name: "combobox", onChange: onChange, options: options, placeholder: "Vyberte...", value: value }),
|
|
57
|
-
react_1.default.createElement(index_1.Combobox, { dropdownPlacement: "top", id: "combobox-1", isClearable: true, label: "Combobox with dropdown top", name: "combobox", onChange: onChange, options: options, placeholder: "Vyberte...", value: value }),
|
|
58
|
-
react_1.default.createElement(index_1.Combobox, { id: "combobox-render", isClearable: true, label: "RenderOption", name: "combobox", onChange: onChange, options: options, placeholder: "Vyberte...", renderOption: (option, isSelected) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
39
|
+
const onChange = (0, action_1.action)("onChange", setValue);
|
|
40
|
+
return (react_1.default.createElement("div", { className: "space-y-4 p-4" },
|
|
41
|
+
react_1.default.createElement(index_1.Combobox, { helperText: "Start typing to see options...", id: "combobox-1", label: "Combobox", name: "combobox", onChange: onChange, options: OPTIONS, placeholder: "Vyberte...", value: value }),
|
|
42
|
+
react_1.default.createElement(index_1.Combobox, { helperText: "Error message", id: "combobox-1", isInvalid: true, isRequired: true, label: "Combobox invalid", name: "combobox", onChange: onChange, options: OPTIONS, placeholder: "Vyberte...", value: value }),
|
|
43
|
+
react_1.default.createElement(index_1.Combobox, { dropdownPlacement: "top", id: "combobox-1", isClearable: true, label: "Combobox with dropdown top", name: "combobox", onChange: onChange, options: OPTIONS, placeholder: "Vyberte...", value: value }),
|
|
44
|
+
react_1.default.createElement(index_1.Combobox, { id: "combobox-render", isClearable: true, label: "RenderOption", name: "combobox", onChange: onChange, options: OPTIONS, placeholder: "Vyberte...", renderOption: (option, isSelected) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
59
45
|
"Option: ",
|
|
60
46
|
option.label,
|
|
61
47
|
isSelected && " (selected)")), value: value })));
|
|
62
|
-
return (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
|
|
63
|
-
react_1.default.createElement("div", { className: "space-y-2 p-20 lg:w-1/2" }, storyComboboxes)));
|
|
64
48
|
}
|
|
65
|
-
function
|
|
49
|
+
function AsynchronousOptions() {
|
|
66
50
|
const [value, setValue] = (0, react_1.useState)(null);
|
|
67
|
-
const onChange = (0, action_1.action)("onChange",
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
setValue(v);
|
|
71
|
-
});
|
|
72
|
-
const loadOptions = (query) => Promise.resolve(options.filter((option) => !query || option.label.toLowerCase().includes(query.toLowerCase())));
|
|
73
|
-
const storyComboboxes = (react_1.default.createElement("div", { className: "space-y-8" },
|
|
51
|
+
const onChange = (0, action_1.action)("onChange", setValue);
|
|
52
|
+
const loadOptions = (query) => Promise.resolve(OPTIONS.filter((option) => !query || option.label.toLowerCase().includes(query.toLowerCase())));
|
|
53
|
+
return (react_1.default.createElement("div", { className: "p-4" },
|
|
74
54
|
react_1.default.createElement(index_1.Combobox, { id: "combobox-1", label: "Combobox", loadOptions: loadOptions, name: "combobox", onChange: onChange, placeholder: "Vyberte...", value: value })));
|
|
75
|
-
return (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
|
|
76
|
-
react_1.default.createElement("div", { className: "space-y-2 p-20 lg:w-1/2" }, storyComboboxes)));
|
|
77
|
-
}
|
|
78
|
-
function ComponentStructure() {
|
|
79
|
-
const [value, onChange] = (0, react_1.useState)(null);
|
|
80
|
-
return (react_1.default.createElement(component_structure_analyzer_1.default, null,
|
|
81
|
-
react_1.default.createElement(index_1.Combobox, { helperText: "Start typing to see options...", id: "combobox-structure", label: "Combobox with helper text", name: "combobox", onChange: onChange, options: options, value: value })));
|
|
82
55
|
}
|