@mirai/ui 1.0.262 → 1.0.264
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 +4 -1
- package/build/components/Form/Form.constants.js +1 -1
- package/build/components/Form/Form.constants.js.map +1 -1
- package/build/components/Form/Form.stories.js +6 -1
- package/build/components/Form/Form.stories.js.map +1 -1
- package/build/components/InputOption/InputOption.js +4 -1
- package/build/components/InputOption/InputOption.js.map +1 -1
- package/build/components/InputOption/InputOption.stories.js +2 -1
- package/build/components/InputOption/InputOption.stories.js.map +1 -1
- package/build/components/InputOption/__tests__/__snapshots__/InputOption.test.js.snap +19 -0
- package/build/primitives/Checkbox/Checkbox.js +4 -2
- package/build/primitives/Checkbox/Checkbox.js.map +1 -1
- package/build/primitives/Checkbox/Checkbox.module.css +6 -1
- package/build/primitives/Checkbox/__tests__/__snapshots__/Checkbox.test.js.snap +31 -0
- package/build/primitives/Switch/Switch.js +4 -2
- package/build/primitives/Switch/Switch.js.map +1 -1
- package/build/primitives/Switch/Switch.module.css +4 -0
- package/build/primitives/Switch/Switch.stories.js +1 -0
- package/build/primitives/Switch/Switch.stories.js.map +1 -1
- package/build/primitives/Switch/__tests__/__snapshots__/Switch.test.js.snap +63 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ This primitive returns a checkbox button based on the following properties:
|
|
|
19
19
|
- `checked:boolean` if true, the checkbox button is checked
|
|
20
20
|
- `children:node`
|
|
21
21
|
- `disabled:boolean` applying 'disabled' attribute
|
|
22
|
+
- `error:boolean` shows error style
|
|
22
23
|
- `name:string` input name (required)
|
|
23
24
|
- `value:string` input value
|
|
24
25
|
- `onChange:function` executed when input value changes
|
|
@@ -285,6 +286,7 @@ This primitive returns a _mobile_ checkbox button based on the following propert
|
|
|
285
286
|
|
|
286
287
|
- `checked:boolean` if true, the checkbox button is checked
|
|
287
288
|
- `disabled:boolean` applying 'disabled' attribute
|
|
289
|
+
- `error:boolean` shows error style
|
|
288
290
|
- `name:string` input name (required)
|
|
289
291
|
- `onChange:function` executed when input value changes
|
|
290
292
|
|
|
@@ -692,6 +694,7 @@ This component is used to display a radio button or checkbox base on a mandatory
|
|
|
692
694
|
|
|
693
695
|
- `checked:boolean` if true, the input is checked
|
|
694
696
|
- `disabled:boolean` applying 'disabled' attribute
|
|
697
|
+
- `error:boolean` shows error style
|
|
695
698
|
- `indeterminate:boolean` applying 'indeterminate' attribute (only for type checkbox)
|
|
696
699
|
- `label:string` input label
|
|
697
700
|
- `name:string` input name
|
|
@@ -853,7 +856,7 @@ Text input component receiving the following props:
|
|
|
853
856
|
|
|
854
857
|
- `caption:string` a support text (Ex. currency symbol)
|
|
855
858
|
- `disabled:boolean` applying 'disabled' attribute
|
|
856
|
-
- `error:boolean`
|
|
859
|
+
- `error:boolean` shows error style
|
|
857
860
|
- `hint:string` brief message
|
|
858
861
|
- `icon:string` if you want use an `<Icon>` within the component
|
|
859
862
|
- `label:string` input label
|
|
@@ -10,6 +10,6 @@ var DEFAULT_TIMEOUT_ONERROR = 10;
|
|
|
10
10
|
exports.DEFAULT_TIMEOUT_ONERROR = DEFAULT_TIMEOUT_ONERROR;
|
|
11
11
|
var FIELDS_BOOLEAN = ['Component:InputOption', 'Primitive:Checkbox', 'Primitive:Radio', 'Primitive.Switch'];
|
|
12
12
|
exports.FIELDS_BOOLEAN = FIELDS_BOOLEAN;
|
|
13
|
-
var FIELDS_WITHOUT_ERROR = [
|
|
13
|
+
var FIELDS_WITHOUT_ERROR = ['Primitive:Radio', 'Component:InputNumber'];
|
|
14
14
|
exports.FIELDS_WITHOUT_ERROR = FIELDS_WITHOUT_ERROR;
|
|
15
15
|
//# sourceMappingURL=Form.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.constants.js","names":["DEFAULT_TIMEOUT_ONCHANGE","DEFAULT_TIMEOUT_ONERROR","FIELDS_BOOLEAN","FIELDS_WITHOUT_ERROR"],"sources":["../../../src/components/Form/Form.constants.js"],"sourcesContent":["const DEFAULT_TIMEOUT_ONCHANGE = 0;\nconst DEFAULT_TIMEOUT_ONERROR = 10;\nconst FIELDS_BOOLEAN = ['Component:InputOption', 'Primitive:Checkbox', 'Primitive:Radio', 'Primitive.Switch'];\nconst FIELDS_WITHOUT_ERROR = [
|
|
1
|
+
{"version":3,"file":"Form.constants.js","names":["DEFAULT_TIMEOUT_ONCHANGE","DEFAULT_TIMEOUT_ONERROR","FIELDS_BOOLEAN","FIELDS_WITHOUT_ERROR"],"sources":["../../../src/components/Form/Form.constants.js"],"sourcesContent":["const DEFAULT_TIMEOUT_ONCHANGE = 0;\nconst DEFAULT_TIMEOUT_ONERROR = 10;\nconst FIELDS_BOOLEAN = ['Component:InputOption', 'Primitive:Checkbox', 'Primitive:Radio', 'Primitive.Switch'];\nconst FIELDS_WITHOUT_ERROR = ['Primitive:Radio', 'Component:InputNumber'];\n\nexport { DEFAULT_TIMEOUT_ONCHANGE, DEFAULT_TIMEOUT_ONERROR, FIELDS_BOOLEAN, FIELDS_WITHOUT_ERROR };\n"],"mappings":";;;;;;AAAA,IAAMA,wBAAwB,GAAG,CAAC;AAAC;AACnC,IAAMC,uBAAuB,GAAG,EAAE;AAAC;AACnC,IAAMC,cAAc,GAAG,CAAC,uBAAuB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,CAAC;AAAC;AAC9G,IAAMC,oBAAoB,GAAG,CAAC,iBAAiB,EAAE,uBAAuB,CAAC;AAAC"}
|
|
@@ -171,7 +171,12 @@ var Story = function Story(props) {
|
|
|
171
171
|
type: "checkbox",
|
|
172
172
|
name: "checkbox",
|
|
173
173
|
label: "checkbox",
|
|
174
|
-
checked: form.checkbox
|
|
174
|
+
checked: form.checkbox
|
|
175
|
+
}), /*#__PURE__*/_react.default.createElement(_.InputOption, {
|
|
176
|
+
type: "checkbox",
|
|
177
|
+
name: "checkboxRequired",
|
|
178
|
+
label: "checkbox",
|
|
179
|
+
checked: form.checkboxRequired,
|
|
175
180
|
required: true,
|
|
176
181
|
showRequired: true
|
|
177
182
|
}), /*#__PURE__*/_react.default.createElement(_.InputOption, {
|
|
@@ -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","setTimeout","password","phone","handleChange","next","others","console","log","handleEnter","handleError","handleLeave","handleSubmit","value","includes","gender","undefined","bio","children","Array","from","keys","map","index","Object","length","justifyContent","marginTop","marginRight","storyName","args","debounce","schema","showErrors","validateOnMount","testId","style","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-0',\n });\n const [error, setError] = useState({});\n\n useEffect(\n () =>\n setTimeout(() => {\n setForm({\n ...form,\n email: 'javi@hotmail.com',\n password: '1234567890',\n dateOfBirth: '',\n switch: false,\n phone: '+34 61570',\n radio: 'radio-1',\n });\n }, 1000),\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 showRequired\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 showRequired\n minLength={10}\n type=\"password\"\n value={form.password}\n />\n <InputSelect\n name=\"gender\"\n emptyOption=\"Select...\"\n error={!!error.gender}\n label=\"Your gender\"\n options={['one', 'two', 'three', 'four', 'five']}\n value={form.gender}\n required\n showRequired\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 showRequired\n type=\"inputDate\"\n value={form.dateOfBirth}\n />\n <InputPhone\n name=\"phone\"\n emptyOption={!form.phone ? 'Select...' : undefined}\n error={!!error.phone}\n label=\"Phone\"\n labelPrefix=\"Prefix\"\n prefixes={['+34', '+44', '+001', '+999', '+39', '+56']}\n required\n showRequired\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} />\n <InputOption type=\"checkbox\" name=\"checkbox\" label=\"checkbox\" checked={form.checkbox} required showRequired />\n <InputOption type=\"switch\" name=\"switch\" label=\"switch\" checked={form.switch} />\n\n {Array.from(Array(3).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 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;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,OACEC,UAAU,CAAC,YAAM;MACfJ,OAAO,iCACFD,IAAI;QACPL,KAAK,EAAE,kBAAkB;QACzBW,QAAQ,EAAE,YAAY;QACtBT,WAAW,EAAE,EAAE;QACfC,MAAM,EAAE,KAAK;QACbS,KAAK,EAAE,WAAW;QAClBR,KAAK,EAAE;MAAS,GAChB;IACJ,CAAC,EAAE,IAAI,CAAC;EAAA,GAEV,EAAE,CACH,CAAC,CAAC;;EAEH,IAAMS,YAAY,GAAG,SAAfA,YAAY,CAAIC,IAAI,EAAgB;IAAA;IACxCR,OAAO,C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Q,EAAEmC,MAAM,CAACH,IAAI,CAACvB,KAAK,CAAC,CAAC2B,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,OAAM9B,OAAO,CAAC,CAAC,CAAC,CAAC;IAAA,CAAC;IAAC,KAAK,EAAE;MAAE+B,WAAW,EAAE;IAA0B;EAAE,WAE7F,eACT,6BAAC,QAAM;IAAC,KAAK;IAAC,SAAS;IAAC,OAAO,EAAE;MAAA,OAAMtC,YAAY,CAAC,CAACD,SAAS,CAAC;IAAA;EAAC,aAC1DA,SAAS,GAAG,MAAM,GAAG,MAAM,oBACxB,CACJ,CACN;AAEP,CAAC;AAAC;AAEFH,KAAK,CAAC2C,SAAS,GAAG,MAAM;AAExB3C,KAAK,CAAC4C,IAAI,GAAG;EACXC,QAAQ,EAAE,CAAC;EACXC,MAAM,EAAE,CAAC,CAAC;EACVC,UAAU,EAAE,KAAK;EACjBC,eAAe,EAAE,KAAK;EACtB;EACAC,MAAM,EAAE,YAAY;EACpBC,KAAK,EAAE,CAAC;AACV,CAAC;AAEDlD,KAAK,CAACmD,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","setTimeout","password","phone","handleChange","next","others","console","log","handleEnter","handleError","handleLeave","handleSubmit","value","includes","gender","undefined","bio","children","checkboxRequired","Array","from","keys","map","index","Object","length","justifyContent","marginTop","marginRight","storyName","args","debounce","schema","showErrors","validateOnMount","testId","style","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-0',\n });\n const [error, setError] = useState({});\n\n useEffect(\n () =>\n setTimeout(() => {\n setForm({\n ...form,\n email: 'javi@hotmail.com',\n password: '1234567890',\n dateOfBirth: '',\n switch: false,\n phone: '+34 61570',\n radio: 'radio-1',\n });\n }, 1000),\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 showRequired\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 showRequired\n minLength={10}\n type=\"password\"\n value={form.password}\n />\n <InputSelect\n name=\"gender\"\n emptyOption=\"Select...\"\n error={!!error.gender}\n label=\"Your gender\"\n options={['one', 'two', 'three', 'four', 'five']}\n value={form.gender}\n required\n showRequired\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 showRequired\n type=\"inputDate\"\n value={form.dateOfBirth}\n />\n <InputPhone\n name=\"phone\"\n emptyOption={!form.phone ? 'Select...' : undefined}\n error={!!error.phone}\n label=\"Phone\"\n labelPrefix=\"Prefix\"\n prefixes={['+34', '+44', '+001', '+999', '+39', '+56']}\n required\n showRequired\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} />\n <InputOption type=\"checkbox\" name=\"checkbox\" label=\"checkbox\" checked={form.checkbox} />\n <InputOption\n type=\"checkbox\"\n name=\"checkboxRequired\"\n label=\"checkbox\"\n checked={form.checkboxRequired}\n required\n showRequired\n />\n <InputOption type=\"switch\" name=\"switch\" label=\"switch\" checked={form.switch} />\n\n {Array.from(Array(3).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 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;A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,EAAE;IAA0B;EAAE,gBACpF,6BAAC,QAAM;IAAC,KAAK;IAAC,SAAS;IAAC,OAAO,EAAE;MAAA,OAAM/B,OAAO,CAAC,CAAC,CAAC,CAAC;IAAA,CAAC;IAAC,KAAK,EAAE;MAAEgC,WAAW,EAAE;IAA0B;EAAE,WAE7F,eACT,6BAAC,QAAM;IAAC,KAAK;IAAC,SAAS;IAAC,OAAO,EAAE;MAAA,OAAMvC,YAAY,CAAC,CAACD,SAAS,CAAC;IAAA;EAAC,aAC1DA,SAAS,GAAG,MAAM,GAAG,MAAM,oBACxB,CACJ,CACN;AAEP,CAAC;AAAC;AAEFH,KAAK,CAAC4C,SAAS,GAAG,MAAM;AAExB5C,KAAK,CAAC6C,IAAI,GAAG;EACXC,QAAQ,EAAE,CAAC;EACXC,MAAM,EAAE,CAAC,CAAC;EACVC,UAAU,EAAE,KAAK;EACjBC,eAAe,EAAE,KAAK;EACtB;EACAC,MAAM,EAAE,YAAY;EACpBC,KAAK,EAAE,CAAC;AACV,CAAC;AAEDnD,KAAK,CAACoD,QAAQ,GAAG,CAAC,CAAC"}
|
|
@@ -11,7 +11,7 @@ var _primitives = require("../../primitives");
|
|
|
11
11
|
var _partials = require("../InputText/partials");
|
|
12
12
|
var _InputOption = require("./InputOption.constants");
|
|
13
13
|
var _InputOptionModule = _interopRequireDefault(require("./InputOption.module.css"));
|
|
14
|
-
var _excluded = ["checked", "disabled", "indeterminate", "label", "name", "required", "showRequired", "small", "type", "value", "onChange"];
|
|
14
|
+
var _excluded = ["checked", "disabled", "error", "indeterminate", "label", "name", "required", "showRequired", "small", "type", "value", "onChange"];
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
17
|
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; }
|
|
@@ -19,6 +19,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
19
19
|
var InputOption = function InputOption(_ref) {
|
|
20
20
|
var checked = _ref.checked,
|
|
21
21
|
disabled = _ref.disabled,
|
|
22
|
+
error = _ref.error,
|
|
22
23
|
indeterminate = _ref.indeterminate,
|
|
23
24
|
label = _ref.label,
|
|
24
25
|
name = _ref.name,
|
|
@@ -45,6 +46,7 @@ var InputOption = function InputOption(_ref) {
|
|
|
45
46
|
}), /*#__PURE__*/_react.default.createElement(Primitive, {
|
|
46
47
|
checked: checked || type === _InputOption.CHECKBOX && indeterminate,
|
|
47
48
|
disabled: disabled,
|
|
49
|
+
error: error,
|
|
48
50
|
name: name,
|
|
49
51
|
type: type,
|
|
50
52
|
value: value
|
|
@@ -65,6 +67,7 @@ InputOption.displayName = 'Component:InputOption';
|
|
|
65
67
|
InputOption.propTypes = {
|
|
66
68
|
checked: _propTypes.default.bool,
|
|
67
69
|
disabled: _propTypes.default.bool,
|
|
70
|
+
error: _propTypes.default.bool,
|
|
68
71
|
indeterminate: _propTypes.default.bool,
|
|
69
72
|
label: _propTypes.default.string,
|
|
70
73
|
name: _propTypes.default.string.isRequired,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputOption.js","names":["InputOption","checked","disabled","indeterminate","label","name","required","showRequired","small","type","CHECKBOX","value","onChange","others","Primitive","Checkbox","RADIO","Radio","Switch","handleChange","event","SWITCH","includes","role","styles","style","inputOption","className","ICON","CHECK","REMOVE","icon","undefined","displayName","propTypes","PropTypes","bool","string","isRequired","oneOf","oneOfType","func"],"sources":["../../../src/components/InputOption/InputOption.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Checkbox, Icon, ICON, Pressable, Radio, Switch } from '../../primitives';\nimport { Label } from '../InputText/partials';\nimport { CHECKBOX, RADIO, SWITCH } from './InputOption.constants';\nimport style from './InputOption.module.css';\n\nconst InputOption = ({\n checked,\n disabled,\n indeterminate,\n label,\n name,\n required,\n showRequired = false,\n small,\n type = CHECKBOX,\n value = '',\n onChange = () => {},\n ...others\n}) => {\n const Primitive = type === CHECKBOX ? Checkbox : type === RADIO ? Radio : Switch;\n\n const handleChange = (event) => {\n onChange([CHECKBOX, SWITCH].includes(type) ? !checked : value, event);\n };\n\n return (\n <Pressable\n {...others}\n role={others.role || 'input-option'}\n preventDefault={false}\n onPress={handleChange}\n className={styles(style.inputOption, others.className)}\n >\n <Primitive\n checked={checked || (type === CHECKBOX && indeterminate)}\n disabled={disabled}\n name={name}\n type={type}\n value={value}\n >\n {type === CHECKBOX && (checked || indeterminate) ? (\n <Icon value={checked ? ICON.CHECK : ICON.REMOVE} className={style.icon} />\n ) : undefined}\n </Primitive>\n {label && (\n <Label\n action={!small}\n small={small}\n {...{ disabled, label, required: showRequired && required }}\n className={style.label}\n />\n )}\n </Pressable>\n );\n};\n\nInputOption.displayName = 'Component:InputOption';\n\nInputOption.propTypes = {\n checked: PropTypes.bool,\n disabled: PropTypes.bool,\n indeterminate: PropTypes.bool,\n label: PropTypes.string,\n name: PropTypes.string.isRequired,\n required: PropTypes.bool,\n showRequired: PropTypes.bool,\n small: PropTypes.bool,\n type: PropTypes.oneOf([CHECKBOX, RADIO, SWITCH]),\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),\n onChange: PropTypes.func,\n};\n\nexport { InputOption };\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAA6C;AAAA;AAAA;AAAA;AAAA;AAE7C,IAAMA,WAAW,GAAG,SAAdA,WAAW,
|
|
1
|
+
{"version":3,"file":"InputOption.js","names":["InputOption","checked","disabled","error","indeterminate","label","name","required","showRequired","small","type","CHECKBOX","value","onChange","others","Primitive","Checkbox","RADIO","Radio","Switch","handleChange","event","SWITCH","includes","role","styles","style","inputOption","className","ICON","CHECK","REMOVE","icon","undefined","displayName","propTypes","PropTypes","bool","string","isRequired","oneOf","oneOfType","func"],"sources":["../../../src/components/InputOption/InputOption.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Checkbox, Icon, ICON, Pressable, Radio, Switch } from '../../primitives';\nimport { Label } from '../InputText/partials';\nimport { CHECKBOX, RADIO, SWITCH } from './InputOption.constants';\nimport style from './InputOption.module.css';\n\nconst InputOption = ({\n checked,\n disabled,\n error,\n indeterminate,\n label,\n name,\n required,\n showRequired = false,\n small,\n type = CHECKBOX,\n value = '',\n onChange = () => {},\n ...others\n}) => {\n const Primitive = type === CHECKBOX ? Checkbox : type === RADIO ? Radio : Switch;\n\n const handleChange = (event) => {\n onChange([CHECKBOX, SWITCH].includes(type) ? !checked : value, event);\n };\n\n return (\n <Pressable\n {...others}\n role={others.role || 'input-option'}\n preventDefault={false}\n onPress={handleChange}\n className={styles(style.inputOption, others.className)}\n >\n <Primitive\n checked={checked || (type === CHECKBOX && indeterminate)}\n disabled={disabled}\n error={error}\n name={name}\n type={type}\n value={value}\n >\n {type === CHECKBOX && (checked || indeterminate) ? (\n <Icon value={checked ? ICON.CHECK : ICON.REMOVE} className={style.icon} />\n ) : undefined}\n </Primitive>\n {label && (\n <Label\n action={!small}\n small={small}\n {...{ disabled, label, required: showRequired && required }}\n className={style.label}\n />\n )}\n </Pressable>\n );\n};\n\nInputOption.displayName = 'Component:InputOption';\n\nInputOption.propTypes = {\n checked: PropTypes.bool,\n disabled: PropTypes.bool,\n error: PropTypes.bool,\n indeterminate: PropTypes.bool,\n label: PropTypes.string,\n name: PropTypes.string.isRequired,\n required: PropTypes.bool,\n showRequired: PropTypes.bool,\n small: PropTypes.bool,\n type: PropTypes.oneOf([CHECKBOX, RADIO, SWITCH]),\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),\n onChange: PropTypes.func,\n};\n\nexport { InputOption };\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAA6C;AAAA;AAAA;AAAA;AAAA;AAE7C,IAAMA,WAAW,GAAG,SAAdA,WAAW,OAcX;EAAA,IAbJC,OAAO,QAAPA,OAAO;IACPC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;IACLC,aAAa,QAAbA,aAAa;IACbC,KAAK,QAALA,KAAK;IACLC,IAAI,QAAJA,IAAI;IACJC,QAAQ,QAARA,QAAQ;IAAA,yBACRC,YAAY;IAAZA,YAAY,kCAAG,KAAK;IACpBC,KAAK,QAALA,KAAK;IAAA,iBACLC,IAAI;IAAJA,IAAI,0BAAGC,qBAAQ;IAAA,kBACfC,KAAK;IAALA,KAAK,2BAAG,EAAE;IAAA,qBACVC,QAAQ;IAARA,QAAQ,8BAAG,YAAM,CAAC,CAAC;IAChBC,MAAM;EAET,IAAMC,SAAS,GAAGL,IAAI,KAAKC,qBAAQ,GAAGK,oBAAQ,GAAGN,IAAI,KAAKO,kBAAK,GAAGC,iBAAK,GAAGC,kBAAM;EAEhF,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,KAAK,EAAK;IAC9BR,QAAQ,CAAC,CAACF,qBAAQ,EAAEW,mBAAM,CAAC,CAACC,QAAQ,CAACb,IAAI,CAAC,GAAG,CAACT,OAAO,GAAGW,KAAK,EAAES,KAAK,CAAC;EACvE,CAAC;EAED,oBACE,6BAAC,qBAAS,eACJP,MAAM;IACV,IAAI,EAAEA,MAAM,CAACU,IAAI,IAAI,cAAe;IACpC,cAAc,EAAE,KAAM;IACtB,OAAO,EAAEJ,YAAa;IACtB,SAAS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,IAAI;EACrB3B,IAAI,EAAE0B,kBAAS,CAACI,KAAK,CAAC,CAAC7B,qBAAQ,EAAEM,kBAAK,EAAEK,mBAAM,CAAC,CAAC;EAChDV,KAAK,EAAEwB,kBAAS,CAACK,SAAS,CAAC,CAACL,kBAAS,CAACE,MAAM,EAAEF,kBAAS,CAACC,IAAI,CAAC,CAAC;EAC9DxB,QAAQ,EAAEuB,kBAAS,CAACM;AACtB,CAAC"}
|
|
@@ -22,7 +22,7 @@ var _default = {
|
|
|
22
22
|
};
|
|
23
23
|
exports.default = _default;
|
|
24
24
|
var Story = function Story(props) {
|
|
25
|
-
var _useState = (0, _react.useState)(
|
|
25
|
+
var _useState = (0, _react.useState)(false),
|
|
26
26
|
_useState2 = _slicedToArray(_useState, 2),
|
|
27
27
|
checked = _useState2[0],
|
|
28
28
|
setChecked = _useState2[1];
|
|
@@ -43,6 +43,7 @@ exports.Story = Story;
|
|
|
43
43
|
Story.storyName = 'InputOption';
|
|
44
44
|
Story.args = {
|
|
45
45
|
disabled: false,
|
|
46
|
+
error: false,
|
|
46
47
|
indeterminate: false,
|
|
47
48
|
label: 'label',
|
|
48
49
|
name: 'name',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputOption.stories.js","names":["title","Story","props","useState","checked","setChecked","handleChange","next","others","console","log","storyName","args","disabled","indeterminate","label","name","required","showRequired","small","type","value","testId","style","argTypes","options","CHECKBOX","RADIO","SWITCH","control","defaultValue"],"sources":["../../../src/components/InputOption/InputOption.stories.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { InputOption } from './InputOption';\nimport { CHECKBOX, RADIO, SWITCH } from './InputOption.constants';\n\nexport default { title: 'Components' };\n\nexport const Story = (props) => {\n const [checked, setChecked] = useState(
|
|
1
|
+
{"version":3,"file":"InputOption.stories.js","names":["title","Story","props","useState","checked","setChecked","handleChange","next","others","console","log","storyName","args","disabled","error","indeterminate","label","name","required","showRequired","small","type","value","testId","style","argTypes","options","CHECKBOX","RADIO","SWITCH","control","defaultValue"],"sources":["../../../src/components/InputOption/InputOption.stories.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { InputOption } from './InputOption';\nimport { CHECKBOX, RADIO, SWITCH } from './InputOption.constants';\n\nexport default { title: 'Components' };\n\nexport const Story = (props) => {\n const [checked, setChecked] = useState(false);\n\n const handleChange = (next, ...others) => {\n setChecked(next);\n console.log('<InputOption>::onChange', next, ...others);\n };\n\n return <InputOption {...props} checked={checked} onChange={handleChange} />;\n};\n\nStory.storyName = 'InputOption';\n\nStory.args = {\n disabled: false,\n error: false,\n indeterminate: false,\n label: 'label',\n name: 'name',\n required: false,\n showRequired: false,\n small: false,\n type: 'checkbox',\n value: 'value',\n // inherited properties\n testId: 'test-story',\n style: {},\n};\n\nStory.argTypes = {\n type: {\n options: [CHECKBOX, RADIO, SWITCH],\n control: { type: 'select' },\n defaultValue: CHECKBOX,\n },\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AAAkE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAEnD;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,CAAIC,KAAK,EAAK;EAC9B,gBAA8B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAAtCC,OAAO;IAAEC,UAAU;EAE1B,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,IAAI,EAAgB;IAAA;IACxCF,UAAU,CAACE,IAAI,CAAC;IAAC,kCADYC,MAAM;MAANA,MAAM;IAAA;IAEnC,YAAAC,OAAO,EAACC,GAAG,kBAAC,yBAAyB,EAAEH,IAAI,SAAKC,MAAM,EAAC;EACzD,CAAC;EAED,oBAAO,6BAAC,wBAAW,eAAKN,KAAK;IAAE,OAAO,EAAEE,OAAQ;IAAC,QAAQ,EAAEE;EAAa,GAAG;AAC7E,CAAC;AAAC;AAEFL,KAAK,CAACU,SAAS,GAAG,aAAa;AAE/BV,KAAK,CAACW,IAAI,GAAG;EACXC,QAAQ,EAAE,KAAK;EACfC,KAAK,EAAE,KAAK;EACZC,aAAa,EAAE,KAAK;EACpBC,KAAK,EAAE,OAAO;EACdC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,KAAK;EACfC,YAAY,EAAE,KAAK;EACnBC,KAAK,EAAE,KAAK;EACZC,IAAI,EAAE,UAAU;EAChBC,KAAK,EAAE,OAAO;EACd;EACAC,MAAM,EAAE,YAAY;EACpBC,KAAK,EAAE,CAAC;AACV,CAAC;AAEDvB,KAAK,CAACwB,QAAQ,GAAG;EACfJ,IAAI,EAAE;IACJK,OAAO,EAAE,CAACC,sBAAQ,EAAEC,mBAAK,EAAEC,oBAAM,CAAC;IAClCC,OAAO,EAAE;MAAET,IAAI,EAAE;IAAS,CAAC;IAC3BU,YAAY,EAAEJ;EAChB;AACF,CAAC"}
|
|
@@ -122,6 +122,25 @@ exports[`primitive:<InputOption> prop:disabled 1`] = `
|
|
|
122
122
|
</DocumentFragment>
|
|
123
123
|
`;
|
|
124
124
|
|
|
125
|
+
exports[`primitive:<InputOption> prop:error 1`] = `
|
|
126
|
+
<DocumentFragment>
|
|
127
|
+
<div
|
|
128
|
+
class="pressable inputOption"
|
|
129
|
+
>
|
|
130
|
+
<div
|
|
131
|
+
class="checkbox"
|
|
132
|
+
>
|
|
133
|
+
<input
|
|
134
|
+
class="error input"
|
|
135
|
+
name="name"
|
|
136
|
+
type="checkbox"
|
|
137
|
+
value=""
|
|
138
|
+
/>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</DocumentFragment>
|
|
142
|
+
`;
|
|
143
|
+
|
|
125
144
|
exports[`primitive:<InputOption> prop:indeterminate && disabled 1`] = `
|
|
126
145
|
<DocumentFragment>
|
|
127
146
|
<div
|
|
@@ -9,7 +9,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
var _helpers = require("../../helpers");
|
|
10
10
|
var _Primitive = require("../Primitive");
|
|
11
11
|
var _CheckboxModule = _interopRequireDefault(require("./Checkbox.module.css"));
|
|
12
|
-
var _excluded = ["checked", "children", "disabled", "name", "value", "onChange"];
|
|
12
|
+
var _excluded = ["checked", "children", "disabled", "error", "name", "value", "onChange"];
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
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; }
|
|
15
15
|
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; }
|
|
@@ -18,6 +18,7 @@ var Checkbox = function Checkbox(_ref) {
|
|
|
18
18
|
checked = _ref$checked === void 0 ? false : _ref$checked,
|
|
19
19
|
children = _ref.children,
|
|
20
20
|
disabled = _ref.disabled,
|
|
21
|
+
error = _ref.error,
|
|
21
22
|
name = _ref.name,
|
|
22
23
|
_ref$value = _ref.value,
|
|
23
24
|
value = _ref$value === void 0 ? '' : _ref$value,
|
|
@@ -42,7 +43,7 @@ var Checkbox = function Checkbox(_ref) {
|
|
|
42
43
|
value: value,
|
|
43
44
|
onChange: handleChange,
|
|
44
45
|
testId: others.testId,
|
|
45
|
-
className: (0, _helpers.styles)(checked && _CheckboxModule.default.checked, _CheckboxModule.default.input)
|
|
46
|
+
className: (0, _helpers.styles)(checked && _CheckboxModule.default.checked, error && !checked && !disabled && _CheckboxModule.default.error, _CheckboxModule.default.input)
|
|
46
47
|
}), children);
|
|
47
48
|
};
|
|
48
49
|
exports.Checkbox = Checkbox;
|
|
@@ -51,6 +52,7 @@ Checkbox.propTypes = {
|
|
|
51
52
|
checked: _propTypes.default.bool,
|
|
52
53
|
children: _propTypes.default.node,
|
|
53
54
|
disabled: _propTypes.default.bool,
|
|
55
|
+
error: _propTypes.default.bool,
|
|
54
56
|
name: _propTypes.default.string.isRequired,
|
|
55
57
|
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
56
58
|
onChange: _propTypes.default.func
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["Checkbox","checked","children","disabled","name","value","onChange","others","handleChange","event","target","role","styles","style","checkbox","className","testId","input","displayName","propTypes","PropTypes","bool","node","string","isRequired","oneOfType","func"],"sources":["../../../src/primitives/Checkbox/Checkbox.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Primitive } from '../Primitive';\nimport style from './Checkbox.module.css';\n\nconst Checkbox = ({ checked = false, children, disabled, name, value = '', onChange = () => {}, ...others }) => {\n const handleChange = (event) => {\n if (disabled) return;\n\n const {\n target: { checked },\n } = event;\n onChange(checked, event);\n };\n\n return (\n <Primitive\n role={others.role || 'checkbox'}\n className={styles(style.checkbox, others.className)}\n style={others.style}\n >\n <Primitive\n checked={checked}\n disabled={disabled}\n name={name}\n tag=\"input\"\n type=\"checkbox\"\n value={value}\n onChange={handleChange}\n testId={others.testId}\n className={styles(checked && style.checked, style.input)}\n />\n {children}\n </Primitive>\n );\n};\n\nCheckbox.displayName = 'Primitive:Checkbox';\n\nCheckbox.propTypes = {\n checked: PropTypes.bool,\n children: PropTypes.node,\n disabled: PropTypes.bool,\n name: PropTypes.string.isRequired,\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),\n onChange: PropTypes.func,\n};\n\nexport { Checkbox };\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AACA;AAA0C;AAAA;AAAA;AAAA;AAE1C,IAAMA,QAAQ,GAAG,SAAXA,QAAQ,
|
|
1
|
+
{"version":3,"file":"Checkbox.js","names":["Checkbox","checked","children","disabled","error","name","value","onChange","others","handleChange","event","target","role","styles","style","checkbox","className","testId","input","displayName","propTypes","PropTypes","bool","node","string","isRequired","oneOfType","func"],"sources":["../../../src/primitives/Checkbox/Checkbox.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Primitive } from '../Primitive';\nimport style from './Checkbox.module.css';\n\nconst Checkbox = ({ checked = false, children, disabled, error, name, value = '', onChange = () => {}, ...others }) => {\n const handleChange = (event) => {\n if (disabled) return;\n\n const {\n target: { checked },\n } = event;\n onChange(checked, event);\n };\n\n return (\n <Primitive\n role={others.role || 'checkbox'}\n className={styles(style.checkbox, others.className)}\n style={others.style}\n >\n <Primitive\n checked={checked}\n disabled={disabled}\n name={name}\n tag=\"input\"\n type=\"checkbox\"\n value={value}\n onChange={handleChange}\n testId={others.testId}\n className={styles(checked && style.checked, error && !checked && !disabled && style.error, style.input)}\n />\n {children}\n </Primitive>\n );\n};\n\nCheckbox.displayName = 'Primitive:Checkbox';\n\nCheckbox.propTypes = {\n checked: PropTypes.bool,\n children: PropTypes.node,\n disabled: PropTypes.bool,\n error: PropTypes.bool,\n name: PropTypes.string.isRequired,\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),\n onChange: PropTypes.func,\n};\n\nexport { Checkbox };\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AACA;AAA0C;AAAA;AAAA;AAAA;AAE1C,IAAMA,QAAQ,GAAG,SAAXA,QAAQ,OAAyG;EAAA,wBAAnGC,OAAO;IAAPA,OAAO,6BAAG,KAAK;IAAEC,QAAQ,QAARA,QAAQ;IAAEC,QAAQ,QAARA,QAAQ;IAAEC,KAAK,QAALA,KAAK;IAAEC,IAAI,QAAJA,IAAI;IAAA,kBAAEC,KAAK;IAALA,KAAK,2BAAG,E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,UAAU;EACjCnB,KAAK,EAAEe,kBAAS,CAACK,SAAS,CAAC,CAACL,kBAAS,CAACG,MAAM,EAAEH,kBAAS,CAACC,IAAI,CAAC,CAAC;EAC9Df,QAAQ,EAAEc,kBAAS,CAACM;AACtB,CAAC"}
|
|
@@ -36,8 +36,13 @@
|
|
|
36
36
|
border-color: var(--mirai-ui-checkbox-checked);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
.checkbox input:not(:disabled).error {
|
|
40
|
+
border-color: var(--mirai-ui-error);
|
|
41
|
+
border-width: calc(var(--mirai-ui-border-width) * 2);
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
/* -- reset defaults -------------------------------------------------------- */
|
|
40
45
|
.checkbox input.input {
|
|
41
46
|
margin-right: 0;
|
|
42
47
|
top: 0;
|
|
43
|
-
}
|
|
48
|
+
}
|
|
@@ -80,6 +80,37 @@ exports[`primitive:<Checkbox> prop:disabled 1`] = `
|
|
|
80
80
|
</DocumentFragment>
|
|
81
81
|
`;
|
|
82
82
|
|
|
83
|
+
exports[`primitive:<Checkbox> prop:error && disabled 1`] = `
|
|
84
|
+
<DocumentFragment>
|
|
85
|
+
<div
|
|
86
|
+
class="checkbox"
|
|
87
|
+
>
|
|
88
|
+
<input
|
|
89
|
+
class="input"
|
|
90
|
+
disabled=""
|
|
91
|
+
name="name"
|
|
92
|
+
type="checkbox"
|
|
93
|
+
value=""
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
</DocumentFragment>
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
exports[`primitive:<Checkbox> prop:error 1`] = `
|
|
100
|
+
<DocumentFragment>
|
|
101
|
+
<div
|
|
102
|
+
class="checkbox"
|
|
103
|
+
>
|
|
104
|
+
<input
|
|
105
|
+
class="error input"
|
|
106
|
+
name="name"
|
|
107
|
+
type="checkbox"
|
|
108
|
+
value=""
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
111
|
+
</DocumentFragment>
|
|
112
|
+
`;
|
|
113
|
+
|
|
83
114
|
exports[`primitive:<Checkbox> prop:value 1`] = `
|
|
84
115
|
<DocumentFragment>
|
|
85
116
|
<div
|
|
@@ -9,7 +9,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
var _helpers = require("../../helpers");
|
|
10
10
|
var _Primitive = require("../Primitive");
|
|
11
11
|
var _SwitchModule = _interopRequireDefault(require("./Switch.module.css"));
|
|
12
|
-
var _excluded = ["checked", "disabled", "name", "onChange"];
|
|
12
|
+
var _excluded = ["checked", "disabled", "error", "name", "onChange"];
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
15
15
|
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; }
|
|
@@ -18,6 +18,7 @@ var Switch = function Switch(_ref) {
|
|
|
18
18
|
var _ref$checked = _ref.checked,
|
|
19
19
|
checked = _ref$checked === void 0 ? false : _ref$checked,
|
|
20
20
|
disabled = _ref.disabled,
|
|
21
|
+
error = _ref.error,
|
|
21
22
|
name = _ref.name,
|
|
22
23
|
onChange = _ref.onChange,
|
|
23
24
|
others = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -36,7 +37,7 @@ var Switch = function Switch(_ref) {
|
|
|
36
37
|
type: "checkbox",
|
|
37
38
|
onChange: function onChange() {}
|
|
38
39
|
}), /*#__PURE__*/_react.default.createElement(_Primitive.Primitive, {
|
|
39
|
-
className: _SwitchModule.default.area
|
|
40
|
+
className: (0, _helpers.styles)(_SwitchModule.default.area, error && !checked && !disabled && _SwitchModule.default.error)
|
|
40
41
|
}, /*#__PURE__*/_react.default.createElement(_Primitive.Primitive, {
|
|
41
42
|
tag: "span",
|
|
42
43
|
className: _SwitchModule.default.toggle
|
|
@@ -47,6 +48,7 @@ Switch.displayName = 'Primitive:Switch';
|
|
|
47
48
|
Switch.propTypes = {
|
|
48
49
|
checked: _propTypes.default.bool,
|
|
49
50
|
disabled: _propTypes.default.bool,
|
|
51
|
+
error: _propTypes.default.bool,
|
|
50
52
|
name: _propTypes.default.string.isRequired,
|
|
51
53
|
onChange: _propTypes.default.func
|
|
52
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","names":["Switch","checked","disabled","name","onChange","others","handleChange","event","role","undefined","styles","style","switch","className","area","toggle","displayName","propTypes","PropTypes","bool","string","isRequired","func"],"sources":["../../../src/primitives/Switch/Switch.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Primitive } from '../Primitive';\nimport style from './Switch.module.css';\n\nconst Switch = ({ checked = false, disabled, name, onChange, ...others }) => {\n const handleChange = (event) => {\n onChange && onChange(!checked, event);\n };\n\n return (\n <Primitive\n {...others}\n role={others.role || 'switch'}\n onClick={!disabled ? handleChange : undefined}\n className={styles(style.switch, others.className)}\n >\n <Primitive checked={checked} disabled={disabled} name={name} tag=\"input\" type=\"checkbox\" onChange={() => {}} />\n <Primitive className={style.area}>\n <Primitive tag=\"span\" className={style.toggle} />\n </Primitive>\n </Primitive>\n );\n};\n\nSwitch.displayName = 'Primitive:Switch';\n\nSwitch.propTypes = {\n checked: PropTypes.bool,\n disabled: PropTypes.bool,\n name: PropTypes.string.isRequired,\n onChange: PropTypes.func,\n};\n\nexport { Switch };\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AACA;AAAwC;AAAA;AAAA;AAAA;AAAA;AAExC,IAAMA,MAAM,GAAG,SAATA,MAAM,
|
|
1
|
+
{"version":3,"file":"Switch.js","names":["Switch","checked","disabled","error","name","onChange","others","handleChange","event","role","undefined","styles","style","switch","className","area","toggle","displayName","propTypes","PropTypes","bool","string","isRequired","func"],"sources":["../../../src/primitives/Switch/Switch.jsx"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nimport { styles } from '../../helpers';\nimport { Primitive } from '../Primitive';\nimport style from './Switch.module.css';\n\nconst Switch = ({ checked = false, disabled, error, name, onChange, ...others }) => {\n const handleChange = (event) => {\n onChange && onChange(!checked, event);\n };\n\n return (\n <Primitive\n {...others}\n role={others.role || 'switch'}\n onClick={!disabled ? handleChange : undefined}\n className={styles(style.switch, others.className)}\n >\n <Primitive checked={checked} disabled={disabled} name={name} tag=\"input\" type=\"checkbox\" onChange={() => {}} />\n <Primitive className={styles(style.area, error && !checked && !disabled && style.error)}>\n <Primitive tag=\"span\" className={style.toggle} />\n </Primitive>\n </Primitive>\n );\n};\n\nSwitch.displayName = 'Primitive:Switch';\n\nSwitch.propTypes = {\n checked: PropTypes.bool,\n disabled: PropTypes.bool,\n error: PropTypes.bool,\n name: PropTypes.string.isRequired,\n onChange: PropTypes.func,\n};\n\nexport { Switch };\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AACA;AAAwC;AAAA;AAAA;AAAA;AAAA;AAExC,IAAMA,MAAM,GAAG,SAATA,MAAM,OAAwE;EAAA,wBAAlEC,OAAO;IAAPA,OAAO,6BAAG,KAAK;IAAEC,QAAQ,QAARA,QAAQ;IAAEC,KAAK,QAALA,KAAK;IAAEC,IAAI,QAAJA,IAAI;IAAEC,QAAQ,QAARA,QAAQ;IAAKC,MAAM;EAC3E,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,KAAK,EAAK;IAC9BH,QAAQ,IAAIA,QAAQ,CAAC,CAACJ,OAAO,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37
|
.switch .toggle {
|
|
34
38
|
background-color: var(--mirai-ui-switch-base);
|
|
35
39
|
border-radius: calc(var(--mirai-ui-switch-border-radius) - var(--mirai-ui-switch-border-size));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.stories.js","names":["title","Story","props","useState","checked","setChecked","handleChange","next","others","console","log","storyName","args","disabled","name","testId","style","argTypes"],"sources":["../../../src/primitives/Switch/Switch.stories.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { Switch } from './Switch';\n\nexport default { title: 'Primitives' };\n\nexport const Story = (props) => {\n const [checked, setChecked] = useState(false);\n\n const handleChange = (next, ...others) => {\n console.log('<Switch>::onChange', next, ...others);\n setChecked(!checked);\n };\n\n return <Switch {...props} checked={checked} onChange={handleChange} />;\n};\n\nStory.storyName = 'Switch';\n\nStory.args = {\n checked: false,\n disabled: false,\n name: 'Switch',\n // inherited properties\n testId: 'test-story',\n style: {},\n};\n\nStory.argTypes = {};\n"],"mappings":";;;;;;;AAAA;AAEA;AAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAEnB;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,CAAIC,KAAK,EAAK;EAC9B,gBAA8B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAAtCC,OAAO;IAAEC,UAAU;EAE1B,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,IAAI,EAAgB;IAAA;IAAA,kCAAXC,MAAM;MAANA,MAAM;IAAA;IACnC,YAAAC,OAAO,EAACC,GAAG,kBAAC,oBAAoB,EAAEH,IAAI,SAAKC,MAAM,EAAC;IAClDH,UAAU,CAAC,CAACD,OAAO,CAAC;EACtB,CAAC;EAED,oBAAO,6BAAC,cAAM,eAAKF,KAAK;IAAE,OAAO,EAAEE,OAAQ;IAAC,QAAQ,EAAEE;EAAa,GAAG;AACxE,CAAC;AAAC;AAEFL,KAAK,CAACU,SAAS,GAAG,QAAQ;AAE1BV,KAAK,CAACW,IAAI,GAAG;EACXR,OAAO,EAAE,KAAK;EACdS,QAAQ,EAAE,KAAK;EACfC,IAAI,EAAE,QAAQ;EACd;EACAC,MAAM,EAAE,YAAY;EACpBC,KAAK,EAAE,CAAC;AACV,CAAC;
|
|
1
|
+
{"version":3,"file":"Switch.stories.js","names":["title","Story","props","useState","checked","setChecked","handleChange","next","others","console","log","storyName","args","disabled","error","name","testId","style","argTypes"],"sources":["../../../src/primitives/Switch/Switch.stories.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { Switch } from './Switch';\n\nexport default { title: 'Primitives' };\n\nexport const Story = (props) => {\n const [checked, setChecked] = useState(false);\n\n const handleChange = (next, ...others) => {\n console.log('<Switch>::onChange', next, ...others);\n setChecked(!checked);\n };\n\n return <Switch {...props} checked={checked} onChange={handleChange} />;\n};\n\nStory.storyName = 'Switch';\n\nStory.args = {\n checked: false,\n disabled: false,\n error: false,\n name: 'Switch',\n // inherited properties\n testId: 'test-story',\n style: {},\n};\n\nStory.argTypes = {};\n"],"mappings":";;;;;;;AAAA;AAEA;AAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAEnB;EAAEA,KAAK,EAAE;AAAa,CAAC;AAAA;AAE/B,IAAMC,KAAK,GAAG,SAARA,KAAK,CAAIC,KAAK,EAAK;EAC9B,gBAA8B,IAAAC,eAAQ,EAAC,KAAK,CAAC;IAAA;IAAtCC,OAAO;IAAEC,UAAU;EAE1B,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,IAAI,EAAgB;IAAA;IAAA,kCAAXC,MAAM;MAANA,MAAM;IAAA;IACnC,YAAAC,OAAO,EAACC,GAAG,kBAAC,oBAAoB,EAAEH,IAAI,SAAKC,MAAM,EAAC;IAClDH,UAAU,CAAC,CAACD,OAAO,CAAC;EACtB,CAAC;EAED,oBAAO,6BAAC,cAAM,eAAKF,KAAK;IAAE,OAAO,EAAEE,OAAQ;IAAC,QAAQ,EAAEE;EAAa,GAAG;AACxE,CAAC;AAAC;AAEFL,KAAK,CAACU,SAAS,GAAG,QAAQ;AAE1BV,KAAK,CAACW,IAAI,GAAG;EACXR,OAAO,EAAE,KAAK;EACdS,QAAQ,EAAE,KAAK;EACfC,KAAK,EAAE,KAAK;EACZC,IAAI,EAAE,QAAQ;EACd;EACAC,MAAM,EAAE,YAAY;EACpBC,KAAK,EAAE,CAAC;AACV,CAAC;AAEDhB,KAAK,CAACiB,QAAQ,GAAG,CAAC,CAAC"}
|
|
@@ -20,6 +20,28 @@ exports[`primitive:<Switch> inherit:className 1`] = `
|
|
|
20
20
|
</DocumentFragment>
|
|
21
21
|
`;
|
|
22
22
|
|
|
23
|
+
exports[`primitive:<Switch> prop:checked && disabled 1`] = `
|
|
24
|
+
<DocumentFragment>
|
|
25
|
+
<div
|
|
26
|
+
class="switch"
|
|
27
|
+
>
|
|
28
|
+
<input
|
|
29
|
+
checked=""
|
|
30
|
+
disabled=""
|
|
31
|
+
name="name"
|
|
32
|
+
type="checkbox"
|
|
33
|
+
/>
|
|
34
|
+
<div
|
|
35
|
+
class="area"
|
|
36
|
+
>
|
|
37
|
+
<span
|
|
38
|
+
class="toggle"
|
|
39
|
+
/>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</DocumentFragment>
|
|
43
|
+
`;
|
|
44
|
+
|
|
23
45
|
exports[`primitive:<Switch> prop:checked 1`] = `
|
|
24
46
|
<DocumentFragment>
|
|
25
47
|
<div
|
|
@@ -62,6 +84,47 @@ exports[`primitive:<Switch> prop:disabled 1`] = `
|
|
|
62
84
|
</DocumentFragment>
|
|
63
85
|
`;
|
|
64
86
|
|
|
87
|
+
exports[`primitive:<Switch> prop:error && disabled 1`] = `
|
|
88
|
+
<DocumentFragment>
|
|
89
|
+
<div
|
|
90
|
+
class="switch"
|
|
91
|
+
>
|
|
92
|
+
<input
|
|
93
|
+
disabled=""
|
|
94
|
+
name="name"
|
|
95
|
+
type="checkbox"
|
|
96
|
+
/>
|
|
97
|
+
<div
|
|
98
|
+
class="area"
|
|
99
|
+
>
|
|
100
|
+
<span
|
|
101
|
+
class="toggle"
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</DocumentFragment>
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
exports[`primitive:<Switch> prop:error 1`] = `
|
|
109
|
+
<DocumentFragment>
|
|
110
|
+
<div
|
|
111
|
+
class="switch"
|
|
112
|
+
>
|
|
113
|
+
<input
|
|
114
|
+
name="name"
|
|
115
|
+
type="checkbox"
|
|
116
|
+
/>
|
|
117
|
+
<div
|
|
118
|
+
class="area error"
|
|
119
|
+
>
|
|
120
|
+
<span
|
|
121
|
+
class="toggle"
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</DocumentFragment>
|
|
126
|
+
`;
|
|
127
|
+
|
|
65
128
|
exports[`primitive:<Switch> render 1`] = `
|
|
66
129
|
<DocumentFragment>
|
|
67
130
|
<div
|