@dropi/react-native-design-system 0.3.24 → 0.3.26

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,21 @@
1
+ export type MultipleSelectOption = {
2
+ label: string;
3
+ value: string | number;
4
+ description?: string;
5
+ };
6
+ type MultipleSelectProps = {
7
+ options: MultipleSelectOption[];
8
+ selectedValues: (string | number)[];
9
+ onChange: (options: MultipleSelectOption[]) => void;
10
+ label?: string;
11
+ placeholder?: string;
12
+ helper?: string;
13
+ hasError?: boolean;
14
+ errorMessage?: string;
15
+ title?: string;
16
+ disabled?: boolean;
17
+ searchFilter?: boolean;
18
+ onRestablish?: () => void;
19
+ };
20
+ export declare const MultipleSelect: ({ options, selectedValues, onChange, label, placeholder, helper, hasError, errorMessage, title, disabled, searchFilter, onRestablish, }: MultipleSelectProps) => import("react/jsx-runtime").JSX.Element;
21
+ export {};
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MultipleSelect = void 0;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _reactNative2 = _interopRequireDefault(require("dropi-lib-icons/react-native"));
10
+ var _BottomSheet = require("../BottomSheet");
11
+ var _atoms = require("../../atoms");
12
+ var _Search = require("../Search");
13
+ var _constants = require("../../constants");
14
+ var _reactNativeGestureHandler = require("react-native-gesture-handler");
15
+ var _Checkbox = require("../Checkbox");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ const MultipleSelect = ({
19
+ options,
20
+ selectedValues,
21
+ onChange,
22
+ label,
23
+ placeholder = "Seleccionar",
24
+ helper,
25
+ hasError = false,
26
+ errorMessage,
27
+ title,
28
+ disabled = false,
29
+ searchFilter = false,
30
+ onRestablish
31
+ }) => {
32
+ const bottomSheetRef = (0, _react.useRef)(null);
33
+ const [isFocus, setIsFocus] = (0, _react.useState)(false);
34
+ const [draftSelection, setDraftSelection] = (0, _react.useState)([]);
35
+ const [filterText, setFilterText] = (0, _react.useState)("");
36
+ const getBorderColor = () => {
37
+ if (hasError) return _constants.colors["Error-500"].light;
38
+ if (isFocus) return _constants.colors["Info-500"].light;
39
+ return _constants.colors["Gray-200"].light;
40
+ };
41
+ const hasChanges = (0, _react.useMemo)(() => {
42
+ if (draftSelection.length !== selectedValues.length) return true;
43
+ const sortedDraft = [...draftSelection].sort();
44
+ const sortedCurrent = [...selectedValues].sort();
45
+ return sortedDraft.some((v, i) => v !== sortedCurrent[i]);
46
+ }, [draftSelection, selectedValues]);
47
+ const displayText = (0, _react.useMemo)(() => {
48
+ if (!selectedValues.length) return null;
49
+ const selectedOptions = options.filter(opt => selectedValues.includes(opt.value));
50
+ const count = selectedOptions.length;
51
+ const labels = selectedOptions.map(opt => opt.label).join(", ");
52
+ return {
53
+ count,
54
+ labels
55
+ };
56
+ }, [selectedValues, options]);
57
+ const handleOpen = (0, _react.useCallback)(() => {
58
+ if (disabled) return;
59
+ setDraftSelection([...selectedValues]);
60
+ setIsFocus(true);
61
+ bottomSheetRef.current?.present();
62
+ }, [disabled, selectedValues]);
63
+ const handleToggle = (0, _react.useCallback)(value => {
64
+ setDraftSelection(prev => prev.includes(value) ? prev.filter(v => v !== value) : [...prev, value]);
65
+ }, []);
66
+ const handleSave = (0, _react.useCallback)(() => {
67
+ const selectedOptions = options.filter(opt => draftSelection.includes(opt.value));
68
+ onChange(selectedOptions);
69
+ bottomSheetRef.current?.dismiss();
70
+ setIsFocus(false);
71
+ }, [draftSelection, onChange, options]);
72
+ const handleDismiss = (0, _react.useCallback)(() => {
73
+ setIsFocus(false);
74
+ setDraftSelection([]);
75
+ setFilterText("");
76
+ }, []);
77
+ const handleRestablish = (0, _react.useCallback)(() => {
78
+ if (onRestablish) {
79
+ onRestablish();
80
+ bottomSheetRef.current?.dismiss();
81
+ setIsFocus(false);
82
+ }
83
+ }, [onRestablish]);
84
+ const filteredOptions = (0, _react.useMemo)(() => {
85
+ if (!searchFilter || !filterText) return options;
86
+ return options.filter(opt => opt.label.toLowerCase().includes(filterText.toLowerCase()));
87
+ }, [options, searchFilter, filterText]);
88
+ const renderOption = (0, _react.useCallback)(({
89
+ item
90
+ }) => {
91
+ const isChecked = draftSelection.includes(item.value);
92
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.Checkbox, {
93
+ title: item.label,
94
+ description: item.description,
95
+ isChecked: isChecked,
96
+ onToggle: () => handleToggle(item.value)
97
+ });
98
+ }, [draftSelection, handleToggle]);
99
+ const footer = (0, _react.useMemo)(() => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
100
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.DefaultButton, {
101
+ label: "Guardar",
102
+ variant: "primary",
103
+ size: "large",
104
+ onPress: handleSave,
105
+ disabled: !hasChanges
106
+ }), onRestablish && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
107
+ style: styles.footerSecondaryButton,
108
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.TextButton, {
109
+ label: "Restablecer",
110
+ variant: "primary",
111
+ size: "large",
112
+ onPress: handleRestablish
113
+ })
114
+ })]
115
+ }), [handleSave, hasChanges, onRestablish, handleRestablish]);
116
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
117
+ style: styles.fieldContainer,
118
+ children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.Body, {
119
+ type: "m-regular",
120
+ style: {
121
+ color: _constants.colors["Gray-600"].light
122
+ },
123
+ children: label
124
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
125
+ style: [styles.selectButton, {
126
+ borderColor: getBorderColor()
127
+ }, disabled && styles.disabled],
128
+ onPress: handleOpen,
129
+ activeOpacity: 0.7,
130
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
131
+ style: styles.displayTextContainer,
132
+ children: displayText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
133
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
134
+ style: styles.countBadge,
135
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.Body, {
136
+ type: "s-regular",
137
+ style: styles.countText,
138
+ children: displayText.count
139
+ })
140
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.Body, {
141
+ type: "m-regular",
142
+ style: {
143
+ color: _constants.colors["Gray-600"].light,
144
+ flex: 1
145
+ },
146
+ numberOfLines: 1,
147
+ ellipsizeMode: "tail",
148
+ children: displayText.labels
149
+ })]
150
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.Body, {
151
+ type: "m-regular",
152
+ style: {
153
+ color: _constants.colors["Gray-500"].light,
154
+ flex: 1
155
+ },
156
+ numberOfLines: 1,
157
+ ellipsizeMode: "tail",
158
+ children: placeholder
159
+ })
160
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative2.default, {
161
+ name: "dropdown-down",
162
+ size: _constants.sizes.xl,
163
+ color: _constants.colors["Gray-400"].light
164
+ })]
165
+ }), helper && !hasError && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
166
+ style: {
167
+ marginTop: _constants.spacing["size-2"]
168
+ },
169
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.Body, {
170
+ type: "s-regular",
171
+ style: {
172
+ color: _constants.colors["Gray-600"].light
173
+ },
174
+ children: helper
175
+ })
176
+ }), hasError && errorMessage && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
177
+ style: styles.errorContainer,
178
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
179
+ style: styles.errorIcon,
180
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative2.default, {
181
+ name: "warning-circle",
182
+ size: _constants.sizes.s,
183
+ color: _constants.colors["Error-500"].light
184
+ })
185
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_atoms.Body, {
186
+ type: "s-regular",
187
+ style: styles.errorText,
188
+ children: errorMessage
189
+ })]
190
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_BottomSheet.BottomSheetComponent, {
191
+ ref: bottomSheetRef,
192
+ title: title ?? label ?? "Seleccionar",
193
+ snapPoints: ["90%"],
194
+ onDismiss: handleDismiss,
195
+ footer: footer,
196
+ children: [searchFilter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
197
+ style: styles.searchContainer,
198
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Search.Search, {
199
+ filterText: filterText,
200
+ setFilterText: setFilterText
201
+ })
202
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.FlatList, {
203
+ data: filteredOptions,
204
+ keyExtractor: item => String(item.value),
205
+ renderItem: renderOption,
206
+ contentContainerStyle: styles.optionsList,
207
+ showsVerticalScrollIndicator: false
208
+ })]
209
+ })]
210
+ });
211
+ };
212
+ exports.MultipleSelect = MultipleSelect;
213
+ const styles = _reactNative.StyleSheet.create({
214
+ fieldContainer: {
215
+ marginBottom: _constants.spacing["size-4"],
216
+ width: "100%"
217
+ },
218
+ selectButton: {
219
+ width: "100%",
220
+ borderRadius: _constants.radius["border-2"],
221
+ borderWidth: 1,
222
+ flexDirection: "row",
223
+ alignItems: "center",
224
+ justifyContent: "space-between",
225
+ marginTop: _constants.spacing["size-2"],
226
+ height: 48,
227
+ paddingHorizontal: _constants.spacing["size-3"]
228
+ },
229
+ disabled: {
230
+ opacity: 0.5
231
+ },
232
+ displayTextContainer: {
233
+ flex: 1,
234
+ flexDirection: "row",
235
+ alignItems: "center",
236
+ marginRight: _constants.spacing["size-2"]
237
+ },
238
+ countBadge: {
239
+ backgroundColor: _constants.colors["Primary-500"].light,
240
+ borderRadius: _constants.radius.circle,
241
+ minWidth: 20,
242
+ height: 20,
243
+ alignItems: "center",
244
+ justifyContent: "center",
245
+ paddingHorizontal: _constants.spacing["size-1"],
246
+ marginRight: _constants.spacing["size-2"]
247
+ },
248
+ countText: {
249
+ color: _constants.colors.White.light,
250
+ fontSize: 11
251
+ },
252
+ errorContainer: {
253
+ marginTop: _constants.spacing["size-2"],
254
+ flexDirection: "row",
255
+ width: "100%"
256
+ },
257
+ errorIcon: {
258
+ alignItems: "center",
259
+ paddingTop: _constants.spacing["size-1"]
260
+ },
261
+ errorText: {
262
+ color: _constants.colors["Error-500"].light,
263
+ marginLeft: _constants.spacing["size-1"],
264
+ flex: 1
265
+ },
266
+ searchContainer: {
267
+ paddingHorizontal: _constants.spacing["size-5"],
268
+ paddingBottom: _constants.spacing["size-3"]
269
+ },
270
+ optionsList: {
271
+ paddingHorizontal: _constants.spacing["size-5"],
272
+ paddingBottom: _constants.spacing["size-8"]
273
+ },
274
+ footerSecondaryButton: {
275
+ marginTop: _constants.spacing["size-4"]
276
+ }
277
+ });
@@ -1 +1,2 @@
1
1
  export * from './Select';
2
+ export * from './MultipleSelect';
@@ -13,4 +13,15 @@ Object.keys(_Select).forEach(function (key) {
13
13
  return _Select[key];
14
14
  }
15
15
  });
16
+ });
17
+ var _MultipleSelect = require("./MultipleSelect");
18
+ Object.keys(_MultipleSelect).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _MultipleSelect[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _MultipleSelect[key];
25
+ }
26
+ });
16
27
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dropi/react-native-design-system",
3
- "version": "0.3.24",
3
+ "version": "0.3.26",
4
4
  "description": "A React Native package built from scratch",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",