@pareto-engineering/design-system 2.0.0-alpha.59 → 2.0.0-alpha.60
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/dist/cjs/f/fields/ChoicesInput/ChoicesInput.js +1 -1
- package/dist/cjs/f/fields/ChoicesInput/common/Choice/Choice.js +5 -2
- package/dist/es/f/fields/ChoicesInput/ChoicesInput.js +1 -1
- package/dist/es/f/fields/ChoicesInput/common/Choice/Choice.js +5 -2
- package/package.json +1 -1
- package/src/__snapshots__/Storyshots.test.js.snap +531 -105
- package/src/stories/f/ChoicesInput.stories.jsx +36 -10
- package/src/ui/f/fields/ChoicesInput/ChoicesInput.jsx +1 -1
- package/src/ui/f/fields/ChoicesInput/common/Choice/Choice.jsx +10 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
|
|
3
|
+
import { useEffect } from 'react'
|
|
4
4
|
import { ChoicesInput, FormDebugger } from 'ui'
|
|
5
|
-
import { Formik, Form } from 'formik'
|
|
5
|
+
import { Formik, Form, useField } from 'formik'
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
title :'f/fields/ChoicesInput',
|
|
@@ -29,14 +29,6 @@ export default {
|
|
|
29
29
|
},
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const Template = (args) => (
|
|
33
|
-
<>
|
|
34
|
-
<ChoicesInput {...args} />
|
|
35
|
-
<FormDebugger />
|
|
36
|
-
</>
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
export const Base = Template.bind({})
|
|
40
32
|
const optionsMap = [
|
|
41
33
|
{
|
|
42
34
|
value:'red',
|
|
@@ -72,18 +64,52 @@ const optionsMap = [
|
|
|
72
64
|
},
|
|
73
65
|
]
|
|
74
66
|
|
|
67
|
+
// eslint-disable-next-line react/prop-types
|
|
68
|
+
const Template = ({ defaultValue, ...args }) => {
|
|
69
|
+
const Content = () => {
|
|
70
|
+
const [, , helpers] = useField(args.name)
|
|
71
|
+
const { setValue } = helpers
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
setValue(defaultValue)
|
|
75
|
+
}, [])
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<ChoicesInput {...args} />
|
|
80
|
+
<FormDebugger />
|
|
81
|
+
</>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
return <Content />
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const Base = Template.bind({})
|
|
75
88
|
Base.args = {
|
|
76
89
|
id :'colors',
|
|
77
90
|
options:optionsMap,
|
|
78
91
|
name :'color',
|
|
79
92
|
}
|
|
80
93
|
|
|
94
|
+
export const WithDefaultFormikValue = Template.bind({})
|
|
95
|
+
WithDefaultFormikValue.args = {
|
|
96
|
+
...Base.args,
|
|
97
|
+
defaultValue:'red',
|
|
98
|
+
}
|
|
99
|
+
|
|
81
100
|
export const Multiple = Template.bind({})
|
|
82
101
|
Multiple.args = {
|
|
83
102
|
...Base.args,
|
|
84
103
|
multiple:true,
|
|
85
104
|
}
|
|
86
105
|
|
|
106
|
+
export const MultipleWithDefaultFormikValue = Template.bind({})
|
|
107
|
+
MultipleWithDefaultFormikValue.args = {
|
|
108
|
+
...Base.args,
|
|
109
|
+
multiple :true,
|
|
110
|
+
defaultValue:['brown', 'violet'],
|
|
111
|
+
}
|
|
112
|
+
|
|
87
113
|
export const MultipleWithGrid = Template.bind({})
|
|
88
114
|
MultipleWithGrid.args = {
|
|
89
115
|
...Base.args,
|
|
@@ -28,7 +28,15 @@ const Choice = ({
|
|
|
28
28
|
validate,
|
|
29
29
|
disabled,
|
|
30
30
|
}) => {
|
|
31
|
-
const
|
|
31
|
+
const type = multiple ? 'checkbox' : 'radio'
|
|
32
|
+
|
|
33
|
+
const [field] = useField({
|
|
34
|
+
name,
|
|
35
|
+
validate,
|
|
36
|
+
type,
|
|
37
|
+
value,
|
|
38
|
+
})
|
|
39
|
+
|
|
32
40
|
return (
|
|
33
41
|
<div
|
|
34
42
|
className={[
|
|
@@ -43,7 +51,7 @@ const Choice = ({
|
|
|
43
51
|
style={style}
|
|
44
52
|
>
|
|
45
53
|
<input
|
|
46
|
-
type={
|
|
54
|
+
type={type}
|
|
47
55
|
id={id}
|
|
48
56
|
name={name}
|
|
49
57
|
{...field}
|