@@ -1,6 +1,7 @@
11module Yoga.Block.Organism.Form.Story where
22
33import Prelude
4+
45import Data.Lens.Record (prop)
56import Data.Maybe (Maybe(..))
67import Data.String.NonEmpty (NonEmptyString, nes)
@@ -17,26 +18,29 @@ import React.Basic.Hooks as React
1718import Type.Prelude (Proxy(..))
1819import Yoga ((/>), (</), (</>))
1920import Yoga.Block as Block
21+import Yoga.Block.Atom.Input.Hook.UseTypingPlaceholders (useTypingPlaceholders)
2022import Yoga.Block.Atom.Input.Types as InputType
2123import Yoga.Block.Container.Style as Styles
24+import Yoga.Block.Internal (NodeRef)
2225import Yoga.Block.Organism.Form (FormBuilder, Validated(..), formDefaults)
2326import Yoga.Block.Organism.Form as Form
2427import Yoga.Block.Organism.Form.Types (RequiredField(..))
2528
26−default ∷
27− { decorators ∷ Array (Effect JSX -> JSX)
28− , title ∷ String
29− }
29+default
30+ ∷ { decorators ∷ Array (Effect JSX -> JSX)
31+ , title ∷ String
32+ }
3033default =
3134 { title: "Organism/Form"
3235 , decorators:
33− [ \storyFn ->
34− Block.container
35− </ {}
36− /> [ element E.global { styles: Styles.global }
37− , unsafePerformEffect storyFn
38− ]
39− ]
36+ [ \storyFn ->
37+ Block.container
38+ </ {}
39+ />
40+ [ element E.global { styles: Styles.global }
41+ , unsafePerformEffect storyFn
42+ ]
43+ ]
4044 }
4145
4246type User =
@@ -72,13 +76,15 @@ aForm = do
7276 where
7377 mkExample =
7478 reactComponent "FormExample" \_ -> React.do
79+ inputRef ← useTypingPlaceholders "First name"
80+ [ "Type in your given name", "WAAAAARUMÄ" ]
7581 _userDialog /\ setUserDialog <- useState' Nothing
7682 { setModified, reset: _reset, validated, form } <-
77− Form.useForm userForm
83+ Form.useForm (userForm inputRef)
7884 { initialState: formDefaults
7985 , formProps:
80− { readOnly: false
81− }
86+ { readOnly: false
87+ }
8288 }
8389 pure
8490 $ fragment
@@ -87,10 +93,10 @@ aForm = do
8793 -- on the form's submit button and `preventDefault` to keep the browser
8894 -- from reloading the page on submission.
8995 { onSubmit:
90− handler preventDefault \_ -> case validated of
91− Nothing -> do
92− setModified
93− Just { firstName, lastName } -> setUserDialog $ Just { firstName, lastName }
96+ handler preventDefault \_ -> case validated of
97+ Nothing -> do
98+ setModified
99+ Just { firstName, lastName } -> setUserDialog $ Just { firstName, lastName }
94100 , style: R.css { alignSelf: "stretch" }
95101 , children: [ form ]
96102 }
@@ -123,13 +129,13 @@ aForm = do
123129 }
124130 in { nickname, age }
125131
126− userForm ∷ ∀ props. FormBuilder { readOnly ∷ Boolean | props } User ValidUser
127− userForm = ado
132+ userForm ∷ ∀ props. NodeRef -> FormBuilder { readOnly ∷ Boolean | props } User ValidUser
133+ userForm inputRef = ado
128134 firstName <-
129135 Form.focus (prop (Proxy ∷ _ "firstName"))
130136 $ Form.validated (Form.nonEmpty' "You must have a first name")
131137 $ Form.inputBox (nes (Proxy ∷ _ "First Name")) Required
132− { placeholder: "First name" }
138+ { id: "firstName", inputRef }
133139 lastName <-
134140 Form.focus (prop (Proxy ∷ _ "lastName"))
135141 $ Form.validated