@@ -8,16 +8,16 @@ import Form.Field exposing (FieldValue(..))
8
8
import Form.Input exposing (Input )
9
9
import Form.Validate
10
10
import Html exposing (..)
11
- import Html.Attributes exposing (class , style )
11
+ import Html.Attributes as Attrs exposing (class , style )
12
12
import Html.Events exposing (onClick , onSubmit )
13
13
import Json.Encode exposing (bool , float , int , list , string )
14
- import Json.Schema
15
14
import Json.Schema.Builder exposing (..)
16
15
import Json.Schema.Definitions
17
16
import Json.Schema.Form exposing (Msg , State )
18
17
import Json.Schema.Form.Encode
19
18
import Json.Schema.Form.Error exposing (ErrorValue (..) , Errors )
20
19
import Json.Schema.Form.Format exposing (Format )
20
+ import Json.Schema.Form.Theme as Theme exposing (Theme )
21
21
import Regex
22
22
23
23
@@ -26,13 +26,100 @@ main =
26
26
Browser . sandbox { init = init, update = update, view = view }
27
27
28
28
29
+ tailwind : Theme
30
+ tailwind =
31
+ let
32
+ theme =
33
+ Theme . default
34
+
35
+ isInvalid =
36
+ " border-2 border-red-500"
37
+ in
38
+ { theme
39
+ | -- inputs
40
+ txt =
41
+ \ { withError, format } ->
42
+ Attrs . classList
43
+ [ ( " block w-full rounded-md py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" , True )
44
+ , ( " border-0" , not withError )
45
+ , ( isInvalid, withError )
46
+ , case format of
47
+ Just str ->
48
+ ( " format-" ++ str, True )
49
+
50
+ Nothing ->
51
+ ( " " , False )
52
+ ]
53
+
54
+ -- checkbox
55
+ , checkboxWrapper = Attrs . class " flex h-6 items-center"
56
+ , checkboxInput =
57
+ \ { withError } ->
58
+ Attrs . classList
59
+ [ ( " h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" , True )
60
+ , ( isInvalid, withError )
61
+ ]
62
+ , checkboxTitle = Attrs . class " ml-3 text-sm leading-6"
63
+
64
+ -- select
65
+ , select =
66
+ \ { withError } ->
67
+ Attrs . classList
68
+ [ ( " block w-full mt-2 rounded-md py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:max-w-xs sm:text-sm sm:leading-6" , True )
69
+ , ( " border-0" , not withError )
70
+ , ( isInvalid, withError )
71
+ ]
72
+
73
+ -- list group
74
+ , listGroup = Attrs . class " mb-2"
75
+ , listGroupItem = Attrs . class " border border-gray-300 rounded-md px-4 py-2 mb-2 shadow-sm"
76
+ , listGroupAddItemButton = Attrs . class " rounded-md bg-gray-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-gray-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-600"
77
+ , listGroupRemoveItemButton = Attrs . class " rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
78
+
79
+ -- tuple
80
+ , formRow = Attrs . class " flex space-x-4"
81
+ , formRowItem = Attrs . class " max-w-full flex-grow"
82
+
83
+ -- radio
84
+ , radioWrapper = Attrs . class " flex items-center gap-x-3"
85
+ , radioInput = Attrs . class " h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600"
86
+ , radioInputLabel = Attrs . class " block text-sm font-medium leading-6 text-gray-900"
87
+ , field =
88
+ \ { withError, withValue } ->
89
+ Attrs . classList
90
+ [ ( " mb-6" , True )
91
+ , ( " text-red-500" , withError )
92
+ , ( " has-value" , withValue )
93
+ ]
94
+ , fieldLabel = Attrs . class " block"
95
+ , fieldInput = Attrs . class " field-input"
96
+ , fieldInputMeta = Attrs . class " field-meta"
97
+ , fieldTitle = Attrs . class " block text-sm font-medium leading-6 text-gray-900"
98
+ , fieldDescription = Attrs . class " mt-2 text-sm leading-6 text-gray-600"
99
+ , group =
100
+ \ { withError, withValue } ->
101
+ Attrs . classList
102
+ [ ( " mb-4" , True )
103
+ , ( " text-red-500" , withError )
104
+ , ( " has-value" , withValue )
105
+ ]
106
+ , liveError = Attrs . class " text-red-500 text-xs my-2"
107
+ , inputGroupPrepend = Attrs . class " inline-flex items-center rounded-l-md border border-r-0 border-gray-300 px-3 text-gray-500 sm:text-sm"
108
+ , inputGroupPrependContent = Attrs . class " text-gray-500 sm:text-sm"
109
+ , inputGroupAppend = Attrs . class " inline-flex items-center rounded-r-md border border-l-0 border-gray-300 px-3 text-gray-500 sm:text-sm"
110
+ , inputGroupAppendContent = Attrs . class " text-gray-500 sm:text-sm"
111
+ , inputGroup = Attrs . class " mt-2 flex shadow-sm"
112
+ }
113
+
114
+
29
115
init : State
30
116
init =
31
117
case schema of
32
118
Ok schema_ ->
33
119
Json . Schema . Form . init
34
120
{ errors = errorString
35
121
, formats = Dict . fromList formats
122
+ , theme = tailwind
36
123
}
37
124
schema_
38
125
@@ -49,7 +136,7 @@ view : State -> Html Msg
49
136
view state =
50
137
form [ onSubmit Json . Schema . Form . submit ]
51
138
[ Json . Schema . Form . view state
52
- , button [ class " btn btn-primary" ] [ text " Submit" ]
139
+ , button [ class " btn btn-primary rounded-md bg-blue-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 " ] [ text " Submit" ]
53
140
, case Form . getOutput state. form of
54
141
Just output ->
55
142
let
@@ -221,7 +308,7 @@ schema =
221
308
, ( " numbers"
222
309
, buildSchema
223
310
|> withType " array"
224
- |> withDefault ( list float [ 6 , 6.8 ] )
311
+ |> withDefault ( list float [ 6 , 7 ] )
225
312
|> withItems
226
313
[ buildSchema
227
314
|> withType " integer"
0 commit comments