@talixo-ds/options-input 1.0.1 → 1.0.3
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/dist/components/min-max-value-label.d.ts +3 -2
- package/dist/components/min-max-value-label.js +2 -2
- package/dist/components/min-max-value-label.js.map +1 -1
- package/dist/components/options-input-content-item.d.ts +2 -2
- package/dist/components/options-input-content-item.js +10 -10
- package/dist/components/options-input-content-item.js.map +1 -1
- package/dist/components/options-input-dropdown-item.d.ts +4 -3
- package/dist/components/options-input-dropdown-item.js +31 -31
- package/dist/components/options-input-dropdown-item.js.map +1 -1
- package/dist/options-input.d.ts +9 -9
- package/dist/options-input.js +44 -47
- package/dist/options-input.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +2 -0
- package/dist/utils.js.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/options-input.spec.tsx +147 -0
- package/src/__tests__/utils.spec.ts +12 -0
- package/src/components/__tests__/min-max-value-label.spec.tsx +19 -19
- package/src/components/__tests__/options-input-content-item.spec.tsx +52 -60
- package/src/components/__tests__/options-input-dropdown-item.spec.tsx +74 -85
- package/src/components/min-max-value-label.tsx +10 -15
- package/src/components/options-input-content-item.tsx +47 -54
- package/src/components/options-input-dropdown-item.tsx +133 -138
- package/src/options-input.tsx +247 -251
- package/src/utils.ts +1 -0
- package/tsconfig.build.json +8 -0
- package/__tests__/__snapshots__/options-input.spec.tsx.snap +0 -119
- package/__tests__/options-input.spec.tsx +0 -242
- package/dist/components/__tests__/min-max-value-label.spec.d.ts +0 -1
- package/dist/components/__tests__/min-max-value-label.spec.js +0 -21
- package/dist/components/__tests__/min-max-value-label.spec.js.map +0 -1
- package/dist/components/__tests__/options-input-content-item.spec.d.ts +0 -1
- package/dist/components/__tests__/options-input-content-item.spec.js +0 -49
- package/dist/components/__tests__/options-input-content-item.spec.js.map +0 -1
- package/dist/components/__tests__/options-input-dropdown-item.spec.d.ts +0 -1
- package/dist/components/__tests__/options-input-dropdown-item.spec.js +0 -67
- package/dist/components/__tests__/options-input-dropdown-item.spec.js.map +0 -1
- package/src/components/__tests__/__snapshots__/min-max-value-label.spec.tsx.snap +0 -17
- package/src/components/__tests__/__snapshots__/options-input-content-item.spec.tsx.snap +0 -138
- package/src/components/__tests__/__snapshots__/options-input-dropdown-item.spec.tsx.snap +0 -134
- package/tsconfig.json +0 -8
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type TypographyProps } from "@mui/material/Typography";
|
|
1
2
|
export type MinMaxValueLabelProps = {
|
|
2
3
|
min?: number;
|
|
3
4
|
max?: number;
|
|
4
|
-
color?:
|
|
5
|
+
color?: TypographyProps["color"];
|
|
5
6
|
};
|
|
6
|
-
export declare const MinMaxValueLabel: ({ min, max, color
|
|
7
|
+
export declare const MinMaxValueLabel: ({ min, max, color }: MinMaxValueLabelProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import Typography from
|
|
3
|
-
export const MinMaxValueLabel = ({ min, max, color
|
|
2
|
+
import Typography, {} from "@mui/material/Typography";
|
|
3
|
+
export const MinMaxValueLabel = ({ min, max, color }) => (_jsxs(Typography, { variant: "caption", color: color, sx: { my: 0 }, children: [!Number.isNaN(Number(min)) && `min: ${min}`, !Number.isNaN(Number(max)) && !Number.isNaN(Number(min)) && ", ", !Number.isNaN(Number(max)) && `max: ${max}`] }));
|
|
4
4
|
//# sourceMappingURL=min-max-value-label.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-max-value-label.js","sourceRoot":"","sources":["../../src/components/min-max-value-label.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"min-max-value-label.js","sourceRoot":"","sources":["../../src/components/min-max-value-label.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,EAAE,EAAwB,MAAM,0BAA0B,CAAC;AAQ5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAyB,EAAE,EAAE,CAAC,CAC/E,MAAC,UAAU,IAAC,OAAO,EAAC,SAAS,EAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,aACvD,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,GAAG,EAAE,EAC3C,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,EAChE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,GAAG,EAAE,IAChC,CACb,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { OptionsInputOption } from
|
|
1
|
+
import type { OptionsInputOption } from "../types";
|
|
2
2
|
export type OptionsInputContentItemProps = {
|
|
3
3
|
item: OptionsInputOption;
|
|
4
4
|
disabled?: boolean;
|
|
5
5
|
displayMinMax?: boolean;
|
|
6
6
|
};
|
|
7
|
-
declare const OptionsInputContentItem: ({ item: { quantity, details, label, max, min, icon }, displayMinMax, disabled
|
|
7
|
+
declare const OptionsInputContentItem: ({ item: { quantity, details, label, max, min, icon }, displayMinMax, disabled }: OptionsInputContentItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export default OptionsInputContentItem;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import Tooltip from
|
|
3
|
-
import Box from
|
|
4
|
-
import Typography from
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
const OptionsInputContentItem = ({ item: { quantity, details, label, max, min, icon }, displayMinMax = false, disabled = false
|
|
9
|
-
const Icon = DesignSystemIcons[icon] ||
|
|
10
|
-
const itemsColor = quantity === 0 || disabled ?
|
|
11
|
-
return (_jsxs(Box, { display: "flex", alignItems: "center", gap: 0.5, color: itemsColor, "data-testid": "option-item", children: [label ? (_jsx(Tooltip, { title: _jsxs(Box, { display: "flex", flexDirection: "column", children: [_jsx(Typography, { variant: "caption", fontWeight: 600, sx: { my: 0 }, children: label }), details && (_jsx(Typography, { variant: "caption", sx: { my: 0 }, children: details })), displayMinMax && _jsx(MinMaxValueLabel, { min: min, max: max })] }), placement: "top", arrow: true, children: _jsx("span", { children: _jsx(Icon, { fontSize: "medium", color: itemsColor }) }) })) : (_jsx(Icon, { fontSize: "medium", color: itemsColor })), _jsx(Typography, { variant: "h6", color: itemsColor, children: quantity })] }));
|
|
2
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
3
|
+
import Box from "@mui/material/Box";
|
|
4
|
+
import Typography from "@mui/material/Typography";
|
|
5
|
+
import * as DesignSystemIcons from "@talixo-ds/icons";
|
|
6
|
+
import { MinMaxValueLabel } from "./min-max-value-label";
|
|
7
|
+
import { capitalize } from "../utils";
|
|
8
|
+
const OptionsInputContentItem = ({ item: { quantity, details, label, max, min, icon }, displayMinMax = false, disabled = false }) => {
|
|
9
|
+
const Icon = DesignSystemIcons[capitalize(icon)] || null;
|
|
10
|
+
const itemsColor = quantity === 0 || disabled ? "#a4a5b2" : "#000000";
|
|
11
|
+
return (_jsxs(Box, { display: "flex", alignItems: "center", gap: 0.5, color: itemsColor, "data-testid": "option-item", children: [label ? (_jsx(Tooltip, { title: _jsxs(Box, { display: "flex", flexDirection: "column", children: [_jsx(Typography, { variant: "caption", fontWeight: 600, sx: { my: 0 }, children: label }), details && (_jsx(Typography, { variant: "caption", sx: { my: 0 }, children: details })), displayMinMax && _jsx(MinMaxValueLabel, { min: min, max: max })] }), placement: "top", arrow: true, children: _jsx("span", { children: _jsx(Icon, { fontSize: "medium", sx: { color: itemsColor } }) }) })) : (_jsx(Icon, { fontSize: "medium", sx: { color: itemsColor } })), _jsx(Typography, { variant: "h6", color: itemsColor, children: quantity })] }));
|
|
12
12
|
};
|
|
13
13
|
export default OptionsInputContentItem;
|
|
14
14
|
//# sourceMappingURL=options-input-content-item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options-input-content-item.js","sourceRoot":"","sources":["../../src/components/options-input-content-item.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"options-input-content-item.js","sourceRoot":"","sources":["../../src/components/options-input-content-item.tsx"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,KAAK,iBAAiB,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAStC,MAAM,uBAAuB,GAAG,CAAC,EAChC,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAClD,aAAa,GAAG,KAAK,EACrB,QAAQ,GAAG,KAAK,EACc,EAAE,EAAE;IAClC,MAAM,IAAI,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAmC,CAAC,IAAI,IAAI,CAAC;IAC3F,MAAM,UAAU,GAAG,QAAQ,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAEtE,OAAO,CACN,MAAC,GAAG,IAAC,OAAO,EAAC,MAAM,EAAC,UAAU,EAAC,QAAQ,EAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,iBAAc,aAAa,aAC5F,KAAK,CAAC,CAAC,CAAC,CACR,KAAC,OAAO,IACP,KAAK,EACJ,MAAC,GAAG,IAAC,OAAO,EAAC,MAAM,EAAC,aAAa,EAAC,QAAQ,aACzC,KAAC,UAAU,IAAC,OAAO,EAAC,SAAS,EAAC,UAAU,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,YAC1D,KAAK,GACM,EACZ,OAAO,IAAI,CACX,KAAC,UAAU,IAAC,OAAO,EAAC,SAAS,EAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,YACzC,OAAO,GACI,CACb,EACA,aAAa,IAAI,KAAC,gBAAgB,IAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAI,IACrD,EAEP,SAAS,EAAC,KAAK,EACf,KAAK,kBAEL,yBACC,KAAC,IAAI,IAAC,QAAQ,EAAC,QAAQ,EAAC,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,GAAI,GAC/C,GACE,CACV,CAAC,CAAC,CAAC,CACH,KAAC,IAAI,IAAC,QAAQ,EAAC,QAAQ,EAAC,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,GAAI,CACrD,EACD,KAAC,UAAU,IAAC,OAAO,EAAC,IAAI,EAAC,KAAK,EAAE,UAAU,YACxC,QAAQ,GACG,IACR,CACN,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { OptionsInputOption } from "../types";
|
|
2
3
|
export type OptionsInputDropdownItemProps = {
|
|
3
4
|
item: OptionsInputOption;
|
|
4
|
-
onBlur: () => void;
|
|
5
|
+
onBlur: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
5
6
|
onChange: (id: string, value: number | string) => void;
|
|
6
7
|
index: number;
|
|
7
8
|
displayMinMax?: boolean;
|
|
8
9
|
};
|
|
9
|
-
declare const OptionsInputDropdownItem: ({ item: { id, quantity, label, max, min, icon, details, inputQuantity }, onChange, onBlur, index, displayMinMax
|
|
10
|
+
declare const OptionsInputDropdownItem: ({ item: { id, quantity, label, max, min, icon, details, inputQuantity }, onChange, onBlur, index, displayMinMax }: OptionsInputDropdownItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
11
|
export default OptionsInputDropdownItem;
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from
|
|
3
|
-
import classNames from
|
|
4
|
-
import Box from
|
|
5
|
-
import Typography from
|
|
6
|
-
import ButtonGroup from
|
|
7
|
-
import Divider from
|
|
8
|
-
import TextField from
|
|
9
|
-
import ListItem from
|
|
10
|
-
import Button from
|
|
11
|
-
import AddIcon from
|
|
12
|
-
import RemoveIcon from
|
|
13
|
-
import * as
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
const OptionsInputDropdownItem = ({ item: { id, quantity = 0, label, max, min, icon, details, inputQuantity }, onChange, onBlur, index, displayMinMax
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Typography from "@mui/material/Typography";
|
|
6
|
+
import ButtonGroup from "@mui/material/ButtonGroup";
|
|
7
|
+
import Divider from "@mui/material/Divider";
|
|
8
|
+
import TextField from "@mui/material/TextField";
|
|
9
|
+
import ListItem from "@mui/material/ListItem";
|
|
10
|
+
import Button from "@mui/material/Button";
|
|
11
|
+
import AddIcon from "@mui/icons-material/Add";
|
|
12
|
+
import RemoveIcon from "@mui/icons-material/Remove";
|
|
13
|
+
import * as DesignSystemIcons from "@talixo-ds/icons";
|
|
14
|
+
import { MinMaxValueLabel } from "./min-max-value-label";
|
|
15
|
+
import { capitalize } from "../utils";
|
|
16
|
+
const OptionsInputDropdownItem = ({ item: { id, quantity = 0, label, max, min, icon, details, inputQuantity }, onChange, onBlur, index, displayMinMax }) => {
|
|
17
17
|
const [shouldDisplayFullDetails, setShouldDisplayFullDetails] = useState(false);
|
|
18
|
-
const Icon = DesignSystemIcons[icon] ||
|
|
19
|
-
return (_jsxs(_Fragment, { children: [!!index &&
|
|
20
|
-
display:
|
|
21
|
-
justifyContent:
|
|
22
|
-
}, className: classNames(
|
|
23
|
-
|
|
24
|
-
}), children: [_jsxs(Box, { display: "flex", alignItems: "center", children: [_jsx(Icon, { fontSize: "small", color: "black" }), _jsx(TextField, { onChange: ({ target }) => onChange(id, target.value), onBlur: onBlur, value: inputQuantity, variant: "standard", inputProps: {
|
|
25
|
-
inputMode:
|
|
26
|
-
pattern:
|
|
18
|
+
const Icon = DesignSystemIcons[capitalize(icon)] || null;
|
|
19
|
+
return (_jsxs(_Fragment, { children: [!!index && _jsx(Divider, { sx: { color: (theme) => theme.palette.primary.main } }), _jsxs(ListItem, { sx: {
|
|
20
|
+
display: "flex",
|
|
21
|
+
justifyContent: "space-between"
|
|
22
|
+
}, className: classNames("options-input__dropdown-item", {
|
|
23
|
+
"options-input__dropdown-item--empty": !quantity
|
|
24
|
+
}), children: [_jsxs(Box, { display: "flex", alignItems: "center", children: [_jsx(Icon, { fontSize: "small", sx: { color: "black" } }), _jsx(TextField, { onChange: ({ target }) => onChange(id, target.value), onBlur: onBlur, value: inputQuantity, variant: "standard", inputProps: {
|
|
25
|
+
inputMode: "numeric",
|
|
26
|
+
pattern: "-?[0-9]*",
|
|
27
27
|
style: {
|
|
28
|
-
textAlign:
|
|
28
|
+
textAlign: "center"
|
|
29
29
|
},
|
|
30
|
-
|
|
30
|
+
"data-testid": "dropdown-item-input"
|
|
31
31
|
},
|
|
32
32
|
// eslint-disable-next-line react/jsx-no-duplicate-props
|
|
33
33
|
InputProps: { disableUnderline: true }, className: "options-input__dropdown-item-input" }), _jsxs(Box, { display: "flex", flexDirection: "column", justifyContent: "center", paddingRight: 2, paddingLeft: 1, minWidth: "5rem", children: [_jsx(Typography, { variant: "caption", fontWeight: 600, fontSize: 13, sx: { my: 0 }, color: "black", children: label || id }), details && (_jsx(Box, { position: "relative", height: "1rem", "data-testid": "option-details-container", onMouseEnter: () => setShouldDisplayFullDetails(true), onMouseLeave: () => setShouldDisplayFullDetails(false), children: _jsx(Typography, { variant: "caption", color: "gray", sx: {
|
|
34
34
|
my: 0,
|
|
35
35
|
zIndex: 10000,
|
|
36
|
-
position:
|
|
36
|
+
position: "fixed",
|
|
37
37
|
...(shouldDisplayFullDetails && {
|
|
38
|
-
backgroundColor: quantity ?
|
|
39
|
-
border:
|
|
40
|
-
})
|
|
38
|
+
backgroundColor: quantity ? "#ffffff" : "#eeeeee",
|
|
39
|
+
border: "thin solid #d3d3d3"
|
|
40
|
+
})
|
|
41
41
|
}, "data-testid": "option-details", children: details?.length <= 15 || shouldDisplayFullDetails
|
|
42
42
|
? details
|
|
43
|
-
: `${details?.slice(0, 15)}...` }) })), displayMinMax &&
|
|
43
|
+
: `${details?.slice(0, 15)}...` }) })), displayMinMax && _jsx(MinMaxValueLabel, { min: min, max: max, color: "gray" })] })] }), _jsxs(ButtonGroup, { variant: "outlined", size: "small", className: "options-input__dropdown-item-buttons", children: [_jsx(Button, { onClick: () => onChange(id, quantity + 1), disabled: quantity === max, className: "options-input__dropdown-item-button", role: "button", color: "primary", children: _jsx(AddIcon, { sx: { color: "primary" } }) }), _jsx(Button, { onClick: () => onChange(id, quantity - 1), disabled: quantity === min, className: "options-input__dropdown-item-button", role: "button", color: "primary", children: _jsx(RemoveIcon, { sx: { color: "primary" } }) })] })] })] }));
|
|
44
44
|
};
|
|
45
45
|
export default OptionsInputDropdownItem;
|
|
46
46
|
//# sourceMappingURL=options-input-dropdown-item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options-input-dropdown-item.js","sourceRoot":"","sources":["../../src/components/options-input-dropdown-item.tsx"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"options-input-dropdown-item.js","sourceRoot":"","sources":["../../src/components/options-input-dropdown-item.tsx"],"names":[],"mappings":";AA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K,GAAG,EAC1B,SAAS,EAAC,qCAAqC,EAC/C,IAAI,EAAC,QAAQ,EACb,KAAK,EAAC,SAAS,YAEf,KAAC,UAAU,IAAC,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAI,GAChC,IACI,IACJ,IACT,CACH,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
package/dist/options-input.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { SxProps } from
|
|
2
|
-
import { OptionsInputOption, OptionsInputValue } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import type { SxProps } from "@mui/material";
|
|
2
|
+
import type { OptionsInputOption, OptionsInputValue } from "./types";
|
|
3
|
+
import "./styles.scss";
|
|
4
|
+
import "@emotion/react";
|
|
5
|
+
import "@emotion/styled";
|
|
6
6
|
export type OptionsInputProps = {
|
|
7
7
|
/** Array of objects representing options available to choose from */
|
|
8
8
|
options: OptionsInputOption[];
|
|
@@ -17,17 +17,17 @@ export type OptionsInputProps = {
|
|
|
17
17
|
/** Boolean to determine if min and max input values should be displayed */
|
|
18
18
|
displayMinMax?: boolean;
|
|
19
19
|
/** Function which handles options input value change */
|
|
20
|
-
onChange?: (OptionsInputValue:
|
|
20
|
+
onChange?: (OptionsInputValue: OptionsInputValue) => void;
|
|
21
21
|
/** Function which handles options input focus event */
|
|
22
|
-
onFocus?: (OptionsInputValue:
|
|
22
|
+
onFocus?: (OptionsInputValue: OptionsInputValue) => void;
|
|
23
23
|
/** Function which handles options input blur event */
|
|
24
|
-
onBlur?: (OptionsInputValue:
|
|
24
|
+
onBlur?: (OptionsInputValue: OptionsInputValue) => void;
|
|
25
25
|
/** className attached to an input container */
|
|
26
26
|
className?: string;
|
|
27
27
|
/** id attached to an input container */
|
|
28
28
|
id?: string;
|
|
29
29
|
/** data test id attached to an input container */
|
|
30
|
-
|
|
30
|
+
"data-testid"?: string;
|
|
31
31
|
/** Gap between input items */
|
|
32
32
|
itemsGap?: string | number;
|
|
33
33
|
/** Custom styles for container */
|
package/dist/options-input.js
CHANGED
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect } from
|
|
3
|
-
import classNames from
|
|
4
|
-
import Box from
|
|
5
|
-
import List from
|
|
6
|
-
import Popper from
|
|
7
|
-
import ClickAwayListener from
|
|
8
|
-
import KeyboardArrowDownIcon from
|
|
9
|
-
import KeyboardArrowUpIcon from
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
2
|
+
import React, { useState, useEffect, useCallback } from "react";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import List from "@mui/material/List";
|
|
6
|
+
import Popper from "@mui/material/Popper";
|
|
7
|
+
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
|
8
|
+
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
|
|
9
|
+
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
|
|
10
|
+
import * as DesignSystemIcons from "@talixo-ds/icons";
|
|
11
|
+
import OptionsInputContentItem from "./components/options-input-content-item";
|
|
12
|
+
import OptionsInputDropdownItem from "./components/options-input-dropdown-item";
|
|
13
|
+
import "./styles.scss";
|
|
14
|
+
import "@emotion/react";
|
|
15
|
+
import "@emotion/styled";
|
|
16
|
+
import { capitalize } from "./utils";
|
|
17
17
|
export const OptionsInput = ({ options, onChange, onFocus, onBlur, persistentOptions = [], defaultValue, displayMinMax = false, disabled = false, readOnly = false, id, className, itemsGap = 1, containerSx = [], ...rest }) => {
|
|
18
|
-
console.log('XXXXX', useState);
|
|
19
18
|
const [currentOptions, setCurrentOptions] = useState([]);
|
|
20
19
|
const [anchorEl, setAnchorEl] = useState();
|
|
21
20
|
const open = !!anchorEl;
|
|
22
21
|
useEffect(() => setCurrentOptions(options.map((option) => {
|
|
23
22
|
const defaultQuantity = defaultValue?.[option.id] ?? 0;
|
|
24
|
-
const minQuantity =
|
|
25
|
-
|
|
23
|
+
const minQuantity = typeof option?.min === "number" && defaultQuantity < option.min
|
|
24
|
+
? option.min
|
|
25
|
+
: defaultQuantity;
|
|
26
|
+
const quantity = typeof option?.max === "number" && minQuantity > option.max ? option.max : minQuantity;
|
|
26
27
|
return {
|
|
27
28
|
...option,
|
|
28
29
|
quantity,
|
|
29
|
-
inputQuantity: quantity
|
|
30
|
+
inputQuantity: quantity
|
|
30
31
|
};
|
|
31
32
|
})), [options, defaultValue]);
|
|
32
|
-
const toggleInput = (event) => {
|
|
33
|
+
const toggleInput = useCallback((event) => {
|
|
33
34
|
const { currentTarget } = event;
|
|
34
35
|
if (!disabled && !readOnly) {
|
|
35
36
|
setTimeout(() => {
|
|
36
|
-
setAnchorEl(
|
|
37
|
+
setAnchorEl((currentAnchor) => (currentAnchor ? undefined : currentTarget));
|
|
37
38
|
}, 0);
|
|
38
39
|
}
|
|
39
|
-
};
|
|
40
|
+
}, [disabled, readOnly, setAnchorEl]);
|
|
40
41
|
const onInputFocus = () => {
|
|
41
42
|
if (onFocus) {
|
|
42
43
|
onFocus(currentOptions.reduce((currentValues, currentOption) => ({
|
|
43
44
|
...currentValues,
|
|
44
|
-
[currentOption.id]: currentOption.quantity
|
|
45
|
+
[currentOption.id]: currentOption.quantity
|
|
45
46
|
}), {}));
|
|
46
47
|
}
|
|
47
48
|
};
|
|
@@ -49,7 +50,7 @@ export const OptionsInput = ({ options, onChange, onFocus, onBlur, persistentOpt
|
|
|
49
50
|
if (onBlur) {
|
|
50
51
|
onBlur(currentOptions.reduce((currentValues, currentOption) => ({
|
|
51
52
|
...currentValues,
|
|
52
|
-
[currentOption.id]: currentOption.quantity
|
|
53
|
+
[currentOption.id]: currentOption.quantity
|
|
53
54
|
}), {}));
|
|
54
55
|
}
|
|
55
56
|
};
|
|
@@ -61,14 +62,14 @@ export const OptionsInput = ({ options, onChange, onFocus, onBlur, persistentOpt
|
|
|
61
62
|
...option,
|
|
62
63
|
...(optionId === option.id && {
|
|
63
64
|
quantity: newQuantity < (option.min || -Infinity) ? option.min : maxQuantity,
|
|
64
|
-
inputQuantity: newValue
|
|
65
|
-
})
|
|
65
|
+
inputQuantity: newValue
|
|
66
|
+
})
|
|
66
67
|
};
|
|
67
68
|
});
|
|
68
69
|
if (onChange) {
|
|
69
70
|
onChange(newCurrentOptions.reduce((currentValues, currentOption) => ({
|
|
70
71
|
...currentValues,
|
|
71
|
-
[currentOption.id]: currentOption.quantity
|
|
72
|
+
[currentOption.id]: currentOption.quantity
|
|
72
73
|
}), {}));
|
|
73
74
|
}
|
|
74
75
|
setCurrentOptions(newCurrentOptions);
|
|
@@ -82,36 +83,32 @@ export const OptionsInput = ({ options, onChange, onFocus, onBlur, persistentOpt
|
|
|
82
83
|
const maxQuantity = finalQuantity > (option.max || Infinity) ? option.max : finalQuantity;
|
|
83
84
|
return {
|
|
84
85
|
...option,
|
|
85
|
-
inputQuantity: finalQuantity < (option.min || -Infinity)
|
|
86
|
-
? option.min
|
|
87
|
-
: maxQuantity,
|
|
86
|
+
inputQuantity: finalQuantity < (option.min || -Infinity) ? option.min : maxQuantity
|
|
88
87
|
};
|
|
89
88
|
}));
|
|
90
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Box, { id: id, onClick: toggleInput, onBlur: onInputBlur, onFocus: onInputFocus, className: classNames(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { id: id, onClick: toggleInput, onBlur: onInputBlur, onFocus: onInputFocus, className: classNames("options-input__container", {
|
|
90
|
+
"options-input__container--open": open,
|
|
91
|
+
"options-input__container--disabled": disabled,
|
|
92
|
+
"options-input__container--read-only": readOnly,
|
|
93
|
+
className
|
|
95
94
|
}), sx: [
|
|
96
|
-
{
|
|
95
|
+
{ "&:hover": { borderColor: "#d3d3d3" } },
|
|
97
96
|
...(Array.isArray(containerSx) ? containerSx : [containerSx]),
|
|
98
97
|
open && {
|
|
99
98
|
borderColor: (theme) => theme.palette.primary.main,
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
], "data-testid": rest[
|
|
103
|
-
.filter(({ quantity, id: optionId, icon }) => !!(
|
|
104
|
-
(quantity !== 0 || persistentOptions.includes(optionId)))
|
|
99
|
+
"&:hover": { borderColor: (theme) => theme.palette.primary.main }
|
|
100
|
+
}
|
|
101
|
+
], "data-testid": rest["data-testid"] || "options-input-container", tabIndex: 0, children: [_jsx(Box, { display: "flex", gap: itemsGap, children: currentOptions
|
|
102
|
+
.filter(({ quantity, id: optionId, icon }) => !!(DesignSystemIcons[capitalize(icon)] &&
|
|
103
|
+
(quantity !== 0 || persistentOptions.includes(optionId))))
|
|
105
104
|
.map((option) => (_jsx(OptionsInputContentItem, { item: option, disabled: disabled, displayMinMax: displayMinMax }, option.id))) }), !readOnly &&
|
|
106
105
|
(open ? (_jsx(KeyboardArrowUpIcon, { color: "primary" })) : (_jsx(KeyboardArrowDownIcon, { sx: {
|
|
107
|
-
color: (theme) => disabled
|
|
108
|
-
? theme.palette.grey[400]
|
|
109
|
-
: theme.palette.action.focus,
|
|
106
|
+
color: (theme) => (disabled ? theme.palette.grey[400] : theme.palette.action.focus)
|
|
110
107
|
} })))] }), _jsx(ClickAwayListener, { onClickAway: () => open && setAnchorEl(undefined), children: _jsx(Popper, { open: open, placement: "bottom-start", anchorEl: anchorEl, sx: (theme) => ({ zIndex: theme.zIndex.modal }), children: _jsx(List, { disablePadding: true, "data-testid": "options-dropdown-list", className: "options-input__dropdown-items-list", sx: {
|
|
111
|
-
bgcolor:
|
|
112
|
-
border: (theme) => `thin solid ${theme.palette.primary.main}
|
|
108
|
+
bgcolor: "Background",
|
|
109
|
+
border: (theme) => `thin solid ${theme.palette.primary.main}`
|
|
113
110
|
}, children: currentOptions
|
|
114
|
-
.filter(({ icon }) => !!
|
|
111
|
+
.filter(({ icon }) => !!DesignSystemIcons[capitalize(icon)])
|
|
115
112
|
.map((option, index) => (_jsx(OptionsInputDropdownItem, { item: option, onBlur: onDropdownItemBlur(option.id), onChange: onValueChange, index: index, displayMinMax: displayMinMax }, option.id))) }) }) })] }));
|
|
116
113
|
};
|
|
117
114
|
//# sourceMappingURL=options-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options-input.js","sourceRoot":"","sources":["../src/options-input.tsx"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"options-input.js","sourceRoot":"","sources":["../src/options-input.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,IAAI,MAAM,oBAAoB,CAAC;AACtC,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,qBAAqB,MAAM,uCAAuC,CAAC;AAC1E,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;AACtE,OAAO,KAAK,iBAAiB,MAAM,kBAAkB,CAAC;AAGtD,OAAO,uBAAuB,MAAM,yCAAyC,CAAC;AAC9E,OAAO,wBAAwB,MAAM,0CAA0C,CAAC;AAChF,OAAO,eAAe,CAAC;AAEvB,OAAO,gBAAgB,CAAC;AACxB,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAiCrC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC5B,OAAO,EACP,QAAQ,EACR,OAAO,EACP,MAAM,EACN,iBAAiB,GAAG,EAAE,EACtB,YAAY,EACZ,aAAa,GAAG,KAAK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ACZ,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAmC,CAAC,CACxE;6BACA,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CACvB,KAAC,wBAAwB,IAExB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,EACrC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,aAAa,IALvB,MAAM,CAAC,EAAE,CAMb,CACF,CAAC,GACG,GACC,GACU,IAClB,CACH,CAAC;AACH,CAAC,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const capitalize: (str: string) => string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talixo-ds/options-input",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "rm -rf dist & tsc && cp src/styles.scss dist/",
|
|
10
|
+
"build": "rm -rf dist & tsc -p tsconfig.build.json && cp src/styles.scss dist/",
|
|
11
11
|
"test": "vitest"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@talixo-ds/icons": "^1.0.
|
|
14
|
+
"@talixo-ds/icons": "^1.0.2"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "618a5d4b960ff0a06427031dc8f41997b465c1d2"
|
|
17
17
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { render, screen, fireEvent, waitFor, act } from "@testing-library/react";
|
|
2
|
+
import { OptionsInput } from "../options-input";
|
|
3
|
+
|
|
4
|
+
const props = {
|
|
5
|
+
options: [
|
|
6
|
+
{
|
|
7
|
+
id: "luggage",
|
|
8
|
+
icon: "luggage",
|
|
9
|
+
label: "luggage",
|
|
10
|
+
details: "This is your luggage",
|
|
11
|
+
min: 0,
|
|
12
|
+
max: 9
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "dog",
|
|
16
|
+
icon: "this icon does not exist",
|
|
17
|
+
label: "dog",
|
|
18
|
+
min: 0,
|
|
19
|
+
max: 3
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "sport-equipment",
|
|
23
|
+
icon: "football",
|
|
24
|
+
label: "sport equipment",
|
|
25
|
+
min: 0,
|
|
26
|
+
max: 1
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
id: "test-id",
|
|
30
|
+
defaultValue: { luggage: 2, "sport-equipment": 5 },
|
|
31
|
+
persistentOptions: ["sport-equipment"],
|
|
32
|
+
className: "test-class",
|
|
33
|
+
onChange: vi.fn(),
|
|
34
|
+
onFocus: vi.fn(),
|
|
35
|
+
onBlur: vi.fn()
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe("OptionsInput", () => {
|
|
39
|
+
describe("events", () => {
|
|
40
|
+
it("should open input dropdown properly", async () => {
|
|
41
|
+
const { getAllByTestId } = render(<OptionsInput {...props} />);
|
|
42
|
+
const optionsInputContainer = getAllByTestId("options-input-container")[0];
|
|
43
|
+
|
|
44
|
+
act(() => {
|
|
45
|
+
fireEvent.click(optionsInputContainer!);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(screen.queryByTestId("options-dropdown-list")).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should not open dropdown when input is disabled", async () => {
|
|
54
|
+
const { getAllByTestId } = render(<OptionsInput {...props} disabled />);
|
|
55
|
+
|
|
56
|
+
const optionsInputContainer = getAllByTestId("options-input-container")[0];
|
|
57
|
+
|
|
58
|
+
act(() => {
|
|
59
|
+
fireEvent.click(optionsInputContainer!);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await waitFor(() => {
|
|
63
|
+
expect(screen.queryByTestId("options-dropdown-list")).not.toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should handle input focus properly", () => {
|
|
68
|
+
const { getAllByTestId } = render(<OptionsInput {...props} />);
|
|
69
|
+
|
|
70
|
+
const optionsInputContainer = getAllByTestId("options-input-container")[0];
|
|
71
|
+
|
|
72
|
+
act(() => {
|
|
73
|
+
fireEvent.focus(optionsInputContainer!);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(props.onFocus).toHaveBeenCalledWith({
|
|
77
|
+
dog: 0,
|
|
78
|
+
luggage: 2,
|
|
79
|
+
"sport-equipment": 1
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should handle input blur properly", () => {
|
|
84
|
+
const { getAllByTestId } = render(<OptionsInput {...props} />);
|
|
85
|
+
|
|
86
|
+
const optionsInputContainer = getAllByTestId("options-input-container")[0];
|
|
87
|
+
|
|
88
|
+
act(() => {
|
|
89
|
+
fireEvent.blur(optionsInputContainer!);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(props.onBlur).toHaveBeenCalledWith({
|
|
93
|
+
dog: 0,
|
|
94
|
+
luggage: 2,
|
|
95
|
+
"sport-equipment": 1
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should handle input option change properly", async () => {
|
|
100
|
+
const { getByTestId } = render(<OptionsInput {...props} />);
|
|
101
|
+
|
|
102
|
+
const optionsInputContainer = getByTestId("options-input-container");
|
|
103
|
+
|
|
104
|
+
fireEvent.click(optionsInputContainer);
|
|
105
|
+
|
|
106
|
+
await waitFor(() => screen.findAllByTestId("dropdown-item-input"));
|
|
107
|
+
|
|
108
|
+
const optionCountInput = screen.getAllByTestId("dropdown-item-input")[0];
|
|
109
|
+
|
|
110
|
+
act(() => {
|
|
111
|
+
fireEvent.change(optionCountInput!, { target: { value: 9 } });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(props.onChange).toHaveBeenCalledWith({
|
|
115
|
+
dog: 0,
|
|
116
|
+
luggage: 9,
|
|
117
|
+
"sport-equipment": 1
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(screen.getAllByTestId("option-item")[0]).toHaveTextContent("9");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should handle input option blur properly", async () => {
|
|
124
|
+
const { getAllByTestId } = render(<OptionsInput {...props} />);
|
|
125
|
+
|
|
126
|
+
const optionsInputContainer = getAllByTestId("options-input-container")[0];
|
|
127
|
+
|
|
128
|
+
fireEvent.click(optionsInputContainer!);
|
|
129
|
+
|
|
130
|
+
await waitFor(() => {
|
|
131
|
+
const optionCountInput = screen.getAllByTestId("dropdown-item-input")[0];
|
|
132
|
+
|
|
133
|
+
act(() => {
|
|
134
|
+
fireEvent.change(optionCountInput!, { target: { value: 500 } });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(optionCountInput).toHaveAttribute("value", "500");
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
fireEvent.blur(optionCountInput!);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(optionCountInput).toHaveAttribute("value", "9");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|