@uxf/ui 11.79.0 → 11.80.0

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.
@@ -1,2 +1,2 @@
1
1
  export { MultiSelect } from "./multi-select";
2
- export type { MultiSelectOption, MultiSelectProps, MultiSelectTypeRef, MultiSelectValueId } from "./types";
2
+ export type { MultiSelectOption, MultiSelectProps, MultiSelectTypeRef, MultiSelectValue, MultiSelectValueId, } from "./types";
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
- import { MultiSelectOption, MultiSelectProps, MultiSelectValueId } from "./types";
2
+ import { MultiSelectOption, MultiSelectProps } from "./types";
3
3
  export declare const MULTI_SELECT_COMPONENT_NAME = "multiSelect";
4
- export declare const MultiSelect: React.ForwardRefExoticComponent<MultiSelectProps<MultiSelectValueId, MultiSelectOption<MultiSelectValueId>> & React.RefAttributes<HTMLDivElement>>;
4
+ export declare const MultiSelect: React.ForwardRefExoticComponent<MultiSelectProps<import("@uxf/core/types").SelectableId, MultiSelectOption<import("@uxf/core/types").SelectableId>> & React.RefAttributes<HTMLDivElement>>;
@@ -84,21 +84,22 @@ exports.MultiSelect = (0, react_3.forwardRef)((props, ref) => {
84
84
  const input = (0, use_input_focus_1.useInputFocus)(innerRef, props.onBlur, props.onFocus);
85
85
  const stableRef = (0, react_3.useMemo)(() => (0, compose_refs_1.composeRefs)(innerRef, ref, dropdown.refs.setReference), [ref, dropdown.refs.setReference]);
86
86
  const iconName = (_c = props.iconName) !== null && _c !== void 0 ? _c : "caretDown";
87
- const selectedOptions = (_d = props.value) !== null && _d !== void 0 ? _d : empty_array_1.EMPTY_ARRAY;
88
- const filteredOptions = props.options.filter((option) => !selectedOptions.some((v) => v.id === option.id) || props.withCheckboxes);
87
+ const value = (_d = props.value) !== null && _d !== void 0 ? _d : empty_array_1.EMPTY_ARRAY;
88
+ const selectedOptions = props.options.filter((o) => value.includes(o.id));
89
+ const filteredOptions = props.options.filter((option) => !value.some((v) => v === option.id) || props.withCheckboxes);
89
90
  const inputKeyDownHandler = (e) => {
90
91
  if (e.key === "Backspace" && (0, is_not_empty_1.isNotEmpty)(selectedOptions)) {
91
- handleInputKeyDownRecursion(selectedOptions, (v) => props.onChange(selectedOptions.filter((option) => option.id !== v)));
92
+ handleInputKeyDownRecursion(selectedOptions, (v) => props.onChange(value.filter((option) => option !== v)));
92
93
  }
93
94
  };
94
- const optionRemoveHandler = (valueId) => props.onChange(selectedOptions.filter((v) => v.id !== valueId));
95
+ const optionRemoveHandler = (valueId) => props.onChange(value.filter((v) => v !== valueId));
95
96
  const chipCloseHandler = (valueId) => (e) => {
96
97
  e.preventDefault();
97
98
  e.stopPropagation();
98
99
  optionRemoveHandler(valueId);
99
100
  };
100
101
  const checkboxChangeHandler = (valueId) => (checked) => {
101
- const isAlreadySelected = selectedOptions.some((v) => v.id === valueId);
102
+ const isAlreadySelected = value.some((v) => v === valueId);
102
103
  if (isAlreadySelected && !checked) {
103
104
  optionRemoveHandler(valueId);
104
105
  return;
@@ -106,14 +107,14 @@ exports.MultiSelect = (0, react_3.forwardRef)((props, ref) => {
106
107
  const newOption = props.options.find((o) => o.id === valueId);
107
108
  // adding new option if not in value
108
109
  if (!isAlreadySelected && checked && newOption) {
109
- props.onChange([...selectedOptions, newOption]);
110
+ props.onChange([...value, newOption.id]);
110
111
  }
111
112
  };
112
- const emptyMessage = (0, is_empty_1.isEmpty)(filteredOptions) && (0, is_not_empty_1.isNotEmpty)(selectedOptions)
113
+ const emptyMessage = (0, is_empty_1.isEmpty)(filteredOptions) && (0, is_not_empty_1.isNotEmpty)(value)
113
114
  ? ((_e = props.allOptionsSelectedMessage) !== null && _e !== void 0 ? _e : t("uxf-ui-multi-select:all-options-selected"))
114
115
  : ((_f = props.noOptionsMessage) !== null && _f !== void 0 ? _f : t("uxf-ui-multi-select:no-options-message"));
115
116
  const isNotInteractive = props.isDisabled || props.isReadOnly;
116
- return (react_3.default.createElement(react_2.Listbox, { as: "div", className: (0, cx_1.cx)("uxf-form-component uxf-multi-select", 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-component": exports.MULTI_SELECT_COMPONENT_NAME, "data-name": props.name, disabled: isNotInteractive, form: props.form, multiple: true, name: props.name, onChange: props.onChange, value: selectedOptions }, (renderProps) => {
117
+ return (react_3.default.createElement(react_2.Listbox, { as: "div", className: (0, cx_1.cx)("uxf-form-component uxf-multi-select", 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-component": exports.MULTI_SELECT_COMPONENT_NAME, "data-name": props.name, disabled: isNotInteractive, form: props.form, multiple: true, name: props.name, onChange: (v) => props.onChange(v.map((o) => o.id)), value: selectedOptions }, (renderProps) => {
117
118
  var _a, _b;
118
119
  return (react_3.default.createElement(react_3.default.Fragment, null,
119
120
  react_3.default.createElement("div", { className: "uxf-form-component__label" },
@@ -122,7 +123,7 @@ exports.MultiSelect = (0, react_3.forwardRef)((props, ref) => {
122
123
  react_3.default.createElement(react_2.Listbox.Button, { "aria-describedby": errorId, "aria-invalid": props.isInvalid, as: "div", className: (0, cx_1.cx)("uxf-input uxf-multi-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" && `${classes_1.CLASSES.IS_OPEN}--bottom`, dropdown.placement === "top" && `${classes_1.CLASSES.IS_OPEN}--top`, renderProps.open && classes_1.CLASSES.IS_OPEN), id: id, onBlur: input.onBlur, onFocus: input.onFocus, onKeyDown: inputKeyDownHandler, ref: stableRef, tabIndex: isNotInteractive ? undefined : 0 },
123
124
  props.leftAddon && react_3.default.createElement(input_1.Input.LeftAddon, null, props.leftAddon),
124
125
  props.leftElement && react_3.default.createElement(input_1.Input.LeftElement, null, props.leftElement),
125
- react_3.default.createElement("div", { className: (0, cx_1.cx)("uxf-input__element uxf-multi-select__input", (0, is_empty_1.isEmpty)(selectedOptions) && `${classes_1.CLASSES.IS_EMPTY} uxf-multi-select__input--is-empty`) }, (0, is_empty_1.isEmpty)(selectedOptions)
126
+ react_3.default.createElement("div", { className: (0, cx_1.cx)("uxf-input__element uxf-multi-select__input", (0, is_empty_1.isEmpty)(value) && `${classes_1.CLASSES.IS_EMPTY} uxf-multi-select__input--is-empty`) }, (0, is_empty_1.isEmpty)(value)
126
127
  ? props.placeholder
127
128
  : selectedOptions.map((item) => (react_3.default.createElement(chip_1.Chip, { className: "uxf-multi-select__input-chip", color: item.color, key: item.id, onClose: props.isDisabled || item.disabled
128
129
  ? undefined
@@ -1,17 +1,20 @@
1
1
  import { Placement, Strategy } from "@floating-ui/react";
2
+ import { SelectableId } from "@uxf/core/types";
2
3
  import { InputGroupSizes, InputGroupVariants } from "@uxf/ui/input/theme";
3
4
  import { CSSProperties, ReactNode } from "react";
4
5
  import { ChipColor } from "../chip";
5
6
  import { IconsSet } from "../icon/theme";
6
7
  import { FormControlProps } from "../types";
7
- export type MultiSelectValueId = number | string;
8
+ /** @deprecated use import { SelectableId } from "@uxf/core/types" */
9
+ export type MultiSelectValueId = SelectableId;
10
+ export type MultiSelectValue<T extends SelectableId> = T[] | null;
8
11
  export type MultiSelectOption<T = MultiSelectValueId> = {
9
12
  color?: ChipColor;
10
13
  disabled?: boolean;
11
14
  id: T;
12
15
  label: ReactNode;
13
16
  };
14
- export interface MultiSelectProps<ValueId = MultiSelectValueId, Option = MultiSelectOption<ValueId>> extends FormControlProps<Option[] | null> {
17
+ export interface MultiSelectProps<ValueId = MultiSelectValueId, Option = MultiSelectOption<ValueId>> extends FormControlProps<ValueId[] | null> {
15
18
  allOptionsSelectedMessage?: string;
16
19
  className?: string;
17
20
  dropdownClassName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "11.79.0",
3
+ "version": "11.80.0",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,10 +23,10 @@
23
23
  "dependencies": {
24
24
  "@floating-ui/react": "0.26.28",
25
25
  "@headlessui/react": "1.7.19",
26
- "@uxf/core": "11.78.0",
27
- "@uxf/core-react": "11.78.0",
26
+ "@uxf/core": "11.80.0",
27
+ "@uxf/core-react": "11.80.0",
28
28
  "@uxf/datepicker": "11.61.0",
29
- "@uxf/styles": "11.78.0",
29
+ "@uxf/styles": "11.80.0",
30
30
  "color2k": "2.0.3",
31
31
  "dayjs": "1.11.13",
32
32
  "jump.js": "1.0.2",
@@ -0,0 +1,12 @@
1
+ import type { TranslationsPaths } from "@uxf/core-react/translations/types";
2
+ import uiTranslations from "@uxf/ui/translations/translations";
3
+
4
+ type uiTypes = typeof uiTranslations;
5
+
6
+ type TranslationsKeys = TranslationsPaths<uiTypes>;
7
+
8
+ type TypeSafeTranslate = (key: TranslationsKeys, options?: Record<string, any>) => string;
9
+
10
+ declare module "@uxf/core-react/translations" {
11
+ export function useUxfTranslation(): TypeSafeTranslate;
12
+ }