You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created my own FormComponent for Thoth.Elmish.FormBuilder.
namespacenojaf.FormInputsopenThoth.Elmish.FormBuilderopenThoth.Elmish.FormBuilder.TypesopenThoth.JsonopenFable.Helpers.ReactopenFable.Helpers.React.Props[<RequireQualifiedAccess>]moduleColorPicker =typeMsg=| ChangeRed ofint| ChangeGreen ofint| ChangeBlue ofintinterface IFieldMsg
typeValidator= State -> ValidationState
typeState={ Label :string
Red:int
Green:int
Blue:int
Name :string }memberthis.Value()= sprintf "rgb(%i,%i,%i)" this.Red this.Green this.Blue
letprivateinit(state:FieldState)=
state, FormCmd.none
letprivatetoJson(state :FieldState)=letstate:State = state :?> State
state.Name, Encode.string (state.Value())letprivateupdate(msg :FieldMsg)(state :FieldState)=// Cast the received message into it's real typeletmsg= msg :?> Msg
// Cast the received state into it's real typeletstate= state :?> State
match msg with| ChangeBlue blue ->{ state with Blue = blue }|> box, FormCmd.none
| ChangeRed red ->{ state with Red = red }|> box, FormCmd.none
| ChangeGreen green ->{ state with Green = green }|> box, FormCmd.none
letprivateview(state:FieldState)(dispatch:IFieldMsg ->unit)=letstate:State = state :?> State
letchangeValue msg (ev:Fable.Import.React.FormEvent)=letvalue= ev.Value |>(int)
dispatch (msg value)
div [][
label [ Class "label"; HtmlFor state.Name ][ str state.Label ]
div [][
strong [][str "R"]
input [Type "range"; Min 0; Max 255; Value state.Red; OnChange (changeValue Msg.ChangeRed)]]
div [][
strong [][str "G"]
input [Type "range"; Min 0; Max 255; Value state.Green; OnChange (changeValue Msg.ChangeGreen)]]
div [][
strong [][str "B"]
input [Type "range"; Min 0; Max 255; Value state.Blue; OnChange (changeValue Msg.ChangeBlue)]]
div [Style [CSSProp.BackgroundColor (state.Value()); CSSProp.Width 100; CSSProp.Height 100; CSSProp.MarginTop 30; CSSProp.MarginBottom 30]][]]letconfig:FieldConfig ={ View = view
Update = update
Init = init
Validate = id
IsValid =fun _ ->true
ToJson = toJson
SetError =fun s _ -> s }typeColorPickerprivate(state: State)=static memberCreate(name:string)=
ColorPicker
{ Label =""
Red =0
Green =0
Blue =0
Name = name }member__.WithDefaultView():FieldBuilder ={ Type ="nojaf-color-picker"
State = state
Name = state.Name
Config = config }member__.WithLabel(label :string)=
ColorPicker { state with Label = label }
When reading the docs while making I think in general it would help if api docs showed the structure of the types as well. Perhaps something similar to how fake does this.
At some points I was a bit confused is this my own type or a FormBuilder type?
The sample State was also a bit confusing. Do I really need all these properties?
The text was updated successfully, but these errors were encountered:
Thursday Jan 10, 2019 at 13:23 GMT
Originally opened as MangelMaxime/Thoth#116
I've created my own FormComponent for
Thoth.Elmish.FormBuilder
.When reading the docs while making I think in general it would help if api docs showed the structure of the types as well. Perhaps something similar to how fake does this.
At some points I was a bit confused is this my own type or a FormBuilder type?
The sample State was also a bit confusing. Do I really need all these properties?
The text was updated successfully, but these errors were encountered: