Skip to content

Commit b149f20

Browse files
committed
Dense layout
1 parent da0fd9a commit b149f20

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

src/Json/Form/Config.elm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module Json.Form.Config exposing (Config, TextFieldStyle(..), decoder, defaultConfig)
22

3-
import Json.Decode as Decode exposing (Decoder, fail, field, string, succeed)
3+
import Json.Decode as Decode exposing (Decoder, bool, fail, field, string, succeed)
44

55

66
type alias Config =
77
{ textFieldStyle : TextFieldStyle
8+
, dense : Bool
89
}
910

1011

@@ -16,12 +17,13 @@ type TextFieldStyle
1617
defaultConfig : Config
1718
defaultConfig =
1819
{ textFieldStyle = Filled
20+
, dense = False
1921
}
2022

2123

2224
decoder : Decoder Config
2325
decoder =
24-
Decode.map Config
26+
Decode.map2 Config
2527
(field "textFieldStyle" <|
2628
Decode.andThen
2729
(\x ->
@@ -37,3 +39,4 @@ decoder =
3739
<|
3840
string
3941
)
42+
(field "dense" bool)

src/Json/Form/TextField.elm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ view model schema isRequired isDisabled path =
3838
( disabled, hidden ) =
3939
applyRule model.value path uiSpec.rule
4040

41+
actuallyDisabled =
42+
isDisabled || disabled
43+
4144
icon =
4245
if isPassword then
4346
if model.showPassword then
@@ -51,14 +54,12 @@ view model schema isRequired isDisabled path =
5154

5255
else
5356
text ""
54-
55-
actuallyDisabled =
56-
isDisabled || disabled
5757
in
5858
div
5959
[ classList
6060
[ ( "jf-textfield", True )
6161
, ( "jf-textfield--outlined", model.config.textFieldStyle == Outlined )
62+
, ( "jf-textfield--dense", model.config.dense )
6263
, ( "jf-textfield--focused", model.focused |> Maybe.map ((==) path) |> Maybe.withDefault False )
6364
, ( "jf-textfield--empty", editedValue == "" )
6465
, ( "jf-textfield--invalid", hasError )
@@ -130,6 +131,7 @@ viewNumeric model schema isRequired isDisabled path =
130131
[ classList
131132
[ ( "jf-textfield", True )
132133
, ( "jf-textfield--outlined", model.config.textFieldStyle == Outlined )
134+
, ( "jf-textfield--dense", model.config.dense )
133135
, ( "jf-textfield--focused", isFocused )
134136
, ( "jf-textfield--empty", editedValue == "" )
135137
, ( "jf-textfield--invalid", hasError )

stylesheets/textfield.css

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
.jf-textfield {
2+
--field-height: 56px;
3+
--label-top: 21px;
4+
--large-font-size: 16px;
5+
--side-padding: 12px;
6+
--filled-background: #f5f5f5;
7+
}
8+
9+
.jf-textfield--dense {
10+
--field-height: 44px;
11+
--label-top: 17px;
12+
--large-font-size: 12px;
13+
--side-padding: 8px;
14+
}
15+
116
.jf-textfield {
217
position: relative;
3-
height: 56px;
4-
font-size: 16px;
18+
height: var(--field-height);
19+
font-size: var(--large-font-size);
520
display: inline-block;
621
box-sizing: border-box;
722
width: 280px;
@@ -14,7 +29,7 @@
1429
border-top-left-radius: 4px;
1530
border-top-right-radius: 4px;
1631
cursor: pointer;
17-
background-color: #e8e8e8;
32+
background-color: var(--filled-background);
1833
color: #00000099;
1934
outline: none;
2035
}
@@ -50,14 +65,14 @@
5065
border-top-left-radius: 4px;
5166
outline: none;
5267
display: block;
53-
font-size: 16px;
68+
font-size: var(--large-font-size);
5469
font-family: var(--font-family);
5570
margin: 0;
56-
padding-left: 12px;
57-
padding-right: 12px;
71+
padding-left: var(--side-padding);
72+
padding-right: var(--side-padding);
5873
padding-top: 20px;
5974
padding-bottom: 12px;
60-
width: calc(100% - 26px);
75+
width: calc(100% - var(--side-padding) * 2 - 2px);
6176
background: 0 0;
6277
text-align: left;
6378
color: inherit;
@@ -74,8 +89,8 @@
7489
}
7590

7691
.jf-textfield--outlined.jf-textfield--empty .jf-textfield__label, .jf-textfield--empty .jf-textfield__label {
77-
top: 21px;
78-
font-size: 16px;
92+
top: var(--label-top);
93+
font-size: var(--large-font-size);
7994
}
8095

8196
.jf-textfield--focused .jf-textfield__label {
@@ -87,8 +102,8 @@
87102

88103
.jf-textfield__label {
89104
color: var(--color-inactive);
90-
padding-left: 12px;
91-
padding-right: 12px;
105+
padding-left: var(--side-padding);
106+
padding-right: var(--side-padding);
92107
font-size: 12px;
93108
left: 0;
94109
right: 0;
@@ -107,14 +122,14 @@
107122
}
108123

109124
.jf-textfield--empty .jf-textfield__label {
110-
font-size: 16px;
125+
font-size: var(--large-font-size);
111126
}
112127

113128
.jf-textfield--outlined .jf-textfield__label {
114129
padding-left: 4px;
115130
padding-right: 4px;
116131
font-size: 12px;
117-
left: 12px;
132+
left: var(--side-padding);
118133
bottom: auto;
119134
right: auto;
120135
width: auto;
@@ -136,8 +151,8 @@
136151
}
137152

138153
.jf-textfield--outlined .jf-textfield__input {
139-
padding-left: 12px;
140-
padding-right: 12px;
154+
padding-left: var(--side-padding);
155+
padding-right: var(--side-padding);
141156
padding-top: 20px;
142157
padding-bottom: 18px;
143158
top: 2px;
@@ -245,15 +260,15 @@
245260
position: absolute;
246261
bottom: -16px;
247262
font-size: 12px;
248-
padding-left: 12px;
249-
padding-right: 12px;
263+
padding-left: var(--side-padding);
264+
padding-right: var(--side-padding);
250265
color: rgba(0, 0, 0, 0.54);
251266
}
252267

253268
.jf-textfield svg {
254269
position: absolute;
255270
top: 16px;
256-
right: 12px;
271+
right: var(--side-padding);
257272
}
258273

259274
.jf-textfield--invalid svg {

0 commit comments

Comments
 (0)