@dropi/react-native-design-system 0.3.23 → 0.3.25

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