@talixo-ds/options-input 1.0.0 → 1.0.2
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 +15 -19
- 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/jest.config.js +0 -9
- 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,148 +1,143 @@
|
|
|
1
|
-
import React, { useState } from
|
|
2
|
-
import classNames from
|
|
3
|
-
import Box from
|
|
4
|
-
import Typography from
|
|
5
|
-
import ButtonGroup from
|
|
6
|
-
import Divider from
|
|
7
|
-
import TextField from
|
|
8
|
-
import ListItem from
|
|
9
|
-
import Button from
|
|
10
|
-
import AddIcon from
|
|
11
|
-
import RemoveIcon from
|
|
12
|
-
import * as
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import { OptionsInputOption } from
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import Box from "@mui/material/Box";
|
|
4
|
+
import Typography from "@mui/material/Typography";
|
|
5
|
+
import ButtonGroup from "@mui/material/ButtonGroup";
|
|
6
|
+
import Divider from "@mui/material/Divider";
|
|
7
|
+
import TextField from "@mui/material/TextField";
|
|
8
|
+
import ListItem from "@mui/material/ListItem";
|
|
9
|
+
import Button from "@mui/material/Button";
|
|
10
|
+
import AddIcon from "@mui/icons-material/Add";
|
|
11
|
+
import RemoveIcon from "@mui/icons-material/Remove";
|
|
12
|
+
import * as DesignSystemIcons from "@talixo-ds/icons/src";
|
|
13
|
+
import { MinMaxValueLabel } from "./min-max-value-label";
|
|
14
|
+
import { capitalize } from "../utils";
|
|
15
|
+
import type { OptionsInputOption } from "../types";
|
|
16
16
|
|
|
17
17
|
export type OptionsInputDropdownItemProps = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
item: OptionsInputOption;
|
|
19
|
+
onBlur: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
20
|
+
onChange: (id: string, value: number | string) => void;
|
|
21
|
+
index: number;
|
|
22
|
+
displayMinMax?: boolean;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const OptionsInputDropdownItem = ({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
item: { id, quantity = 0, label, max, min, icon, details, inputQuantity },
|
|
27
|
+
onChange,
|
|
28
|
+
onBlur,
|
|
29
|
+
index,
|
|
30
|
+
displayMinMax
|
|
31
31
|
}: OptionsInputDropdownItemProps) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const Icon = DesignSystemIcons[icon] || MuiIcons[icon];
|
|
32
|
+
const [shouldDisplayFullDetails, setShouldDisplayFullDetails] = useState<boolean>(false);
|
|
33
|
+
const Icon = DesignSystemIcons[capitalize(icon) as keyof typeof DesignSystemIcons] || null;
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
</ButtonGroup>
|
|
143
|
-
</ListItem>
|
|
144
|
-
</>
|
|
145
|
-
);
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
{!!index && <Divider sx={{ color: (theme) => theme.palette.primary.main }} />}
|
|
38
|
+
<ListItem
|
|
39
|
+
sx={{
|
|
40
|
+
display: "flex",
|
|
41
|
+
justifyContent: "space-between"
|
|
42
|
+
}}
|
|
43
|
+
className={classNames("options-input__dropdown-item", {
|
|
44
|
+
"options-input__dropdown-item--empty": !quantity
|
|
45
|
+
})}
|
|
46
|
+
>
|
|
47
|
+
<Box display="flex" alignItems="center">
|
|
48
|
+
<Icon fontSize="small" sx={{ color: "black" }} />
|
|
49
|
+
<TextField
|
|
50
|
+
onChange={({ target }) => onChange(id, target.value)}
|
|
51
|
+
onBlur={onBlur}
|
|
52
|
+
value={inputQuantity}
|
|
53
|
+
variant="standard"
|
|
54
|
+
inputProps={{
|
|
55
|
+
inputMode: "numeric",
|
|
56
|
+
pattern: "-?[0-9]*",
|
|
57
|
+
style: {
|
|
58
|
+
textAlign: "center"
|
|
59
|
+
},
|
|
60
|
+
"data-testid": "dropdown-item-input"
|
|
61
|
+
}}
|
|
62
|
+
// eslint-disable-next-line react/jsx-no-duplicate-props
|
|
63
|
+
InputProps={{ disableUnderline: true }}
|
|
64
|
+
className="options-input__dropdown-item-input"
|
|
65
|
+
/>
|
|
66
|
+
<Box
|
|
67
|
+
display="flex"
|
|
68
|
+
flexDirection="column"
|
|
69
|
+
justifyContent="center"
|
|
70
|
+
paddingRight={2}
|
|
71
|
+
paddingLeft={1}
|
|
72
|
+
minWidth="5rem"
|
|
73
|
+
>
|
|
74
|
+
<Typography
|
|
75
|
+
variant="caption"
|
|
76
|
+
fontWeight={600}
|
|
77
|
+
fontSize={13}
|
|
78
|
+
sx={{ my: 0 }}
|
|
79
|
+
color="black"
|
|
80
|
+
>
|
|
81
|
+
{label || id}
|
|
82
|
+
</Typography>
|
|
83
|
+
{details && (
|
|
84
|
+
<Box
|
|
85
|
+
position="relative"
|
|
86
|
+
height="1rem"
|
|
87
|
+
data-testid="option-details-container"
|
|
88
|
+
onMouseEnter={() => setShouldDisplayFullDetails(true)}
|
|
89
|
+
onMouseLeave={() => setShouldDisplayFullDetails(false)}
|
|
90
|
+
>
|
|
91
|
+
<Typography
|
|
92
|
+
variant="caption"
|
|
93
|
+
color="gray"
|
|
94
|
+
sx={{
|
|
95
|
+
my: 0,
|
|
96
|
+
zIndex: 10000,
|
|
97
|
+
position: "fixed",
|
|
98
|
+
...(shouldDisplayFullDetails && {
|
|
99
|
+
backgroundColor: quantity ? "#ffffff" : "#eeeeee",
|
|
100
|
+
border: "thin solid #d3d3d3"
|
|
101
|
+
})
|
|
102
|
+
}}
|
|
103
|
+
data-testid="option-details"
|
|
104
|
+
>
|
|
105
|
+
{details?.length <= 15 || shouldDisplayFullDetails
|
|
106
|
+
? details
|
|
107
|
+
: `${details?.slice(0, 15)}...`}
|
|
108
|
+
</Typography>
|
|
109
|
+
</Box>
|
|
110
|
+
)}
|
|
111
|
+
{displayMinMax && <MinMaxValueLabel min={min} max={max} color="gray" />}
|
|
112
|
+
</Box>
|
|
113
|
+
</Box>
|
|
114
|
+
<ButtonGroup
|
|
115
|
+
variant="outlined"
|
|
116
|
+
size="small"
|
|
117
|
+
className="options-input__dropdown-item-buttons"
|
|
118
|
+
>
|
|
119
|
+
<Button
|
|
120
|
+
onClick={() => onChange(id, quantity + 1)}
|
|
121
|
+
disabled={quantity === max}
|
|
122
|
+
className="options-input__dropdown-item-button"
|
|
123
|
+
role="button"
|
|
124
|
+
color="primary"
|
|
125
|
+
>
|
|
126
|
+
<AddIcon sx={{ color: "primary" }} />
|
|
127
|
+
</Button>
|
|
128
|
+
<Button
|
|
129
|
+
onClick={() => onChange(id, quantity - 1)}
|
|
130
|
+
disabled={quantity === min}
|
|
131
|
+
className="options-input__dropdown-item-button"
|
|
132
|
+
role="button"
|
|
133
|
+
color="primary"
|
|
134
|
+
>
|
|
135
|
+
<RemoveIcon sx={{ color: "primary" }} />
|
|
136
|
+
</Button>
|
|
137
|
+
</ButtonGroup>
|
|
138
|
+
</ListItem>
|
|
139
|
+
</>
|
|
140
|
+
);
|
|
146
141
|
};
|
|
147
142
|
|
|
148
143
|
export default OptionsInputDropdownItem;
|