Skip to content

Commit 203d5fa

Browse files
Luke BowermanLuke Bowerman
authored andcommitted
Update Form component to support gap property
1 parent 42b770d commit 203d5fa

File tree

4 files changed

+64
-52
lines changed

4 files changed

+64
-52
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515

16-
- removed labelFontWeight from FieldInline and update test for it
16+
- `InputText` will now show red error icon when validation fails
17+
- `Field*` components no longer have a bottom margin by default (see `Form` update)
18+
- `Form` now acts as `SpaceVertical` component automatically putting a gap between each child item
1719

18-
### Fixed
20+
### Removed
1921

20-
- updated InputText to have Icon warning when ValidationType = error
22+
- `FieldInline` no longer supports `labelFontWeight`
2123

2224
## [0.7.27] - 2020-04-15
2325

packages/components/src/Form/Form.tsx

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,15 @@ import React, {
3131
FormEventHandler,
3232
createContext,
3333
} from 'react'
34-
import styled from 'styled-components'
3534
import omit from 'lodash/omit'
36-
import {
37-
CompatibleHTMLProps,
38-
border,
39-
flexbox,
40-
layout,
41-
reset,
42-
space,
43-
BorderProps,
44-
FlexboxProps,
45-
LayoutProps,
46-
SpaceProps,
47-
} from '@looker/design-tokens'
35+
import { CompatibleHTMLProps } from '@looker/design-tokens'
36+
import { SpaceVertical, SpaceHelperProps } from '../Layout'
4837
import { ValidationMessageProps } from './ValidationMessage'
4938

5039
export type ValidationMessages = Record<string, ValidationMessageProps>
5140

5241
export interface FormProps
53-
extends BorderProps,
54-
FlexboxProps,
55-
LayoutProps,
56-
SpaceProps,
42+
extends SpaceHelperProps,
5743
CompatibleHTMLProps<HTMLFormElement> {
5844
/**
5945
* A record of all validation messages for the form, where the key is the name
@@ -72,22 +58,18 @@ export interface FormContext {
7258

7359
export const FormContext = createContext<FormContext>({})
7460

75-
const FormBase = styled.form`
76-
${reset}
77-
${border}
78-
${flexbox}
79-
${layout}
80-
${space}
81-
`
82-
8361
export const Form = forwardRef(
8462
(props: FormProps, ref: Ref<HTMLFormElement>) => (
8563
<FormContext.Provider
8664
value={{
8765
validationMessages: props.validationMessages,
8866
}}
8967
>
90-
<FormBase {...omit(props, 'validationMessages')} ref={ref} />
68+
<SpaceVertical
69+
as="form"
70+
{...omit(props, 'validationMessages')}
71+
ref={ref}
72+
/>
9173
</FormContext.Provider>
9274
)
9375
)

packages/components/src/Form/__snapshots__/Form.test.tsx.snap

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Form with one child 1`] = `
4-
.c4 {
4+
.c0 {
5+
display: -webkit-box;
6+
display: -webkit-flex;
7+
display: -ms-flexbox;
8+
display: flex;
9+
-webkit-align-items: flex-start;
10+
-webkit-box-align: flex-start;
11+
-ms-flex-align: flex-start;
12+
align-items: flex-start;
13+
-webkit-flex-direction: column;
14+
-ms-flex-direction: column;
15+
flex-direction: column;
16+
}
17+
18+
.c0 > * {
19+
margin-top: 1rem;
20+
}
21+
22+
.c0 > :first-child {
23+
margin-top: 0rem;
24+
}
25+
26+
.c5 {
527
-webkit-align-items: center;
628
-webkit-box-align: center;
729
-ms-flex-align: center;
@@ -18,7 +40,7 @@ exports[`Form with one child 1`] = `
1840
justify-content: space-evenly;
1941
}
2042
21-
.c4 input {
43+
.c5 input {
2244
border: none;
2345
background: transparent;
2446
-webkit-flex: 1;
@@ -31,34 +53,34 @@ exports[`Form with one child 1`] = `
3153
padding: 0;
3254
}
3355
34-
.c4::-webkit-input-placeholder {
56+
.c5::-webkit-input-placeholder {
3557
color: #939BA5;
3658
}
3759
38-
.c4::-moz-placeholder {
60+
.c5::-moz-placeholder {
3961
color: #939BA5;
4062
}
4163
42-
.c4:-ms-input-placeholder {
64+
.c5:-ms-input-placeholder {
4365
color: #939BA5;
4466
}
4567
46-
.c4::placeholder {
68+
.c5::placeholder {
4769
color: #939BA5;
4870
}
4971
50-
.c4:hover {
72+
.c5:hover {
5173
border-color: #C1C6CC;
5274
}
5375
54-
.c4:focus,
55-
.c4:focus-within {
76+
.c5:focus,
77+
.c5:focus-within {
5678
border-color: #9785F2;
5779
box-shadow: 0 0 0 2px #E8E5FF;
5880
outline: none;
5981
}
6082
61-
.c5 {
83+
.c6 {
6284
border-radius: 0.25rem;
6385
border: solid 1px;
6486
border-color: #DEE1E5;
@@ -72,14 +94,14 @@ exports[`Form with one child 1`] = `
7294
color: #343C42;
7395
}
7496
75-
.c2 {
97+
.c3 {
7698
color: #343C42;
7799
font-weight: 600;
78100
font-size: 0.75rem;
79101
display: inline-block;
80102
}
81103
82-
.c0 {
104+
.c1 {
83105
-webkit-align-items: left;
84106
-webkit-box-align: left;
85107
-ms-flex-align: left;
@@ -96,41 +118,41 @@ exports[`Form with one child 1`] = `
96118
width: 100%;
97119
}
98120
99-
.c0 .c3 {
121+
.c1 .c4 {
100122
display: -webkit-box;
101123
display: -webkit-flex;
102124
display: -ms-flexbox;
103125
display: flex;
104126
grid-area: input;
105127
}
106128
107-
.c0 .c6 {
129+
.c1 .c7 {
108130
grid-area: messages;
109131
}
110132
111-
.c0 .c1 {
133+
.c1 .c2 {
112134
grid-area: label;
113135
padding-bottom: 0.5rem;
114136
}
115137
116-
.c0 .c8 {
138+
.c1 .c9 {
117139
grid-area: detail;
118140
justify-self: end;
119141
}
120142
121-
.c0 .c7 {
143+
.c1 .c8 {
122144
margin-right: 0.5rem;
123145
margin-top: 0.5rem;
124146
}
125147
126148
<form
127-
className=""
149+
className="c0"
128150
>
129151
<div
130-
className="c0 "
152+
className="c1 "
131153
>
132154
<label
133-
className="c1 c2"
155+
className="c2 c3"
134156
color="palette.charcoal700"
135157
fontSize="xsmall"
136158
fontWeight="semiBold"
@@ -139,10 +161,10 @@ exports[`Form with one child 1`] = `
139161
label
140162
</label>
141163
<div
142-
className="c3 "
164+
className="c4 "
143165
>
144166
<div
145-
className="c4 c5 "
167+
className="c5 c6 "
146168
onClick={[Function]}
147169
>
148170
<input
@@ -153,7 +175,7 @@ exports[`Form with one child 1`] = `
153175
</div>
154176
</div>
155177
<div
156-
className="c6 "
178+
className="c7 "
157179
/>
158180
</div>
159181
</form>

packages/playground/src/Form/FieldsDemo.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
FieldCheckbox,
3232
FieldRadio,
3333
FieldToggleSwitch,
34+
Form,
3435
Grid,
3536
InputText,
3637
Select,
@@ -46,6 +47,11 @@ export const FieldsDemo: FC = () => {
4647
<InputText />
4748

4849
<Grid>
50+
<Form>
51+
<FieldText label="Text Input" prefix="$" placeholder="Money" />
52+
<FieldText label="Text Input" prefix="$" placeholder="Money" />
53+
<FieldText label="Text Input" prefix="$" placeholder="MONEY!!!" />
54+
</Form>
4955
<FieldText disabled label="Text Input" placeholder="placeholder" />
5056
<FieldText
5157
disabled

0 commit comments

Comments
 (0)