@mirai/ui 1.0.152 → 1.0.154-beta

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.
package/README.md CHANGED
@@ -113,6 +113,7 @@ This primitive returns an element that displays with relative position to other
113
113
  - `timestamp:number` if you want to force render to recalculate the position of content, assign this property with a number (`Date.now()`).
114
114
  - `top:bool` if you want open the content above the reference component.
115
115
  - `visible:boolean` showing or hiding the layer
116
+ - `onPosition:boolean` called when the position of the layer is calculated or updated. It receives `orientation` argument, which is an object containing information about the layer's position with `top` and `left` properties
116
117
 
117
118
  The position of the layer is based on the position of the element to be displayed. If the layer can show on right or left because have a gap in this direction, the layer will be shown on the right or left of the element to be displayed. If the layer can open on top or bottom because have a gap in this direction, the layer will be shown on the top or bottom of the element to be displayed
118
119
 
@@ -219,7 +220,7 @@ This primitive is used to make vertically scrollable views and receives the foll
219
220
  - `snap:bool` if you want use the CSS feature `scroll-snap`
220
221
  - `tag:string` html tag of resulting element
221
222
  - `width:number` width value
222
- - `onscroll:function` executed when user scrolls over the element
223
+ - `onScroll:function` executed when user scrolls over the element
223
224
 
224
225
  ```jsx
225
226
  import { ScrollView, View } from '@mirai/ui';
@@ -234,7 +235,38 @@ const MyComponent = ({ isDesktop }) => (
234
235
 
235
236
  ### Select
236
237
 
237
- > @TODO
238
+ This primitive returns a select element and receives the following props:
239
+
240
+ - `disabled:boolean` applying 'disabled' attribute
241
+ - `emptyOption:string` label for the empty default value (e.g. 'Select an option')
242
+ - `options:string[]` select options text and values
243
+ - `value:string` current value
244
+ - `onChange:function` executed when input value changes
245
+ - `onEnter` executed when select is focused
246
+ - `onError` executed when an error occurs
247
+ - `onLeave` executed when select loses
248
+
249
+ ```jsx
250
+ import { Select } from '@mirai/ui';
251
+
252
+ const Example = (props) => {
253
+ const [value, setValue] = useState('');
254
+
255
+ const handleChange = (next, ...others) => {
256
+ setValue(next);
257
+ };
258
+
259
+ return (
260
+ <Select
261
+ emptyOption="Select one option..."
262
+ name="Select"
263
+ options={['foo', 'bar']}
264
+ value={value}
265
+ onChange={handleChange}
266
+ />
267
+ );
268
+ };
269
+ ```
238
270
 
239
271
  ### Switch
240
272
 
@@ -283,6 +315,7 @@ A primitive for displaying text. It receives the following props:
283
315
  - `tag:string` html tag of resulting element
284
316
  - `underline:boolean` use an underline text decoration
285
317
  - `upperCase:boolean` switching text to upper case
318
+ - `wide:boolean` specifies whether the component should have more width or not
286
319
 
287
320
  ```jsx
288
321
  import { Text, View } from '@mirai/ui';
@@ -422,6 +455,7 @@ const MyComponent = (props) => {
422
455
 
423
456
  A calendar component that receives the following props:
424
457
 
458
+ - `autoScroll:boolean` specifies whether the calendar should automatically scroll to the selected date or the focused month
425
459
  - `captions:object` captions to be placed into calendar cells
426
460
  - `disabledDates:[string]` dates to be shown as unavailable and can't be selected
427
461
  - `disabledPast:boolean` past dates to be shown as unavailable and can't be selected
@@ -489,11 +523,115 @@ const MyComponent = props => {
489
523
 
490
524
  ### Form
491
525
 
492
- > @TODO
526
+ Component that unites various inputs of different types into a single form. It receives the following props:
527
+
528
+ - `children:node` elements to be rendered within the form
529
+ - `debounce:number` the delay before triggering the onChange callback after the form values have changed (0 by default)
530
+ - `schema:object` defines validation schema for the form fields. Maps field names to their respective validation rules
531
+ - `showErrors:boolean` indicates whether to display the validation errors for the form fields
532
+ - `tag:string` HTML tag name to be used for rendering the form element ('form' by default)
533
+ - `validateOnMount:boolean` indicates whether to perform validation on form mount
534
+ - `onChange:function` executed when any field value changes
535
+ - `onEnter:function` when a form field gets focus
536
+ - `onError:function` executed when one or more fields have errors
537
+ - `onLeave:function` executed when a form field loses focus
538
+ - `onSubmit:function` executed when the form is submitted
539
+
540
+ ```jsx
541
+ import { Button, Form, InputDate, InputText } from '@mirai/ui';
542
+
543
+ const Example = (props) => {
544
+ const [condition, setCondition] = useState(false);
545
+ const [form, setForm] = useState({
546
+ email: 'javi@mirai.com',
547
+ dateOfBirth: '04/10/1980',
548
+ });
549
+ const [error, setError] = useState({});
550
+
551
+ const handleChange = (next, ...others) => setForm(next);
552
+
553
+ const handleEnter = (...others) => console.log('<Form>::onEnter', ...others);
554
+
555
+ const handleError = (next, ...others) => setError(next);
556
+
557
+ const handleLeave = (...others) => console.log('<Form>::onLeave', ...others);
558
+
559
+ const handleSubmit = (...others) => console.log('<Form>::onSubmit', ...others);
560
+
561
+ return (
562
+ <Form
563
+ {...props}
564
+ onChange={handleChange}
565
+ onEnter={handleEnter}
566
+ onError={handleError}
567
+ onLeave={handleLeave}
568
+ onSubmit={handleSubmit}
569
+ >
570
+ <InputText
571
+ name="email"
572
+ error={!!error.email}
573
+ test={(value) => value.includes('@mirai.com')}
574
+ label="Email"
575
+ hint="Should contains @mirai.com"
576
+ required
577
+ type="email"
578
+ value={form.email}
579
+ />
580
+ <InputDate
581
+ name="dateOfBirth"
582
+ error={!!error.dateOfBirth}
583
+ label="Your birthdate"
584
+ max="31/12/2022"
585
+ min="10/04/1980"
586
+ required
587
+ type="inputDate"
588
+ value={form.dateOfBirth}
589
+ />
590
+
591
+ <Button disabled={Object.keys(error).length !== 0} type="submit" wide>
592
+ Submit
593
+ </Button>
594
+ </Form>
595
+ );
596
+ };
597
+ ```
493
598
 
494
599
  ### InputDate
495
600
 
496
- > @TODO
601
+ Input date component that receives the following props:
602
+
603
+ - `format:string` date format to be applied ('DD/MM/YYYY' by default)
604
+ - `max:string` maximum date value allowed
605
+ - `min:string` minimum date value allowed
606
+ - `placeholder:bool` indicated whether to show placeholder with format or not
607
+ - `value:string` current value
608
+ - `onChange:function` executed when the value is changed
609
+ - `onError:function` executed when there's an error
610
+
611
+ ```jsx
612
+ import { InputDate } from '@mirai/ui';
613
+
614
+ const Example = ({ value: propValue, ...props }) => {
615
+ const [value, setValue] = useState(propValue);
616
+
617
+ const handleChange = (next, ...others) => {
618
+ setValue(next);
619
+ };
620
+
621
+ const handleError = (...others) => console.log('<InputDate>::onError', ...others);
622
+
623
+ return (
624
+ <InputDate
625
+ format="MM/DD/YYYY"
626
+ min="03/20/2023"
627
+ max="03/20/2028"
628
+ value={value}
629
+ onChange={handleChange}
630
+ onError={handleError}
631
+ />
632
+ );
633
+ };
634
+ ```
497
635
 
498
636
  ### InputNumber
499
637
 
@@ -593,11 +731,99 @@ const MyComponent = () => {
593
731
 
594
732
  ### InputPhone
595
733
 
596
- > @TODO
734
+ Input element for phone numbers that receives the following props:
735
+
736
+ - `disabled:boolean` applying 'disabled' attribute
737
+ - `error:boolean` indicating whether there is an error in the input
738
+ - `hint:string` text with additional info to be displayed below the input
739
+ - `icon:function` icon component to be displayed before the input
740
+ - `label:string` label text for the phone number part
741
+ - `labelPrefix:string` label text for the country code part
742
+ - `name:string` - required prop, input name
743
+ - `prefixes:string[]` available country codes
744
+ - `showRequired:boolean` indicating whether the "required" indicator should be shown
745
+ - `showState:boolean` indicating whether to show the state icons for errors, success, and warning
746
+ - `success:boolean` indicating whether the input has a success state
747
+ - `value:string` current value
748
+ - `warning:boolean` indicating whether the input has a warning state
749
+ - `onChange:function` executed when input value changes
750
+ - `onEnter:function` executed when input gets focus
751
+ - `onError:function` executed when there are validation errors in the input
752
+ - `onLeave:function` executed when input loses focus
753
+
754
+ ```jsx
755
+ import { InputPhone } from '@mirai/ui';
756
+
757
+ export const Story = (props) => {
758
+ const [value, setValue] = useState('+34 123456789');
759
+
760
+ const handleChange = (next, ...others) => {
761
+ setValue(next);
762
+ };
763
+
764
+ const handleError = (...others) => console.log('<InputSelect>::onError', ...others);
765
+
766
+ return (
767
+ <InputPhone
768
+ hint="hint"
769
+ label="Phone Number"
770
+ labelPrefix="Code"
771
+ name="name"
772
+ prefixes={['+34', '+44', '+001', '+999', '+39', '+56']}
773
+ required
774
+ value={value}
775
+ onChange={handleChange}
776
+ onError={handleError}
777
+ />
778
+ );
779
+ };
780
+ ```
597
781
 
598
782
  ### InputSelect
599
783
 
600
- > @TODO
784
+ A select input component that receives the following props:
785
+
786
+ - `disabled:boolean` applying 'disabled' attribute
787
+ - `error:boolean` indicating whether there is an error in the input
788
+ - `hint:string` text with additional info to be displayed below the input
789
+ - `label:string` label text
790
+ - `name:string` - required prop, input name
791
+ - `showRequired:boolean` indicating whether the "required" indicator should be shown
792
+ - `showState:boolean` indicating whether to show the state icons for errors, success, and warning
793
+ - `success:boolean` indicating whether the input has a success state
794
+ - `warning:boolean` indicating whether the input has a warning state
795
+ - `onChange:function` executed when input value changes
796
+ - `onEnter:function` executed when input gets focus
797
+ - `onError:function` executed when there are validation errors in the input
798
+ - `onLeave:function` executed when input loses focus
799
+
800
+ ```jsx
801
+ import { InputSelect } from '@mirai/ui';
802
+
803
+ const Example = (props) => {
804
+ const [value, setValue] = useState('two');
805
+
806
+ const handleChange = (next, ...others) => {
807
+ setValue(next);
808
+ };
809
+
810
+ const handleEnter = (...others) => console.log('<InputSelect>::onEnter', ...others);
811
+ const handleLeave = (...others) => console.log('<InputSelect>::onLeave', ...others);
812
+
813
+ return (
814
+ <InputSelect
815
+ hint="hint"
816
+ label="label"
817
+ name="name"
818
+ options={['one', 'two', 'three', 'four', 'five']}
819
+ value={value}
820
+ onChange={handleChange}
821
+ onEnter={handleEnter}
822
+ onLeave={handleLeave}
823
+ />
824
+ );
825
+ };
826
+ ```
601
827
 
602
828
  ### InputText
603
829
 
@@ -751,7 +977,28 @@ const MyComponent = (props) => {
751
977
 
752
978
  ### Notification
753
979
 
754
- > @TODO
980
+ A component that displays a notification message with optional icons and close button and receives the following props:
981
+
982
+ - `children: node` required prop, the content of the notification (any valid React node)
983
+ - `error:bool` indicating whether the notification represents an error message with corresponding styles
984
+ - `info:bool` indicating whether the notification represents an informational message
985
+ - `inline:bool` indicating whether the notification should be displayed inline
986
+ - `large:bool` indicating whether the notification should be displayed in a large size
987
+ - `small:bool` indicating whether the notification should be displayed in a small size
988
+ - `success:bool` indicating whether the notification represents a success message with corresponding styles
989
+ - `warning:bool` indicating whether the notification represents a warning message with corresponding styles
990
+ - `wide:bool` indicating whether the notification should be displayed in a wide format
991
+ - `onClose:function` executed when the close button is clicked
992
+
993
+ ```jsx
994
+ import { Notification } from '@mirai/ui';
995
+
996
+ const Example = (props) => (
997
+ <Notification error large wide onClose={() => console.log('Closing...')}>
998
+ Something went wrong...
999
+ </Notification>
1000
+ );
1001
+ ```
755
1002
 
756
1003
  ### Progress
757
1004
 
@@ -784,7 +1031,9 @@ const MyComponent = (props) => {
784
1031
 
785
1032
  This component helps you to create a pure html table receiving the following props:
786
1033
 
787
- - `dataSource:arrayOf(shape)` The datasource of your model data schema
1034
+ - `dataSource:arrayOf(shape)` datasource of your model data schema
1035
+ - `filter:object[]` array of filter items that are applied to the table data. Each filter item represents a specific filter configuration.
1036
+ - `inline:shape` specifies whether the table should be displayed inline
788
1037
  - `schema:shape` the model data schema
789
1038
  - `search:string` the query string you want use for filter the datasource
790
1039
  - `selected:arrayOf(dataSource.row)` if you want pre-select some rows in 1st render
@@ -859,9 +1108,12 @@ const MyComponent = () => {
859
1108
  This component helps you to create a tooltip over a determinate component receiving the following props:
860
1109
 
861
1110
  - `children:node` The element which we will use as reference for display the menu.
1111
+ - `left:bool` positioning of the tooltip relative to its parent element
862
1112
  - `pressable:bool` Change event dispatcher to `onPress` instead of ` onEnter`.
1113
+ - `right:bool` positioning of the tooltip relative to its parent element
863
1114
  - `Template:node` if you don't want use the default scaffold.
864
1115
  - `text:string` text it will appears when hover on `children`.
1116
+ - `timestamp:number` value used to force render to recalculate the position of the tooltip
865
1117
  - `top:bool` Change the position to the top of reference element.
866
1118
  - `visible:boolean` the default state of visibility of the instance.
867
1119
 
@@ -9,7 +9,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _Form = require("./Form.constants");
11
11
  var _helpers = require("./helpers");
12
- var _excluded = ["children", "debounce", "schema", "showErrors", "tag", "validateOnMount", "onBlur", "onChange", "onError", "onFocus", "onSubmit"];
12
+ var _excluded = ["children", "debounce", "schema", "showErrors", "tag", "validateOnMount", "onChange", "onEnter", "onError", "onLeave", "onSubmit"];
13
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -37,10 +37,10 @@ var Form = function Form(_ref) {
37
37
  tag = _ref$tag === void 0 ? 'form' : _ref$tag,
38
38
  _ref$validateOnMount = _ref.validateOnMount,
39
39
  validateOnMount = _ref$validateOnMount === void 0 ? false : _ref$validateOnMount,
40
- onBlur = _ref.onBlur,
41
40
  onChange = _ref.onChange,
41
+ onEnter = _ref.onEnter,
42
42
  onError = _ref.onError,
43
- onFocus = _ref.onFocus,
43
+ onLeave = _ref.onLeave,
44
44
  onSubmit = _ref.onSubmit,
45
45
  others = _objectWithoutProperties(_ref, _excluded);
46
46
  var _useState = (0, _react.useState)({}),
@@ -130,9 +130,9 @@ var Form = function Form(_ref) {
130
130
  hasError: hasError
131
131
  };
132
132
  };
133
- var handleFocus = function handleFocus(field, event) {
133
+ var handleLeave = function handleLeave(field, event) {
134
134
  setTouched(_objectSpread(_objectSpread({}, touched), {}, _defineProperty({}, field, true)));
135
- if (onFocus) onFocus(field, event);
135
+ if (onEnter) onEnter(field, event);
136
136
  };
137
137
  var handleSubmit = function handleSubmit(event) {
138
138
  var _handleError = handleError(values),
@@ -163,13 +163,13 @@ var Form = function Form(_ref) {
163
163
  key: index
164
164
  }, field ? _objectSpread(_objectSpread(_objectSpread({}, props), schema[field]), {}, (_objectSpread4 = {
165
165
  error: !_Form.FIELDS_WITHOUT_ERRORS.includes(displayName) ? props.error || showErrors && error[field] : undefined
166
- }, _defineProperty(_objectSpread4, _Form.FIELDS_BOOLEAN.includes(displayName) ? 'checked' : 'value', values[field]), _defineProperty(_objectSpread4, "onBlur", onBlur ? function (event) {
167
- return onBlur(field, event);
168
- } : undefined), _defineProperty(_objectSpread4, "onChange", function onChange(value) {
166
+ }, _defineProperty(_objectSpread4, _Form.FIELDS_BOOLEAN.includes(displayName) ? 'checked' : 'value', values[field]), _defineProperty(_objectSpread4, "onChange", function onChange(value) {
169
167
  return handleChange(field, value);
170
- }), _defineProperty(_objectSpread4, "onFocus", function onFocus(event) {
171
- return handleFocus(field, event);
172
- }), _objectSpread4)) : type === 'submit' ? _objectSpread(_objectSpread({}, props), {}, {
168
+ }), _defineProperty(_objectSpread4, "onEnter", function onEnter(event) {
169
+ return handleLeave(field, event);
170
+ }), _defineProperty(_objectSpread4, "onLeave", onLeave ? function (event) {
171
+ return onLeave(field, event);
172
+ } : undefined), _objectSpread4)) : type === 'submit' ? _objectSpread(_objectSpread({}, props), {}, {
173
173
  onPress: handleSubmit
174
174
  }) : undefined));
175
175
  }));
@@ -186,10 +186,10 @@ Form.propTypes = {
186
186
  showErrors: _propTypes.default.bool,
187
187
  tag: _propTypes.default.string,
188
188
  validateOnMount: _propTypes.default.bool,
189
- onBlur: _propTypes.default.func,
190
189
  onChange: _propTypes.default.func,
190
+ onEnter: _propTypes.default.func,
191
191
  onError: _propTypes.default.func,
192
- onFocus: _propTypes.default.func,
192
+ onLeave: _propTypes.default.func,
193
193
  onSubmit: _propTypes.default.func
194
194
  };
195
195
  //# sourceMappingURL=Form.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Form.js","names":["Form","children","debounce","DEFAULT_TIMEOUT_ONCHANGE","schema","showErrors","tag","validateOnMount","onBlur","onChange","onError","onFocus","onSubmit","others","useState","error","setError","initialValue","setInitialValue","touched","setTouched","values","setValues","useEffect","nextValues","getChildrenValues","nextChildrenKeys","Object","keys","sort","length","JSON","stringify","nextError","getChildrenErrors","collision","some","key","groupState","value","timer","setTimeout","clearTimeout","handleChange","field","fieldValue","handleError","DEFAULT_TIMEOUT_ONERROR","hasError","changed","errors","handleFocus","event","handleSubmit","preventDefault","useMemo","React","createElement","Children","map","child","index","props","type","displayName","getField","cloneElement","FIELDS_WITHOUT_ERRORS","includes","undefined","FIELDS_BOOLEAN","onPress","propTypes","PropTypes","node","number","shape","bool","string","func"],"sources":["../../../src/components/Form/Form.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React, { useEffect, useMemo, useState } from 'react';\n\nimport {\n DEFAULT_TIMEOUT_ONCHANGE,\n DEFAULT_TIMEOUT_ONERROR,\n FIELDS_BOOLEAN,\n FIELDS_WITHOUT_ERRORS,\n} from './Form.constants';\nimport { getChildrenErrors, getChildrenValues, getField, groupState } from './helpers';\n\nconst Form = ({\n children,\n debounce = DEFAULT_TIMEOUT_ONCHANGE,\n schema = {},\n showErrors,\n tag = 'form',\n validateOnMount = false,\n onBlur,\n onChange,\n onError,\n onFocus,\n onSubmit,\n ...others\n}) => {\n const [error, setError] = useState({});\n const [initialValue, setInitialValue] = useState({});\n const [touched, setTouched] = useState({});\n const [values, setValues] = useState({});\n\n useEffect(() => {\n const nextValues = getChildrenValues(children);\n const nextChildrenKeys = Object.keys(nextValues).sort();\n\n if (!Object.keys(nextValues).length) return;\n\n if (JSON.stringify(nextChildrenKeys) !== JSON.stringify(Object.keys(initialValue).sort())) {\n setInitialValue(nextValues);\n setValues(nextValues);\n\n if (validateOnMount) {\n const nextError = getChildrenErrors({ children, schema, values: nextValues });\n setError(nextError);\n onError && onError(nextError);\n } else {\n setError({});\n }\n setTouched({});\n } else {\n const collision = nextChildrenKeys.some((key) => JSON.stringify(values[key]) !== JSON.stringify(nextValues[key]));\n if (collision) setValues(nextValues);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [children]);\n\n useEffect(() => {\n if (!onChange || values === initialValue || !Object.keys(values).length) return;\n\n if (!debounce) return onChange(values, groupState({ initialValue, value: values, touched }));\n\n const timer = setTimeout(() => onChange(values, groupState({ initialValue, value: values, touched })), debounce);\n return () => clearTimeout(timer);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [values]);\n\n const handleChange = (field, fieldValue) => {\n const nextValues = { ...values, [field]: fieldValue };\n\n setValues(nextValues);\n setTimeout(() => handleError(nextValues), DEFAULT_TIMEOUT_ONERROR);\n };\n\n const handleError = (values) => {\n const nextError = getChildrenErrors({ children, schema, values });\n const hasError = Object.keys(nextError).length > 0;\n const changed = JSON.stringify(error) !== JSON.stringify(nextError);\n\n if (changed) {\n setError(nextError);\n onError && onError(nextError, hasError);\n }\n\n return { changed, errors: nextError, hasError };\n };\n\n const handleFocus = (field, event) => {\n setTouched({ ...touched, [field]: true });\n if (onFocus) onFocus(field, event);\n };\n\n const handleSubmit = (event) => {\n const { errors, hasError } = handleError(values);\n\n if (hasError && onError) onError(errors, hasError);\n else if (onSubmit) onSubmit(values, groupState({ initialValue, value: values, touched }), event);\n event.preventDefault();\n };\n\n return useMemo(\n () =>\n React.createElement(\n tag,\n { ...others, onSubmit: handleSubmit },\n React.Children.map(children, (child, index) => {\n if (!child || child === null) return;\n\n const { props = {}, type: { displayName } = {} } = child || {};\n const { type } = props;\n const field = getField(props);\n\n return React.cloneElement(child, {\n key: index,\n ...(field\n ? {\n ...props,\n ...schema[field],\n error: !FIELDS_WITHOUT_ERRORS.includes(displayName)\n ? props.error || (showErrors && error[field])\n : undefined,\n [FIELDS_BOOLEAN.includes(displayName) ? 'checked' : 'value']: values[field],\n onBlur: onBlur ? (event) => onBlur(field, event) : undefined,\n onChange: (value) => handleChange(field, value),\n onFocus: (event) => handleFocus(field, event),\n }\n : type === 'submit'\n ? { ...props, onPress: handleSubmit }\n : undefined),\n });\n }),\n ),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [children, error, others, schema],\n );\n};\n\nForm.displayName = 'Component:Form';\n\nForm.propTypes = {\n children: PropTypes.node,\n debounce: PropTypes.number,\n schema: PropTypes.shape({}),\n showErrors: PropTypes.bool,\n tag: PropTypes.string,\n validateOnMount: PropTypes.bool,\n onBlur: PropTypes.func,\n onChange: PropTypes.func,\n onError: PropTypes.func,\n onFocus: PropTypes.func,\n onSubmit: PropTypes.func,\n};\n\nexport { Form };\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AAMA;AAAuF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEvF,IAAMA,IAAI,GAAG,SAAPA,IAAI,OAaJ;EAAA,IAZJC,QAAQ,QAARA,QAAQ;IAAA,qBACRC,QAAQ;IAARA,QAAQ,8BAAGC,8BAAwB;IAAA,mBACnCC,MAAM;IAANA,MAAM,4BAAG,CAAC,CAAC;IACXC,UAAU,QAAVA,UAAU;IAAA,gBACVC,GAAG;IAAHA,GAAG,yBAAG,MAAM;IAAA,4BACZC,eAAe;IAAfA,eAAe,qCAAG,KAAK;IACvBC,MAAM,QAANA,MAAM;IACNC,QAAQ,QAARA,QAAQ;IACRC,OAAO,QAAPA,OAAO;IACPC,OAAO,QAAPA,OAAO;IACPC,QAAQ,QAARA,QAAQ;IACLC,MAAM;EAET,gBAA0B,IAAAC,eAAQ,EAAC,CAAC,CAAC,CAAC;IAAA;IAA/BC,KAAK;IAAEC,QAAQ;EACtB,iBAAwC,IAAAF,eAAQ,EAAC,CAAC,CAAC,CAAC;IAAA;IAA7CG,YAAY;IAAEC,eA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AC,CACH;EAAA;EACH;EACA,CAACpE,QAAQ,EAAEc,KAAK,EAAEF,MAAM,EAAET,MAAM,CAAC,CAClC;AACH,CAAC;AAAC;AAEFJ,IAAI,CAACgE,WAAW,GAAG,gBAAgB;AAEnChE,IAAI,CAACwE,SAAS,GAAG;EACfvE,QAAQ,EAAEwE,kBAAS,CAACC,IAAI;EACxBxE,QAAQ,EAAEuE,kBAAS,CAACE,MAAM;EAC1BvE,MAAM,EAAEqE,kBAAS,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC;EAC3BvE,UAAU,EAAEoE,kBAAS,CAACI,IAAI;EAC1BvE,GAAG,EAAEmE,kBAAS,CAACK,MAAM;EACrBvE,eAAe,EAAEkE,kBAAS,CAACI,IAAI;EAC/BrE,MAAM,EAAEiE,kBAAS,CAACM,IAAI;EACtBtE,QAAQ,EAAEgE,kBAAS,CAACM,IAAI;EACxBrE,OAAO,EAAE+D,kBAAS,CAACM,IAAI;EACvBpE,OAAO,EAAE8D,kBAAS,CAACM,IAAI;EACvBnE,QAAQ,EAAE6D,kBAAS,CAACM;AACtB,CAAC"}
1
+ {"version":3,"file":"Form.js","names":["Form","children","debounce","DEFAULT_TIMEOUT_ONCHANGE","schema","showErrors","tag","validateOnMount","onChange","onEnter","onError","onLeave","onSubmit","others","useState","error","setError","initialValue","setInitialValue","touched","setTouched","values","setValues","useEffect","nextValues","getChildrenValues","nextChildrenKeys","Object","keys","sort","length","JSON","stringify","nextError","getChildrenErrors","collision","some","key","groupState","value","timer","setTimeout","clearTimeout","handleChange","field","fieldValue","handleError","DEFAULT_TIMEOUT_ONERROR","hasError","changed","errors","handleLeave","event","handleSubmit","preventDefault","useMemo","React","createElement","Children","map","child","index","props","type","displayName","getField","cloneElement","FIELDS_WITHOUT_ERRORS","includes","undefined","FIELDS_BOOLEAN","onPress","propTypes","PropTypes","node","number","shape","bool","string","func"],"sources":["../../../src/components/Form/Form.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React, { useEffect, useMemo, useState } from 'react';\n\nimport {\n DEFAULT_TIMEOUT_ONCHANGE,\n DEFAULT_TIMEOUT_ONERROR,\n FIELDS_BOOLEAN,\n FIELDS_WITHOUT_ERRORS,\n} from './Form.constants';\nimport { getChildrenErrors, getChildrenValues, getField, groupState } from './helpers';\n\nconst Form = ({\n children,\n debounce = DEFAULT_TIMEOUT_ONCHANGE,\n schema = {},\n showErrors,\n tag = 'form',\n validateOnMount = false,\n onChange,\n onEnter,\n onError,\n onLeave,\n onSubmit,\n ...others\n}) => {\n const [error, setError] = useState({});\n const [initialValue, setInitialValue] = useState({});\n const [touched, setTouched] = useState({});\n const [values, setValues] = useState({});\n\n useEffect(() => {\n const nextValues = getChildrenValues(children);\n const nextChildrenKeys = Object.keys(nextValues).sort();\n\n if (!Object.keys(nextValues).length) return;\n\n if (JSON.stringify(nextChildrenKeys) !== JSON.stringify(Object.keys(initialValue).sort())) {\n setInitialValue(nextValues);\n setValues(nextValues);\n\n if (validateOnMount) {\n const nextError = getChildrenErrors({ children, schema, values: nextValues });\n setError(nextError);\n onError && onError(nextError);\n } else {\n setError({});\n }\n setTouched({});\n } else {\n const collision = nextChildrenKeys.some((key) => JSON.stringify(values[key]) !== JSON.stringify(nextValues[key]));\n if (collision) setValues(nextValues);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [children]);\n\n useEffect(() => {\n if (!onChange || values === initialValue || !Object.keys(values).length) return;\n\n if (!debounce) return onChange(values, groupState({ initialValue, value: values, touched }));\n\n const timer = setTimeout(() => onChange(values, groupState({ initialValue, value: values, touched })), debounce);\n return () => clearTimeout(timer);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [values]);\n\n const handleChange = (field, fieldValue) => {\n const nextValues = { ...values, [field]: fieldValue };\n\n setValues(nextValues);\n setTimeout(() => handleError(nextValues), DEFAULT_TIMEOUT_ONERROR);\n };\n\n const handleError = (values) => {\n const nextError = getChildrenErrors({ children, schema, values });\n const hasError = Object.keys(nextError).length > 0;\n const changed = JSON.stringify(error) !== JSON.stringify(nextError);\n\n if (changed) {\n setError(nextError);\n onError && onError(nextError, hasError);\n }\n\n return { changed, errors: nextError, hasError };\n };\n\n const handleLeave = (field, event) => {\n setTouched({ ...touched, [field]: true });\n if (onEnter) onEnter(field, event);\n };\n\n const handleSubmit = (event) => {\n const { errors, hasError } = handleError(values);\n\n if (hasError && onError) onError(errors, hasError);\n else if (onSubmit) onSubmit(values, groupState({ initialValue, value: values, touched }), event);\n event.preventDefault();\n };\n\n return useMemo(\n () =>\n React.createElement(\n tag,\n { ...others, onSubmit: handleSubmit },\n React.Children.map(children, (child, index) => {\n if (!child || child === null) return;\n\n const { props = {}, type: { displayName } = {} } = child || {};\n const { type } = props;\n const field = getField(props);\n\n return React.cloneElement(child, {\n key: index,\n ...(field\n ? {\n ...props,\n ...schema[field],\n error: !FIELDS_WITHOUT_ERRORS.includes(displayName)\n ? props.error || (showErrors && error[field])\n : undefined,\n [FIELDS_BOOLEAN.includes(displayName) ? 'checked' : 'value']: values[field],\n onChange: (value) => handleChange(field, value),\n onEnter: (event) => handleLeave(field, event),\n onLeave: onLeave ? (event) => onLeave(field, event) : undefined,\n }\n : type === 'submit'\n ? { ...props, onPress: handleSubmit }\n : undefined),\n });\n }),\n ),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [children, error, others, schema],\n );\n};\n\nForm.displayName = 'Component:Form';\n\nForm.propTypes = {\n children: PropTypes.node,\n debounce: PropTypes.number,\n schema: PropTypes.shape({}),\n showErrors: PropTypes.bool,\n tag: PropTypes.string,\n validateOnMount: PropTypes.bool,\n onChange: PropTypes.func,\n onEnter: PropTypes.func,\n onError: PropTypes.func,\n onLeave: PropTypes.func,\n onSubmit: PropTypes.func,\n};\n\nexport { Form };\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AAMA;AAAuF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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IAAI;EACvBnE,QAAQ,EAAE6D,kBAAS,CAACM;AACtB,CAAC"}
@@ -54,20 +54,20 @@ var Story = function Story(props) {
54
54
  });
55
55
  }, []); // * Simulate a state hydration
56
56
 
57
- var handleBlur = function handleBlur() {
57
+ var handleChange = function handleChange(next) {
58
58
  var _console;
59
- for (var _len = arguments.length, others = new Array(_len), _key = 0; _key < _len; _key++) {
60
- others[_key] = arguments[_key];
59
+ setForm(next);
60
+ for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
61
+ others[_key - 1] = arguments[_key];
61
62
  }
62
- return (_console = console).log.apply(_console, ['<Form>::onBlur'].concat(others));
63
+ (_console = console).log.apply(_console, ['<Form>::onChange', next].concat(others));
63
64
  };
64
- var handleChange = function handleChange(next) {
65
+ var handleEnter = function handleEnter() {
65
66
  var _console2;
66
- setForm(next);
67
- for (var _len2 = arguments.length, others = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
68
- others[_key2 - 1] = arguments[_key2];
67
+ for (var _len2 = arguments.length, others = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
68
+ others[_key2] = arguments[_key2];
69
69
  }
70
- (_console2 = console).log.apply(_console2, ['<Form>::onChange', next].concat(others));
70
+ return (_console2 = console).log.apply(_console2, ['<Form>::onEnter'].concat(others));
71
71
  };
72
72
  var handleError = function handleError(next) {
73
73
  var _console3;
@@ -77,12 +77,12 @@ var Story = function Story(props) {
77
77
  }
78
78
  (_console3 = console).log.apply(_console3, ['<Form>::onError', next].concat(others));
79
79
  };
80
- var handleFocus = function handleFocus() {
80
+ var handleLeave = function handleLeave() {
81
81
  var _console4;
82
82
  for (var _len4 = arguments.length, others = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
83
83
  others[_key4] = arguments[_key4];
84
84
  }
85
- return (_console4 = console).log.apply(_console4, ['<Form>::onFocus'].concat(others));
85
+ return (_console4 = console).log.apply(_console4, ['<Form>::onLeave'].concat(others));
86
86
  };
87
87
  var handleSubmit = function handleSubmit() {
88
88
  var _console5;
@@ -92,10 +92,10 @@ var Story = function Story(props) {
92
92
  return (_console5 = console).log.apply(_console5, ['<Form>::onSubmit'].concat(others));
93
93
  };
94
94
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Form.Form, _extends({}, props, {
95
- onBlur: handleBlur,
95
+ onLeave: handleLeave,
96
96
  onChange: handleChange,
97
97
  onError: handleError,
98
- onFocus: handleFocus,
98
+ onEnter: handleEnter,
99
99
  onSubmit: handleSubmit
100
100
  }), /*#__PURE__*/_react.default.createElement(_.View, {
101
101
  row: true
@@ -1 +1 @@
1
- {"version":3,"file":"Form.stories.js","names":["title","Story","props","useState","condition","setCondition","email","checkbox","dateOfBirth","switch","radio","form","setForm","error","setError","useEffect","handleBlur","others","console","log","handleChange","next","handleError","handleFocus","handleSubmit","value","includes","password","emptyOption","gender","phone","bio","children","Array","from","keys","map","index","Object","length","justifyContent","marginTop","marginRight","storyName","args","debounce","schema","showErrors","validateOnMount","argTypes"],"sources":["../../../src/components/Form/Form.stories.jsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\n\nimport { Button, InputDate, InputNumber, InputOption, InputPhone, InputText, InputSelect, Text, View } from '../../';\nimport { Form } from './Form';\n\nexport default { title: 'Components' };\n\nexport const Story = (props) => {\n const [condition, setCondition] = useState(false);\n const [form, setForm] = useState({\n email: 'javi@mirai.com',\n checkbox: true,\n dateOfBirth: '04/10/1980',\n switch: true,\n radio: 'radio-2',\n });\n const [error, setError] = useState({});\n\n useEffect(\n () =>\n setForm({\n email: 'javi@mirai.com',\n checkbox: true,\n dateOfBirth: '04/10/1980',\n switch: true,\n radio: 'radio-2',\n }),\n [],\n ); // * Simulate a state hydration\n\n const handleBlur = (...others) => console.log('<Form>::onBlur', ...others);\n\n const handleChange = (next, ...others) => {\n setForm(next);\n console.log('<Form>::onChange', next, ...others);\n };\n\n const handleError = (next, ...others) => {\n setError(next);\n console.log('<Form>::onError', next, ...others);\n };\n\n const handleFocus = (...others) => console.log('<Form>::onFocus', ...others);\n\n const handleSubmit = (...others) => console.log('<Form>::onSubmit', ...others);\n\n return (\n <>\n <Form\n {...props}\n onBlur={handleBlur}\n onChange={handleChange}\n onError={handleError}\n onFocus={handleFocus}\n onSubmit={handleSubmit}\n >\n <View row>\n <Text headline>Form component</Text>\n </View>\n\n <InputText\n name=\"email\"\n error={!!error.email}\n test={(value) => value.includes('@mirai.com')}\n label=\"Email\"\n hint=\"Should contains @mirai.com\"\n required\n type=\"email\"\n value={form.email}\n />\n <InputText\n name=\"password\"\n error={!!error.password}\n hint=\"At least 10 chars.\"\n label=\"Password\"\n required\n minLength={10}\n type=\"password\"\n value={form.password}\n />\n <InputSelect\n name=\"gender\"\n emptyOption=\"Select...\"\n error={!!error.emptyOption}\n label=\"Your gender\"\n options={['one', 'two', 'three', 'four', 'five']}\n value={form.gender}\n />\n <InputDate\n name=\"dateOfBirth\"\n error={!!error.dateOfBirth}\n label=\"Your birthdate\"\n max=\"31/12/2022\"\n min=\"10/04/1980\"\n required\n type=\"inputDate\"\n value={form.dateOfBirth}\n />\n <InputPhone\n name=\"phone\"\n error={!!error.phone}\n label=\"Phone\"\n labelPrefix=\"Prefix\"\n prefixes={['+34', '+44', '+001', '+999', '+39', '+56']}\n required\n type=\"inputPhone\"\n value={form.phone}\n />\n <InputText name=\"bio\" label=\"Bio\" multiLine value={form.bio} />\n <InputNumber name=\"children\" label=\"Children\" hint=\"Ages 0 - 17\" value={form.children} required />\n <InputOption type=\"checkbox\" name=\"checkbox\" label=\"checkbox\" checked={form.checkbox} required />\n <InputOption type=\"switch\" name=\"switch\" label=\"switch\" checked={form.switch} />\n {Array.from(Array(2).keys()).map((index) => (\n <InputOption\n key={index}\n type=\"radio\"\n name=\"radio\"\n value={`radio-${index}`}\n label={`radio-${index}`}\n checked={form.radio === `radio-${index}`}\n />\n ))}\n {condition && <InputText label=\"condition\" name=\"condition\" />}\n\n <Button disabled={Object.keys(error).length !== 0} type=\"submit\" wide>\n Submit\n </Button>\n </Form>\n\n <View row style={{ justifyContent: 'flex-end', marginTop: 'var(--mirai-ui-space-L)' }}>\n <Button small secondary onPress={() => setForm({})} style={{ marginRight: 'var(--mirai-ui-space-M)' }}>\n Reset\n </Button>\n <Button small secondary onPress={() => setCondition(!condition)}>\n {`${condition ? 'Hide' : 'Show'} dynamic field`}\n </Button>\n </View>\n </>\n );\n};\n\nStory.storyName = 'Form';\n\nStory.args = {\n debounce: 0,\n schema: {},\n showErrors: false,\n validateOnMount: false,\n // inherited properties\n ['data-testid']: 'test-story',\n style: {},\n};\n\nStory.argTypes = {};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAEf;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,CAAIC,KAAK,EAAK;EAC9B,gBAAkC,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAA1CC,SAAS;IAAEC,YAAY;EAC9B,iBAAwB,IAAAF,eAAQ,EAAC;MAC/BG,KAAK,EAAE,gBAAgB;MACvBC,QAAQ,EAAE,IAAI;MACdC,WAAW,EAAE,YAAY;MACzBC,MAAM,EAAE,IAAI;MACZC,KAAK,EAAE;IACT,CAAC,CAAC;IAAA;IANKC,IAAI;IAAEC,OAAO;EAOpB,iBAA0B,IAAAT,eAAQ,EAAC,CAAC,CAAC,CAAC;IAAA;IAA/BU,KAAK;IAAEC,QAAQ;EAEtB,IAAAC,gBAAS,EACP;IAAA,OACEH,OAAO,CAAC;MACNN,KAAK,EAAE,gBAAgB;MACvBC,QAAQ,EAAE,IAAI;MACdC,WAAW,EAAE,YAAY;MACzBC,MAAM,EAAE,IAAI;MACZC,KAAK,EAAE;IACT,CAAC,CAAC;EAAA,GACJ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I,CAACtB,KAAK,CAAC,CAAC0B,MAAM,KAAK,CAAE;IAAC,IAAI,EAAC,QAAQ;IAAC,IAAI;EAAA,YAE5D,CACJ,eAEP,6BAAC,MAAI;IAAC,GAAG;IAAC,KAAK,EAAE;MAAEC,cAAc,EAAE,UAAU;MAAEC,SAAS,EAAE;IAA0B;EAAE,gBACpF,6BAAC,QAAM;IAAC,KAAK;IAAC,SAAS;IAAC,OAAO,EAAE;MAAA,OAAM7B,OAAO,CAAC,CAAC,CAAC,CAAC;IAAA,CAAC;IAAC,KAAK,EAAE;MAAE8B,WAAW,EAAE;IAA0B;EAAE,WAE7F,eACT,6BAAC,QAAM;IAAC,KAAK;IAAC,SAAS;IAAC,OAAO,EAAE;MAAA,OAAMrC,YAAY,CAAC,CAACD,SAAS,CAAC;IAAA;EAAC,aAC1DA,SAAS,GAAG,MAAM,GAAG,MAAM,oBACxB,CACJ,CACN;AAEP,CAAC;AAAC;AAEFH,KAAK,CAAC0C,SAAS,GAAG,MAAM;AAExB1C,KAAK,CAAC2C,IAAI;EACRC,QAAQ,EAAE,CAAC;EACXC,MAAM,EAAE,CAAC,CAAC;EACVC,UAAU,EAAE,KAAK;EACjBC,eAAe,EAAE;AAAK,gCAErB,aAAa,EAAG,YAAY,yCACtB,CAAC,CAAC,eACV;AAED/C,KAAK,CAACgD,QAAQ,GAAG,CAAC,CAAC"}
1
+ {"version":3,"file":"Form.stories.js","names":["title","Story","props","useState","condition","setCondition","email","checkbox","dateOfBirth","switch","radio","form","setForm","error","setError","useEffect","handleChange","next","others","console","log","handleEnter","handleError","handleLeave","handleSubmit","value","includes","password","emptyOption","gender","phone","bio","children","Array","from","keys","map","index","Object","length","justifyContent","marginTop","marginRight","storyName","args","debounce","schema","showErrors","validateOnMount","argTypes"],"sources":["../../../src/components/Form/Form.stories.jsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\n\nimport { Button, InputDate, InputNumber, InputOption, InputPhone, InputText, InputSelect, Text, View } from '../../';\nimport { Form } from './Form';\n\nexport default { title: 'Components' };\n\nexport const Story = (props) => {\n const [condition, setCondition] = useState(false);\n const [form, setForm] = useState({\n email: 'javi@mirai.com',\n checkbox: true,\n dateOfBirth: '04/10/1980',\n switch: true,\n radio: 'radio-2',\n });\n const [error, setError] = useState({});\n\n useEffect(\n () =>\n setForm({\n email: 'javi@mirai.com',\n checkbox: true,\n dateOfBirth: '04/10/1980',\n switch: true,\n radio: 'radio-2',\n }),\n [],\n ); // * Simulate a state hydration\n\n const handleChange = (next, ...others) => {\n setForm(next);\n console.log('<Form>::onChange', next, ...others);\n };\n\n const handleEnter = (...others) => console.log('<Form>::onEnter', ...others);\n\n const handleError = (next, ...others) => {\n setError(next);\n console.log('<Form>::onError', next, ...others);\n };\n\n const handleLeave = (...others) => console.log('<Form>::onLeave', ...others);\n\n const handleSubmit = (...others) => console.log('<Form>::onSubmit', ...others);\n\n return (\n <>\n <Form\n {...props}\n onLeave={handleLeave}\n onChange={handleChange}\n onError={handleError}\n onEnter={handleEnter}\n onSubmit={handleSubmit}\n >\n <View row>\n <Text headline>Form component</Text>\n </View>\n\n <InputText\n name=\"email\"\n error={!!error.email}\n test={(value) => value.includes('@mirai.com')}\n label=\"Email\"\n hint=\"Should contains @mirai.com\"\n required\n type=\"email\"\n value={form.email}\n />\n <InputText\n name=\"password\"\n error={!!error.password}\n hint=\"At least 10 chars.\"\n label=\"Password\"\n required\n minLength={10}\n type=\"password\"\n value={form.password}\n />\n <InputSelect\n name=\"gender\"\n emptyOption=\"Select...\"\n error={!!error.emptyOption}\n label=\"Your gender\"\n options={['one', 'two', 'three', 'four', 'five']}\n value={form.gender}\n />\n <InputDate\n name=\"dateOfBirth\"\n error={!!error.dateOfBirth}\n label=\"Your birthdate\"\n max=\"31/12/2022\"\n min=\"10/04/1980\"\n required\n type=\"inputDate\"\n value={form.dateOfBirth}\n />\n <InputPhone\n name=\"phone\"\n error={!!error.phone}\n label=\"Phone\"\n labelPrefix=\"Prefix\"\n prefixes={['+34', '+44', '+001', '+999', '+39', '+56']}\n required\n type=\"inputPhone\"\n value={form.phone}\n />\n <InputText name=\"bio\" label=\"Bio\" multiLine value={form.bio} />\n <InputNumber name=\"children\" label=\"Children\" hint=\"Ages 0 - 17\" value={form.children} required />\n <InputOption type=\"checkbox\" name=\"checkbox\" label=\"checkbox\" checked={form.checkbox} required />\n <InputOption type=\"switch\" name=\"switch\" label=\"switch\" checked={form.switch} />\n {Array.from(Array(2).keys()).map((index) => (\n <InputOption\n key={index}\n type=\"radio\"\n name=\"radio\"\n value={`radio-${index}`}\n label={`radio-${index}`}\n checked={form.radio === `radio-${index}`}\n />\n ))}\n {condition && <InputText label=\"condition\" name=\"condition\" />}\n\n <Button disabled={Object.keys(error).length !== 0} type=\"submit\" wide>\n Submit\n </Button>\n </Form>\n\n <View row style={{ justifyContent: 'flex-end', marginTop: 'var(--mirai-ui-space-L)' }}>\n <Button small secondary onPress={() => setForm({})} style={{ marginRight: 'var(--mirai-ui-space-M)' }}>\n Reset\n </Button>\n <Button small secondary onPress={() => setCondition(!condition)}>\n {`${condition ? 'Hide' : 'Show'} dynamic field`}\n </Button>\n </View>\n </>\n );\n};\n\nStory.storyName = 'Form';\n\nStory.args = {\n debounce: 0,\n schema: {},\n showErrors: false,\n validateOnMount: false,\n // inherited properties\n ['data-testid']: 'test-story',\n style: {},\n};\n\nStory.argTypes = {};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAEf;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,CAAIC,KAAK,EAAK;EAC9B,gBAAkC,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAA1CC,SAAS;IAAEC,YAAY;EAC9B,iBAAwB,IAAAF,eAAQ,EAAC;MAC/BG,KAAK,EAAE,gBAAgB;MACvBC,QAAQ,EA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QAAQ,GAAG,CAAC,CAAC"}
@@ -176,6 +176,7 @@ var InputPhone = function InputPhone(_ref) {
176
176
  value: phone
177
177
  }), /*#__PURE__*/_react.default.createElement(_primitives.Input, _extends({}, others, {
178
178
  disabled: disabled,
179
+ maxLength: 12,
179
180
  name: "".concat(name, "-phone"),
180
181
  type: "tel",
181
182
  value: phone || '',
@@ -1 +1 @@
1
- {"version":3,"file":"InputPhone.js","names":["InputPhone","disabled","error","hint","icon","label","labelPrefix","name","prefixes","showRequired","showState","success","propValue","value","warning","onChange","onEnter","onError","onLeave","others","useState","focus","setFocus","prefixFocus","setPrefixFocus","setValue","useEffect","handleChange","next","event","isPhone","hasPrefixes","split","undefined","prefix","phone","nextValue","replace","join","trim","getInputPhoneErrors","handleEnter","handleLeave","length","has","stateIcon","testId","styles","stylePhone","container","className","style","inputBorder","content","required","input","withLabel","empty","ICON","EXPAND_MORE","select","expand","separator","left","displayName","propTypes","PropTypes","bool","string","func","isRequired","arrayOf"],"sources":["../../../src/components/InputPhone/InputPhone.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React, { useEffect, useState } from 'react';\n\nimport { styles } from '../../helpers';\nimport { getInputPhoneErrors } from '../../helpers';\nimport { Icon, ICON, Input, Select, View } from '../../primitives';\nimport style from '../InputText/InputText.module.css';\nimport { Hint, IconState, Label } from '../InputText/partials';\nimport stylePhone from './InputPhone.module.css';\n\nconst InputPhone = ({\n disabled,\n error,\n hint,\n icon,\n label,\n labelPrefix,\n name,\n prefixes,\n showRequired = false,\n showState = true,\n success,\n value: propValue,\n warning,\n onChange = () => {},\n onEnter = () => {},\n onError,\n onLeave = () => {},\n ...others\n}) => {\n const [focus, setFocus] = useState(false);\n const [prefixFocus, setPrefixFocus] = useState(false);\n const [value, setValue] = useState();\n\n useEffect(() => {\n setValue(propValue);\n }, [propValue]);\n\n const handleChange = (next, event, { isPhone = true } = {}) => {\n const [prefix = '', phone = ''] = hasPrefixes ? value?.split(' ') || [] : [undefined, value];\n let nextValue = (isPhone ? [prefix, next?.replace(/[^\\d]/g, '')] : [next, phone]).join(' ');\n if (!hasPrefixes) nextValue = nextValue.trim();\n\n setValue(nextValue);\n onError && onError(getInputPhoneErrors({ prefixes, value: nextValue }));\n onChange(nextValue, event);\n };\n\n const handleEnter = (event, { isPhone = true } = {}) => {\n isPhone ? setFocus(true) : setPrefixFocus(true);\n onEnter(event);\n };\n\n const handleLeave = (event, { isPhone = true } = {}) => {\n isPhone ? setFocus(false) : setPrefixFocus(false);\n onLeave(event);\n };\n const hasPrefixes = !!prefixes?.length;\n const [prefix, phone] = hasPrefixes ? value?.split(' ') || [] : [undefined, value];\n const has = {\n icon: !!icon,\n label: !!label,\n labelPrefix: !!labelPrefix,\n prefix: prefix?.length > 0,\n phone: phone?.length > 0,\n stateIcon: showState && (error || success || warning),\n };\n const { ['data-testid']: testId } = others;\n\n return (\n <View className={styles(stylePhone.container, others.className)} style={others.style}>\n <View\n row\n className={styles(\n style.inputBorder,\n disabled && style.disabled,\n error && style.error,\n (focus || prefixFocus) && !error && style.focus,\n )}\n >\n {hasPrefixes && (\n <>\n <View row>\n <View className={styles(style.content)}>\n {labelPrefix && (\n <Label\n {...{\n disabled,\n error,\n focus: prefixFocus,\n label: labelPrefix,\n required: showRequired && others.required,\n value: prefix,\n }}\n />\n )}\n <Select\n {...others}\n disabled={disabled}\n name={`${name}-prefix`}\n options={prefixes}\n style={undefined}\n type={undefined}\n value={prefix || ''}\n onChange={(value, event) => handleChange(value, event, { isPhone: false })}\n onEnter={(event) => handleEnter(event, { isPhone: false })}\n onLeave={(event) => handleLeave(event, { isPhone: false })}\n className={styles(\n style.input,\n stylePhone.prefix,\n has.labelPrefix && style.withLabel,\n has.labelPrefix && !(prefixFocus || error || has.prefix) && style.empty,\n )}\n data-testid={testId ? `${testId}-select` : undefined}\n />\n </View>\n {!disabled && <Icon value={ICON.EXPAND_MORE} className={(style.icon, style.select, stylePhone.expand)} />}\n </View>\n <View forceRow className={stylePhone.separator}></View>\n </>\n )}\n\n <View row wide>\n {has.icon && (\n <Icon\n value={icon}\n className={styles(style.icon, style.left, disabled && style.disabled, error && style.error)}\n />\n )}\n <View wide className={style.content}>\n {label && (\n <Label {...{ disabled, error, focus, label, required: showRequired && others.required, value: phone }} />\n )}\n <Input\n {...others}\n disabled={disabled}\n name={`${name}-phone`}\n type=\"tel\"\n value={phone || ''}\n onChange={(value, event) => handleChange(value, event)}\n onEnter={(event) => handleEnter(event)}\n onLeave={(event) => handleLeave(event)}\n className={styles(style.input, has.label && style.withLabel)}\n data-testid={testId ? `${testId}-input` : undefined}\n />\n </View>\n </View>\n {has.stateIcon && <IconState {...{ error, success, warning }} />}\n </View>\n {hint && <Hint {...{ disabled, error, hint }} />}\n </View>\n );\n};\n\nInputPhone.displayName = 'Component:InputPhone';\n\nInputPhone.propTypes = {\n disabled: PropTypes.bool,\n error: PropTypes.bool,\n hint: PropTypes.string,\n icon: PropTypes.func,\n label: PropTypes.string,\n labelPrefix: PropTypes.string,\n name: PropTypes.string.isRequired,\n prefixes: PropTypes.arrayOf(PropTypes.string),\n showRequired: PropTypes.bool,\n showState: PropTypes.bool,\n success: PropTypes.bool,\n value: PropTypes.string,\n warning: PropTypes.bool,\n onChange: PropTypes.func,\n onEnter: PropTypes.func,\n onError: PropTypes.func,\n onLeave: PropTypes.func,\n};\n\nexport { InputPhone };\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AAEA;AACA;AACA;AACA;AAAiD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEjD,IAAMA,UAAU,GAAG,SAAbA,UAAU,OAmBV;EAAA,IAlBJC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;IACLC,IAAI,QAAJA,IAAI;IACJC,IAAI,QAAJA,IAAI;IACJC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;IACXC,IAAI,QAAJA,IAAI;IACJC,QAAQ,QAARA,QAAQ;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EACNX,IAAI,iBAAI,6BAAC,cAAI;IAAOF,QAAQ,EAARA,QAAQ;IAAEC,KAAK,EAALA,KAAK;IAAEC,IAAI,EAAJA;EAAI,EAAM,CAC3C;AAEX,CAAC;AAAC;AAEFH,UAAU,CAACgE,WAAW,GAAG,sBAAsB;AAE/ChE,UAAU,CAACiE,SAAS,GAAG;EACrBhE,QAAQ,EAAEiE,kBAAS,CAACC,IAAI;EACxBjE,KAAK,EAAEgE,kBAAS,CAACC,IAAI;EACrBhE,IAAI,EAAE+D,kBAAS,CAACE,MAAM;EACtBhE,IAAI,EAAE8D,kBAAS,CAACG,IAAI;EACpBhE,KAAK,EAAE6D,kBAAS,CAACE,MAAM;EACvB9D,WAAW,EAAE4D,kBAAS,CAACE,MAAM;EAC7B7D,IAAI,EAAE2D,kBAAS,CAACE,MAAM,CAACE,UAAU;EACjC9D,QAAQ,EAAE0D,kBAAS,CAACK,OAAO,CAACL,kBAAS,CAACE,MAAM,CAAC;EAC7C3D,YAAY,EAAEyD,kBAAS,CAACC,IAAI;EAC5BzD,SAAS,EAAEwD,kBAAS,CAACC,IAAI;EACzBxD,OAAO,EAAEuD,kBAAS,CAACC,IAAI;EACvBtD,KAAK,EAAEqD,kBAAS,CAACE,MAAM;EACvBtD,OAAO,EAAEoD,kBAAS,CAACC,IAAI;EACvBpD,QAAQ,EAAEmD,kBAAS,CAACG,IAAI;EACxBrD,OAAO,EAAEkD,kBAAS,CAACG,IAAI;EACvBpD,OAAO,EAAEiD,kBAAS,CAACG,IAAI;EACvBnD,OAAO,EAAEgD,kBAAS,CAACG;AACrB,CAAC"}
1
+ {"version":3,"file":"InputPhone.js","names":["InputPhone","disabled","error","hint","icon","label","labelPrefix","name","prefixes","showRequired","showState","success","propValue","value","warning","onChange","onEnter","onError","onLeave","others","useState","focus","setFocus","prefixFocus","setPrefixFocus","setValue","useEffect","handleChange","next","event","isPhone","hasPrefixes","split","undefined","prefix","phone","nextValue","replace","join","trim","getInputPhoneErrors","handleEnter","handleLeave","length","has","stateIcon","testId","styles","stylePhone","container","className","style","inputBorder","content","required","input","withLabel","empty","ICON","EXPAND_MORE","select","expand","separator","left","displayName","propTypes","PropTypes","bool","string","func","isRequired","arrayOf"],"sources":["../../../src/components/InputPhone/InputPhone.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React, { useEffect, useState } from 'react';\n\nimport { styles } from '../../helpers';\nimport { getInputPhoneErrors } from '../../helpers';\nimport { Icon, ICON, Input, Select, View } from '../../primitives';\nimport style from '../InputText/InputText.module.css';\nimport { Hint, IconState, Label } from '../InputText/partials';\nimport stylePhone from './InputPhone.module.css';\n\nconst InputPhone = ({\n disabled,\n error,\n hint,\n icon,\n label,\n labelPrefix,\n name,\n prefixes,\n showRequired = false,\n showState = true,\n success,\n value: propValue,\n warning,\n onChange = () => {},\n onEnter = () => {},\n onError,\n onLeave = () => {},\n ...others\n}) => {\n const [focus, setFocus] = useState(false);\n const [prefixFocus, setPrefixFocus] = useState(false);\n const [value, setValue] = useState();\n\n useEffect(() => {\n setValue(propValue);\n }, [propValue]);\n\n const handleChange = (next, event, { isPhone = true } = {}) => {\n const [prefix = '', phone = ''] = hasPrefixes ? value?.split(' ') || [] : [undefined, value];\n let nextValue = (isPhone ? [prefix, next?.replace(/[^\\d]/g, '')] : [next, phone]).join(' ');\n if (!hasPrefixes) nextValue = nextValue.trim();\n\n setValue(nextValue);\n onError && onError(getInputPhoneErrors({ prefixes, value: nextValue }));\n onChange(nextValue, event);\n };\n\n const handleEnter = (event, { isPhone = true } = {}) => {\n isPhone ? setFocus(true) : setPrefixFocus(true);\n onEnter(event);\n };\n\n const handleLeave = (event, { isPhone = true } = {}) => {\n isPhone ? setFocus(false) : setPrefixFocus(false);\n onLeave(event);\n };\n const hasPrefixes = !!prefixes?.length;\n const [prefix, phone] = hasPrefixes ? value?.split(' ') || [] : [undefined, value];\n const has = {\n icon: !!icon,\n label: !!label,\n labelPrefix: !!labelPrefix,\n prefix: prefix?.length > 0,\n phone: phone?.length > 0,\n stateIcon: showState && (error || success || warning),\n };\n const { ['data-testid']: testId } = others;\n\n return (\n <View className={styles(stylePhone.container, others.className)} style={others.style}>\n <View\n row\n className={styles(\n style.inputBorder,\n disabled && style.disabled,\n error && style.error,\n (focus || prefixFocus) && !error && style.focus,\n )}\n >\n {hasPrefixes && (\n <>\n <View row>\n <View className={styles(style.content)}>\n {labelPrefix && (\n <Label\n {...{\n disabled,\n error,\n focus: prefixFocus,\n label: labelPrefix,\n required: showRequired && others.required,\n value: prefix,\n }}\n />\n )}\n <Select\n {...others}\n disabled={disabled}\n name={`${name}-prefix`}\n options={prefixes}\n style={undefined}\n type={undefined}\n value={prefix || ''}\n onChange={(value, event) => handleChange(value, event, { isPhone: false })}\n onEnter={(event) => handleEnter(event, { isPhone: false })}\n onLeave={(event) => handleLeave(event, { isPhone: false })}\n className={styles(\n style.input,\n stylePhone.prefix,\n has.labelPrefix && style.withLabel,\n has.labelPrefix && !(prefixFocus || error || has.prefix) && style.empty,\n )}\n data-testid={testId ? `${testId}-select` : undefined}\n />\n </View>\n {!disabled && <Icon value={ICON.EXPAND_MORE} className={(style.icon, style.select, stylePhone.expand)} />}\n </View>\n <View forceRow className={stylePhone.separator}></View>\n </>\n )}\n\n <View row wide>\n {has.icon && (\n <Icon\n value={icon}\n className={styles(style.icon, style.left, disabled && style.disabled, error && style.error)}\n />\n )}\n <View wide className={style.content}>\n {label && (\n <Label {...{ disabled, error, focus, label, required: showRequired && others.required, value: phone }} />\n )}\n <Input\n {...others}\n disabled={disabled}\n maxLength={12}\n name={`${name}-phone`}\n type=\"tel\"\n value={phone || ''}\n onChange={(value, event) => handleChange(value, event)}\n onEnter={(event) => handleEnter(event)}\n onLeave={(event) => handleLeave(event)}\n className={styles(style.input, has.label && style.withLabel)}\n data-testid={testId ? `${testId}-input` : undefined}\n />\n </View>\n </View>\n {has.stateIcon && <IconState {...{ error, success, warning }} />}\n </View>\n {hint && <Hint {...{ disabled, error, hint }} />}\n </View>\n );\n};\n\nInputPhone.displayName = 'Component:InputPhone';\n\nInputPhone.propTypes = {\n disabled: PropTypes.bool,\n error: PropTypes.bool,\n hint: PropTypes.string,\n icon: PropTypes.func,\n label: PropTypes.string,\n labelPrefix: PropTypes.string,\n name: PropTypes.string.isRequired,\n prefixes: PropTypes.arrayOf(PropTypes.string),\n showRequired: PropTypes.bool,\n showState: PropTypes.bool,\n success: PropTypes.bool,\n value: PropTypes.string,\n warning: PropTypes.bool,\n onChange: PropTypes.func,\n onEnter: PropTypes.func,\n onError: PropTypes.func,\n onLeave: PropTypes.func,\n};\n\nexport { InputPhone };\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AAEA;AACA;AACA;AACA;AAAiD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEjD,IAAMA,UAAU,GAAG,SAAbA,UAAU,OAmBV;EAAA,IAlBJC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;IACLC,IAAI,QAAJA,IAAI;IACJC,IAAI,QAAJA,IAAI;IACJC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;IACXC,IAAI,QAAJA,IAAI;IACJC,QAAQ,QAARA,QAAQ;IAAA,yBACRC,YAAY;IAAZA,YAAY,kCAAG,KAAK;IAAA,sBACpBC,SAAS;IAATA,SAAS,+BAAG,IAAI;IAChBC,OAAO,QAAPA,OAAO;IACAC,SAAS,QAAhBC,KAAK;IACLC,OAAO,QAAPA,OAAO;IAAA,qBACPC,QAAQ;IAARA,QAAQ,8BAAG,YAAM,CAAC,CAAC;IAAA,oBACnBC,OAAO;IAAPA,OAAO,6BAAG,YAAM,CAAC,CAAC;IAClBC,OAAO,QAAPA,OAAO;IAAA,oBACPC,OAAO;IAAPA,OAAO,6BAAG,YAAM,CAAC,CAAC;IACfC,MAAM;EAET,gBAA0B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAAlCC,KAAK;IAAEC,QAAQ;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AW,EAAE4D,kBAAS,CAACE,MAAM;EAC7B7D,IAAI,EAAE2D,kBAAS,CAACE,MAAM,CAACE,UAAU;EACjC9D,QAAQ,EAAE0D,kBAAS,CAACK,OAAO,CAACL,kBAAS,CAACE,MAAM,CAAC;EAC7C3D,YAAY,EAAEyD,kBAAS,CAACC,IAAI;EAC5BzD,SAAS,EAAEwD,kBAAS,CAACC,IAAI;EACzBxD,OAAO,EAAEuD,kBAAS,CAACC,IAAI;EACvBtD,KAAK,EAAEqD,kBAAS,CAACE,MAAM;EACvBtD,OAAO,EAAEoD,kBAAS,CAACC,IAAI;EACvBpD,QAAQ,EAAEmD,kBAAS,CAACG,IAAI;EACxBrD,OAAO,EAAEkD,kBAAS,CAACG,IAAI;EACvBpD,OAAO,EAAEiD,kBAAS,CAACG,IAAI;EACvBnD,OAAO,EAAEgD,kBAAS,CAACG;AACrB,CAAC"}
@@ -9,6 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
9
9
  var _primitives = require("../../primitives");
10
10
  var _InputPhone = require("./InputPhone");
11
11
  var _Story$args;
12
+ var _excluded = ["value"];
12
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
15
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
@@ -25,12 +26,16 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
25
26
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
26
27
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
27
28
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
30
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
28
31
  var _default = {
29
32
  title: 'Components'
30
33
  };
31
34
  exports.default = _default;
32
- var Story = function Story(props) {
33
- var _useState = (0, _react.useState)('+34 615702323'),
35
+ var Story = function Story(_ref) {
36
+ var propValue = _ref.value,
37
+ props = _objectWithoutProperties(_ref, _excluded);
38
+ var _useState = (0, _react.useState)(propValue),
34
39
  _useState2 = _slicedToArray(_useState, 2),
35
40
  value = _useState2[0],
36
41
  setValue = _useState2[1];
@@ -87,6 +92,7 @@ Story.args = (_Story$args = {
87
92
  showRequired: false,
88
93
  showState: true,
89
94
  success: false,
95
+ value: '+34 615702323',
90
96
  warning: false
91
97
  }, _defineProperty(_Story$args, 'data-testid', 'test-story'), _defineProperty(_Story$args, "style", {}), _Story$args);
92
98
  Story.argTypes = {
@@ -1 +1 @@
1
- {"version":3,"file":"InputPhone.stories.js","names":["title","Story","props","useState","value","setValue","handleChange","next","others","console","log","handleEnter","handleError","handleLeave","ICON","icon","storyName","args","disabled","error","hint","undefined","label","labelPrefix","name","prefixes","required","showRequired","showState","success","warning","argTypes","options","Object","keys","control","type","defaultValue"],"sources":["../../../src/components/InputPhone/InputPhone.stories.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { ICON } from '../../primitives';\nimport { InputPhone } from './InputPhone';\nexport default { title: 'Components' };\n\nexport const Story = (props) => {\n const [value, setValue] = useState('+34 615702323');\n\n const handleChange = (next, ...others) => {\n setValue(next);\n console.log('<InputPhone>::onChange', next, ...others);\n };\n\n const handleEnter = (...others) => console.log('<InputSelect>::onEnter', ...others);\n\n const handleError = (...others) => console.log('<InputSelect>::onError', ...others);\n\n const handleLeave = (...others) => console.log('<InputSelect>::onLeave', ...others);\n\n return (\n <InputPhone\n {...props}\n icon={ICON[props.icon]}\n value={value}\n onChange={handleChange}\n onEnter={handleEnter}\n onError={handleError}\n onLeave={handleLeave}\n />\n );\n};\n\nStory.storyName = 'InputPhone';\n\nStory.args = {\n disabled: false,\n error: false,\n hint: 'hint',\n icon: undefined,\n label: 'Phone Number',\n labelPrefix: 'Code',\n name: 'name',\n prefixes: ['+34', '+44', '+001', '+999', '+39', '+56'],\n required: true,\n showRequired: false,\n showState: true,\n success: false,\n warning: false,\n // inherited properties\n ['data-testid']: 'test-story',\n style: {},\n};\n\nStory.argTypes = {\n icon: {\n options: [undefined, ...Object.keys(ICON)],\n control: { type: 'select' },\n defaultValue: undefined,\n },\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAC3B;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,CAAIC,KAAK,EAAK;EAC9B,gBAA0B,IAAAC,eAAQ,EAAC,eAAe,CAAC;IAAA;IAA5CC,KAAK;IAAEC,QAAQ;EAEtB,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,IAAI,EAAgB;IAAA;IACxCF,QAAQ,CAACE,IAAI,CAAC;IAAC,kCADcC,MAAM;MAANA,MAAM;IAAA;IAEnC,YAAAC,OAAO,EAACC,GAAG,kBAAC,wBAAwB,EAAEH,IAAI,SAAKC,MAAM,EAAC;EACxD,CAAC;EAED,IAAMG,WAAW,GAAG,SAAdA,WAAW;IAAA;IAAA,mCAAOH,MAAM;MAANA,MAAM;IAAA;IAAA,OAAK,aAAAC,OAAO,EAACC,GAAG,mBAAC,wBAAwB,SAAKF,MAAM,EAAC;EAAA;EAEnF,IAAMI,WAAW,GAAG,SAAdA,WAAW;IAAA;IAAA,mCAAOJ,MAAM;MAANA,MAAM;IAAA;IAAA,OAAK,aAAAC,OAAO,EAACC,GAAG,mBAAC,wBAAwB,SAAKF,MAAM,EAAC;EAAA;EAEnF,IAAMK,WAAW,GAAG,SAAdA,WAAW;IAAA;IAAA,mCAAOL,MAAM;MAANA,MAAM;IAAA;IAAA,OAAK,aAAAC,OAAO,EAACC,GAAG,mBAAC,wBAAwB,SAAKF,MAAM,EAAC;EAAA;EAEnF,oBACE,6BAAC,sBAAU,eACLN,KAAK;IACT,IAAI,EAAEY,gBAAI,CAACZ,KAAK,CAACa,IAAI,CAAE;IACvB,KAAK,EAAEX,KAAM;IACb,QAAQ,EAAEE,YAAa;IACvB,OAAO,EAAEK,WAAY;IACrB,OAAO,EAAEC,WAAY;IACrB,OAAO,EAAEC;EAAY,GACrB;AAEN,CAAC;AAAC;AAEFZ,KAAK,CAACe,SAAS,GAAG,YAAY;AAE9Bf,KAAK,CAACgB,IAAI;EACRC,QAAQ,EAAE,KAAK;EACfC,KAAK,EAAE,KAAK;EACZC,IAAI,EAAE,MAAM;EACZL,IAAI,EAAEM,SAAS;EACfC,KAAK,EAAE,cAAc;EACrBC,WAAW,EAAE,MAAM;EACnBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;EACtDC,QAAQ,EAAE,IAAI;EACdC,YAAY,EAAE,KAAK;EACnBC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAE,KAAK;EACdC,OAAO,EAAE;AAAK,gCAEb,aAAa,EAAG,YAAY,yCACtB,CAAC,CAAC,eACV;AAED7B,KAAK,CAAC8B,QAAQ,GAAG;EACfhB,IAAI,EAAE;IACJiB,OAAO,GAAGX,SAAS,4BAAKY,MAAM,CAACC,IAAI,CAACpB,gBAAI,CAAC,EAAC;IAC1CqB,OAAO,EAAE;MAAEC,IAAI,EAAE;IAAS,CAAC;IAC3BC,YAAY,EAAEhB;EAChB;AACF,CAAC"}
1
+ {"version":3,"file":"InputPhone.stories.js","names":["title","Story","propValue","value","props","useState","setValue","handleChange","next","others","console","log","handleEnter","handleError","handleLeave","ICON","icon","storyName","args","disabled","error","hint","undefined","label","labelPrefix","name","prefixes","required","showRequired","showState","success","warning","argTypes","options","Object","keys","control","type","defaultValue"],"sources":["../../../src/components/InputPhone/InputPhone.stories.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { ICON } from '../../primitives';\nimport { InputPhone } from './InputPhone';\nexport default { title: 'Components' };\n\nexport const Story = ({ value: propValue, ...props }) => {\n const [value, setValue] = useState(propValue);\n\n const handleChange = (next, ...others) => {\n setValue(next);\n console.log('<InputPhone>::onChange', next, ...others);\n };\n\n const handleEnter = (...others) => console.log('<InputSelect>::onEnter', ...others);\n\n const handleError = (...others) => console.log('<InputSelect>::onError', ...others);\n\n const handleLeave = (...others) => console.log('<InputSelect>::onLeave', ...others);\n\n return (\n <InputPhone\n {...props}\n icon={ICON[props.icon]}\n value={value}\n onChange={handleChange}\n onEnter={handleEnter}\n onError={handleError}\n onLeave={handleLeave}\n />\n );\n};\n\nStory.storyName = 'InputPhone';\n\nStory.args = {\n disabled: false,\n error: false,\n hint: 'hint',\n icon: undefined,\n label: 'Phone Number',\n labelPrefix: 'Code',\n name: 'name',\n prefixes: ['+34', '+44', '+001', '+999', '+39', '+56'],\n required: true,\n showRequired: false,\n showState: true,\n success: false,\n value: '+34 615702323',\n warning: false,\n // inherited properties\n ['data-testid']: 'test-story',\n style: {},\n};\n\nStory.argTypes = {\n icon: {\n options: [undefined, ...Object.keys(ICON)],\n control: { type: 'select' },\n defaultValue: undefined,\n },\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAC3B;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,OAAuC;EAAA,IAA1BC,SAAS,QAAhBC,KAAK;IAAgBC,KAAK;EAChD,gBAA0B,IAAAC,eAAQ,EAACH,SAAS,CAAC;IAAA;IAAtCC,KAAK;IAAEG,QAAQ;EAEtB,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,IAAI,EAAgB;IA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AC;EACtDC,QAAQ,EAAE,IAAI;EACdC,YAAY,EAAE,KAAK;EACnBC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAE,KAAK;EACd3B,KAAK,EAAE,eAAe;EACtB4B,OAAO,EAAE;AAAK,gCAEb,aAAa,EAAG,YAAY,yCACtB,CAAC,CAAC,eACV;AAED9B,KAAK,CAAC+B,QAAQ,GAAG;EACfhB,IAAI,EAAE;IACJiB,OAAO,GAAGX,SAAS,4BAAKY,MAAM,CAACC,IAAI,CAACpB,gBAAI,CAAC,EAAC;IAC1CqB,OAAO,EAAE;MAAEC,IAAI,EAAE;IAAS,CAAC;IAC3BC,YAAY,EAAEhB;EAChB;AACF,CAAC"}
@@ -69,6 +69,7 @@ exports[`component:<InputPhone> inherit:className 1`] = `
69
69
  >
70
70
  <input
71
71
  class="input input"
72
+ maxlength="12"
72
73
  name="name-phone"
73
74
  type="tel"
74
75
  value=""
@@ -129,6 +130,7 @@ exports[`component:<InputPhone> prop:disabled 1`] = `
129
130
  <input
130
131
  class="input input"
131
132
  disabled=""
133
+ maxlength="12"
132
134
  name="name-phone"
133
135
  type="tel"
134
136
  value=""
@@ -209,6 +211,7 @@ exports[`component:<InputPhone> prop:error 1`] = `
209
211
  >
210
212
  <input
211
213
  class="input input"
214
+ maxlength="12"
212
215
  name="name-phone"
213
216
  type="tel"
214
217
  value=""
@@ -310,6 +313,7 @@ exports[`component:<InputPhone> prop:hint 1`] = `
310
313
  >
311
314
  <input
312
315
  class="input input"
316
+ maxlength="12"
313
317
  name="name-phone"
314
318
  type="tel"
315
319
  value=""
@@ -396,6 +400,7 @@ exports[`component:<InputPhone> prop:icon & disabled 1`] = `
396
400
  <input
397
401
  class="input input"
398
402
  disabled=""
403
+ maxlength="12"
399
404
  name="name-phone"
400
405
  type="tel"
401
406
  value=""
@@ -497,6 +502,7 @@ exports[`component:<InputPhone> prop:icon & error 1`] = `
497
502
  >
498
503
  <input
499
504
  class="input input"
505
+ maxlength="12"
500
506
  name="name-phone"
501
507
  type="tel"
502
508
  value=""
@@ -619,6 +625,7 @@ exports[`component:<InputPhone> prop:icon 1`] = `
619
625
  >
620
626
  <input
621
627
  class="input input"
628
+ maxlength="12"
622
629
  name="name-phone"
623
630
  type="tel"
624
631
  value=""
@@ -704,6 +711,7 @@ exports[`component:<InputPhone> prop:label 1`] = `
704
711
  </span>
705
712
  <input
706
713
  class="input input withLabel"
714
+ maxlength="12"
707
715
  name="name-phone"
708
716
  type="tel"
709
717
  value=""
@@ -789,6 +797,7 @@ exports[`component:<InputPhone> prop:labelPrefix 1`] = `
789
797
  >
790
798
  <input
791
799
  class="input input"
800
+ maxlength="12"
792
801
  name="name-phone"
793
802
  type="tel"
794
803
  value=""
@@ -890,6 +899,7 @@ exports[`component:<InputPhone> prop:required & prop:showRequired (true) 1`] = `
890
899
  </span>
891
900
  <input
892
901
  class="input input withLabel"
902
+ maxlength="12"
893
903
  name="name-phone"
894
904
  required=""
895
905
  type="tel"
@@ -982,6 +992,7 @@ exports[`component:<InputPhone> prop:required 1`] = `
982
992
  </span>
983
993
  <input
984
994
  class="input input withLabel"
995
+ maxlength="12"
985
996
  name="name-phone"
986
997
  required=""
987
998
  type="tel"
@@ -1063,6 +1074,7 @@ exports[`component:<InputPhone> prop:showState (false) & error 1`] = `
1063
1074
  >
1064
1075
  <input
1065
1076
  class="input input"
1077
+ maxlength="12"
1066
1078
  name="name-phone"
1067
1079
  type="tel"
1068
1080
  value=""
@@ -1164,6 +1176,7 @@ exports[`component:<InputPhone> prop:showState (false) & success 1`] = `
1164
1176
  >
1165
1177
  <input
1166
1178
  class="input input"
1179
+ maxlength="12"
1167
1180
  name="name-phone"
1168
1181
  type="tel"
1169
1182
  value=""
@@ -1265,6 +1278,7 @@ exports[`component:<InputPhone> prop:showState (false) & warning 1`] = `
1265
1278
  >
1266
1279
  <input
1267
1280
  class="input input"
1281
+ maxlength="12"
1268
1282
  name="name-phone"
1269
1283
  type="tel"
1270
1284
  value=""
@@ -1362,6 +1376,7 @@ exports[`component:<InputPhone> prop:success 1`] = `
1362
1376
  >
1363
1377
  <input
1364
1378
  class="input input"
1379
+ maxlength="12"
1365
1380
  name="name-phone"
1366
1381
  type="tel"
1367
1382
  value=""
@@ -1463,6 +1478,7 @@ exports[`component:<InputPhone> prop:value 1`] = `
1463
1478
  >
1464
1479
  <input
1465
1480
  class="input input"
1481
+ maxlength="12"
1466
1482
  name="name-phone"
1467
1483
  type="tel"
1468
1484
  value="212123789"
@@ -1490,6 +1506,7 @@ exports[`component:<InputPhone> prop:value:without prefixes 1`] = `
1490
1506
  >
1491
1507
  <input
1492
1508
  class="input input"
1509
+ maxlength="12"
1493
1510
  name="name-phone"
1494
1511
  type="tel"
1495
1512
  value="212123789"
@@ -1570,6 +1587,7 @@ exports[`component:<InputPhone> prop:warning 1`] = `
1570
1587
  >
1571
1588
  <input
1572
1589
  class="input input"
1590
+ maxlength="12"
1573
1591
  name="name-phone"
1574
1592
  type="tel"
1575
1593
  value=""
@@ -1667,6 +1685,7 @@ exports[`component:<InputPhone> renders 1`] = `
1667
1685
  >
1668
1686
  <input
1669
1687
  class="input input"
1688
+ maxlength="12"
1670
1689
  name="name-phone"
1671
1690
  type="tel"
1672
1691
  value=""
@@ -1749,6 +1768,7 @@ exports[`component:<InputPhone> testID 1`] = `
1749
1768
  <input
1750
1769
  class="input input"
1751
1770
  data-testid="mirai-input"
1771
+ maxlength="12"
1752
1772
  name="name-phone"
1753
1773
  type="tel"
1754
1774
  value=""
@@ -1777,6 +1797,7 @@ exports[`component:<InputPhone> testID:without prefixes 1`] = `
1777
1797
  <input
1778
1798
  class="input input"
1779
1799
  data-testid="mirai-input"
1800
+ maxlength="12"
1780
1801
  name="name-phone"
1781
1802
  type="tel"
1782
1803
  value=""
@@ -6,20 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getInputPhoneErrors = void 0;
7
7
  var getInputPhoneErrors = function getInputPhoneErrors() {
8
8
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9
- prefixes = _ref.prefixes,
9
+ _ref$prefixes = _ref.prefixes,
10
+ prefixes = _ref$prefixes === void 0 ? [] : _ref$prefixes,
10
11
  _ref$value = _ref.value,
11
12
  value = _ref$value === void 0 ? '' : _ref$value;
12
- if (value === '') return;
13
+ if (value.trim().length === 0) return;
13
14
  var errors = {};
14
- var hasPrefixes = (prefixes === null || prefixes === void 0 ? void 0 : prefixes.length) && (prefixes === null || prefixes === void 0 ? void 0 : prefixes.length) > 0;
15
- var minLength = hasPrefixes ? 10 : 8;
16
- var validPrefix = !hasPrefixes || prefixes.some(function (prefix) {
17
- return value.includes(prefix);
18
- });
15
+ var withPrefix = prefixes.length > 0;
19
16
  var _value$replace = value.replace(/\D/g, ''),
20
17
  length = _value$replace.length;
21
- if (!(validPrefix && length >= minLength && length <= 15)) errors.format = true;
22
- return errors;
18
+ if (length < (withPrefix ? 10 : 8)) errors.minLength = true;
19
+ if (withPrefix && !prefixes.some(function (item) {
20
+ return value.includes(item);
21
+ })) errors.format = true;
22
+ return Object.keys(errors).length > 0 ? errors : undefined;
23
23
  };
24
24
  exports.getInputPhoneErrors = getInputPhoneErrors;
25
25
  //# sourceMappingURL=getInputPhoneErrors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getInputPhoneErrors.js","names":["getInputPhoneErrors","prefixes","value","errors","hasPrefixes","length","minLength","validPrefix","some","prefix","includes","replace","format"],"sources":["../../src/helpers/getInputPhoneErrors.js"],"sourcesContent":["export const getInputPhoneErrors = ({ prefixes, value = '' } = {}) => {\n if (value === '') return;\n\n const errors = {};\n const hasPrefixes = prefixes?.length && prefixes?.length > 0;\n const minLength = hasPrefixes ? 10 : 8;\n const validPrefix = !hasPrefixes || prefixes.some((prefix) => value.includes(prefix));\n const { length } = value.replace(/\\D/g, '');\n\n if (!(validPrefix && length >= minLength && length <= 15)) errors.format = true;\n\n return errors;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAmB,GAAsC;EAAA,+EAAP,CAAC,CAAC;IAA3BC,QAAQ,QAARA,QAAQ;IAAA,kBAAEC,KAAK;IAALA,KAAK,2BAAG,EAAE;EACxD,IAAIA,KAAK,KAAK,EAAE,EAAE;EAElB,IAAMC,MAAM,GAAG,CAAC,CAAC;EACjB,IAAMC,WAAW,GAAG,CAAAH,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEI,MAAM,KAAI,CAAAJ,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEI,MAAM,IAAG,CAAC;EAC5D,IAAMC,SAAS,GAAGF,WAAW,GAAG,EAAE,GAAG,CAAC;EACtC,IAAMG,WAAW,GAAG,CAACH,WAAW,IAAIH,QAAQ,CAACO,IAAI,CAAC,UAACC,MAAM;IAAA,OAAKP,KAAK,CAACQ,QAAQ,CAACD,MAAM,CAAC;EAAA,EAAC;EACrF,qBAAmBP,KAAK,CAACS,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAAnCN,MAAM,kBAANA,MAAM;EAEd,IAAI,EAAEE,WAAW,IAAIF,MAAM,IAAIC,SAAS,IAAID,MAAM,IAAI,EAAE,CAAC,EAAEF,MAAM,CAACS,MAAM,GAAG,IAAI;EAE/E,OAAOT,MAAM;AACf,CAAC;AAAC"}
1
+ {"version":3,"file":"getInputPhoneErrors.js","names":["getInputPhoneErrors","prefixes","value","trim","length","errors","withPrefix","replace","minLength","some","item","includes","format","Object","keys","undefined"],"sources":["../../src/helpers/getInputPhoneErrors.js"],"sourcesContent":["export const getInputPhoneErrors = ({ prefixes = [], value = '' } = {}) => {\n if (value.trim().length === 0) return;\n\n const errors = {};\n const withPrefix = prefixes.length > 0;\n const { length } = value.replace(/\\D/g, '');\n\n if (length < (withPrefix ? 10 : 8)) errors.minLength = true;\n if (withPrefix && !prefixes.some((item) => value.includes(item))) errors.format = true;\n\n return Object.keys(errors).length > 0 ? errors : undefined;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAmB,GAA2C;EAAA,+EAAP,CAAC,CAAC;IAAA,qBAAhCC,QAAQ;IAARA,QAAQ,8BAAG,EAAE;IAAA,kBAAEC,KAAK;IAALA,KAAK,2BAAG,EAAE;EAC7D,IAAIA,KAAK,CAACC,IAAI,EAAE,CAACC,MAAM,KAAK,CAAC,EAAE;EAE/B,IAAMC,MAAM,GAAG,CAAC,CAAC;EACjB,IAAMC,UAAU,GAAGL,QAAQ,CAACG,MAAM,GAAG,CAAC;EACtC,qBAAmBF,KAAK,CAACK,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAAnCH,MAAM,kBAANA,MAAM;EAEd,IAAIA,MAAM,IAAIE,UAAU,GAAG,EAAE,GAAG,CAAC,CAAC,EAAED,MAAM,CAACG,SAAS,GAAG,IAAI;EAC3D,IAAIF,UAAU,IAAI,CAACL,QAAQ,CAACQ,IAAI,CAAC,UAACC,IAAI;IAAA,OAAKR,KAAK,CAACS,QAAQ,CAACD,IAAI,CAAC;EAAA,EAAC,EAAEL,MAAM,CAACO,MAAM,GAAG,IAAI;EAEtF,OAAOC,MAAM,CAACC,IAAI,CAACT,MAAM,CAAC,CAACD,MAAM,GAAG,CAAC,GAAGC,MAAM,GAAGU,SAAS;AAC5D,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirai/ui",
3
- "version": "1.0.152",
3
+ "version": "1.0.154-beta",
4
4
  "repository": "git@gitlab.com:miraicorp/dev/frontend/ui.git",
5
5
  "author": "JΛVI <hello@soyjavi.com>",
6
6
  "license": "MIT",