@uxf/ui 1.0.0-beta.122 → 1.0.0-beta.124

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/chip/chip.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import React, { HTMLAttributes } from "react";
2
1
  import { ChipColors, ChipSizes } from "@uxf/ui/chip/theme";
2
+ import React, { HTMLAttributes } from "react";
3
3
  export declare type ChipColor = keyof ChipColors;
4
4
  export declare type ChipSize = keyof ChipSizes;
5
5
  export interface ChipProps extends HTMLAttributes<HTMLDivElement> {
6
6
  color?: ChipColor;
7
- size?: ChipSize;
8
7
  onClose?: () => void;
8
+ size?: ChipSize;
9
+ suppressFocus?: boolean;
9
10
  }
10
11
  export declare const Chip: React.ForwardRefExoticComponent<ChipProps & React.RefAttributes<HTMLDivElement>>;
package/chip/chip.js CHANGED
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Chip = void 0;
7
7
  const cx_1 = require("@uxf/core/utils/cx");
8
- const react_1 = __importDefault(require("react"));
9
8
  const forwardRef_1 = require("@uxf/core/utils/forwardRef");
9
+ const react_1 = __importDefault(require("react"));
10
10
  exports.Chip = (0, forwardRef_1.forwardRef)("Chip", (props, ref) => {
11
11
  var _a, _b;
12
12
  const chipClassName = (0, cx_1.cx)("uxf-chip", `uxf-chip--color-${(_a = props.color) !== null && _a !== void 0 ? _a : "default"}`, `uxf-chip--size-${(_b = props.size) !== null && _b !== void 0 ? _b : "default"}`, props.onClose && "has-button", props.className);
13
13
  return (react_1.default.createElement("div", { ref: ref, className: chipClassName },
14
14
  typeof props.children === "string" ? (react_1.default.createElement("span", { className: "uxf-chip__text" }, props.children)) : (props.children),
15
- props.onClose && (react_1.default.createElement("button", { type: "button", onClick: props.onClose, className: "uxf-chip__button" },
15
+ props.onClose && (react_1.default.createElement("button", { className: "uxf-chip__button", onClick: props.onClose, tabIndex: props.suppressFocus ? -1 : undefined, type: "button" },
16
16
  react_1.default.createElement("span", { className: "sr-only" }, "Remove option"),
17
17
  react_1.default.createElement("svg", { stroke: "currentColor", fill: "none", viewBox: "0 0 8 8" },
18
18
  react_1.default.createElement("path", { strokeLinecap: "round", strokeWidth: "1.5", d: "M1 1l6 6m0-6L1 7" }))))));
@@ -1,6 +1,6 @@
1
1
  import { Placement } from "@floating-ui/react";
2
2
  import { IconsSet } from "@uxf/ui/icon/theme";
3
- import { FormControlProps } from "@uxf/ui/types";
3
+ import { Clearable, FormControlProps } from "@uxf/ui/types";
4
4
  import React, { ReactNode } from "react";
5
5
  export declare type ComboboxValueId = number | string;
6
6
  export declare type ComboboxValue<ValueId = ComboboxValueId> = {
@@ -10,7 +10,7 @@ export declare type ComboboxValue<ValueId = ComboboxValueId> = {
10
10
  export interface ComboboxOption<ValueId = ComboboxValueId> extends ComboboxValue<ValueId> {
11
11
  disabled?: boolean;
12
12
  }
13
- export interface ComboboxProps<ValueId = ComboboxValueId, Option = ComboboxOption<ValueId>> extends FormControlProps<Option | null> {
13
+ export interface ComboboxProps<ValueId = ComboboxValueId, Option = ComboboxOption<ValueId>> extends FormControlProps<Option | null>, Clearable {
14
14
  className?: string;
15
15
  dropdownPlacement?: Placement;
16
16
  helperText?: ReactNode;
@@ -58,8 +58,8 @@ exports.Combobox = (0, forwardRef_1.forwardRef)("Combobox", (props, ref) => {
58
58
  return (react_2.default.createElement(react_1.Combobox, { as: "div", className: (0, cx_1.cx)("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), onChange: (v) => { var _a; return (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v); }, value: (_g = props.value) !== null && _g !== void 0 ? _g : null, disabled: props.isDisabled || props.isReadOnly }, (renderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
59
59
  react_2.default.createElement(react_1.Combobox.Label, { as: label_1.Label, isHidden: props.hiddenLabel, onClick: props.isDisabled || props.isReadOnly ? undefined : input.focus }, props.label),
60
60
  react_2.default.createElement(react_1.Combobox.Button, { as: "div", className: (0, cx_1.cx)("uxf-combobox__button", (renderProps.open || input.focused) && classes_1.CLASSES.IS_FOCUSED, renderProps.disabled && classes_1.CLASSES.IS_DISABLED, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isInvalid && classes_1.CLASSES.IS_INVALID, dropdown.placement === "bottom" && "is-open--bottom", dropdown.placement === "top" && "is-open--top", renderProps.open && classes_1.CLASSES.IS_OPEN), onBlur: input.onBlur, onFocus: input.onFocus, tabIndex: props.isDisabled || props.isReadOnly ? undefined : 0, ref: stableRef, "aria-invalid": props.isInvalid, "aria-describedby": errorId },
61
- react_2.default.createElement(react_1.Combobox.Input, { className: (0, cx_1.cx)("uxf-combobox__input"), displayValue: (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.label) !== null && _a !== void 0 ? _a : ""; }, onBlur: props.onBlur, onChange: (event) => setQuery(event.target.value), placeholder: props.placeholder, ref: stableRef, type: "text" }),
62
- props.value && !props.isDisabled && !props.isReadOnly && (react_2.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
61
+ react_2.default.createElement(react_1.Combobox.Input, { className: "uxf-combobox__input", displayValue: (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.label) !== null && _a !== void 0 ? _a : ""; }, onBlur: props.onBlur, onChange: (event) => setQuery(event.target.value), placeholder: props.placeholder, type: "text" }),
62
+ props.value && !props.isDisabled && !props.isReadOnly && props.isClearable && (react_2.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
63
63
  react_2.default.createElement(icon_1.Icon, { className: (0, cx_1.cx)("uxf-select__button-icon", renderProps.open && "is-open"), name: iconName })),
64
64
  react_2.default.createElement(react_1.Combobox.Options, { className: (0, cx_1.cx)("uxf-dropdown", dropdown.placement === "bottom" && "uxf-dropdown--bottom", dropdown.placement === "top" && "uxf-dropdown--top"), ref: dropdown.floating }, filteredData.length > 0 ? (filteredData.map((option) => {
65
65
  var _a, _b, _c, _d;
@@ -51,7 +51,7 @@ function Default() {
51
51
  react_1.default.createElement(index_1.Combobox, { id: "combobox-1", label: "Combobox", name: "combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
52
52
  react_1.default.createElement(index_1.Combobox, { helperText: "Start typing to see options...", id: "combobox-1", label: "Combobox with helper text", name: "combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
53
53
  react_1.default.createElement(index_1.Combobox, { helperText: "Error message", id: "combobox-1", isInvalid: true, isRequired: true, label: "Combobox invalid", name: "combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
54
- react_1.default.createElement(index_1.Combobox, { dropdownPlacement: "top", id: "combobox-1", label: "Combobox with dropdown top", name: "combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value })));
54
+ react_1.default.createElement(index_1.Combobox, { dropdownPlacement: "top", id: "combobox-1", label: "Combobox with dropdown top", name: "combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", isClearable: true, value: value })));
55
55
  return (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
56
56
  react_1.default.createElement("div", { className: "light space-y-2 p-20 lg:w-1/2" }, storyComboboxes),
57
57
  react_1.default.createElement("div", { className: "dark space-y-2 bg-gray-900 p-20 lg:w-1/2" }, storyComboboxes)));
@@ -2,11 +2,17 @@
2
2
  @apply relative;
3
3
 
4
4
  &__button {
5
- @apply relative flex flex-row w-full cursor-default flex-wrap items-center rounded-lg pl-4 pr-8 pb-2 text-left
5
+ min-height: theme("inputSize.default");
6
+
7
+ @apply relative flex flex-row w-full cursor-default flex-wrap items-center rounded-lg pl-4 pr-8 text-left
6
8
  outline-none before:absolute before:inset-0 before:pointer-events-none before:border before:rounded-lg;
7
9
 
10
+ &--with-popover {
11
+ @apply cursor-text;
12
+ }
13
+
8
14
  .uxf-icon {
9
- @apply absolute top-3 right-4 h-4;
15
+ @apply absolute top-3.5 right-4 h-3;
10
16
  }
11
17
 
12
18
  :root .light & {
@@ -25,7 +31,8 @@
25
31
  }
26
32
  }
27
33
 
28
- &.is-focused {
34
+ &.is-focused,
35
+ &:focus-visible {
29
36
  @apply ring-2;
30
37
 
31
38
  :root .light & {
@@ -59,7 +66,18 @@
59
66
  }
60
67
 
61
68
  &__input {
62
- @apply bg-inherit focus-visible:ring-0 focus-visible:border-0 focus-visible:outline-none;
69
+ @apply bg-inherit focus-visible:ring-0 focus-visible:border-0 focus-visible:outline-none
70
+ shrink grow truncate;
71
+
72
+ &-placeholder {
73
+ &--with-popover {
74
+ @apply text-gray-400;
75
+ }
76
+ }
77
+
78
+ &--with-popover {
79
+ @apply my-1;
80
+ }
63
81
 
64
82
  :root .light & {
65
83
  @apply placeholder:text-lightLow;
@@ -69,4 +87,8 @@
69
87
  @apply placeholder:text-darkLow;
70
88
  }
71
89
  }
90
+
91
+ &__popover-panel {
92
+ @apply absolute top-0 left-0 z-10 w-full;
93
+ }
72
94
  }
@@ -1,7 +1,7 @@
1
1
  import { InputProps } from "@uxf/ui/input/input";
2
- import { FormControlProps } from "@uxf/ui/types";
2
+ import { Clearable, FormControlProps } from "@uxf/ui/types";
3
3
  import React, { ReactNode } from "react";
4
- export interface DatePickerInputProps extends Omit<FormControlProps<Date | null>, "value">, Pick<InputProps, "size" | "variant"> {
4
+ export interface DatePickerInputProps extends Omit<FormControlProps<Date | null>, "value">, Pick<InputProps, "size" | "variant">, Clearable {
5
5
  className?: string;
6
6
  defaultValue?: string;
7
7
  error?: ReactNode;
@@ -83,7 +83,7 @@ exports.DatePickerInput = (0, forwardRef_1.forwardRef)("DatePickerInput", (props
83
83
  react_3.default.createElement(react_2.Popover.Button, { as: "div", className: "uxf-date-picker-input__wrapper", ref: stableRef },
84
84
  react_3.default.createElement("span", { className: "uxf-date-picker-input__left-element" }, props.leftElement),
85
85
  react_3.default.createElement("input", { "aria-describedby": errorId, "aria-errormessage": props.error && errorId ? `${errorId}__error-message` : undefined, "aria-invalid": !!props.error, "aria-live": "polite", autoComplete: "off", className: "uxf-date-picker-input__element", disabled: props.isDisabled, form: props.form, id: id, inputMode: "none", name: props.name, onBlur: onBlur, onChange: () => props.onChange, onFocus: onFocus, placeholder: "Vyberte datum...", readOnly: props.isReadOnly, ref: ref, required: props.isRequired, tabIndex: props.isReadOnly ? -1 : undefined, value: props.value ? (0, dayjs_1.default)(props.value).format("l") : "" }),
86
- props.value && !props.isDisabled && !props.isReadOnly && (react_3.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
86
+ props.value && !props.isDisabled && !props.isReadOnly && props.isClearable && (react_3.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
87
87
  react_3.default.createElement("span", { className: "uxf-date-picker-input__right-element" }, props.rightElement)),
88
88
  !props.isDisabled && !props.isReadOnly && (react_3.default.createElement(react_2.Transition, { as: react_3.Fragment, enter: "transition duration-200 ease-out", enterFrom: "origin-top scale-50 opacity-0", enterTo: "origin-top scale-100 opacity-100", leave: "transition duration-200 ease-out", leaveFrom: "origin-top scale-50 opacity-100", leaveTo: "origin-top scale-0 opacity-0" },
89
89
  react_3.default.createElement(react_2.Popover.Panel, { className: "uxf-date-picker-input__popover", ref: floatingDatePicker.floating, static: true }, ({ close }) => (react_3.default.createElement(date_picker_provider_1.DatePickerProvider, { closePopoverHandler: close, onChange: props.onChange, selectedDate: props.value }))))))));
@@ -28,8 +28,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Default = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
- const date_picker_input_1 = require("./date-picker-input");
32
31
  const icon_1 = require("../icon");
32
+ const date_picker_input_1 = require("./date-picker-input");
33
33
  const date_picker_docs_mdx_1 = __importDefault(require("./date-picker.docs.mdx"));
34
34
  exports.default = {
35
35
  title: "UI/DatePickerInput",
@@ -46,7 +46,7 @@ function Default() {
46
46
  react_1.default.createElement(date_picker_input_1.DatePickerInput, { id: "date-test", name: "date", label: "Datum \u010Dehokoliv", rightElement: react_1.default.createElement(icon_1.Icon, { name: "calendar", size: 20 }), value: date, onChange: (data) => setDate(data !== null && data !== void 0 ? data : null) }),
47
47
  react_1.default.createElement(date_picker_input_1.DatePickerInput, { id: "date-test-disabled", name: "date-disabled", label: "Datum disabled", rightElement: react_1.default.createElement(icon_1.Icon, { name: "calendar", size: 20 }), value: date, onChange: (data) => setDate(data !== null && data !== void 0 ? data : null), isDisabled: true }),
48
48
  react_1.default.createElement(date_picker_input_1.DatePickerInput, { id: "date-test-readonly", name: "date-readonly", label: "Datum readonly", rightElement: react_1.default.createElement(icon_1.Icon, { name: "calendar", size: 20 }), value: date, onChange: (data) => setDate(data !== null && data !== void 0 ? data : null), isReadOnly: true }),
49
- react_1.default.createElement(date_picker_input_1.DatePickerInput, { id: "date-test-invalid", name: "date-invalid", label: "Datum invalid", rightElement: react_1.default.createElement(icon_1.Icon, { name: "calendar", size: 20 }), value: date, onChange: (data) => setDate(data !== null && data !== void 0 ? data : null), isInvalid: true })));
49
+ react_1.default.createElement(date_picker_input_1.DatePickerInput, { id: "date-test-invalid", name: "date-invalid", label: "Datum invalid", rightElement: react_1.default.createElement(icon_1.Icon, { name: "calendar", size: 20 }), value: date, onChange: (data) => setDate(data !== null && data !== void 0 ? data : null), isInvalid: true, isClearable: true })));
50
50
  return (react_1.default.createElement(react_1.default.Fragment, null,
51
51
  react_1.default.createElement("div", { className: "light max-w-[640px] space-y-4 rounded bg-white p-8" }, testDatePickers),
52
52
  react_1.default.createElement("div", { className: "dark max-w-[640px] space-y-4 rounded bg-gray-900 p-8 text-white" }, testDatePickers)));
@@ -1,7 +1,8 @@
1
1
  import { InputGroupSizes, InputGroupVariants } from "@uxf/ui/input/theme";
2
+ import { Clearable } from "@uxf/ui/types";
2
3
  import React, { ReactNode } from "react";
3
4
  import { BaseFileInputProps } from "./file-input-base";
4
- export interface FileInputProps extends BaseFileInputProps {
5
+ export interface FileInputProps extends BaseFileInputProps, Clearable {
5
6
  helperText?: ReactNode;
6
7
  label?: ReactNode;
7
8
  placeholder?: string;
@@ -60,12 +60,12 @@ exports.FileInput = (0, forwardRef_1.forwardRef)("FileInput", (props, ref) => {
60
60
  setIsUploading(false);
61
61
  }
62
62
  };
63
- return (react_1.default.createElement(form_control_1.FormControl, { className: (0, cx_1.cx)(input.focused && classes_1.CLASSES.IS_FOCUSED, (props.isDisabled || props.isReadOnly) && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID), errorId: errorId, form: props.form, helperText: props.helperText, inputId: id, isRequired: props.isRequired, label: props.label },
63
+ return (react_1.default.createElement(form_control_1.FormControl, { className: (0, cx_1.cx)(input.focused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY), errorId: errorId, form: props.form, helperText: props.helperText, inputId: id, isRequired: props.isRequired, label: props.label },
64
64
  react_1.default.createElement(react_1.default.Fragment, null,
65
65
  react_1.default.createElement(file_input_base_1.BaseFileInput, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: "uxf-file-input__input", form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onChange: onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile: props.onUploadFile, ref: ref }),
66
66
  react_1.default.createElement("label", { className: (0, cx_1.cx)("uxf-input", "uxf-file-input__label", input.focused && classes_1.CLASSES.IS_FOCUSED, (props.isDisabled || props.isReadOnly) && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, isUploading && classes_1.CLASSES.IS_LOADING, isUploading && "uxf-file-input__label--has-right-addon", `uxf-input--size-${(_a = props.size) !== null && _a !== void 0 ? _a : "default"}`, `uxf-input--variant-${(_b = props.variant) !== null && _b !== void 0 ? _b : "default"}`), htmlFor: id },
67
67
  react_1.default.createElement("div", { className: "uxf-input__left-addon uxf-file-input__label__button" }, !isUploading ? ("Vyberte soubor") : (react_1.default.createElement(loader_1.Loader, { className: "uxf-file-input__label__loader", size: "sm" }))),
68
68
  react_1.default.createElement("div", { className: "uxf-file-input__label__wrapper" },
69
69
  react_1.default.createElement("span", { className: "uxf-file-input__label__wrapper__file-name" }, props.value ? `${props.value.name}` : props.placeholder || "No file has been selected yet"),
70
- props.value && !props.isDisabled && !props.isReadOnly && (react_1.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })))))));
70
+ props.value && !props.isDisabled && !props.isReadOnly && props.isClearable && (react_1.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })))))));
71
71
  });
@@ -39,7 +39,7 @@ function Default() {
39
39
  };
40
40
  const storyFileInputs = (react_1.default.createElement("div", { className: "space-y-2" },
41
41
  react_1.default.createElement(index_1.FileInput, { label: "Default file input", onChange: setValue, onUploadError: handleUploadError, onUploadFile: uploadFIle_mock_1.uploadFile, value: value }),
42
- react_1.default.createElement(index_1.FileInput, { helperText: "Error file input", id: "error-file-input", isInvalid: true, label: "Error file input", onChange: setValue, onUploadError: handleUploadError, onUploadFile: uploadFIle_mock_1.uploadFile, value: value }),
42
+ react_1.default.createElement(index_1.FileInput, { helperText: "Error file input", id: "error-file-input", isInvalid: true, label: "Error file input", onChange: setValue, onUploadError: handleUploadError, onUploadFile: uploadFIle_mock_1.uploadFile, value: value, isClearable: true }),
43
43
  react_1.default.createElement(index_1.FileInput, { helperText: "Readonly/disabled file input", label: "Readonly/disabled file input", isReadOnly: true, isDisabled: true, onChange: setValue, onUploadError: handleUploadError, onUploadFile: uploadFIle_mock_1.uploadFile, value: value })));
44
44
  return (react_1.default.createElement(react_1.default.Fragment, null,
45
45
  react_1.default.createElement("div", { className: "light space-y-2 p-20" }, storyFileInputs),
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.InputRemoveButton = void 0;
7
- const icon_1 = require("../icon");
7
+ const icon_1 = require("@uxf/ui/icon");
8
8
  const react_1 = __importDefault(require("react"));
9
9
  const InputRemoveButton = (props) => {
10
10
  const onRemoveClick = (e) => {
11
11
  var _a;
12
+ e.preventDefault();
12
13
  e.stopPropagation();
13
14
  (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, null);
14
15
  };
@@ -1 +1,2 @@
1
1
  export * from "./multi-combobox";
2
+ export * from "./types";
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./multi-combobox"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { MultiComboboxProps } from "./types";
3
+ interface MultiComboboxBaseProps extends MultiComboboxProps {
4
+ errorId?: string;
5
+ isPopoverOpen?: boolean;
6
+ }
7
+ export declare const MultiComboboxBase: React.ForwardRefExoticComponent<MultiComboboxBaseProps & React.RefAttributes<HTMLInputElement>>;
8
+ export {};
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.MultiComboboxBase = void 0;
27
+ const react_1 = require("@headlessui/react");
28
+ const classes_1 = require("@uxf/core/constants/classes");
29
+ const useInputFocus_1 = require("@uxf/core/hooks/useInputFocus");
30
+ const composeRefs_1 = require("@uxf/core/utils/composeRefs");
31
+ const cx_1 = require("@uxf/core/utils/cx");
32
+ const forwardRef_1 = require("@uxf/core/utils/forwardRef");
33
+ const slugify_1 = require("@uxf/core/utils/slugify");
34
+ const checkbox_1 = require("@uxf/ui/checkbox");
35
+ const chip_1 = require("@uxf/ui/chip");
36
+ const use_async_loading_1 = require("@uxf/ui/hooks/use-async-loading");
37
+ const icon_1 = require("@uxf/ui/icon");
38
+ const label_1 = require("@uxf/ui/label");
39
+ const react_2 = __importStar(require("react"));
40
+ const use_dropdown_1 = require("../hooks/use-dropdown");
41
+ exports.MultiComboboxBase = (0, forwardRef_1.forwardRef)("MultiComboboxBase", (props, ref) => {
42
+ var _a, _b, _c, _d, _e, _f, _g;
43
+ const isAsync = !!props.loadOptions;
44
+ const [query, setQuery] = (0, react_2.useState)("");
45
+ const options = (0, use_async_loading_1.useAsyncLoading)(query, (_a = props.options) !== null && _a !== void 0 ? _a : [], props.loadOptions);
46
+ const selectedOptions = (_b = props.value) !== null && _b !== void 0 ? _b : [];
47
+ const filteredData = isAsync
48
+ ? options
49
+ : options.filter((item) => {
50
+ var _a;
51
+ return (!((_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === item.id)) || props.withCheckboxes) &&
52
+ (query === "" || (0, slugify_1.slugify)(item.label).includes((0, slugify_1.slugify)(query)));
53
+ });
54
+ const iconName = (_c = props.iconName) !== null && _c !== void 0 ? _c : "chevronDown";
55
+ const dropdown = (0, use_dropdown_1.useDropdown)((_d = props.dropdownPlacement) !== null && _d !== void 0 ? _d : "bottom", true);
56
+ const inputRef = (0, react_2.useRef)(null);
57
+ const input = (0, useInputFocus_1.useInputFocus)(inputRef, props.onBlur, props.onFocus);
58
+ const stableRef = (0, react_2.useMemo)(() => (0, composeRefs_1.composeRefs)(inputRef, ref, dropdown.reference), [ref, dropdown.reference]);
59
+ const handleRemove = (valueId) => (e) => {
60
+ var _a, _b, _c;
61
+ e === null || e === void 0 ? void 0 : e.preventDefault();
62
+ e === null || e === void 0 ? void 0 : e.stopPropagation();
63
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.filter((v) => v.id !== valueId)) !== null && _c !== void 0 ? _c : []);
64
+ };
65
+ const handleCheckboxChange = (valueId) => (checked) => {
66
+ var _a, _b, _c, _d;
67
+ if (((_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === valueId)) && !checked) {
68
+ handleRemove(valueId)();
69
+ return;
70
+ }
71
+ const newOption = options.find((o) => o.id === valueId);
72
+ //adding new option if not in value
73
+ if (!((_b = props.value) === null || _b === void 0 ? void 0 : _b.some((v) => v.id === valueId)) && checked && newOption) {
74
+ (_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, [...((_d = props.value) !== null && _d !== void 0 ? _d : []), newOption]);
75
+ }
76
+ };
77
+ const handleInputKeyDown = (event) => {
78
+ if (event.key === "Backspace" && query === "" && selectedOptions.length > 0) {
79
+ handleRemove(selectedOptions[selectedOptions.length - 1].id)();
80
+ }
81
+ };
82
+ const handleInputChange = (event) => setQuery(event.target.value);
83
+ const handleComboboxValueChange = (v) => {
84
+ var _a;
85
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v.map((option) => option));
86
+ setQuery("");
87
+ };
88
+ const emptyMessage = query.length === 0
89
+ ? (_e = props.noQueryMessage) !== null && _e !== void 0 ? _e : "Pro zobrazení možností začněte psát"
90
+ : selectedOptions.length === options.length && selectedOptions.length > 0
91
+ ? (_f = props.allOptionsSelectedMessage) !== null && _f !== void 0 ? _f : "Všechny možnosti jsou již vybrány"
92
+ : (_g = props.notFoundMessage) !== null && _g !== void 0 ? _g : "Nic nenalezeno";
93
+ return (react_2.default.createElement(react_1.Combobox, { as: "div", by: "id", className: (0, cx_1.cx)("uxf-multi-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), disabled: props.isDisabled || props.isReadOnly, multiple: true, onChange: handleComboboxValueChange, value: selectedOptions }, (renderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
94
+ !props.withPopover && (react_2.default.createElement(react_1.Combobox.Label, { as: label_1.Label, isHidden: props.hiddenLabel, onClick: props.isDisabled || props.isReadOnly ? undefined : input.focus }, props.label)),
95
+ react_2.default.createElement(react_1.Combobox.Button, { as: "div", className: (0, cx_1.cx)("uxf-multi-combobox__button pb-[7px]", (renderProps.open || input.focused) && classes_1.CLASSES.IS_FOCUSED, renderProps.disabled && classes_1.CLASSES.IS_DISABLED, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isInvalid && classes_1.CLASSES.IS_INVALID, dropdown.placement === "bottom" && "is-open--bottom", dropdown.placement === "top" && "is-open--top", renderProps.open && classes_1.CLASSES.IS_OPEN), onBlur: input.onBlur, onFocus: input.onFocus, ref: stableRef, tabIndex: props.isDisabled || props.isReadOnly ? undefined : 0, "aria-invalid": props.isInvalid, "aria-describedby": props.errorId },
96
+ selectedOptions.map((item) => (react_2.default.createElement(chip_1.Chip, { className: "mt-[7px] mr-2", color: item.color, key: item.id, onClose: handleRemove(item.id), size: "large", suppressFocus: true }, item.label))),
97
+ react_2.default.createElement(react_1.Combobox.Input, { className: "uxf-multi-combobox__input mt-[7px]", onChange: handleInputChange, onKeyDown: handleInputKeyDown, placeholder: props.placeholder, type: "text", value: query }),
98
+ react_2.default.createElement(icon_1.Icon, { className: (0, cx_1.cx)("uxf-select__button-icon", (props.withPopover ? props.isPopoverOpen : renderProps.open) && "is-open"), name: iconName })),
99
+ react_2.default.createElement(react_1.Combobox.Options, { className: (0, cx_1.cx)("uxf-dropdown", dropdown.placement === "bottom" && "uxf-dropdown--bottom", dropdown.placement === "top" && "uxf-dropdown--top"), static: props.withPopover, ref: dropdown.floating }, filteredData.length > 0 ? (filteredData.map((option) => {
100
+ var _a, _b, _c, _d;
101
+ const label = (_b = (_a = props.renderOption) === null || _a === void 0 ? void 0 : _a.call(props, option)) !== null && _b !== void 0 ? _b : option.label;
102
+ return (react_2.default.createElement(react_1.Combobox.Option, { className: (optionState) => (0, cx_1.cx)("uxf-dropdown__item", optionState.active && !props.withCheckboxes && classes_1.CLASSES.IS_ACTIVE, optionState.disabled && classes_1.CLASSES.IS_DISABLED, optionState.selected && classes_1.CLASSES.IS_SELECTED), key: (_d = (_c = props.keyExtractor) === null || _c === void 0 ? void 0 : _c.call(props, option)) !== null && _d !== void 0 ? _d : option.id, value: option }, (optionState) => (react_2.default.createElement(react_2.default.Fragment, null, props.withCheckboxes ? (react_2.default.createElement(checkbox_1.Checkbox, { isDisabled: optionState.disabled, isFocused: optionState.active, label: label, onChange: handleCheckboxChange(option.id), value: optionState.selected })) : (label)))));
103
+ })) : (react_2.default.createElement("div", { className: "uxf-dropdown__empty-wrapper" }, emptyMessage))),
104
+ props.helperText && !props.withPopover && (react_2.default.createElement("div", { className: (0, cx_1.cx)("uxf-helper-text", props.isInvalid && classes_1.CLASSES.IS_INVALID), id: props.errorId }, props.helperText))))));
105
+ });
@@ -1,33 +1,3 @@
1
- import { Placement } from "@floating-ui/react";
2
- import React, { ReactNode } from "react";
3
- import { ChipColor } from "../chip";
4
- import { IconsSet } from "../icon/theme";
5
- import { FormControlProps } from "../types";
6
- export declare type MultiComboboxValueId = number | string;
7
- export declare type MultiComboboxValue<ValueId = MultiComboboxValueId> = {
8
- id: ValueId;
9
- label: string;
10
- };
11
- export interface MultiComboboxOption<ValueId = MultiComboboxValueId> extends MultiComboboxValue<ValueId> {
12
- color?: ChipColor;
13
- disabled?: boolean;
14
- }
15
- export interface MultiComboboxProps<ValueId = MultiComboboxValueId, Option = MultiComboboxOption<ValueId>> extends FormControlProps<Option[] | null> {
16
- allOptionsSelectedMessage?: string;
17
- className?: string;
18
- dropdownPlacement?: Placement;
19
- helperText?: ReactNode;
20
- hiddenLabel?: boolean;
21
- iconName?: keyof IconsSet;
22
- id?: string;
23
- keyExtractor?: (option: Option) => string | number;
24
- label: string;
25
- loadOptions?: (query: string) => Promise<Option[]>;
26
- noQueryMessage?: string;
27
- notFoundMessage?: string;
28
- options?: Option[];
29
- placeholder?: string;
30
- renderOption?: (option: Option) => ReactNode;
31
- withCheckboxes?: boolean;
32
- }
33
- export declare const MultiCombobox: React.ForwardRefExoticComponent<MultiComboboxProps<MultiComboboxValueId, MultiComboboxOption<MultiComboboxValueId>> & React.RefAttributes<HTMLDivElement>>;
1
+ import React from "react";
2
+ import { MultiComboboxProps } from "./types";
3
+ export declare const MultiCombobox: React.ForwardRefExoticComponent<MultiComboboxProps<import("./types").MultiComboboxValueId, import("./types").MultiComboboxOption<import("./types").MultiComboboxValueId>> & React.RefAttributes<HTMLInputElement>>;
@@ -26,81 +26,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.MultiCombobox = void 0;
27
27
  const react_1 = require("@headlessui/react");
28
28
  const classes_1 = require("@uxf/core/constants/classes");
29
- const useInputFocus_1 = require("@uxf/core/hooks/useInputFocus");
30
- const composeRefs_1 = require("@uxf/core/utils/composeRefs");
31
29
  const cx_1 = require("@uxf/core/utils/cx");
32
30
  const forwardRef_1 = require("@uxf/core/utils/forwardRef");
33
- const slugify_1 = require("@uxf/core/utils/slugify");
31
+ const form_control_1 = require("@uxf/ui/form-control");
32
+ const icon_1 = require("@uxf/ui/icon");
34
33
  const react_2 = __importStar(require("react"));
35
- const checkbox_1 = require("../checkbox");
36
- const chip_1 = require("../chip");
37
- const use_dropdown_1 = require("../hooks/use-dropdown");
38
- const icon_1 = require("../icon");
39
- const label_1 = require("../label");
40
- const use_async_loading_1 = require("../hooks/use-async-loading");
34
+ const multi_combobox_base_1 = require("./multi-combobox-base");
41
35
  exports.MultiCombobox = (0, forwardRef_1.forwardRef)("MultiCombobox", (props, ref) => {
42
- var _a, _b, _c, _d, _e, _f, _g, _h;
36
+ var _a, _b, _c;
43
37
  const generatedId = (0, react_2.useId)();
44
38
  const id = (_a = props.id) !== null && _a !== void 0 ? _a : generatedId;
45
- const isAsync = !!props.loadOptions;
46
- const [query, setQuery] = (0, react_2.useState)("");
47
- const options = (0, use_async_loading_1.useAsyncLoading)(query, (_b = props.options) !== null && _b !== void 0 ? _b : [], props.loadOptions);
48
- const selectedOptions = (_c = props.value) !== null && _c !== void 0 ? _c : [];
49
- const filteredData = isAsync
50
- ? options
51
- : options.filter((item) => {
52
- var _a;
53
- return (!((_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === item.id)) || props.withCheckboxes) &&
54
- (query === "" || (0, slugify_1.slugify)(item.label).includes((0, slugify_1.slugify)(query)));
55
- });
56
- const innerRef = (0, react_2.useRef)(null);
57
39
  const errorId = props.isInvalid ? `${id}--error-message` : undefined;
58
- const input = (0, useInputFocus_1.useInputFocus)(innerRef, props.onBlur, props.onFocus);
59
- const dropdown = (0, use_dropdown_1.useDropdown)((_d = props.dropdownPlacement) !== null && _d !== void 0 ? _d : "bottom", true);
60
- const stableRef = (0, react_2.useMemo)(() => (0, composeRefs_1.composeRefs)(innerRef, ref, dropdown.reference), [ref, dropdown.reference]);
61
- const iconName = (_e = props.iconName) !== null && _e !== void 0 ? _e : "chevronDown";
62
- const handleRemove = (valueId) => () => {
63
- var _a, _b, _c;
64
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.filter((v) => v.id !== valueId)) !== null && _c !== void 0 ? _c : []);
65
- };
66
- const handleCheckboxChange = (valueId) => (checked) => {
67
- var _a, _b, _c, _d;
68
- if (((_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === valueId)) && !checked) {
69
- handleRemove(valueId)();
70
- return;
71
- }
72
- const newOption = options.find((o) => o.id === valueId);
73
- //adding new option if not in value
74
- if (!((_b = props.value) === null || _b === void 0 ? void 0 : _b.some((v) => v.id === valueId)) && checked && newOption) {
75
- (_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, [...((_d = props.value) !== null && _d !== void 0 ? _d : []), newOption]);
76
- }
77
- };
78
- const handleInputKeyDown = (event) => {
79
- if (event.key === "Backspace" && query === "" && selectedOptions.length > 0) {
80
- handleRemove(selectedOptions[selectedOptions.length - 1].id)();
81
- }
82
- };
83
- const handleInputChange = (event) => setQuery(event.target.value);
84
- const handleComboboxValueChange = (v) => {
40
+ const fakeInputId = `${id}--fake-input`;
41
+ const iconName = (_b = props.iconName) !== null && _b !== void 0 ? _b : "chevronDown";
42
+ const selectedOptions = (_c = props.value) !== null && _c !== void 0 ? _c : [];
43
+ const fakeInputRef = (0, react_2.useRef)(null);
44
+ const handlePopoverButtonKeyPress = (e) => {
85
45
  var _a;
86
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v.map((option) => option));
87
- setQuery("");
46
+ if (e.key.length === 1 || e.key === "Backspace" || e.key === "Delete") {
47
+ (_a = fakeInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
48
+ e.stopPropagation();
49
+ if (e.key === "Backspace" || e.key === "Delete" || e.key === " ") {
50
+ e.preventDefault();
51
+ }
52
+ }
88
53
  };
89
- const emptyMessage = query.length === 0
90
- ? (_f = props.noQueryMessage) !== null && _f !== void 0 ? _f : "Pro zobrazení možností začněte psát"
91
- : selectedOptions.length === options.length && selectedOptions.length > 0
92
- ? (_g = props.allOptionsSelectedMessage) !== null && _g !== void 0 ? _g : "Všechny možnosti jsou již vybrány"
93
- : (_h = props.notFoundMessage) !== null && _h !== void 0 ? _h : "Nic nenalezeno";
94
- return (react_2.default.createElement(react_1.Combobox, { as: "div", by: "id", className: (0, cx_1.cx)("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), disabled: props.isDisabled || props.isReadOnly, multiple: true, onChange: handleComboboxValueChange, value: selectedOptions }, (renderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
95
- react_2.default.createElement(react_1.Combobox.Label, { as: label_1.Label, isHidden: props.hiddenLabel, onClick: props.isDisabled || props.isReadOnly ? undefined : input.focus }, props.label),
96
- react_2.default.createElement(react_1.Combobox.Button, { as: "div", className: (0, cx_1.cx)("uxf-multi-combobox__button", (renderProps.open || input.focused) && classes_1.CLASSES.IS_FOCUSED, renderProps.disabled && classes_1.CLASSES.IS_DISABLED, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isInvalid && classes_1.CLASSES.IS_INVALID, dropdown.placement === "bottom" && "is-open--bottom", dropdown.placement === "top" && "is-open--top", renderProps.open && classes_1.CLASSES.IS_OPEN), onBlur: input.onBlur, onFocus: input.onFocus, tabIndex: props.isDisabled || props.isReadOnly ? undefined : 0, ref: stableRef, "aria-invalid": props.isInvalid, "aria-describedby": errorId },
97
- selectedOptions.map((item) => (react_2.default.createElement(chip_1.Chip, { className: "mr-2 mt-2", color: item.color, key: item.id, onClose: handleRemove(item.id), size: "large" }, item.label))),
98
- react_2.default.createElement(react_1.Combobox.Input, { className: (0, cx_1.cx)("uxf-multi-combobox__input", "mt-2"), onBlur: props.onBlur, onChange: handleInputChange, onKeyDown: handleInputKeyDown, placeholder: props.placeholder, ref: stableRef, type: "text", value: query }),
99
- react_2.default.createElement(icon_1.Icon, { className: (0, cx_1.cx)("uxf-select__button-icon", renderProps.open && "is-open"), name: iconName })),
100
- react_2.default.createElement(react_1.Combobox.Options, { className: (0, cx_1.cx)("uxf-dropdown", dropdown.placement === "bottom" && "uxf-dropdown--bottom", dropdown.placement === "top" && "uxf-dropdown--top"), ref: dropdown.floating }, filteredData.length > 0 ? (filteredData.map((option) => {
101
- var _a, _b, _c, _d;
102
- const label = (_b = (_a = props.renderOption) === null || _a === void 0 ? void 0 : _a.call(props, option)) !== null && _b !== void 0 ? _b : option.label;
103
- return (react_2.default.createElement(react_1.Combobox.Option, { className: (optionState) => (0, cx_1.cx)("uxf-dropdown__item", optionState.active && !props.withCheckboxes && classes_1.CLASSES.IS_ACTIVE, optionState.disabled && classes_1.CLASSES.IS_DISABLED, optionState.selected && classes_1.CLASSES.IS_SELECTED), key: (_d = (_c = props.keyExtractor) === null || _c === void 0 ? void 0 : _c.call(props, option)) !== null && _d !== void 0 ? _d : option.id, value: option }, (optionState) => (react_2.default.createElement(react_2.default.Fragment, null, props.withCheckboxes ? (react_2.default.createElement(checkbox_1.Checkbox, { isDisabled: optionState.disabled, isFocused: optionState.active, label: label, onChange: handleCheckboxChange(option.id), value: optionState.selected })) : (label)))));
104
- })) : (react_2.default.createElement("div", { className: "uxf-dropdown__empty-wrapper" }, emptyMessage))),
105
- props.helperText && (react_2.default.createElement("div", { className: (0, cx_1.cx)("uxf-helper-text", props.isInvalid && classes_1.CLASSES.IS_INVALID), id: errorId }, props.helperText))))));
54
+ if (!props.withPopover) {
55
+ return react_2.default.createElement(multi_combobox_base_1.MultiComboboxBase, { ...props, errorId: errorId, ref: ref });
56
+ }
57
+ return (react_2.default.createElement(form_control_1.FormControl, { className: (0, cx_1.cx)(props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY), errorId: errorId, form: props.form, helperText: props.helperText, inputId: fakeInputId, isRequired: props.isRequired, label: props.label },
58
+ react_2.default.createElement(react_1.Popover, { className: (0, cx_1.cx)("uxf-multi-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) }, (popoverRenderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
59
+ react_2.default.createElement(react_1.Popover.Button, { className: (0, cx_1.cx)("uxf-multi-combobox__button uxf-multi-combobox__button--with-popover", popoverRenderProps.open && classes_1.CLASSES.IS_OPEN, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isInvalid && classes_1.CLASSES.IS_INVALID), id: fakeInputId, onKeyDown: handlePopoverButtonKeyPress, ref: fakeInputRef },
60
+ react_2.default.createElement("span", { className: (0, cx_1.cx)("uxf-multi-combobox__input uxf-multi-combobox__input--with-popover", selectedOptions.length === 0 &&
61
+ "uxf-multi-combobox__input-placeholder--with-popover") }, selectedOptions.length > 0
62
+ ? selectedOptions.map((e) => e.label).join(", ")
63
+ : props.placeholder),
64
+ react_2.default.createElement(icon_1.Icon, { className: "uxf-select__button-icon", name: iconName })),
65
+ react_2.default.createElement(react_1.Popover.Panel, { className: "uxf-multi-combobox__popover-panel", focus: popoverRenderProps.open, unmount: false },
66
+ react_2.default.createElement(multi_combobox_base_1.MultiComboboxBase, { ...props, errorId: errorId, isPopoverOpen: popoverRenderProps.open, ref: ref, withPopover: true })))))));
106
67
  });
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
- import { MultiComboboxOption } from "./index";
2
+ import { MultiComboboxOption } from "./types";
3
3
  declare const _default: {
4
4
  title: string;
5
- component: React.ForwardRefExoticComponent<import("./multi-combobox").MultiComboboxProps<import("./multi-combobox").MultiComboboxValueId, MultiComboboxOption<import("./multi-combobox").MultiComboboxValueId>> & React.RefAttributes<HTMLDivElement>>;
5
+ component: React.ForwardRefExoticComponent<import("./types").MultiComboboxProps<import("./types").MultiComboboxValueId, MultiComboboxOption<import("./types").MultiComboboxValueId>> & React.RefAttributes<HTMLInputElement>>;
6
6
  };
7
7
  export default _default;
8
8
  export declare function Default(): JSX.Element;
@@ -29,10 +29,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ComponentStructure = exports.Async = exports.Default = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
31
  const component_structure_analyzer_1 = __importDefault(require("../utils/component-structure-analyzer"));
32
- const index_1 = require("./index");
32
+ const multi_combobox_1 = require("./multi-combobox");
33
33
  exports.default = {
34
34
  title: "UI/MultiCombobox",
35
- component: index_1.MultiCombobox,
35
+ component: multi_combobox_1.MultiCombobox,
36
36
  };
37
37
  const options = [
38
38
  { id: "one", label: "Option red", color: "red" },
@@ -50,11 +50,13 @@ function Default() {
50
50
  setValues(v);
51
51
  };
52
52
  const storyComboboxes = (react_1.default.createElement("div", { className: "space-y-8" },
53
- react_1.default.createElement(index_1.MultiCombobox, { id: "multi-combobox-1", label: "MultiCombobox", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values }),
54
- react_1.default.createElement(index_1.MultiCombobox, { id: "multi-combobox-1", label: "MultiCombobox with checkboxes", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values, withCheckboxes: true }),
55
- react_1.default.createElement(index_1.MultiCombobox, { helperText: "Start typing to see options...", id: "multi-combobox-1", label: "MultiCombobox with helper text", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values }),
56
- react_1.default.createElement(index_1.MultiCombobox, { helperText: "Error message", id: "multi-combobox-1", isInvalid: true, isRequired: true, label: "MultiCombobox invalid", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values }),
57
- react_1.default.createElement(index_1.MultiCombobox, { dropdownPlacement: "top", id: "multi-combobox-1", label: "MultiCombobox with dropdown top", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values })));
53
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { id: "multi-combobox-1", label: "MultiCombobox", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte pros\u00EDm jednu nebo v\u00EDce mo\u017Enost\u00ED", value: values }),
54
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { id: "multi-combobox-2", label: "MultiCombobox with checkboxes", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values, withCheckboxes: true }),
55
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { dropdownPlacement: "top", id: "multi-combobox-3", label: "MultiCombobox with popover", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values, withPopover: true }),
56
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { id: "multi-combobox-4", label: "MultiCombobox with popup and checkboxes", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values, withCheckboxes: true, withPopover: true }),
57
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { helperText: "Start typing to see options...", id: "multi-combobox-5", label: "MultiCombobox with helper text", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values }),
58
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { helperText: "Error message", id: "multi-combobox-6", isInvalid: true, isRequired: true, label: "MultiCombobox invalid", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values }),
59
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { dropdownPlacement: "top", id: "multi-combobox-7", label: "MultiCombobox with dropdown top", name: "multi-combobox", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: values })));
58
60
  return (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
59
61
  react_1.default.createElement("div", { className: "light space-y-2 p-20 lg:w-1/2" }, storyComboboxes),
60
62
  react_1.default.createElement("div", { className: "dark space-y-2 bg-gray-900 p-20 lg:w-1/2" }, storyComboboxes)));
@@ -68,7 +70,7 @@ function Async() {
68
70
  setValues(v);
69
71
  };
70
72
  const storyComboboxes = (react_1.default.createElement("div", { className: "space-y-8" },
71
- react_1.default.createElement(index_1.MultiCombobox, { id: "multi-combobox-1", label: "MultiCombobox", name: "multi-combobox", onChange: handleChange, loadOptions: (query) => Promise.resolve(options.filter((option) => !query || option.label.toLowerCase().includes(query.toLowerCase()))), placeholder: "Vyberte ..", value: values })));
73
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { id: "multi-combobox-async-1", label: "MultiCombobox", name: "multi-combobox", onChange: handleChange, loadOptions: (query) => Promise.resolve(options.filter((option) => !query || option.label.toLowerCase().includes(query.toLowerCase()))), placeholder: "Vyberte ..", value: values })));
72
74
  return (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
73
75
  react_1.default.createElement("div", { className: "light space-y-2 p-20 lg:w-1/2" }, storyComboboxes),
74
76
  react_1.default.createElement("div", { className: "dark space-y-2 bg-gray-900 p-20 lg:w-1/2" }, storyComboboxes)));
@@ -80,6 +82,6 @@ function ComponentStructure() {
80
82
  setValues(v);
81
83
  };
82
84
  return (react_1.default.createElement(component_structure_analyzer_1.default, null,
83
- react_1.default.createElement(index_1.MultiCombobox, { id: "multi-combobox-structure", name: "multi-combobox", label: "MultiCombobox with helper text", options: options, onChange: handleChange, value: values, helperText: "Start typing to see options..." })));
85
+ react_1.default.createElement(multi_combobox_1.MultiCombobox, { id: "multi-combobox-structure", name: "multi-combobox", label: "MultiCombobox with helper text", options: options, onChange: handleChange, value: values, helperText: "Start typing to see options..." })));
84
86
  }
85
87
  exports.ComponentStructure = ComponentStructure;
@@ -0,0 +1,35 @@
1
+ import { Placement } from "@floating-ui/react";
2
+ import { ReactNode } from "react";
3
+ import { ChipColor } from "../chip";
4
+ import { IconsSet } from "../icon/theme";
5
+ import { FormControlProps } from "../types";
6
+ export declare type MultiComboboxValueId = number | string;
7
+ export declare type MultiComboboxValue<ValueId = MultiComboboxValueId> = {
8
+ id: ValueId;
9
+ label: string;
10
+ };
11
+ export interface MultiComboboxOption<ValueId = MultiComboboxValueId> extends MultiComboboxValue<ValueId> {
12
+ color?: ChipColor;
13
+ disabled?: boolean;
14
+ }
15
+ export interface MultiComboboxProps<ValueId = MultiComboboxValueId, Option = MultiComboboxOption<ValueId>> extends FormControlProps<Option[] | null> {
16
+ allOptionsSelectedMessage?: string;
17
+ className?: string;
18
+ dropdownPlacement?: Placement;
19
+ form?: string;
20
+ helperText?: ReactNode;
21
+ hiddenLabel?: boolean;
22
+ iconName?: keyof IconsSet;
23
+ id?: string;
24
+ keyExtractor?: (option: Option) => string | number;
25
+ label: string;
26
+ loadOptions?: (query: string) => Promise<Option[]>;
27
+ noQueryMessage?: string;
28
+ notFoundMessage?: string;
29
+ options?: Option[];
30
+ placeholder?: string;
31
+ renderOption?: (option: Option) => ReactNode;
32
+ withCheckboxes?: boolean;
33
+ withPopover?: boolean;
34
+ }
35
+ export declare type MultiComboboxRef = HTMLInputElement;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "1.0.0-beta.122",
3
+ "version": "1.0.0-beta.124",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,7 +1,7 @@
1
1
  import type { Placement } from "@floating-ui/react";
2
2
  import { IconsSet } from "@uxf/ui/icon/theme";
3
3
  import { SelectSizes } from "@uxf/ui/select/theme";
4
- import { FormControlProps } from "@uxf/ui/types";
4
+ import { Clearable, FormControlProps } from "@uxf/ui/types";
5
5
  import React, { ReactNode } from "react";
6
6
  export declare type SelectValue = number | string;
7
7
  export declare type SelectOption<T = SelectValue> = {
@@ -9,7 +9,7 @@ export declare type SelectOption<T = SelectValue> = {
9
9
  id: T;
10
10
  label: ReactNode;
11
11
  };
12
- export interface SelectProps<Value = SelectValue, Option = SelectOption<Value>> extends FormControlProps<Value | null> {
12
+ export interface SelectProps<Value = SelectValue, Option = SelectOption<Value>> extends FormControlProps<Value | null>, Clearable {
13
13
  className?: string;
14
14
  dropdownPlacement?: Placement;
15
15
  helperText?: ReactNode;
package/select/select.js CHANGED
@@ -30,8 +30,8 @@ const useInputFocus_1 = require("@uxf/core/hooks/useInputFocus");
30
30
  const composeRefs_1 = require("@uxf/core/utils/composeRefs");
31
31
  const cx_1 = require("@uxf/core/utils/cx");
32
32
  const forwardRef_1 = require("@uxf/core/utils/forwardRef");
33
+ const icon_1 = require("@uxf/ui//icon");
33
34
  const use_dropdown_1 = require("@uxf/ui/hooks/use-dropdown");
34
- const icon_1 = require("../icon");
35
35
  const input_1 = require("@uxf/ui/input");
36
36
  const label_1 = require("@uxf/ui/label");
37
37
  const react_2 = __importStar(require("react"));
@@ -50,7 +50,7 @@ exports.Select = (0, forwardRef_1.forwardRef)("Select", (props, ref) => {
50
50
  react_2.default.createElement(react_1.Listbox.Label, { as: label_1.Label, isHidden: props.hiddenLabel, onClick: props.isDisabled || props.isReadOnly ? undefined : input.focus }, props.label),
51
51
  react_2.default.createElement(react_1.Listbox.Button, { as: "div", className: (0, cx_1.cx)("uxf-select__button", (renderProps.open || input.focused) && classes_1.CLASSES.IS_FOCUSED, renderProps.disabled && classes_1.CLASSES.IS_DISABLED, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isInvalid && classes_1.CLASSES.IS_INVALID, dropdown.placement === "bottom" && "is-open--bottom", dropdown.placement === "top" && "is-open--top", renderProps.open && "is-open"), onBlur: input.onBlur, onFocus: input.onFocus, tabIndex: props.isDisabled || props.isReadOnly ? undefined : 0, ref: stableRef, "aria-invalid": props.isInvalid, "aria-describedby": errorId },
52
52
  react_2.default.createElement("div", { className: (0, cx_1.cx)("uxf-select__button-text", !(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) && "is-empty") }, (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || props.placeholder),
53
- props.value && !props.isDisabled && !props.isReadOnly && (react_2.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
53
+ props.value && !props.isDisabled && !props.isReadOnly && props.isClearable && (react_2.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
54
54
  react_2.default.createElement(icon_1.Icon, { className: (0, cx_1.cx)("uxf-select__button-icon", renderProps.open && "is-open"), name: iconName })),
55
55
  react_2.default.createElement(react_1.Listbox.Options, { ref: dropdown.floating, className: (0, cx_1.cx)("uxf-dropdown", dropdown.placement === "bottom" && "uxf-dropdown--bottom", dropdown.placement === "top" && "uxf-dropdown--top") }, props.options.map((option) => {
56
56
  var _a, _b, _c, _d;
@@ -55,7 +55,7 @@ function Default() {
55
55
  };
56
56
  const storySelects = (react_1.default.createElement(react_1.default.Fragment, null,
57
57
  react_1.default.createElement(index_1.Select, { helperText: "Helper text", label: "Default select", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
58
- react_1.default.createElement(index_1.Select, { helperText: "Helper text", isInvalid: true, label: "Invalid select", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
58
+ react_1.default.createElement(index_1.Select, { helperText: "Helper text", isInvalid: true, label: "Invalid select", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value, isClearable: true }),
59
59
  react_1.default.createElement(index_1.Select, { helperText: "Helper text", isDisabled: true, label: "Disabled select", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
60
60
  react_1.default.createElement(index_1.Select, { helperText: "Helper text", isReadOnly: true, label: "Read only select", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
61
61
  react_1.default.createElement(index_1.Select, { helperText: "Helper text", isRequired: true, label: "Required select", onChange: handleChange, options: options, placeholder: "Vyberte ..", value: value }),
@@ -36,7 +36,7 @@ exports.TextInput = (0, forwardRef_1.forwardRef)("TextInput", (props, ref) => {
36
36
  const generatedId = (0, react_1.useId)();
37
37
  const id = (_a = props.id) !== null && _a !== void 0 ? _a : generatedId;
38
38
  const errorId = props.isInvalid ? `${id}--error-message` : undefined;
39
- const rootClassName = (0, cx_1.cx)("uxf-text-input", isFocused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isRequired && classes_1.CLASSES.IS_REQUIRED, props.className);
39
+ const rootClassName = (0, cx_1.cx)("uxf-text-input", isFocused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isRequired && classes_1.CLASSES.IS_REQUIRED, props.className);
40
40
  const onFocus = (e) => {
41
41
  var _a;
42
42
  setIsFocused(true);
@@ -49,7 +49,7 @@ exports.Textarea = (0, forwardRef_1.forwardRef)("Textarea", (props, ref) => {
49
49
  const generatedId = (0, react_1.useId)();
50
50
  const id = (_a = props.id) !== null && _a !== void 0 ? _a : generatedId;
51
51
  const errorId = props.isInvalid ? `${id}--error-message` : undefined;
52
- const rootClassName = (0, cx_1.cx)("uxf-textarea", isFocused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isRequired && classes_1.CLASSES.IS_REQUIRED, props.isReadOnly && classes_1.CLASSES.IS_READONLY);
52
+ const rootClassName = (0, cx_1.cx)("uxf-textarea", isFocused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isRequired && classes_1.CLASSES.IS_REQUIRED, props.className);
53
53
  const onFocus = (e) => {
54
54
  var _a;
55
55
  setIsFocused(true);
@@ -1,8 +1,8 @@
1
1
  import { TimeType } from "@uxf/datepicker/hooks/use-time-picker";
2
2
  import { InputProps } from "@uxf/ui/input/input";
3
- import { FormControlProps } from "@uxf/ui/types";
3
+ import { Clearable, FormControlProps } from "@uxf/ui/types";
4
4
  import React, { ReactNode } from "react";
5
- export interface TimePickerInputProps extends Omit<FormControlProps<TimeType | null>, "value">, Pick<InputProps, "size" | "variant"> {
5
+ export interface TimePickerInputProps extends Omit<FormControlProps<TimeType | null>, "value">, Pick<InputProps, "size" | "variant">, Clearable {
6
6
  className?: string;
7
7
  defaultValue?: string;
8
8
  error?: ReactNode;
@@ -34,6 +34,7 @@ const form_control_1 = require("@uxf/ui/form-control");
34
34
  const input_1 = require("@uxf/ui/input");
35
35
  const react_3 = __importStar(require("react"));
36
36
  const time_picker_1 = require("./time-picker");
37
+ // eslint-disable-next-line complexity
37
38
  exports.TimePickerInput = (0, forwardRef_1.forwardRef)("TimePickerInput", (props, ref) => {
38
39
  var _a;
39
40
  const [isFocused, setIsFocused] = (0, react_3.useState)(false);
@@ -81,7 +82,7 @@ exports.TimePickerInput = (0, forwardRef_1.forwardRef)("TimePickerInput", (props
81
82
  react_3.default.createElement("input", { "aria-describedby": errorId, "aria-errormessage": props.error && errorId ? `${errorId}__error-message` : undefined, "aria-invalid": !!props.error, "aria-live": "polite", autoComplete: "off", className: "uxf-time-picker-input__element", disabled: props.isDisabled, form: props.form, id: id, inputMode: "text", name: props.name, onBlur: onBlur, onChange: () => props.onChange, onFocus: onFocus, placeholder: "Vyberte \u010Das...", readOnly: props.isReadOnly, ref: ref, required: props.isRequired, tabIndex: props.isReadOnly ? -1 : undefined, value: props.value
82
83
  ? `${props.value.hour}:${props.value.minute < 10 ? "0" + props.value.minute : props.value.minute}`
83
84
  : "" }),
84
- props.value && !props.isDisabled && !props.isReadOnly && (react_3.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
85
+ props.value && !props.isDisabled && !props.isReadOnly && props.isClearable && (react_3.default.createElement(input_1.Input.RemoveButton, { onChange: props.onChange })),
85
86
  react_3.default.createElement("span", { className: "uxf-time-picker-input__right-element" }, props.rightElement)),
86
87
  !props.isDisabled && !props.isReadOnly && (react_3.default.createElement(react_2.Transition, { as: react_3.Fragment, enter: "transition duration-200 ease-out", enterFrom: "origin-top scale-50 opacity-0", enterTo: "origin-top scale-100 opacity-100", leave: "transition duration-200 ease-out", leaveFrom: "origin-top scale-50 opacity-100", leaveTo: "origin-top scale-0 opacity-0" },
87
88
  react_3.default.createElement(react_2.Popover.Panel, { className: "uxf-time-picker-input__popover", ref: floatingTimePicker.floating, static: true }, ({ close }) => {
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Default = void 0;
27
+ const icon_1 = require("@uxf/ui//icon");
27
28
  const react_1 = __importStar(require("react"));
28
29
  const time_picker_input_1 = require("./time-picker-input");
29
- const icon_1 = require("../icon");
30
30
  exports.default = {
31
31
  title: "UI/TimePickerInput",
32
32
  component: time_picker_input_1.TimePickerInput,
@@ -37,7 +37,7 @@ function Default() {
37
37
  react_1.default.createElement(time_picker_input_1.TimePickerInput, { id: "time-test", name: "time", label: "\u010Cas \u010Dehokoliv", rightElement: react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }), value: time, onChange: (data) => setTime(data) }),
38
38
  react_1.default.createElement(time_picker_input_1.TimePickerInput, { id: "time-test-disabled", name: "time-disabled", label: "\u010Cas disabled", rightElement: react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }), value: time, onChange: (data) => setTime(data), isDisabled: true }),
39
39
  react_1.default.createElement(time_picker_input_1.TimePickerInput, { id: "time-test-readonly", name: "time-readonly", label: "\u010Cas readonly", rightElement: react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }), value: time, onChange: (data) => setTime(data), isReadOnly: true }),
40
- react_1.default.createElement(time_picker_input_1.TimePickerInput, { id: "time-test-invalid", name: "time-invalid", label: "\u010Cas invalid", rightElement: react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }), value: time, onChange: (data) => setTime(data), isInvalid: true })));
40
+ react_1.default.createElement(time_picker_input_1.TimePickerInput, { id: "time-test-invalid", name: "time-invalid", label: "\u010Cas invalid", rightElement: react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }), value: time, onChange: (data) => setTime(data), isInvalid: true, isClearable: true })));
41
41
  return (react_1.default.createElement(react_1.default.Fragment, null,
42
42
  react_1.default.createElement("div", { className: "light max-w-[640px] space-y-4 rounded bg-white p-8" }, testTimePickers),
43
43
  react_1.default.createElement("div", { className: "dark max-w-[640px] space-y-4 rounded bg-gray-900 p-8 text-white" }, testTimePickers)));
@@ -22,3 +22,6 @@ export declare type OptionType<ValueType = string, LabelType = string> = {
22
22
  value: ValueType;
23
23
  label: LabelType;
24
24
  };
25
+ export interface Clearable {
26
+ isClearable?: boolean;
27
+ }