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