contentoh-components-library 21.2.93 → 21.2.95

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 (44) hide show
  1. package/dist/components/atoms/ButtonV2/ButtonV2.stories.js +1 -1
  2. package/dist/components/atoms/ButtonV2/index.js +1 -1
  3. package/dist/components/atoms/ButtonV2/styles.js +1 -1
  4. package/dist/components/atoms/Image/Image.stories.js +15 -5
  5. package/dist/components/atoms/Image/index.js +3 -1
  6. package/dist/components/atoms/Image/styles.js +10 -7
  7. package/dist/components/atoms/SelectItemV2/SelectItemV2.stories.js +45 -0
  8. package/dist/components/atoms/SelectItemV2/index.js +46 -0
  9. package/dist/components/atoms/SelectItemV2/styles.js +23 -0
  10. package/dist/components/molecules/SelectV2/SelectV2.stories.js +119 -0
  11. package/dist/components/molecules/SelectV2/index.js +298 -0
  12. package/dist/components/molecules/SelectV2/styles.js +42 -0
  13. package/dist/components/organisms/OrderDetail/OrderDetail.stories.js +3 -3
  14. package/dist/components/organisms/OrderDetail/index.js +5 -3
  15. package/dist/index.js +25 -12
  16. package/package.json +1 -1
  17. package/src/assets/fonts/{Roboto → roboto}/LICENSE.txt +0 -0
  18. package/src/assets/fonts/{Roboto → roboto}/Roboto-Black.ttf +0 -0
  19. package/src/assets/fonts/{Roboto → roboto}/Roboto-BlackItalic.ttf +0 -0
  20. package/src/assets/fonts/{Roboto → roboto}/Roboto-Bold.ttf +0 -0
  21. package/src/assets/fonts/{Roboto → roboto}/Roboto-BoldItalic.ttf +0 -0
  22. package/src/assets/fonts/{Roboto → roboto}/Roboto-Italic.ttf +0 -0
  23. package/src/assets/fonts/{Roboto → roboto}/Roboto-Light.ttf +0 -0
  24. package/src/assets/fonts/{Roboto → roboto}/Roboto-LightItalic.ttf +0 -0
  25. package/src/assets/fonts/{Roboto → roboto}/Roboto-Medium.ttf +0 -0
  26. package/src/assets/fonts/{Roboto → roboto}/Roboto-MediumItalic.ttf +0 -0
  27. package/src/assets/fonts/{Roboto → roboto}/Roboto-Regular.ttf +0 -0
  28. package/src/assets/fonts/{Roboto → roboto}/Roboto-Thin.ttf +0 -0
  29. package/src/assets/fonts/{Roboto → roboto}/Roboto-ThinItalic.ttf +0 -0
  30. package/src/components/atoms/ButtonV2/ButtonV2.stories.js +1 -0
  31. package/src/components/atoms/ButtonV2/index.js +11 -6
  32. package/src/components/atoms/ButtonV2/styles.js +9 -1
  33. package/src/components/atoms/Image/Image.stories.js +10 -2
  34. package/src/components/atoms/Image/index.js +2 -1
  35. package/src/components/atoms/Image/styles.js +9 -0
  36. package/src/components/atoms/SelectItemV2/SelectItemV2.stories.js +26 -0
  37. package/src/components/atoms/SelectItemV2/index.js +45 -0
  38. package/src/components/atoms/SelectItemV2/styles.js +55 -0
  39. package/src/components/molecules/SelectV2/SelectV2.stories.js +114 -0
  40. package/src/components/molecules/SelectV2/index.js +332 -0
  41. package/src/components/molecules/SelectV2/styles.js +100 -0
  42. package/src/components/organisms/OrderDetail/OrderDetail.stories.js +1 -1
  43. package/src/components/organisms/OrderDetail/index.js +2 -2
  44. package/src/index.js +1 -0
@@ -13,6 +13,7 @@ export const Image = (props) => {
13
13
  src, // imagen a cargar (string)
14
14
  componentDefault, // componente a mostrar en caso de que no cargue src (JSX)
15
15
  classNameImg, // string
16
+ borderType, // "rectangle" | "circle" -> por default none
16
17
  } = props;
17
18
  const [imgLoad, setImgLoad] = useState();
18
19
  const [loading, setLoading] = useState(false);
@@ -25,7 +26,7 @@ export const Image = (props) => {
25
26
  }, []); */
26
27
 
27
28
  return (
28
- <Container className={className} width={width}>
29
+ <Container className={className} width={width} borderType={borderType}>
29
30
  {src && (imgLoad === undefined || loading) && (
30
31
  <ContainerLoading
31
32
  className={classNameLoading}
@@ -6,6 +6,14 @@ export const Container = styled.div`
6
6
  place-items: center;
7
7
  width: ${({ width }) => (width ? width : "min-content")};
8
8
  min-width: min-content;
9
+ overflow: hidden;
10
+ border-radius: ${({ borderType }) => {
11
+ return borderType?.toLowerCase() === "rectangle"
12
+ ? "6px"
13
+ : borderType?.toLowerCase() === "circle"
14
+ ? "50%"
15
+ : "0px"; // default none
16
+ }};
9
17
  `;
10
18
 
11
19
  export const ContainerLoading = styled.div`
@@ -22,4 +30,5 @@ export const Img = styled.img`
22
30
  display: ${({ show }) => (show ? "grid" : "none")};
23
31
  width: 100%;
24
32
  object-fit: contain;
33
+ border-radius: inherit;
25
34
  `;
@@ -0,0 +1,26 @@
1
+ import { SelectItemV2 } from "./index";
2
+
3
+ export default {
4
+ title: "Components/atoms/SelectItemV2",
5
+ component: SelectItemV2,
6
+ argTypes: {
7
+ checkbox: {
8
+ options: [undefined, true, false],
9
+ control: { type: "select" },
10
+ },
11
+ },
12
+ };
13
+
14
+ const Template = (args) => <SelectItemV2 {...args} />;
15
+
16
+ export const SelectItemV2Test = Template.bind({});
17
+ SelectItemV2Test.args = {
18
+ label: "Label del item",
19
+ value: 1,
20
+ checkbox: true,
21
+ selected: false,
22
+ onClick: (isSelected, value) => {
23
+ console.log("isSelected:", isSelected);
24
+ console.log("value:", value);
25
+ },
26
+ };
@@ -0,0 +1,45 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { Checkbox } from "@mui/material";
3
+ import { Container } from "./styles";
4
+ import React from "react";
5
+ import { isStringEmpty } from "../../../global-files/utils";
6
+
7
+ export const SelectItemV2 = (props) => {
8
+ const {
9
+ id,
10
+ keyId,
11
+ className, // (string) clase del container
12
+ label, // (string) texto visible del item
13
+ value, // valor del item
14
+ checkbox /* (boolean)
15
+ true -> item con checkbox
16
+ false -> item sin checkbox pero respeta el espacio del checkbox
17
+ undefined -> item sin checkbox
18
+ */,
19
+ selected, // (boolean) item seleccionado??
20
+ onClick, // (isSelected , value) => {}
21
+ } = props;
22
+
23
+ return (
24
+ <Container
25
+ className={
26
+ "selectItemV2" +
27
+ (isStringEmpty(className) ? "" : " " + className) +
28
+ (!checkbox && selected ? " selectedItem" : "")
29
+ }
30
+ id={id}
31
+ key={keyId}
32
+ checkbox={checkbox}
33
+ onClick={(event) => onClick && onClick(!selected, value)}
34
+ >
35
+ {checkbox !== undefined && (
36
+ <Checkbox
37
+ className={"checkbox" + (checkbox ? "" : " hidden")}
38
+ checked={selected}
39
+ />
40
+ )}
41
+
42
+ <label className="label">{label}</label>
43
+ </Container>
44
+ );
45
+ };
@@ -0,0 +1,55 @@
1
+ import styled from "styled-components";
2
+ import { GlobalColors, FontFamily } from "../../../global-files/variables";
3
+
4
+ export const Container = styled.div`
5
+ width: fit-content;
6
+ display: flex;
7
+ flex-direction: row;
8
+ flex-wrap: nowrap;
9
+ gap: 11px;
10
+ justify-content: flex-start;
11
+ align-items: center;
12
+ cursor: pointer;
13
+ padding: 8px;
14
+ transition: background 0.25s;
15
+ //border: 1px solid lightgray;
16
+
17
+ &:hover {
18
+ background-color: #f0f0f0;
19
+ }
20
+
21
+ .checkbox {
22
+ padding: 3px;
23
+
24
+ &.hidden {
25
+ visibility: hidden;
26
+ }
27
+
28
+ &.Mui-checked {
29
+ color: #808080;
30
+ }
31
+
32
+ .MuiSvgIcon-root {
33
+ font-size: 16px;
34
+ }
35
+ }
36
+
37
+ .label {
38
+ cursor: inherit;
39
+ font-family: ${FontFamily.RobotoRegular}, sans-serif;
40
+ font-size: 12px;
41
+ text-align: left;
42
+ color: #262626;
43
+ line-height: 1.25;
44
+ padding: ${({ checkbox }) => (checkbox === undefined ? "3" : "0")}px;
45
+ }
46
+
47
+ // para item sin checkbox seleccionado
48
+ &.selectedItem {
49
+ background-color: #8e8e8e;
50
+ .label {
51
+ font-family: ${FontFamily.RobotoMedium}, sans-serif;
52
+ color: white;
53
+ }
54
+ }
55
+ `;
@@ -0,0 +1,114 @@
1
+ import { SelectV2 } from "./index";
2
+
3
+ export default {
4
+ title: "Components/molecules/SelectV2",
5
+ component: SelectV2,
6
+ argTypes: {
7
+ positionDropdown: {
8
+ options: [
9
+ undefined,
10
+ "topStart",
11
+ "topEnd",
12
+ "topCenter",
13
+ "rightStart",
14
+ "rightEnd",
15
+ "rightCenter",
16
+ "bottomStart",
17
+ "bottomEnd",
18
+ "bottomCenter",
19
+ "leftStart",
20
+ "leftEnd",
21
+ "leftCenter",
22
+ ],
23
+ control: { type: "select" },
24
+ },
25
+ triggerType: {
26
+ options: [undefined, "hover", "click"],
27
+ control: { type: "select" },
28
+ },
29
+ typeSelectItems: {
30
+ options: [undefined, "checkbox", "marginCheckbox", "labelOnly"],
31
+ control: { type: "select" },
32
+ },
33
+ borderType: {
34
+ options: [undefined, "rectangle", "oval"],
35
+ control: { type: "select" },
36
+ },
37
+ alignmentItemsOverflow: {
38
+ options: [undefined, "columns", "rows"],
39
+ control: { type: "select" },
40
+ },
41
+ },
42
+ };
43
+
44
+ const Template = (args) => <SelectV2 {...args} />;
45
+
46
+ export const SelectV2Test = Template.bind({});
47
+ SelectV2Test.args = {
48
+ items: [
49
+ {
50
+ label: "Palomitas de maiz",
51
+ value: 1,
52
+ selected: false,
53
+ },
54
+ {
55
+ label: "Sabritas",
56
+ value: 2,
57
+ selected: true,
58
+ },
59
+ {
60
+ label: "sabritas Doritos",
61
+ value: 3,
62
+ selected: false,
63
+ },
64
+ {
65
+ label:
66
+ "Este es un texto muy largo que deberia llegar al limite establecido para el width",
67
+ value: 4,
68
+ selected: true,
69
+ },
70
+ {
71
+ label: "galletas",
72
+ value: 5,
73
+ selected: false,
74
+ },
75
+ {
76
+ label: "jugo de uva",
77
+ value: 6,
78
+ selected: false,
79
+ },
80
+ ],
81
+ triggerType: "hover",
82
+ selectButton: {
83
+ className: "btnSelectPrueba",
84
+ type: "whiteS3",
85
+ transparent: undefined,
86
+ disabled: false,
87
+ label: "select de prueba",
88
+ size: 12,
89
+ borderType: "oval",
90
+ },
91
+ defaultItem: {
92
+ label: "Ningun filtro",
93
+ itemType: undefined,
94
+ showLabelInSelect: true,
95
+ },
96
+ inputSearch: {
97
+ className: "inputBusqueda",
98
+ defaultText: "hola",
99
+ },
100
+ typeSelectItems: undefined,
101
+ borderType: undefined,
102
+ maxWidthSelect: "150px",
103
+ maxWidthDropdown: "300px",
104
+ maxHeightDropdown: "300px",
105
+ maxWidthItems: "100px",
106
+ alignmentItemsOverflow: undefined,
107
+ multiple: true,
108
+ classNameSelect: "selectPrueba",
109
+ classNameDropdown: "dropdownSelectPrueba",
110
+ positionDropdown: undefined,
111
+ onChange: (selectedItems) => {
112
+ console.log("selectedItems:", selectedItems);
113
+ },
114
+ };
@@ -0,0 +1,332 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import {
3
+ ClickAwayListener,
4
+ Fade,
5
+ Grow,
6
+ Popper,
7
+ Tooltip as TooltipMUI,
8
+ Zoom,
9
+ } from "@mui/material";
10
+ import { Container, ContainerSelect } from "./styles";
11
+ import React from "react";
12
+ import { ButtonV2 } from "../../atoms/ButtonV2";
13
+ import {
14
+ faCaretDown as IconDownArrow,
15
+ faSearch as IconSearch,
16
+ } from "@fortawesome/free-solid-svg-icons";
17
+ import { isArrayEmpty, isStringEmpty } from "../../../global-files/utils";
18
+ import { SelectItemV2 } from "../../atoms/SelectItemV2";
19
+ import { InputText } from "../../atoms/InputText";
20
+
21
+ export const SelectV2 = (props) => {
22
+ const {
23
+ items /* [
24
+ {
25
+ label: string,
26
+ value: string | number,
27
+ selected: (boolean) true -> item seleccionado al inicio
28
+ } ,
29
+ ...
30
+ ] */,
31
+ triggerType, // (string) "hover" | "click"
32
+ selectButton /* {
33
+ className: string,
34
+ type: (string) tipos validos de ButtonV2,
35
+ transparent: boolean,
36
+ disabled: boolean,
37
+ label: string ,
38
+ size: number ,
39
+ } */,
40
+ defaultItem /* {
41
+ label: string,
42
+ itemType: (string) "checkbox" | "marginCheckbox" | "labelOnly"
43
+ showLabelInSelect: boolean, cuando esta seleccionado ver label en el btnSelect??
44
+ } */,
45
+ inputSearch /* {
46
+ className: string,
47
+ defaultText: string ,
48
+ } */,
49
+ maxWidthSelect, // string
50
+ maxWidthDropdown, // string
51
+ maxHeightDropdown, // string
52
+ maxWidthItems, // string
53
+ alignmentItemsOverflow, // (string) "columns" | "rows" -> por default "rows"
54
+ typeSelectItems, // (string) "checkbox" | "marginCheckbox" | "labelOnly"
55
+ multiple, // (boolean) se permite multiple seleccion??
56
+ borderType, // (string) "rectangle" | "oval" -> por default oval
57
+ classNameSelect, // (string) clase del container select
58
+ classNameDropdown, // (string) clase del contenedor tooltip
59
+ positionDropdown, // (string) posicion del contenedor tooltip (values en object positions)
60
+ onChange, // (selectedItems: []) = {} array con los values de los items seleccionados
61
+ } = props;
62
+ const positions = {
63
+ topStart: "top-start",
64
+ topEnd: "top-end",
65
+ topCenter: "top",
66
+
67
+ rightStart: "right-start",
68
+ rightEnd: "right-end",
69
+ rightCenter: "right",
70
+
71
+ bottomStart: "bottom-start",
72
+ bottomEnd: "bottom-end",
73
+ bottomCenter: "bottom",
74
+
75
+ leftStart: "left-start",
76
+ leftEnd: "left-end",
77
+ leftCenter: "left",
78
+ };
79
+ const [selectedItems, setSelectedItems] = useState(); // { .. }
80
+ const [customItems, setCustomItems] = useState([]);
81
+ const [showDropdown, setShowDropdown] = useState(false);
82
+ const [labelSelect, setLabelSelect] = useState("Sin titulo");
83
+ const [textInputSearch, setTextInputSearch] = useState("");
84
+
85
+ const refInputTextSearch = useRef();
86
+
87
+ // cada que cambie la lista de items
88
+ useEffect(() => {
89
+ if (isArrayEmpty(items)) {
90
+ setSelectedItems({});
91
+ return;
92
+ }
93
+ // items iniciales seleccionados
94
+ let initialSelectedItems = {};
95
+ items.forEach((item) => {
96
+ if (item.selected) {
97
+ if (multiple) initialSelectedItems[item.value] = item.value;
98
+ else initialSelectedItems = { [item.value]: item.value };
99
+ }
100
+ });
101
+ setSelectedItems(initialSelectedItems);
102
+ }, [items]);
103
+
104
+ // cada que cambien los items seleccionados
105
+ useEffect(() => {
106
+ if (!selectedItems) return;
107
+ renderItems();
108
+ renderLabelSelect();
109
+ onChange && onChange(Object.values(selectedItems));
110
+ }, [selectedItems]);
111
+
112
+ // evento click de cada item de la lista
113
+ const onClickItem = (isSelected, value) => {
114
+ let selectedItemsCopy = { ...selectedItems };
115
+ if (isSelected) {
116
+ multiple
117
+ ? (selectedItemsCopy[value] = value)
118
+ : (selectedItemsCopy = { [value]: value });
119
+ } else delete selectedItemsCopy[value];
120
+ setSelectedItems(selectedItemsCopy);
121
+ };
122
+
123
+ const onClickSearch = () => {
124
+ setTextInputSearch(textInputSearch.trim());
125
+ refInputTextSearch?.current && refInputTextSearch.current.blur();
126
+ renderItems(textInputSearch.trim());
127
+ };
128
+
129
+ const renderLabelSelect = () => {
130
+ if (!selectedItems) return;
131
+ const selectedItemsCopy = Object.values(selectedItems);
132
+ if (selectedItemsCopy.length > 1) {
133
+ setLabelSelect("Personalizado");
134
+ } else if (selectedItemsCopy.length === 1) {
135
+ let labelItem = undefined;
136
+ for (const item of items) {
137
+ if (item.value == selectedItemsCopy[0]) {
138
+ labelItem = item.label;
139
+ break;
140
+ }
141
+ }
142
+ !isStringEmpty(labelItem)
143
+ ? setLabelSelect(labelItem)
144
+ : setLabelSelect("Sin titulo");
145
+ } else {
146
+ if (
147
+ !isStringEmpty(defaultItem?.label) &&
148
+ defaultItem?.showLabelInSelect
149
+ ) {
150
+ setLabelSelect(defaultItem.label);
151
+ } else if (!isStringEmpty(selectButton?.label)) {
152
+ setLabelSelect(selectButton.label);
153
+ } else {
154
+ setLabelSelect("Sin titulo");
155
+ }
156
+ }
157
+ };
158
+
159
+ const renderItems = (textSearch = "") => {
160
+ if (isArrayEmpty(items)) setCustomItems([]);
161
+ setCustomItems(
162
+ items.map((item, index) => {
163
+ if (
164
+ !isStringEmpty(textSearch) &&
165
+ !item.label
166
+ .trim()
167
+ .toLowerCase()
168
+ .includes(textSearch.trim().toLowerCase())
169
+ ) {
170
+ return null;
171
+ }
172
+ return (
173
+ <SelectItemV2
174
+ key={classNameSelect + "_item" + index}
175
+ label={item.label}
176
+ value={item.value}
177
+ checkbox={
178
+ typeSelectItems === "checkbox"
179
+ ? true
180
+ : typeSelectItems === "marginCheckbox"
181
+ ? false
182
+ : undefined
183
+ }
184
+ selected={selectedItems && selectedItems[item.value] ? true : false}
185
+ onClick={onClickItem}
186
+ />
187
+ );
188
+ })
189
+ );
190
+ };
191
+
192
+ return (
193
+ <ClickAwayListener
194
+ onClickAway={(event) => {
195
+ if (triggerType !== "hover") setShowDropdown(false);
196
+ }}
197
+ >
198
+ <Container
199
+ className={!isStringEmpty(classNameSelect) ? classNameSelect : ""}
200
+ borderType={borderType}
201
+ maxWidthSelect={maxWidthSelect}
202
+ maxWidthDropdown={maxWidthDropdown}
203
+ maxHeightDropdown={maxHeightDropdown}
204
+ alignmentItemsOverflow={alignmentItemsOverflow}
205
+ maxWidthItems={maxWidthItems}
206
+ >
207
+ <TooltipMUI
208
+ {...props}
209
+ placement={positions[positionDropdown] ?? positions.bottomCenter}
210
+ open={triggerType !== "hover" ? showDropdown : undefined}
211
+ arrow={false}
212
+ componentsProps={{
213
+ tooltip: {
214
+ className:
215
+ "dropdownSelect" +
216
+ (isStringEmpty(classNameDropdown)
217
+ ? ""
218
+ : " " + classNameDropdown),
219
+ },
220
+ popper: { disablePortal: true },
221
+ transition: { timeout: 300 },
222
+ }}
223
+ TransitionComponent={Fade}
224
+ enterDelay={100}
225
+ followCursor={false}
226
+ disableFocusListener
227
+ disableTouchListener
228
+ disableHoverListener={triggerType !== "hover"}
229
+ title={
230
+ <>
231
+ {/* input search */}
232
+ {inputSearch && (
233
+ <div
234
+ className={
235
+ "container-inputSearch" +
236
+ (!isStringEmpty(inputSearch?.className)
237
+ ? " " + inputSearch.className
238
+ : "")
239
+ }
240
+ >
241
+ <ButtonV2
242
+ className="buttonSearch"
243
+ type={"gray"}
244
+ transparent
245
+ size={14}
246
+ icon={IconSearch}
247
+ onClick={(event) => {
248
+ if (
249
+ isStringEmpty(textInputSearch) &&
250
+ refInputTextSearch?.current
251
+ ) {
252
+ setTextInputSearch("");
253
+ refInputTextSearch.current.focus();
254
+ } else {
255
+ onClickSearch();
256
+ }
257
+ }}
258
+ />
259
+
260
+ <InputText
261
+ className="inputSearch"
262
+ type="black"
263
+ transparent
264
+ size={12}
265
+ placeHolder={
266
+ isStringEmpty(inputSearch?.defaultText)
267
+ ? "Texto a buscar"
268
+ : inputSearch.defaultText
269
+ }
270
+ text={textInputSearch}
271
+ onChangeText={(newValue) => setTextInputSearch(newValue)}
272
+ onEnter={(event) => onClickSearch()}
273
+ refInputText={refInputTextSearch}
274
+ />
275
+ </div>
276
+ )}
277
+
278
+ {/* item por default */}
279
+ {defaultItem && (
280
+ <SelectItemV2
281
+ label={defaultItem.label}
282
+ value={null}
283
+ checkbox={
284
+ defaultItem.itemType === "checkbox"
285
+ ? true
286
+ : defaultItem.itemType === "marginCheckbox"
287
+ ? false
288
+ : undefined
289
+ }
290
+ selected={
291
+ selectedItems && Object.keys(selectedItems).length
292
+ ? false
293
+ : true
294
+ }
295
+ onClick={(isSelected, value) => {
296
+ selectedItems &&
297
+ Object.keys(selectedItems).length &&
298
+ setSelectedItems({});
299
+ }}
300
+ />
301
+ )}
302
+
303
+ {/* lista de items */}
304
+ <div className="container-items">{customItems}</div>
305
+ </>
306
+ }
307
+ >
308
+ <ContainerSelect className={"container-buttonSelect"}>
309
+ <ButtonV2
310
+ className={
311
+ "buttonSelect" +
312
+ (!isStringEmpty(selectButton?.className)
313
+ ? " " + selectButton.className
314
+ : "")
315
+ }
316
+ disabled={selectButton?.disabled}
317
+ type={selectButton?.type}
318
+ transparent={selectButton?.transparent}
319
+ label={labelSelect}
320
+ size={selectButton?.size}
321
+ icon={IconDownArrow}
322
+ iconPosition="end"
323
+ onClick={(event) => {
324
+ if (triggerType !== "hover") setShowDropdown((prev) => !prev);
325
+ }}
326
+ />
327
+ </ContainerSelect>
328
+ </TooltipMUI>
329
+ </Container>
330
+ </ClickAwayListener>
331
+ );
332
+ };