@appquality/unguess-design-system 2.12.55 → 2.12.57
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 +25 -0
- package/build/index.js +35 -54
- package/build/stories/multiselect/_types.d.ts +3 -2
- package/build/stories/multiselect/index.d.ts +1 -1
- package/build/stories/multiselect/index.stories.d.ts +1 -1
- package/package.json +1 -1
- package/build/stories/multiselect/useOptions.d.ts +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# v2.12.57 (Tue Jan 17 2023)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- Handle state from outside component in multiselect [#178](https://github.com/AppQuality/unguess-design-system/pull/178) ([@d-beezee](https://github.com/d-beezee))
|
|
6
|
+
- feat(multiselect): Handle state from outside [#177](https://github.com/AppQuality/unguess-design-system/pull/177) ([@d-beezee](https://github.com/d-beezee))
|
|
7
|
+
|
|
8
|
+
#### Authors: 1
|
|
9
|
+
|
|
10
|
+
- [@d-beezee](https://github.com/d-beezee)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# v2.12.56 (Mon Jan 16 2023)
|
|
15
|
+
|
|
16
|
+
#### 🐛 Bug Fix
|
|
17
|
+
|
|
18
|
+
- Multiselect fixes [#176](https://github.com/AppQuality/unguess-design-system/pull/176) ([@cannarocks](https://github.com/cannarocks))
|
|
19
|
+
|
|
20
|
+
#### Authors: 1
|
|
21
|
+
|
|
22
|
+
- Luca Cannarozzo ([@cannarocks](https://github.com/cannarocks))
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
1
26
|
# v2.12.55 (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(
|
|
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,59 +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
|
|
3570
|
-
|
|
3571
|
-
|
|
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
|
|
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 =
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
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
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
const itemToString = (item) => (item ? item.id : "");
|
|
3612
|
-
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: () => {
|
|
3613
|
-
selectItems(currentSelectedItems.filter((item) => item.id !== value.id));
|
|
3614
|
-
} })] }))) })] }), jsxRuntime.jsxs(reactDropdowns.Menu, { children: [jsxRuntime.jsxs("div", Object.assign({ style: { maxHeight: menuHeight !== null && menuHeight !== void 0 ? menuHeight : "200px" } }, { children: [matchingOptions.map((option) => {
|
|
3615
|
-
const items = currentSelectedItems.map((item) => itemToString(item));
|
|
3616
|
-
return (jsxRuntime.jsx(Item, { option: option, checked: items.includes(itemToString(option)) }));
|
|
3617
|
-
}), 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 &&
|
|
3618
|
-
inputValue.length > 0 &&
|
|
3619
|
-
!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)
|
|
3620
|
-
? i18n.addNew(inputValue)
|
|
3621
|
-
: `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] })] })));
|
|
3622
3603
|
};
|
|
3623
3604
|
|
|
3624
3605
|
const StyledModal$1 = styled__default["default"](Modal) `
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
declare type Item = {
|
|
2
|
-
id:
|
|
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<
|
|
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,
|
|
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,
|
|
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,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
|
-
};
|