@uxf/ui 1.0.0-beta.102 → 1.0.0-beta.103

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.
@@ -2,13 +2,15 @@ import { Placement } from "@floating-ui/react";
2
2
  import React, { ReactNode } from "react";
3
3
  import { IconsSet } from "../icon/theme";
4
4
  import { FormControlProps } from "../types";
5
- export declare type ComboboxValue = number | string;
6
- export declare type ComboboxOption<T = ComboboxValue> = {
7
- disabled?: boolean;
8
- id: T;
5
+ export declare type ComboboxValueId = number | string;
6
+ export declare type ComboboxValue<ValueId = ComboboxValueId> = {
7
+ id: ValueId;
9
8
  label: string;
10
9
  };
11
- export interface ComboboxProps<Value = ComboboxValue, Option = ComboboxOption<Value>> extends FormControlProps<Value | null> {
10
+ export interface ComboboxOption<ValueId = ComboboxValueId> extends ComboboxValue<ValueId> {
11
+ disabled?: boolean;
12
+ }
13
+ export interface ComboboxProps<ValueId = ComboboxValueId, Option = ComboboxOption<ValueId>> extends FormControlProps<Option | null> {
12
14
  className?: string;
13
15
  dropdownPlacement?: Placement;
14
16
  helperText?: ReactNode;
@@ -22,4 +24,4 @@ export interface ComboboxProps<Value = ComboboxValue, Option = ComboboxOption<Va
22
24
  placeholder?: string;
23
25
  renderOption?: (option: Option) => ReactNode;
24
26
  }
25
- export declare const Combobox: React.ForwardRefExoticComponent<ComboboxProps<ComboboxValue, ComboboxOption<ComboboxValue>> & React.RefAttributes<HTMLDivElement>>;
27
+ export declare const Combobox: React.ForwardRefExoticComponent<ComboboxProps<ComboboxValueId, ComboboxOption<ComboboxValueId>> & React.RefAttributes<HTMLDivElement>>;
@@ -36,6 +36,7 @@ const use_dropdown_1 = require("../hooks/use-dropdown");
36
36
  const icon_1 = require("../icon");
37
37
  const label_1 = require("../label");
38
38
  const use_async_loading_1 = require("../hooks/use-async-loading");
39
+ // TODO make the component generic ComboboxProps<T>
39
40
  exports.Combobox = (0, forwardRef_1.forwardRef)("Combobox", (props, ref) => {
40
41
  var _a, _b, _c, _d;
41
42
  const generatedId = (0, react_2.useId)();
@@ -43,7 +44,7 @@ exports.Combobox = (0, forwardRef_1.forwardRef)("Combobox", (props, ref) => {
43
44
  const isAsync = !!props.loadOptions;
44
45
  const [query, setQuery] = (0, react_2.useState)("");
45
46
  const options = (0, use_async_loading_1.useAsyncLoading)(query, (_b = props.options) !== null && _b !== void 0 ? _b : [], props.loadOptions);
46
- const selectedOption = options.find((option) => option.id === props.value);
47
+ const selectedOption = options.find((option) => { var _a; return option.id === ((_a = props.value) === null || _a === void 0 ? void 0 : _a.id); });
47
48
  const filteredData = query === "" || isAsync ? options : options.filter((item) => (0, slugify_1.slugify)(item.label).includes((0, slugify_1.slugify)(query)));
48
49
  const innerRef = (0, react_2.useRef)(null);
49
50
  const errorId = props.isInvalid ? `${id}--error-message` : undefined;
@@ -51,7 +52,7 @@ exports.Combobox = (0, forwardRef_1.forwardRef)("Combobox", (props, ref) => {
51
52
  const dropdown = (0, use_dropdown_1.useDropdown)((_c = props.dropdownPlacement) !== null && _c !== void 0 ? _c : "bottom", true);
52
53
  const stableRef = (0, react_2.useMemo)(() => (0, composeRefs_1.composeRefs)(innerRef, ref, dropdown.reference), [ref, dropdown.reference]);
53
54
  const iconName = (_d = props.iconName) !== null && _d !== void 0 ? _d : "chevronDown";
54
- 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.id); }, value: selectedOption, disabled: props.isDisabled || props.isReadOnly }, (renderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
55
+ 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: selectedOption, disabled: props.isDisabled || props.isReadOnly }, (renderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
55
56
  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),
56
57
  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 },
57
58
  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" }),
@@ -1,8 +1,7 @@
1
1
  import React from "react";
2
- import { ComboboxValue } from "./combobox";
3
2
  declare const _default: {
4
3
  title: string;
5
- component: React.ForwardRefExoticComponent<import("./combobox").ComboboxProps<ComboboxValue, import("./combobox").ComboboxOption<ComboboxValue>> & React.RefAttributes<HTMLDivElement>>;
4
+ component: React.ForwardRefExoticComponent<import("./combobox").ComboboxProps<import("./combobox").ComboboxValueId, import("./combobox").ComboboxOption<import("./combobox").ComboboxValueId>> & React.RefAttributes<HTMLDivElement>>;
6
5
  };
7
6
  export default _default;
8
7
  export declare function Default(): JSX.Element;
@@ -3,14 +3,16 @@ import React, { ReactNode } from "react";
3
3
  import { ChipColor } from "../chip";
4
4
  import { IconsSet } from "../icon/theme";
5
5
  import { FormControlProps } from "../types";
6
- export declare type MultiComboboxValue = number | string;
7
- export declare type MultiComboboxOption<T = MultiComboboxValue> = {
8
- color?: ChipColor;
9
- disabled?: boolean;
10
- id: T;
6
+ export declare type MultiComboboxValueId = number | string;
7
+ export declare type MultiComboboxValue<ValueId = MultiComboboxValueId> = {
8
+ id: ValueId;
11
9
  label: string;
12
10
  };
13
- export interface MultiComboboxProps<Value = MultiComboboxValue[], Option = MultiComboboxOption> extends FormControlProps<Value | null> {
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> {
14
16
  className?: string;
15
17
  dropdownPlacement?: Placement;
16
18
  helperText?: ReactNode;
@@ -25,4 +27,4 @@ export interface MultiComboboxProps<Value = MultiComboboxValue[], Option = Multi
25
27
  renderOption?: (option: Option) => ReactNode;
26
28
  withCheckboxes?: boolean;
27
29
  }
28
- export declare const MultiCombobox: React.ForwardRefExoticComponent<MultiComboboxProps<MultiComboboxValue[], MultiComboboxOption<MultiComboboxValue>> & React.RefAttributes<HTMLDivElement>>;
30
+ export declare const MultiCombobox: React.ForwardRefExoticComponent<MultiComboboxProps<MultiComboboxValueId, MultiComboboxOption<MultiComboboxValueId>> & React.RefAttributes<HTMLDivElement>>;
@@ -45,12 +45,12 @@ exports.MultiCombobox = (0, forwardRef_1.forwardRef)("MultiCombobox", (props, re
45
45
  const isAsync = !!props.loadOptions;
46
46
  const [query, setQuery] = (0, react_2.useState)("");
47
47
  const options = (0, use_async_loading_1.useAsyncLoading)(query, (_b = props.options) !== null && _b !== void 0 ? _b : [], props.loadOptions);
48
- const [selectedOptions, setSelectedOptions] = (0, react_2.useState)(() => options.filter((option) => { var _a; return (_a = props.value) === null || _a === void 0 ? void 0 : _a.includes(option.id); }));
48
+ const [selectedOptions, setSelectedOptions] = (0, react_2.useState)(() => options.filter((option) => { var _a; return (_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === option.id); }));
49
49
  const filteredData = isAsync
50
50
  ? options
51
51
  : options.filter((item) => {
52
52
  var _a;
53
- return (!((_a = props.value) === null || _a === void 0 ? void 0 : _a.includes(item.id)) || props.withCheckboxes) &&
53
+ return (!((_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === item.id)) || props.withCheckboxes) &&
54
54
  (query === "" || (0, slugify_1.slugify)(item.label).includes((0, slugify_1.slugify)(query)));
55
55
  });
56
56
  const innerRef = (0, react_2.useRef)(null);
@@ -59,19 +59,21 @@ exports.MultiCombobox = (0, forwardRef_1.forwardRef)("MultiCombobox", (props, re
59
59
  const dropdown = (0, use_dropdown_1.useDropdown)((_c = props.dropdownPlacement) !== null && _c !== void 0 ? _c : "bottom", true);
60
60
  const stableRef = (0, react_2.useMemo)(() => (0, composeRefs_1.composeRefs)(innerRef, ref, dropdown.reference), [ref, dropdown.reference]);
61
61
  const iconName = (_d = props.iconName) !== null && _d !== void 0 ? _d : "chevronDown";
62
- const handleRemove = (value) => () => {
62
+ const handleRemove = (valueId) => () => {
63
63
  var _a, _b, _c;
64
- setSelectedOptions((prev) => prev.filter((v) => v.id !== value));
65
- (_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 !== value)) !== null && _c !== void 0 ? _c : []);
64
+ setSelectedOptions((prev) => prev.filter((v) => v.id !== valueId));
65
+ (_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 : []);
66
66
  };
67
- const handleCheckboxChange = (value) => (checked) => {
67
+ const handleCheckboxChange = (valueId) => (checked) => {
68
68
  var _a, _b, _c, _d;
69
- if (((_a = props.value) === null || _a === void 0 ? void 0 : _a.includes(value)) && !checked) {
70
- handleRemove(value)();
69
+ if (((_a = props.value) === null || _a === void 0 ? void 0 : _a.some((v) => v.id === valueId)) && !checked) {
70
+ handleRemove(valueId)();
71
71
  return;
72
72
  }
73
- if (!((_b = props.value) === null || _b === void 0 ? void 0 : _b.includes(value)) && checked) {
74
- (_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, [...((_d = props.value) !== null && _d !== void 0 ? _d : []), value]);
73
+ const newOption = options.find((o) => o.id === valueId);
74
+ //adding new option if not in value
75
+ if (!((_b = props.value) === null || _b === void 0 ? void 0 : _b.some((v) => v.id === valueId)) && checked && newOption) {
76
+ (_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, [...((_d = props.value) !== null && _d !== void 0 ? _d : []), newOption]);
75
77
  }
76
78
  };
77
79
  const handleInputKeyDown = (event) => {
@@ -83,7 +85,7 @@ exports.MultiCombobox = (0, forwardRef_1.forwardRef)("MultiCombobox", (props, re
83
85
  const handleComboboxValueChange = (v) => {
84
86
  var _a;
85
87
  setSelectedOptions(v);
86
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v.map((option) => option.id));
88
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v.map((option) => option));
87
89
  setQuery("");
88
90
  };
89
91
  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), disabled: props.isDisabled || props.isReadOnly, multiple: true, onChange: handleComboboxValueChange, value: selectedOptions }, (renderProps) => (react_2.default.createElement(react_2.default.Fragment, null,
@@ -1,9 +1,8 @@
1
1
  import React from "react";
2
2
  import { MultiComboboxOption } from "./index";
3
- import { MultiComboboxValue } from "./multi-combobox";
4
3
  declare const _default: {
5
4
  title: string;
6
- component: React.ForwardRefExoticComponent<import("./multi-combobox").MultiComboboxProps<MultiComboboxValue[], MultiComboboxOption<MultiComboboxValue>> & React.RefAttributes<HTMLDivElement>>;
5
+ component: React.ForwardRefExoticComponent<import("./multi-combobox").MultiComboboxProps<import("./multi-combobox").MultiComboboxValueId, MultiComboboxOption<import("./multi-combobox").MultiComboboxValueId>> & React.RefAttributes<HTMLDivElement>>;
7
6
  };
8
7
  export default _default;
9
8
  export declare function Default(): JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "1.0.0-beta.102",
3
+ "version": "1.0.0-beta.103",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -40,7 +40,7 @@ exports.Tooltip = (0, forwardRef_1.forwardRef)("Tooltip", ({ children, content,
40
40
  const arrowRef = (0, react_2.useRef)(null);
41
41
  const tooltip = (0, use_tooltip_1.useTooltip)({ arrowRef, ...options });
42
42
  const { getReferenceProps, getFloatingProps } = (0, react_1.useInteractions)([
43
- (0, react_1.useHover)(tooltip.context),
43
+ (0, react_1.useHover)(tooltip.context, { delay: 200, handleClose: (0, react_1.safePolygon)() }),
44
44
  (0, react_1.useFocus)(tooltip.context),
45
45
  (0, react_1.useRole)(tooltip.context, { role: "tooltip" }),
46
46
  (0, react_1.useDismiss)(tooltip.context),