@@ -3,7 +3,7 @@ import { Formik } from 'formik';
3
3
import { storiesOf } from '@storybook/react' ;
4
4
import { action } from '@storybook/addon-actions' ;
5
5
import { injectIntl } from 'react-intl' ;
6
- import { withKnobs } from '@storybook/addon-knobs' ;
6
+ import { withKnobs , number } from '@storybook/addon-knobs' ;
7
7
import withReadme from 'storybook-readme/with-readme' ;
8
8
import omitEmpty from 'omit-empty' ;
9
9
import ErrorMessage from '../../messages/error-message' ;
@@ -25,68 +25,82 @@ const validate = (formValues, locale) => {
25
25
}
26
26
return omitEmpty ( errors ) ;
27
27
} ;
28
- const Story = injectIntl ( props => (
29
- < Section >
30
- < Formik
31
- initialValues = { { price : { currencyCode : '' , amount : '' } } }
32
- validate = { formValues => validate ( formValues , props . intl . locale ) }
33
- onSubmit = { ( values , formik ) => {
34
- // eslint-disable-next-line no-console
35
- console . log (
36
- 'money value' ,
37
- MoneyInput . convertToMoneyValue ( values . price , props . intl . locale )
38
- ) ;
39
- action ( 'onSubmit' ) ( values , formik ) ;
40
- formik . resetForm ( values ) ;
41
- } }
42
- render = { formik => (
43
- < Spacings . Stack scale = "l" >
44
- < Spacings . Stack scale = "s" >
45
- < MoneyInput
46
- name = "price"
47
- currencies = { [ 'EUR' , 'USD' , 'AED' , 'KWD' , 'JPY' ] }
48
- value = { formik . values . price }
49
- onChange = { formik . handleChange }
50
- onBlur = { formik . handleBlur }
51
- hasError = {
52
- MoneyInput . isTouched ( formik . touched . price ) &&
53
- Boolean ( formik . errors . price )
54
- }
55
- horizontalConstraint = "m"
56
- />
57
- { MoneyInput . isTouched ( formik . touched . price ) &&
58
- formik . errors . price &&
59
- formik . errors . price . missing && (
60
- < ErrorMessage > Missing price</ ErrorMessage >
61
- ) }
62
- { MoneyInput . isTouched ( formik . touched . price ) &&
63
- formik . errors . price &&
64
- formik . errors . price . unsupportedHighPrecision && (
65
- < ErrorMessage >
66
- This value is a high precision value. High precision pricing
67
- is not supported for products.
68
- </ ErrorMessage >
69
- ) }
28
+ const Story = injectIntl ( props => {
29
+ const initialCentAmount = number ( 'initial cent amount' , 10099 ) ;
30
+ const initialFractionDigits = number ( 'initial fraction digits' , 2 ) ;
31
+ return (
32
+ < Section >
33
+ < Formik
34
+ initialValues = { {
35
+ price : MoneyInput . parseMoneyValue (
36
+ {
37
+ centAmount : initialCentAmount ,
38
+ currencyCode : 'EUR' ,
39
+ fractionDigits : initialFractionDigits ,
40
+ type : 'centPrecision' ,
41
+ } ,
42
+ props . intl . locale
43
+ ) ,
44
+ } }
45
+ validate = { formValues => validate ( formValues , props . intl . locale ) }
46
+ onSubmit = { ( values , formik ) => {
47
+ // eslint-disable-next-line no-console
48
+ console . log (
49
+ 'money value' ,
50
+ MoneyInput . convertToMoneyValue ( values . price , props . intl . locale )
51
+ ) ;
52
+ action ( 'onSubmit' ) ( values , formik ) ;
53
+ formik . resetForm ( values ) ;
54
+ } }
55
+ render = { formik => (
56
+ < Spacings . Stack scale = "l" >
57
+ < Spacings . Stack scale = "s" >
58
+ < MoneyInput
59
+ name = "price"
60
+ currencies = { [ 'EUR' , 'USD' , 'AED' , 'KWD' , 'JPY' ] }
61
+ value = { formik . values . price }
62
+ onChange = { formik . handleChange }
63
+ onBlur = { formik . handleBlur }
64
+ hasError = {
65
+ MoneyInput . isTouched ( formik . touched . price ) &&
66
+ Boolean ( formik . errors . price )
67
+ }
68
+ horizontalConstraint = "m"
69
+ />
70
+ { MoneyInput . isTouched ( formik . touched . price ) &&
71
+ formik . errors . price &&
72
+ formik . errors . price . missing && (
73
+ < ErrorMessage > Missing price</ ErrorMessage >
74
+ ) }
75
+ { MoneyInput . isTouched ( formik . touched . price ) &&
76
+ formik . errors . price &&
77
+ formik . errors . price . unsupportedHighPrecision && (
78
+ < ErrorMessage >
79
+ This value is a high precision value. High precision pricing
80
+ is not supported for products.
81
+ </ ErrorMessage >
82
+ ) }
83
+ </ Spacings . Stack >
84
+ < Spacings . Inline >
85
+ < SecondaryButton
86
+ onClick = { formik . handleReset }
87
+ isDisabled = { formik . isSubmitting }
88
+ label = "Reset"
89
+ />
90
+ < PrimaryButton
91
+ onClick = { formik . handleSubmit }
92
+ isDisabled = { formik . isSubmitting || ! formik . dirty }
93
+ label = "Submit"
94
+ />
95
+ </ Spacings . Inline >
96
+ < hr />
97
+ < FormikBox formik = { formik } />
70
98
</ Spacings . Stack >
71
- < Spacings . Inline >
72
- < SecondaryButton
73
- onClick = { formik . handleReset }
74
- isDisabled = { formik . isSubmitting }
75
- label = "Reset"
76
- />
77
- < PrimaryButton
78
- onClick = { formik . handleSubmit }
79
- isDisabled = { formik . isSubmitting || ! formik . dirty }
80
- label = "Submit"
81
- />
82
- </ Spacings . Inline >
83
- < hr />
84
- < FormikBox formik = { formik } />
85
- </ Spacings . Stack >
86
- ) }
87
- />
88
- </ Section >
89
- ) ) ;
99
+ ) }
100
+ />
101
+ </ Section >
102
+ ) ;
103
+ } ) ;
90
104
storiesOf ( 'Examples|Forms/Inputs' , module )
91
105
. addDecorator ( withKnobs )
92
106
. addDecorator ( withReadme ( Readme ) )
0 commit comments