@appquality/unguess-design-system 2.12.56 → 2.12.58

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/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ # v2.12.58 (Tue Jan 17 2023)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Develop [#179](https://github.com/AppQuality/unguess-design-system/pull/179) ([@cannarocks](https://github.com/cannarocks))
6
+
7
+ #### Authors: 1
8
+
9
+ - Luca Cannarozzo ([@cannarocks](https://github.com/cannarocks))
10
+
11
+ ---
12
+
13
+ # v2.12.57 (Tue Jan 17 2023)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - Handle state from outside component in multiselect [#178](https://github.com/AppQuality/unguess-design-system/pull/178) ([@d-beezee](https://github.com/d-beezee))
18
+ - feat(multiselect): Handle state from outside [#177](https://github.com/AppQuality/unguess-design-system/pull/177) ([@d-beezee](https://github.com/d-beezee))
19
+
20
+ #### Authors: 1
21
+
22
+ - [@d-beezee](https://github.com/d-beezee)
23
+
24
+ ---
25
+
1
26
  # v2.12.56 (Mon Jan 16 2023)
2
27
 
3
28
  #### 🐛 Bug Fix
package/build/index.js CHANGED
@@ -3553,12 +3553,18 @@ var SvgPlus = function SvgPlus(props) {
3553
3553
  };
3554
3554
 
3555
3555
  const CustomItem$1 = reactDropdowns.Item;
3556
+ const GridAdd = styled__default["default"](SvgPlus) `
3557
+ display: flex;
3558
+ position: absolute;
3559
+ top: 0;
3560
+ left: 12px;
3561
+ align-items: center;
3562
+ justify-content: center;
3563
+ width: 16px;
3564
+ height: calc(20px + 16px);
3565
+ `;
3556
3566
  const AddableItem = (props) => {
3557
- return (jsxRuntime.jsxs(CustomItem$1, Object.assign({ onClick: props.onClick, addable: true, disabled: true }, { children: [jsxRuntime.jsx(SvgPlus, { style: {
3558
- position: "absolute",
3559
- left: "0.6%",
3560
- top: "calc(50% - 8px)",
3561
- } }), props.label] })));
3567
+ return (jsxRuntime.jsxs(CustomItem$1, Object.assign({ onClick: props.onClick, addable: true, disabled: true }, { children: [jsxRuntime.jsx(GridAdd, {}), props.label] })));
3562
3568
  };
3563
3569
 
3564
3570
  const CustomItem = reactDropdowns.Item;
@@ -3566,62 +3572,34 @@ const Item = ({ option, checked, }) => {
3566
3572
  return (jsxRuntime.jsx(CustomItem, Object.assign({ value: option, checked: checked }, { children: jsxRuntime.jsx("span", { children: option.label }) }), `${option.label}-${option.id}`));
3567
3573
  };
3568
3574
 
3569
- const useOptions = ({ options, selectedItems, onChange, }) => {
3570
- const [currentOptions, setCurrentOptions] = React.useState(options);
3571
- const [isLoading, setIsLoading] = React.useState(false);
3572
- const [currentSelectedItems, setSelectedItems] = React.useState(selectedItems || []);
3575
+ const DisabledItem = ({ label }) => (jsxRuntime.jsx(reactDropdowns.Item, Object.assign({ disabled: true }, { children: label })));
3576
+ const MultiSelect = ({ options, onChange, creatable, i18n, maxItems, size, menuHeight, }) => {
3577
+ var _a, _b, _c;
3573
3578
  const [inputValue, setInputValue] = React.useState("");
3574
3579
  const [matchingOptions, setMatchingOptions] = React.useState(options);
3575
- const selectItems = (selection, newLabel) => __awaiter(void 0, void 0, void 0, function* () {
3576
- setIsLoading(true);
3577
- const unselectedItems = currentOptions.filter((option) => !selection.find((selectedItem) => selectedItem.id === option.id));
3578
- let newSelectedItems = selection;
3579
- if (onChange) {
3580
- newSelectedItems = yield onChange(selection, newLabel);
3581
- }
3582
- setCurrentOptions([...unselectedItems, ...newSelectedItems]);
3583
- setSelectedItems(newSelectedItems);
3584
- setInputValue("");
3585
- setIsLoading(false);
3586
- });
3580
+ const itemToString = (item) => (item ? item.id : "");
3587
3581
  React.useEffect(() => {
3588
- const matchedOptions = currentOptions.filter((option) => {
3589
- return (option.label
3590
- .trim()
3591
- .toLowerCase()
3592
- .indexOf(inputValue.trim().toLowerCase()) !== -1);
3593
- });
3582
+ const matchedOptions = options.filter((option) => option.label
3583
+ .trim()
3584
+ .toLowerCase()
3585
+ .indexOf(inputValue.trim().toLowerCase()) !== -1);
3594
3586
  setMatchingOptions(matchedOptions);
3595
- }, [inputValue]);
3596
- return {
3597
- currentOptions,
3598
- currentSelectedItems,
3599
- matchingOptions,
3600
- inputValue,
3601
- setInputValue,
3602
- selectItems,
3603
- isLoading,
3604
- };
3605
- };
3606
-
3607
- const DisabledItem = ({ label }) => (jsxRuntime.jsx(reactDropdowns.Item, Object.assign({ disabled: true }, { children: label })));
3608
- const MultiSelect = ({ options, selectedItems, onChange, creatable, i18n, maxItems, size, menuHeight, }) => {
3609
- var _a, _b, _c;
3610
- const { isLoading, currentSelectedItems, matchingOptions, inputValue, setInputValue, selectItems, } = useOptions({ options, selectedItems, onChange });
3611
- React.useEffect(() => {
3612
- selectItems(selectedItems || []);
3613
- }, [options, selectedItems]);
3614
- const itemToString = (item) => (item ? item.id : "");
3615
- return (jsxRuntime.jsx("div", Object.assign({ style: isLoading ? { pointerEvents: "none", opacity: "0.3" } : {} }, { children: jsxRuntime.jsxs(reactDropdowns.Dropdown, Object.assign({ inputValue: inputValue, selectedItems: currentSelectedItems, onSelect: (items) => selectItems(items), downshiftProps: { itemToString }, onInputValueChange: (value) => setInputValue(value) }, { children: [jsxRuntime.jsxs(reactDropdowns.Field, { children: [jsxRuntime.jsx(reactDropdowns.Label, Object.assign({ hidden: true }, { children: (_a = i18n === null || i18n === void 0 ? void 0 : i18n.label) !== null && _a !== void 0 ? _a : "Multiselect" })), jsxRuntime.jsx(reactDropdowns.Multiselect, { placeholder: (_b = i18n === null || i18n === void 0 ? void 0 : i18n.placeholder) !== null && _b !== void 0 ? _b : "Select Items", isCompact: size !== "medium", maxItems: maxItems, renderItem: ({ value }) => (jsxRuntime.jsxs(reactTags.Tag, Object.assign({ isPill: true }, { children: [jsxRuntime.jsx("span", { children: value.label }), jsxRuntime.jsx(reactTags.Tag.Close, { onClick: () => {
3616
- selectItems(currentSelectedItems.filter((item) => item.id !== value.id));
3617
- } })] }))) })] }), jsxRuntime.jsxs(reactDropdowns.Menu, { children: [jsxRuntime.jsxs("div", Object.assign({ style: { maxHeight: menuHeight !== null && menuHeight !== void 0 ? menuHeight : "200px" } }, { children: [matchingOptions.map((option) => {
3618
- const items = currentSelectedItems.map((item) => itemToString(item));
3619
- return (jsxRuntime.jsx(Item, { option: option, checked: items.includes(itemToString(option)) }));
3620
- }), matchingOptions.length === 0 && (jsxRuntime.jsx(DisabledItem, { label: (_c = i18n === null || i18n === void 0 ? void 0 : i18n.noMatches) !== null && _c !== void 0 ? _c : "No matches found" }))] })), creatable &&
3621
- inputValue.length > 0 &&
3622
- !matchingOptions.find((item) => item.label.toLowerCase() === inputValue.toLowerCase()) ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Separator, {}), jsxRuntime.jsx(AddableItem, { onClick: () => selectItems(currentSelectedItems, inputValue), label: (i18n === null || i18n === void 0 ? void 0 : i18n.addNew)
3623
- ? i18n.addNew(inputValue)
3624
- : `Want to add ${inputValue}?` })] })) : null] })] })) })));
3587
+ }, [inputValue, options]);
3588
+ return (jsxRuntime.jsxs(reactDropdowns.Dropdown, Object.assign({ inputValue: inputValue, selectedItems: options.filter((option) => option.selected), onSelect: (items) => onChange &&
3589
+ onChange(options.map((o) => (Object.assign(Object.assign({}, o), { selected: items.some((i) => i.id === o.id) })))), downshiftProps: { itemToString }, onInputValueChange: (value) => setInputValue(value) }, { children: [jsxRuntime.jsxs(reactDropdowns.Field, { children: [jsxRuntime.jsx(reactDropdowns.Label, Object.assign({ hidden: true }, { children: (_a = i18n === null || i18n === void 0 ? void 0 : i18n.label) !== null && _a !== void 0 ? _a : "Multiselect" })), jsxRuntime.jsx(reactDropdowns.Multiselect, { placeholder: (_b = i18n === null || i18n === void 0 ? void 0 : i18n.placeholder) !== null && _b !== void 0 ? _b : "Select Items", isCompact: size !== "medium", maxItems: maxItems, renderItem: ({ value }) => (jsxRuntime.jsxs(reactTags.Tag, Object.assign({ isPill: true }, { children: [jsxRuntime.jsx("span", { children: value.label }), jsxRuntime.jsx(reactTags.Tag.Close, { onClick: () => onChange &&
3590
+ onChange(options.map((o) => (Object.assign(Object.assign({}, o), { selected: o.selected && o.id !== value.id })))) })] }))) })] }), jsxRuntime.jsxs(reactDropdowns.Menu, { children: [jsxRuntime.jsxs("div", Object.assign({ style: { maxHeight: menuHeight !== null && menuHeight !== void 0 ? menuHeight : "200px" } }, { children: [matchingOptions.map((option) => {
3591
+ const items = options
3592
+ .filter((o) => o.selected)
3593
+ .map((item) => itemToString(item));
3594
+ return (jsxRuntime.jsx(Item, { option: option, checked: items.includes(itemToString(option)) }));
3595
+ }), matchingOptions.length === 0 && (jsxRuntime.jsx(DisabledItem, { label: (_c = i18n === null || i18n === void 0 ? void 0 : i18n.noMatches) !== null && _c !== void 0 ? _c : "No matches found" }))] })), creatable &&
3596
+ inputValue.length > 0 &&
3597
+ !matchingOptions.find((item) => item.label.toLowerCase() === inputValue.toLowerCase()) ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Separator, {}), jsxRuntime.jsx(AddableItem, { onClick: () => __awaiter(void 0, void 0, void 0, function* () {
3598
+ onChange && (yield onChange(options, inputValue));
3599
+ setInputValue("");
3600
+ }), label: (i18n === null || i18n === void 0 ? void 0 : i18n.addNew)
3601
+ ? i18n.addNew(inputValue)
3602
+ : `Want to add ${inputValue}?` })] })) : null] })] })));
3625
3603
  };
3626
3604
 
3627
3605
  const StyledModal$1 = styled__default["default"](Modal) `
@@ -4336,6 +4314,7 @@ const StyledSlick = styled__default["default"](SlickSlider__default["default"])
4336
4314
  height: 100%;
4337
4315
  width: auto;
4338
4316
  margin: 0 auto;
4317
+ max-width: 100%;
4339
4318
  }
4340
4319
 
4341
4320
  &.dragging img {
@@ -1,12 +1,13 @@
1
1
  declare type Item = {
2
- id: string | number;
2
+ id: number;
3
3
  label: string;
4
+ selected?: boolean;
4
5
  };
5
6
  export declare type MultiSelectProps = {
6
7
  maxItems?: number;
7
8
  options: Item[];
8
9
  selectedItems?: Item[];
9
- onChange?: (selectedItems: Item[], newItem?: string) => Promise<Item[]>;
10
+ onChange?: (selectedItems: Item[], newItem?: string) => Promise<void>;
10
11
  creatable?: boolean;
11
12
  size: "small" | "medium";
12
13
  menuHeight?: string;
@@ -1,2 +1,2 @@
1
1
  import { MultiSelectProps } from "./_types";
2
- export declare const MultiSelect: ({ options, selectedItems, onChange, creatable, i18n, maxItems, size, menuHeight, }: MultiSelectProps) => JSX.Element;
2
+ export declare const MultiSelect: ({ options, onChange, creatable, i18n, maxItems, size, menuHeight, }: MultiSelectProps) => JSX.Element;
@@ -2,5 +2,5 @@ import { ComponentMeta, Story } from "@storybook/react";
2
2
  import { MultiSelectProps } from "./_types";
3
3
  export declare const Default: Story<MultiSelectProps>;
4
4
  export declare const WithTagCreation: Story<MultiSelectProps>;
5
- declare const _default: ComponentMeta<({ options, selectedItems, onChange, creatable, i18n, maxItems, size, menuHeight, }: MultiSelectProps) => JSX.Element>;
5
+ declare const _default: ComponentMeta<({ options, onChange, creatable, i18n, maxItems, size, menuHeight, }: MultiSelectProps) => JSX.Element>;
6
6
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appquality/unguess-design-system",
3
- "version": "2.12.56",
3
+ "version": "2.12.58",
4
4
  "dependencies": {
5
5
  "@nivo/bar": "^0.80.0",
6
6
  "@nivo/bullet": "^0.80.0",
@@ -1,27 +0,0 @@
1
- /// <reference types="react" />
2
- import { MultiSelectProps } from "./_types";
3
- export declare const useOptions: ({ options, selectedItems, onChange, }: {
4
- options: MultiSelectProps["options"];
5
- selectedItems: MultiSelectProps["selectedItems"];
6
- onChange: MultiSelectProps["onChange"];
7
- }) => {
8
- currentOptions: {
9
- id: string | number;
10
- label: string;
11
- }[];
12
- currentSelectedItems: {
13
- id: string | number;
14
- label: string;
15
- }[];
16
- matchingOptions: {
17
- id: string | number;
18
- label: string;
19
- }[];
20
- inputValue: string;
21
- setInputValue: import("react").Dispatch<import("react").SetStateAction<string>>;
22
- selectItems: (selection: {
23
- id: string | number;
24
- label: string;
25
- }[], newLabel?: string) => Promise<void>;
26
- isLoading: boolean;
27
- };