contentoh-components-library 21.6.25 → 21.6.27

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.
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.SingleSelect = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _styles = require("./styles");
15
+
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+
18
+ /*
19
+ Select de opción única con búsqueda escribiendo.
20
+
21
+ Es el CustomSelect que la aplicación usa en el alta de productos, traído a la
22
+ librería para que las pantallas que viven aquí no tengan que caer en el <select>
23
+ del sistema, que se ve ajeno al resto de la plataforma.
24
+
25
+ Se llama distinto porque la librería ya exporta un `CustomSelect`: aquel es un
26
+ filtro de selección múltiple con calendario, otra cosa. Compartir nombre habría
27
+ roto el export global.
28
+
29
+ Tres cambios respecto al original, todos porque aquí el entorno es otro:
30
+ el ancho es flexible en vez de 210px fijos —en el modal van tres en fila—, los
31
+ colores salen de las variables de la librería en lugar de `var(--gray)`, y la
32
+ flecha va dibujada porque la fuente de iconos de Material la carga la
33
+ aplicación, no esta librería.
34
+
35
+ props:
36
+ - options: [{ label, value }]
37
+ - value: el value seleccionado
38
+ - onChange: recibe el value elegido, o null al limpiar
39
+ - placeholder, disabled, loading
40
+ */
41
+ var SingleSelect = function SingleSelect(_ref) {
42
+ var id = _ref.id,
43
+ className = _ref.className,
44
+ _ref$placeholder = _ref.placeholder,
45
+ placeholder = _ref$placeholder === void 0 ? "Selecciona una opción" : _ref$placeholder,
46
+ _ref$options = _ref.options,
47
+ options = _ref$options === void 0 ? [] : _ref$options,
48
+ onChange = _ref.onChange,
49
+ _ref$loading = _ref.loading,
50
+ loading = _ref$loading === void 0 ? false : _ref$loading,
51
+ _ref$value = _ref.value,
52
+ value = _ref$value === void 0 ? "" : _ref$value,
53
+ _ref$disabled = _ref.disabled,
54
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
55
+
56
+ var _useState = (0, _react.useState)(false),
57
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
58
+ isOpen = _useState2[0],
59
+ setIsOpen = _useState2[1];
60
+
61
+ var _useState3 = (0, _react.useState)(value),
62
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
63
+ selectedValue = _useState4[0],
64
+ setSelectedValue = _useState4[1];
65
+
66
+ var _useState5 = (0, _react.useState)(""),
67
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
68
+ inputValue = _useState6[0],
69
+ setInputValue = _useState6[1];
70
+
71
+ var wrapperRef = (0, _react.useRef)(null);
72
+ var inputRef = (0, _react.useRef)(null);
73
+ var selectedOption = options.find(function (option) {
74
+ return "".concat(option === null || option === void 0 ? void 0 : option.value) === "".concat(selectedValue);
75
+ });
76
+ var filteredOptions = loading ? [] : options.filter(function (option) {
77
+ var _option$label;
78
+
79
+ return ((_option$label = option === null || option === void 0 ? void 0 : option.label) !== null && _option$label !== void 0 ? _option$label : "").toLowerCase().includes(inputValue.toLowerCase());
80
+ });
81
+
82
+ var handleSelect = function handleSelect(option) {
83
+ setSelectedValue(option === null || option === void 0 ? void 0 : option.value);
84
+ setInputValue("");
85
+ onChange === null || onChange === void 0 ? void 0 : onChange(option === null || option === void 0 ? void 0 : option.value);
86
+ setIsOpen(false);
87
+ };
88
+
89
+ var clearSelected = function clearSelected() {
90
+ setSelectedValue("");
91
+ setInputValue("");
92
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
93
+ };
94
+
95
+ (0, _react.useEffect)(function () {
96
+ var handleClickOutside = function handleClickOutside(event) {
97
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
98
+ setIsOpen(false);
99
+ }
100
+ };
101
+
102
+ document.addEventListener("mousedown", handleClickOutside);
103
+ return function () {
104
+ return document.removeEventListener("mousedown", handleClickOutside);
105
+ };
106
+ }, []); // Al deshabilitarse se limpia: un nivel de cascada que se apaga no puede
107
+ // quedarse mostrando la elección anterior, que ya no significa nada.
108
+
109
+ (0, _react.useEffect)(function () {
110
+ if (disabled) {
111
+ setSelectedValue("");
112
+ setInputValue("");
113
+ }
114
+ }, [disabled]);
115
+ (0, _react.useEffect)(function () {
116
+ setSelectedValue(value);
117
+ }, [value]);
118
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SelectWrapper, {
119
+ id: id,
120
+ className: className,
121
+ ref: wrapperRef,
122
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SelectBase, {
123
+ disabled: disabled,
124
+ className: "selectBase",
125
+ onClick: function onClick() {
126
+ if (!disabled && !isOpen) setIsOpen(true);
127
+ },
128
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
129
+ children: [selectedOption ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.SelectedOptionItem, {
130
+ title: selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label,
131
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
132
+ children: selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label
133
+ })
134
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
135
+ type: "text",
136
+ placeholder: selectedOption ? "" : placeholder,
137
+ value: inputValue,
138
+ disabled: disabled,
139
+ ref: inputRef,
140
+ onChange: function onChange(event) {
141
+ return setInputValue(event.target.value);
142
+ },
143
+ onFocus: function onFocus() {
144
+ if (!isOpen) setIsOpen(true);
145
+ },
146
+ onKeyDown: function onKeyDown(event) {
147
+ var _inputRef$current;
148
+
149
+ var esBorrar = event.key === "Backspace";
150
+ var vacio = (((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) || "") === "";
151
+ if (!isOpen) setIsOpen(true); // Borrar con el campo vacío deshace la elección, que es lo que
152
+ // espera quien escribe para cambiarla.
153
+
154
+ if (esBorrar && vacio && selectedValue !== "") clearSelected();
155
+
156
+ if (event.key === "Enter" && filteredOptions.length > 0) {
157
+ event.preventDefault();
158
+ handleSelect(filteredOptions[0]);
159
+ }
160
+ },
161
+ onBlur: function onBlur() {
162
+ setTimeout(function () {
163
+ if (wrapperRef.current && !wrapperRef.current.contains(document.activeElement)) {
164
+ setIsOpen(false);
165
+ }
166
+ }, 0);
167
+ }
168
+ })]
169
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Arrow, {
170
+ "aria-hidden": "true",
171
+ children: "\u25BC"
172
+ })]
173
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Options, {
174
+ open: isOpen,
175
+ "data-testid": "options",
176
+ children: filteredOptions.length > 0 ? filteredOptions.map(function (option) {
177
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.OptionItem, {
178
+ selected: "".concat(option === null || option === void 0 ? void 0 : option.value) === "".concat(selectedValue),
179
+ onClick: function onClick() {
180
+ return handleSelect(option);
181
+ },
182
+ className: inputValue.trim() !== "" && option === filteredOptions[0] ? "first" : "",
183
+ tabIndex: -1,
184
+ children: option === null || option === void 0 ? void 0 : option.label
185
+ }, option === null || option === void 0 ? void 0 : option.value);
186
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.OptionItem, {
187
+ disabled: true,
188
+ style: {
189
+ pointerEvents: "none",
190
+ opacity: 0.5
191
+ },
192
+ children: loading ? "Cargando…" : "No se encontraron elementos"
193
+ })
194
+ })]
195
+ });
196
+ };
197
+
198
+ exports.SingleSelect = SingleSelect;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.SelectedOptionItem = exports.SelectWrapper = exports.SelectBase = exports.Options = exports.OptionItem = exports.Arrow = void 0;
9
+
10
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/taggedTemplateLiteral"));
11
+
12
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
13
+
14
+ require("../../../global-files/global-styles.css");
15
+
16
+ var _variables = require("../../../global-files/variables");
17
+
18
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
19
+
20
+ var PINK = "#E13AA8";
21
+
22
+ var SelectWrapper = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n display: flex;\n align-items: center;\n flex: 1 1 0;\n min-width: 0;\n font-family: ", ";\n font-size: 13px;\n user-select: none;\n box-sizing: border-box;\n"])), _variables.FontFamily.Raleway);
23
+
24
+ exports.SelectWrapper = SelectWrapper;
25
+
26
+ var SelectBase = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n width: 100%;\n min-width: 0;\n border-radius: 5px 5px 0 0;\n border-bottom: 1px solid rgba(225, 58, 168, 0.5);\n color: ", ";\n display: flex;\n gap: 8px;\n align-items: center;\n white-space: nowrap;\n overflow-x: hidden;\n padding: 0;\n\n cursor: ", ";\n opacity: ", ";\n pointer-events: ", ";\n\n > div {\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n min-width: 0;\n }\n\n > div > input {\n width: 100%;\n min-width: 0;\n border: none;\n outline: none;\n padding: 9px 22px 9px 10px;\n border-radius: 5px 5px 0 0;\n font-family: ", ";\n font-size: 13px;\n color: ", ";\n background: none;\n }\n\n > div > input::placeholder {\n color: ", ";\n }\n"])), _variables.GlobalColors.deep_gray, function (_ref) {
27
+ var disabled = _ref.disabled;
28
+ return disabled ? "not-allowed" : "pointer";
29
+ }, function (_ref2) {
30
+ var disabled = _ref2.disabled;
31
+ return disabled ? 0.5 : 1;
32
+ }, function (_ref3) {
33
+ var disabled = _ref3.disabled;
34
+ return disabled ? "none" : "auto";
35
+ }, _variables.FontFamily.Raleway, _variables.GlobalColors.deep_gray, _variables.GlobalColors.gray);
36
+
37
+ exports.SelectBase = SelectBase;
38
+
39
+ var SelectedOptionItem = _styledComponents.default.div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n max-width: 60%;\n display: flex;\n align-items: center;\n border-radius: 5px;\n padding: 5px 8px;\n background-color: rgba(225, 58, 168, 0.06);\n color: ", ";\n font-size: 12px;\n\n > p {\n width: 100%;\n margin: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n"])), _variables.GlobalColors.gray);
40
+ /*
41
+ Flecha dibujada, no un icono de fuente. El componente original usaba
42
+ material-symbols-outlined, que la aplicación carga y esta librería no: aquí
43
+ habría salido la palabra "arrow_drop_down" escrita donde debería ir el triángulo.
44
+ */
45
+
46
+
47
+ exports.SelectedOptionItem = SelectedOptionItem;
48
+
49
+ var Arrow = _styledComponents.default.span(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n position: absolute;\n right: 6px;\n pointer-events: none;\n color: ", ";\n font-size: 10px;\n line-height: 1;\n"])), PINK);
50
+
51
+ exports.Arrow = Arrow;
52
+
53
+ var Options = _styledComponents.default.ul(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n position: absolute;\n top: 100%;\n left: 0;\n width: 100%;\n max-height: 180px;\n overflow-y: auto;\n background-color: ", ";\n border-radius: 8px;\n border: 1px solid ", ";\n box-shadow: 0 4px 8px rgb(0 0 0 / 18%);\n margin: 0;\n padding: 0;\n list-style: none;\n display: ", ";\n z-index: 1000;\n"])), _variables.GlobalColors.white, _variables.GlobalColors.s2, function (_ref4) {
54
+ var open = _ref4.open;
55
+ return open ? "block" : "none";
56
+ });
57
+
58
+ exports.Options = Options;
59
+
60
+ var OptionItem = _styledComponents.default.li(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n padding: 9px 12px;\n cursor: pointer;\n font-size: 12px;\n white-space: normal;\n background-color: ", ";\n color: ", ";\n\n &.first {\n background-color: ", ";\n }\n\n &:hover {\n background-color: ", ";\n }\n"])), function (_ref5) {
61
+ var selected = _ref5.selected;
62
+ return selected ? PINK : _variables.GlobalColors.white;
63
+ }, function (_ref6) {
64
+ var selected = _ref6.selected;
65
+ return selected ? _variables.GlobalColors.white : _variables.GlobalColors.gray;
66
+ }, function (_ref7) {
67
+ var selected = _ref7.selected;
68
+ return selected ? PINK : "rgba(225, 58, 168, 0.1)";
69
+ }, function (_ref8) {
70
+ var selected = _ref8.selected;
71
+ return selected ? PINK : "rgba(225, 58, 168, 0.06)";
72
+ });
73
+
74
+ exports.OptionItem = OptionItem;