|
1 | | -module Json.Schema.Form.Theme exposing (Theme, default) |
| 1 | +module Json.Schema.Form.Theme exposing (Theme, default, tailwind) |
2 | 2 |
|
3 | 3 | {-| Theme allows you to set styling of generated Form elements
|
4 | 4 |
|
5 | | -@docs Theme, default |
| 5 | +@docs Theme, default, tailwind |
6 | 6 |
|
7 | 7 | -}
|
8 | 8 |
|
@@ -123,3 +123,88 @@ default =
|
123 | 123 | , inputGroupAppendContent = Attrs.class "input-group-text"
|
124 | 124 | , inputGroup = Attrs.class "input-group"
|
125 | 125 | }
|
| 126 | + |
| 127 | + |
| 128 | +{-| Optional tailwindcss theme |
| 129 | +-} |
| 130 | +tailwind : Theme |
| 131 | +tailwind = |
| 132 | + let |
| 133 | + isInvalid = |
| 134 | + "border-2 border-red-500" |
| 135 | + in |
| 136 | + { default |
| 137 | + | -- inputs |
| 138 | + txt = |
| 139 | + \{ withError, format } -> |
| 140 | + Attrs.classList |
| 141 | + [ ( "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 ) |
| 142 | + , ( "border-0", not withError ) |
| 143 | + , ( isInvalid, withError ) |
| 144 | + , case format of |
| 145 | + Just str -> |
| 146 | + ( "format-" ++ str, True ) |
| 147 | + |
| 148 | + Nothing -> |
| 149 | + ( "", False ) |
| 150 | + ] |
| 151 | + |
| 152 | + -- checkbox |
| 153 | + , checkboxWrapper = Attrs.class "flex h-6 items-center" |
| 154 | + , checkboxInput = |
| 155 | + \{ withError } -> |
| 156 | + Attrs.classList |
| 157 | + [ ( "h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600", True ) |
| 158 | + , ( isInvalid, withError ) |
| 159 | + ] |
| 160 | + , checkboxTitle = Attrs.class "ml-3 text-sm leading-6" |
| 161 | + |
| 162 | + -- select |
| 163 | + , select = |
| 164 | + \{ withError } -> |
| 165 | + Attrs.classList |
| 166 | + [ ( "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 ) |
| 167 | + , ( "border-0", not withError ) |
| 168 | + , ( isInvalid, withError ) |
| 169 | + ] |
| 170 | + |
| 171 | + -- list group |
| 172 | + , listGroup = Attrs.class "mb-2" |
| 173 | + , listGroupItem = Attrs.class "border border-gray-300 rounded-md px-4 py-2 mb-2 shadow-sm" |
| 174 | + , 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" |
| 175 | + , 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" |
| 176 | + |
| 177 | + -- tuple |
| 178 | + , formRow = Attrs.class "flex space-x-4" |
| 179 | + , formRowItem = Attrs.class "max-w-full flex-grow" |
| 180 | + |
| 181 | + -- radio |
| 182 | + , radioWrapper = Attrs.class "flex items-center gap-x-3" |
| 183 | + , radioInput = Attrs.class "h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600" |
| 184 | + , radioInputLabel = Attrs.class "block text-sm font-medium leading-6 text-gray-900" |
| 185 | + , field = |
| 186 | + \{ withError, withValue } -> |
| 187 | + Attrs.classList |
| 188 | + [ ( "mb-6", True ) |
| 189 | + , ( "text-red-500", withError ) |
| 190 | + , ( "has-value", withValue ) |
| 191 | + ] |
| 192 | + , fieldLabel = Attrs.class "block" |
| 193 | + , fieldInput = Attrs.class "field-input" |
| 194 | + , fieldInputMeta = Attrs.class "field-meta" |
| 195 | + , fieldTitle = Attrs.class "block text-sm font-medium leading-6 text-gray-900" |
| 196 | + , fieldDescription = Attrs.class "mt-2 text-sm leading-6 text-gray-600" |
| 197 | + , group = |
| 198 | + \{ withError, withValue } -> |
| 199 | + Attrs.classList |
| 200 | + [ ( "mb-4", True ) |
| 201 | + , ( "text-red-500", withError ) |
| 202 | + , ( "has-value", withValue ) |
| 203 | + ] |
| 204 | + , liveError = Attrs.class "text-red-500 text-xs my-2" |
| 205 | + , 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" |
| 206 | + , inputGroupPrependContent = Attrs.class "text-gray-500 sm:text-sm" |
| 207 | + , 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" |
| 208 | + , inputGroupAppendContent = Attrs.class "text-gray-500 sm:text-sm" |
| 209 | + , inputGroup = Attrs.class "mt-2 flex shadow-sm" |
| 210 | + } |
0 commit comments