aport-tools 4.1.31 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.1.31 | ISC */
1
+ /*! aport-tools v4.2.1 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -83,6 +83,16 @@ function __generator(thisArg, body) {
83
83
  }
84
84
  }
85
85
 
86
+ function __spreadArray(to, from, pack) {
87
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
88
+ if (ar || !(i in from)) {
89
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
90
+ ar[i] = from[i];
91
+ }
92
+ }
93
+ return to.concat(ar || Array.prototype.slice.call(from));
94
+ }
95
+
86
96
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
87
97
  var e = new Error(message);
88
98
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -152,6 +162,8 @@ var Form = function Form(_a) {
152
162
  * @param size - Size of the text. Defaults to 'medium'.
153
163
  * @param b - If true, applies bold styling.
154
164
  * @param i - If true, applies italic styling.
165
+ * @param type - Type of Text component. Defaults to 'text'.
166
+ * @param typeFont - Type of Font component. Defaults to 'body'.
155
167
  * @param u - If true, applies underline styling.
156
168
  * @param align - Paragraph alignment. Defaults to 'left'.
157
169
  * @param h - Header level. Accepts 0 (none), 1, 2, or 3. Defaults to 0.
@@ -172,16 +184,22 @@ var Text = function Text(_a) {
172
184
  align = _g === void 0 ? 'left' : _g,
173
185
  _h = _a.type,
174
186
  type = _h === void 0 ? 'text' : _h,
175
- _j = _a.h,
176
- h = _j === void 0 ? 0 : _j,
187
+ _j = _a.typeFont,
188
+ typeFont = _j === void 0 ? 'body' : _j,
189
+ _k = _a.h,
190
+ h = _k === void 0 ? 0 : _k,
177
191
  style = _a.style;
178
192
  var theme = React.useContext(aportThemes.ThemeContext).theme;
179
- var colors = theme.colors;
193
+ var colors = theme.colors,
194
+ fonts = theme.fonts;
195
+ // Determine font family and size based on 'typeFont'
196
+ var fontSettings = fonts[typeFont] || fonts.body;
197
+ var fontFamily = fontSettings.fontFamily;
198
+ var fontSize = fontSettings.fontSize || size;
180
199
  // Calculate header size based on 'h' prop
181
- var fontSize = size;
182
200
  if (h === 1) fontSize = 32;else if (h === 2) fontSize = 24;else if (h === 3) fontSize = 18;
183
201
  // Define font weight based on bold prop
184
- var fontWeight = b ? '700' : '400';
202
+ var fontWeight = b ? '700' : fontSettings.fontWeight || '400';
185
203
  // Define font style based on italic prop
186
204
  var fontStyle = i ? 'italic' : 'normal';
187
205
  // Define text decoration based on underline prop
@@ -194,6 +212,7 @@ var Text = function Text(_a) {
194
212
  var textStyles = {
195
213
  fontSize: fontSize,
196
214
  fontWeight: fontWeight,
215
+ fontFamily: fontFamily,
197
216
  fontStyle: fontStyle,
198
217
  textDecorationLine: textDecorationLine,
199
218
  textAlign: textAlign,
@@ -213,23 +232,23 @@ var ErrorList = function ErrorList(_a) {
213
232
  var theme = React.useContext(aportThemes.ThemeContext).theme;
214
233
  var colors = theme.colors;
215
234
  return /*#__PURE__*/React.createElement(reactNative.View, {
216
- style: styles$5.container
235
+ style: styles$6.container
217
236
  }, errors.map(function (error, index) {
218
237
  return /*#__PURE__*/React.createElement(reactNative.View, {
219
238
  key: index,
220
- style: styles$5.errorItem
239
+ style: styles$6.errorItem
221
240
  }, /*#__PURE__*/React.createElement(Text, {
222
- style: [styles$5.bullet, {
241
+ style: [styles$6.bullet, {
223
242
  color: colors.error.hex
224
243
  }]
225
244
  }, "\u2022"), /*#__PURE__*/React.createElement(Text, {
226
- style: [styles$5.errorText, {
245
+ style: [styles$6.errorText, {
227
246
  color: colors.error.hex
228
247
  }]
229
248
  }, error));
230
249
  }));
231
250
  };
232
- var styles$5 = reactNative.StyleSheet.create({
251
+ var styles$6 = reactNative.StyleSheet.create({
233
252
  container: {
234
253
  marginTop: 4
235
254
  },
@@ -307,13 +326,13 @@ var Input = function Input(_a) {
307
326
  setFormValue(name, formattedText);
308
327
  };
309
328
  return /*#__PURE__*/React.createElement(reactNative.View, {
310
- style: styles$4.container
329
+ style: styles$5.container
311
330
  }, /*#__PURE__*/React.createElement(Text, {
312
- style: [styles$4.label, {
331
+ style: [styles$5.label, {
313
332
  color: colors.text.hex
314
333
  }]
315
334
  }, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
316
- style: [styles$4.input, {
335
+ style: [styles$5.input, {
317
336
  backgroundColor: colors.body.hex,
318
337
  borderColor: formErrors[name] ? colors.error.hex : "#CCC",
319
338
  color: colors.text.hex
@@ -326,7 +345,7 @@ var Input = function Input(_a) {
326
345
  errors: formErrors[name]
327
346
  })));
328
347
  };
329
- var styles$4 = reactNative.StyleSheet.create({
348
+ var styles$5 = reactNative.StyleSheet.create({
330
349
  container: {
331
350
  marginBottom: 16
332
351
  },
@@ -357,11 +376,11 @@ var TextArea = function TextArea(_a) {
357
376
  setFormValue(name, text);
358
377
  };
359
378
  return /*#__PURE__*/React.createElement(reactNative.View, {
360
- style: styles$3.container
379
+ style: styles$4.container
361
380
  }, /*#__PURE__*/React.createElement(Text, {
362
- style: styles$3.label
381
+ style: styles$4.label
363
382
  }, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
364
- style: [styles$3.textArea, style],
383
+ style: [styles$4.textArea, style],
365
384
  value: formValues[name] || '',
366
385
  onChangeText: handleChange,
367
386
  placeholder: label,
@@ -374,7 +393,7 @@ var TextArea = function TextArea(_a) {
374
393
  errors: formErrors[name]
375
394
  })));
376
395
  };
377
- var styles$3 = reactNative.StyleSheet.create({
396
+ var styles$4 = reactNative.StyleSheet.create({
378
397
  container: {
379
398
  marginBottom: 16
380
399
  },
@@ -403,18 +422,191 @@ var Label = function Label(_a) {
403
422
  var theme = React.useContext(aportThemes.ThemeContext).theme;
404
423
  var colors = theme.colors;
405
424
  return /*#__PURE__*/React.createElement(Text, {
406
- style: [styles$2.label, style, {
425
+ style: [styles$3.label, style, {
407
426
  color: colors.text.hex
408
427
  }]
409
428
  }, text);
410
429
  };
411
- var styles$2 = reactNative.StyleSheet.create({
430
+ var styles$3 = reactNative.StyleSheet.create({
412
431
  label: {
413
432
  marginBottom: 4,
414
433
  fontWeight: '500'
415
434
  }
416
435
  });
417
436
 
437
+ /**
438
+ * InputList component - A custom dropdown list component for React Native with multi-selection support,
439
+ * customizable styling, sorting, and configurable close behavior on selection or scrolling.
440
+ *
441
+ * @param {string} placeholder - Placeholder text for the input.
442
+ * @param {object} style - Custom styles for the component.
443
+ * @param {Option[]} options - Array of options to display in the dropdown.
444
+ * @param {boolean} multi - Enables multi-selection mode.
445
+ * @param {boolean} disabled - Disables the dropdown input.
446
+ * @param {keyof Option} sortBy - Key to sort options by (e.g., 'id').
447
+ * @param {boolean} separator - If true, adds a separator line between options.
448
+ * @param {boolean} closeOnScroll - Closes the dropdown if the user scrolls the list.
449
+ * @param {boolean} closeOnSelect - Closes the dropdown on selection in single-select mode.
450
+ * @param {number} maxSelection - Maximum number of items selectable in multi-select mode.
451
+ */
452
+ var InputList = function InputList(_a) {
453
+ var name = _a.name,
454
+ _b = _a.placeholder,
455
+ placeholder = _b === void 0 ? "Choose value/s" : _b,
456
+ style = _a.style,
457
+ options = _a.options,
458
+ _c = _a.multi,
459
+ multi = _c === void 0 ? false : _c,
460
+ _d = _a.disabled,
461
+ disabled = _d === void 0 ? false : _d,
462
+ sortBy = _a.sortBy,
463
+ _e = _a.separator,
464
+ separator = _e === void 0 ? false : _e,
465
+ _f = _a.closeOnScroll,
466
+ closeOnScroll = _f === void 0 ? false : _f,
467
+ _g = _a.closeOnSelect,
468
+ closeOnSelect = _g === void 0 ? true : _g,
469
+ maxSelection = _a.maxSelection;
470
+ var _h = useFormContext(),
471
+ formValues = _h.formValues,
472
+ setFormValue = _h.setFormValue;
473
+ var _j = React.useState(false),
474
+ isDropdownVisible = _j[0],
475
+ setIsDropdownVisible = _j[1];
476
+ var selectedOptions = formValues[name] || (multi ? [] : null);
477
+ var sortedOptions = sortBy ? __spreadArray([], options, true).sort(function (a, b) {
478
+ return a[sortBy] > b[sortBy] ? 1 : -1;
479
+ }) : options;
480
+ var theme = React.useContext(aportThemes.ThemeContext).theme;
481
+ var colors = theme.colors;
482
+ /**
483
+ * Handles selection of an option. Adds or removes the option from selectedOptions based on
484
+ * multi-selection and maxSelection criteria.
485
+ * @param {Option} option - The selected option object.
486
+ */
487
+ var handleSelectOption = function handleSelectOption(option) {
488
+ if (multi) {
489
+ var alreadySelected = selectedOptions.some(function (opt) {
490
+ return opt.id === option.id;
491
+ });
492
+ var updatedSelections = alreadySelected ? selectedOptions.filter(function (opt) {
493
+ return opt.id !== option.id;
494
+ }) : __spreadArray(__spreadArray([], selectedOptions, true), [option], false);
495
+ // Close dropdown if max selection reached
496
+ if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
497
+ setIsDropdownVisible(false);
498
+ }
499
+ // Update form value with selected items
500
+ setFormValue(name, updatedSelections);
501
+ } else {
502
+ setFormValue(name, option);
503
+ if (closeOnSelect) setIsDropdownVisible(false);
504
+ }
505
+ };
506
+ /**
507
+ * Renders selected options as a comma-separated string or the placeholder if none selected.
508
+ * @returns {string} - The display text for selected options or placeholder.
509
+ */
510
+ var renderSelectedText = function renderSelectedText() {
511
+ if (multi) return selectedOptions.map(function (opt) {
512
+ return opt.label;
513
+ }).join(', ') || placeholder;
514
+ return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
515
+ };
516
+ /**
517
+ * Toggles dropdown visibility. Disables toggle if the component is disabled.
518
+ */
519
+ var toggleDropdown = function toggleDropdown() {
520
+ if (!disabled) {
521
+ setIsDropdownVisible(!isDropdownVisible);
522
+ if (!isDropdownVisible) reactNative.Keyboard.dismiss();
523
+ }
524
+ };
525
+ /**
526
+ * Closes the dropdown when pressing outside.
527
+ */
528
+ var handleCloseDropdown = React.useCallback(function () {
529
+ if (isDropdownVisible) setIsDropdownVisible(false);
530
+ }, [isDropdownVisible]);
531
+ return /*#__PURE__*/React.createElement(reactNative.View, {
532
+ style: [styles$2.container, style]
533
+ }, /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
534
+ style: styles$2.inputContainer,
535
+ onPress: toggleDropdown,
536
+ disabled: disabled
537
+ }, /*#__PURE__*/React.createElement(reactNative.Text, {
538
+ style: {
539
+ color: colors.text.hex
540
+ }
541
+ }, renderSelectedText())), /*#__PURE__*/React.createElement(reactNative.Modal, {
542
+ visible: isDropdownVisible,
543
+ transparent: true,
544
+ animationType: "fade"
545
+ }, /*#__PURE__*/React.createElement(reactNative.Pressable, {
546
+ style: styles$2.overlay,
547
+ onPress: handleCloseDropdown
548
+ }), /*#__PURE__*/React.createElement(reactNative.View, {
549
+ style: [styles$2.dropdownContainer, {
550
+ backgroundColor: colors.body.hex
551
+ }]
552
+ }, /*#__PURE__*/React.createElement(reactNative.FlatList, {
553
+ data: sortedOptions,
554
+ keyExtractor: function keyExtractor(item) {
555
+ return item.id.toString();
556
+ },
557
+ renderItem: function renderItem(_a) {
558
+ var item = _a.item;
559
+ return /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
560
+ onPress: function onPress() {
561
+ return handleSelectOption(item);
562
+ },
563
+ style: styles$2.optionItem
564
+ }, /*#__PURE__*/React.createElement(reactNative.Text, {
565
+ style: {
566
+ color: colors.text.hex
567
+ }
568
+ }, item.label));
569
+ },
570
+ ItemSeparatorComponent: function ItemSeparatorComponent() {
571
+ return separator ? /*#__PURE__*/React.createElement(reactNative.View, {
572
+ style: styles$2.separator
573
+ }) : null;
574
+ },
575
+ scrollEnabled: !closeOnScroll
576
+ }))));
577
+ };
578
+ var styles$2 = reactNative.StyleSheet.create({
579
+ container: {
580
+ padding: 8
581
+ },
582
+ inputContainer: {
583
+ padding: 12,
584
+ borderWidth: 1,
585
+ borderColor: '#ccc',
586
+ borderRadius: 5
587
+ },
588
+ dropdownContainer: {
589
+ position: 'absolute',
590
+ top: 60,
591
+ width: '90%',
592
+ borderRadius: 8,
593
+ elevation: 5,
594
+ alignSelf: 'center'
595
+ },
596
+ optionItem: {
597
+ padding: 12
598
+ },
599
+ separator: {
600
+ height: 1,
601
+ backgroundColor: '#ddd',
602
+ marginHorizontal: 8
603
+ },
604
+ overlay: {
605
+ flex: 1,
606
+ backgroundColor: 'rgba(0,0,0,0.3)'
607
+ }
608
+ });
609
+
418
610
  // src/components/Button.tsx
419
611
  /**
420
612
  * Determines the styles based on the button type and whether it is disabled.
@@ -598,6 +790,7 @@ exports.Card = Card;
598
790
  exports.ErrorList = ErrorList;
599
791
  exports.Form = Form;
600
792
  exports.Input = Input;
793
+ exports.InputList = InputList;
601
794
  exports.Label = Label;
602
795
  exports.Text = Text;
603
796
  exports.TextArea = TextArea;