11module Lumi.Components.Form
2- ( module Internal
2+ ( module Defaults
3+ , module Internal
34 , module Validation
45 , build
5- , buildConcurrently
6- , buildWithDefaults
76 , static
87 , section
98 , inputBox
@@ -66,7 +65,8 @@ import JSS (JSS, jss)
6665import Lumi.Components.Color (colors )
6766import Lumi.Components.Column (column )
6867import 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 )
7070import Lumi.Components.Form.Internal (FormBuilder , SeqFormBuilder , formBuilder , formBuilder_ , invalidate , listen , parallel , revalidate , sequential ) as Internal
7171import Lumi.Components.Form.Validation (Validated (..), Validator , _Validated , fromValidated , mustBe , mustEqual , nonEmpty , nonEmptyArray , nonNull , validNumber , validInt , optional , setFresh , setModified , validated , warn ) as Validation
7272import Lumi.Components.Input (alignToInput )
@@ -98,30 +98,6 @@ import Unsafe.Coerce (unsafeCoerce)
9898-- | _Note_: this function should be fully applied, to avoid remounting
9999-- | the component on each render.
100100build
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
125101 :: forall props unvalidated result
126102 . FormBuilder { readonly :: Boolean | props } unvalidated result
127103 -> { value :: unvalidated
@@ -132,7 +108,7 @@ buildConcurrently
132108 | props
133109 }
134110 -> JSX
135- buildConcurrently editor = makeStateless (createComponent " Form" ) render where
111+ build editor = makeStateless (createComponent " Form" ) render where
136112 render props@{ value, onChange, inlineTable, forceTopLabels, readonly } =
137113
138114 let forest = Array .mapMaybe pruneTree $ edit onChange
@@ -182,29 +158,6 @@ buildConcurrently editor = makeStateless (createComponent "Form") render where
182158 , children: surround fieldDivider (map toRow forest)
183159 }
184160
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-
208161-- | Create an always-valid `FormBuilder` that renders the supplied `JSX`.
209162static :: forall props value . JSX -> FormBuilder props value Unit
210163static edit = formBuilder \_ _ -> { edit: const edit, validate: pure unit }
0 commit comments