@mirai/ui 1.0.152 → 1.0.154

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,eAAe;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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;AAEvF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I;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,E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AACtB,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,EAAE,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Q,GAAG,CAAC,CAAC"}
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",
4
4
  "repository": "git@gitlab.com:miraicorp/dev/frontend/ui.git",
5
5
  "author": "JΛVI <hello@soyjavi.com>",
6
6
  "license": "MIT",