1
1
module Lumi.Components.Form
2
- ( module Internal
2
+ ( module Defaults
3
+ , module Internal
3
4
, module Validation
4
5
, build
5
- , buildConcurrently
6
- , buildWithDefaults
7
6
, static
8
7
, section
9
8
, inputBox
@@ -66,7 +65,8 @@ import JSS (JSS, jss)
66
65
import Lumi.Components.Color (colors )
67
66
import Lumi.Components.Column (column )
68
67
import Lumi.Components.FetchCache as FetchCache
69
- import Lumi.Components.Form.Internal (FormBuilder (..), SeqFormBuilder , Tree (..), formBuilder , formBuilder_ , invalidate , revalidate , sequential , pruneTree )
68
+ import Lumi.Components.Form.Defaults (formDefaults ) as Defaults
69
+ import Lumi.Components.Form.Internal (FormBuilder (..), SeqFormBuilder , Tree (..), formBuilder , formBuilder_ , invalidate , pruneTree , sequential )
70
70
import Lumi.Components.Form.Internal (FormBuilder , SeqFormBuilder , formBuilder , formBuilder_ , invalidate , listen , parallel , revalidate , sequential ) as Internal
71
71
import Lumi.Components.Form.Validation (Validated (..), Validator , _Validated , fromValidated , mustBe , mustEqual , nonEmpty , nonEmptyArray , nonNull , validNumber , validInt , optional , setFresh , setModified , validated , warn ) as Validation
72
72
import Lumi.Components.Input (alignToInput )
@@ -98,30 +98,6 @@ import Unsafe.Coerce (unsafeCoerce)
98
98
-- | _Note_: this function should be fully applied, to avoid remounting
99
99
-- | the component on each render.
100
100
build
101
- :: forall props unvalidated result
102
- . FormBuilder { readonly :: Boolean | props } unvalidated result
103
- -> { value :: unvalidated
104
- , onChange :: Maybe result -> unvalidated -> Effect Unit
105
- , inlineTable :: Boolean
106
- , forceTopLabels :: Boolean
107
- , readonly :: Boolean
108
- | props
109
- }
110
- -> JSX
111
- build editor = \props ->
112
- form props
113
- { onChange = \f ->
114
- let v = f props.value
115
- in props.onChange (revalidate editor (unsafeCoerce props) v) v
116
- }
117
- where
118
- form = buildConcurrently editor
119
-
120
- -- | Create a React component for a form from a `FormBuilder`.
121
- -- |
122
- -- | _Note_: this function should be fully applied, to avoid remounting
123
- -- | the component on each render.
124
- buildConcurrently
125
101
:: forall props unvalidated result
126
102
. FormBuilder { readonly :: Boolean | props } unvalidated result
127
103
-> { value :: unvalidated
@@ -132,7 +108,7 @@ buildConcurrently
132
108
| props
133
109
}
134
110
-> JSX
135
- buildConcurrently editor = makeStateless (createComponent " Form" ) render where
111
+ build editor = makeStateless (createComponent " Form" ) render where
136
112
render props@{ value, onChange, inlineTable, forceTopLabels, readonly } =
137
113
138
114
let forest = Array .mapMaybe pruneTree $ edit onChange
@@ -182,29 +158,6 @@ buildConcurrently editor = makeStateless (createComponent "Form") render where
182
158
, children: surround fieldDivider (map toRow forest)
183
159
}
184
160
185
- -- | Utility function.
186
- -- | Create a React component for a form from a `FormBuilder` and a default
187
- -- | form state. This default value is used in the form whenever the `value`
188
- -- | prop is `Nothing`.
189
- -- |
190
- -- | _Note_: this function should be fully applied, to avoid remounting
191
- -- | the component on each render.
192
- buildWithDefaults
193
- :: forall props unvalidated result
194
- . unvalidated
195
- -> FormBuilder { readonly :: Boolean | props } unvalidated result
196
- -> { value :: Maybe unvalidated
197
- , onChange :: Maybe result -> unvalidated -> Effect Unit
198
- , inlineTable :: Boolean
199
- , forceTopLabels :: Boolean
200
- , readonly :: Boolean
201
- | props
202
- }
203
- -> JSX
204
- buildWithDefaults defaults editor = \props -> form props { value = fromMaybe defaults props.value }
205
- where
206
- form = build editor
207
-
208
161
-- | Create an always-valid `FormBuilder` that renders the supplied `JSX`.
209
162
static :: forall props value . JSX -> FormBuilder props value Unit
210
163
static edit = formBuilder \_ _ -> { edit: const edit, validate: pure unit }
0 commit comments