Skip to content

Commit 4e5b12b

Browse files
authored
Support for Jetpack Form Block (#2153)
* Apply input styles to Jetpack form fields * Apply checkbox styles to Jetpack contact forms * Style Jetpack contact form messaging
1 parent 39176b5 commit 4e5b12b

File tree

9 files changed

+701
-333
lines changed

9 files changed

+701
-333
lines changed

.changeset/green-shoes-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add support for Jetpack Form Block

src/components/checkbox/checkbox.scss

Lines changed: 2 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,5 @@
1-
@use '../../compiled/tokens/scss/color';
2-
@use '../../compiled/tokens/scss/ease';
3-
@use '../../compiled/tokens/scss/size';
4-
@use '../../compiled/tokens/scss/transition';
5-
@use '../../mixins/focus';
6-
@use '../../mixins/theme';
7-
8-
/**
9-
* Themed properties
10-
*/
11-
12-
@include theme.props {
13-
--theme-color-text-checkbox-checked-hover: var(
14-
--theme-color-text-checkbox-hover
15-
);
16-
--theme-color-text-checkbox-disabled: #{color.$base-gray-dark};
17-
--theme-color-text-checkbox-hover: #{color.$brand-primary};
18-
}
19-
20-
@include theme.props(dark) {
21-
--theme-color-text-checkbox-checked-hover: #{color.$brand-primary-darker};
22-
--theme-color-text-checkbox-disabled: #{color.$text-light};
23-
--theme-color-text-checkbox-hover: #{color.$text-dark};
24-
}
25-
26-
/**
27-
* 1. This `@supports` query prevents IE11 (and older browsers) from applying
28-
* these styles, falling back to the native checkbox appearance.
29-
* 2. Modern browsers let us apply wholly custom styles to certain elements,
30-
* but only when `appearance` is set to `none`. Because this property is not
31-
* a finalized standard, vendor prefixes are still required.
32-
* 3. Some browsers will squish the checkbox in flex containers, which we never,
33-
* ever want.
34-
* 4. Without this, checkboxes appear too small unless hard-pixel sizes are
35-
* used (ew).
36-
*/
1+
@use '../../mixins/toggle-input';
372

383
.c-checkbox {
39-
@supports (-moz-appearance: none) or (-webkit-appearance: none) or
40-
(appearance: none) {
41-
/* 1 */
42-
-moz-appearance: none; /* stylelint-disable-line property-no-vendor-prefix */
43-
-webkit-appearance: none; /* stylelint-disable-line property-no-vendor-prefix */
44-
appearance: none; /* 2 */
45-
background-color: color.$text-light;
46-
block-size: size.$square-toggle-medium;
47-
border: size.$edge-control solid currentColor;
48-
border-radius: size.$border-radius-medium;
49-
color: color.$text-dark;
50-
cursor: pointer;
51-
flex: none; /* 3 */
52-
font: inherit; /* 4 */
53-
inline-size: size.$square-toggle-medium;
54-
padding: 0;
55-
position: relative;
56-
transition-duration: transition.$quick;
57-
transition-property: background-color, border-color, color;
58-
transition-timing-function: ease.$out;
59-
vertical-align: middle;
60-
61-
/**
62-
* State: Focused
63-
*
64-
* We use `focus-visible` here because checkboxes do not inherently require
65-
* keyboard interactions.
66-
*/
67-
68-
@include focus.focus-visible {
69-
box-shadow: 0 0 0 size.$edge-large color.$brand-primary-lighter;
70-
}
71-
72-
/**
73-
* We add the check mark via a pseudo element so we can easily apply
74-
* transitions to it without requiring separate elements.
75-
*
76-
* 1. The icon looks kind of claustrophobic if it runs right up to the
77-
* element edge, so we re-use the border size as an inset value. This
78-
* appears much more balanced!
79-
* 2. Starting state of animation.
80-
*/
81-
82-
&::after {
83-
background-image: svg-load(
84-
'icons/check.svg',
85-
stroke=color.$text-light-emphasis
86-
);
87-
background-position: center;
88-
background-repeat: no-repeat;
89-
background-size: contain;
90-
content: '';
91-
inset: size.$edge-control; /* 1 */
92-
opacity: 0; /* 2 */
93-
position: absolute;
94-
transform: scale(0); /* 2 */
95-
transition-duration: transition.$quick;
96-
transition-property: opacity, transform;
97-
transition-timing-function: ease.$out;
98-
}
99-
100-
/**
101-
* State: Hover
102-
*/
103-
104-
&:hover {
105-
background-color: color.$text-light-emphasis;
106-
color: var(--theme-color-text-checkbox-hover);
107-
}
108-
109-
/**
110-
* State: Checked
111-
*/
112-
113-
&:checked {
114-
background-color: currentColor;
115-
116-
/**
117-
* End state of animation
118-
*/
119-
120-
&::after {
121-
opacity: 1;
122-
transform: scale(1);
123-
}
124-
125-
&:hover {
126-
color: var(--theme-color-text-checkbox-checked-hover);
127-
}
128-
}
129-
130-
/**
131-
* State: Disabled
132-
*
133-
* 1. We want the checkbox to appear "read-only." A transparent background
134-
* and dashed line help symbolize a lack of interactivity.
135-
* 2. Same color used for disabled `c-input` borders.
136-
*/
137-
138-
&:disabled {
139-
background-color: transparent; /* 1 */
140-
border-style: dashed; /* 1 */
141-
color: var(--theme-color-text-checkbox-disabled); /* 2 */
142-
cursor: not-allowed;
143-
144-
&::after {
145-
/**
146-
* Inline SVGs aren't aware of custom properties, so we have to do a bit
147-
* of theming trickery here
148-
*/
149-
150-
@include theme.styles {
151-
background-image: svg-load(
152-
'icons/check.svg',
153-
stroke=color.$base-gray-dark
154-
);
155-
}
156-
157-
@include theme.styles(dark) {
158-
background-image: svg-load(
159-
'icons/check.svg',
160-
stroke=color.$text-light
161-
);
162-
}
163-
}
164-
165-
/**
166-
* We can forego the border entirely for a disabled checkmark, as the hit
167-
* area is unimportant.
168-
*/
169-
170-
&:checked {
171-
border-color: transparent;
172-
}
173-
}
174-
}
4+
@include toggle-input.checkbox;
1755
}

src/components/input/input.scss

Lines changed: 2 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,5 @@
1-
@use 'sass:math';
2-
@use '../../compiled/tokens/scss/color';
3-
@use '../../compiled/tokens/scss/ease';
4-
@use '../../compiled/tokens/scss/size';
5-
@use '../../compiled/tokens/scss/transition';
6-
@use '../../mixins/theme';
7-
8-
/**
9-
* Themed properties
10-
*/
11-
12-
@include theme.props {
13-
--theme-color-background-input-disabled: #{color.$base-gray-light};
14-
--theme-color-border-input-disabled: #{color.$base-gray};
15-
--theme-color-border-input-hover: #{color.$brand-primary};
16-
}
17-
18-
@include theme.props(dark) {
19-
--theme-color-background-input-disabled: #{color.$brand-primary-lighter};
20-
--theme-color-border-input-disabled: #{color.$brand-primary-dark};
21-
--theme-color-border-input-hover: currentColor;
22-
}
23-
24-
/**
25-
* 1. Browsers apply certain default styles unless appearance is set to `none`.
26-
* Unfortunately Chrome, Safari and Mozilla all still rely on the
27-
* vendor-prefixed version of this property at the time of this writing.
28-
* 2. Input heights vary between different types in certain browsers unless a
29-
* height is explicitly set.
30-
* 3. Non-normal line heights break placeholder text alignment in Safari.
31-
* 4. Safari will not style disabled inputs with readable text unless we set
32-
* this property in addition to `color`. Unfortunately this also resets the
33-
* appearance of `::placeholder`, which we'll style later on.
34-
*/
1+
@use '../../mixins/input';
352

363
.c-input {
37-
-moz-appearance: none; /* stylelint-disable-line property-no-vendor-prefix */
38-
-webkit-appearance: none; /* stylelint-disable-line property-no-vendor-prefix */
39-
appearance: none; /* 1 */
40-
background-color: color.$text-light;
41-
block-size: size.$height-control-default; /* 2 */
42-
border: size.$edge-control solid currentColor;
43-
border-radius: size.$border-radius-medium;
44-
color: color.$text-dark;
45-
display: block;
46-
font: inherit;
47-
font-style: normal;
48-
inline-size: 100%;
49-
line-height: normal; /* 3 */
50-
outline: none;
51-
padding: size.$padding-control-vertical size.$spacing-control-text-inset;
52-
-webkit-text-fill-color: color.$text-dark; /* 4 */
53-
transition-duration: transition.$quick;
54-
transition-property: background-color, border-color;
55-
transition-timing-function: ease.$out;
56-
vertical-align: middle;
57-
58-
/**
59-
* For certain single-line input types, using `text-indent` instead of
60-
* `padding-left` gives a more natural and intuitive appearance when text
61-
* content overflows.
62-
*
63-
* We do not apply this for search inputs because Safari gets weird about
64-
* search input padding.
65-
*/
66-
67-
&[type='email'],
68-
&[type='text'] {
69-
padding-inline-start: 0;
70-
text-indent: size.$spacing-control-text-inset;
71-
}
72-
73-
/**
74-
* For textareas with rows, overrides static default height
75-
*/
76-
77-
&[rows] {
78-
block-size: auto;
79-
}
80-
81-
/**
82-
* Progressively-enhanced styles; `is-elastic` is added by JavaScript
83-
*/
84-
85-
&.is-elastic {
86-
resize: none;
87-
}
88-
89-
/**
90-
* Multi-line types should be taller
91-
*/
92-
93-
@at-root textarea#{&} {
94-
block-size: size.$height-control-multiline;
95-
}
96-
97-
/**
98-
* Types that disclose additional options should have an icon
99-
*
100-
* 1. Setting the background size to `100%` avoids a strange background shift
101-
* bug on hover in Chrome but has no visible effect in other browsers as
102-
* long as the image is an SVG that does not preserve its aspect ratio.
103-
* 2. Firefox misaligns inner options when padding is applied, but all modern
104-
* browsers seem to align selects predictably even when there is no
105-
* vertical padding. We still keep a small amount of padding because
106-
* Firefox's inner dotted outline looks gross when it runs into the outer
107-
* border, and existing hacks around this visibly degrade text rendering.
108-
* 3. Prevents option text from overlapping icon.
109-
*/
110-
111-
@at-root select#{&} {
112-
background-image: svg-load('icons/caret-down.svg', fill=color.$text-dark);
113-
background-position: right size.$spacing-control-icon-inset center;
114-
background-repeat: no-repeat;
115-
background-size: size.$square-control-icon 100%; /* 1 */
116-
padding-block: math.div(size.$padding-control-vertical, 2); /* 2 */
117-
padding-inline-end: size.$spacing-control-icon-inset +
118-
size.$square-control-icon; /* 3 */
119-
}
120-
121-
&:hover:not(:disabled):not([readonly]) {
122-
background-color: color.$text-light-emphasis;
123-
border-color: var(--theme-color-border-input-hover);
124-
}
125-
126-
/**
127-
* We use plain ol' `focus` rather than `focus-visible` because text inputs
128-
* are almost always in a state of keyboard interaction, making the difference
129-
* (if any) minimal.
130-
*/
131-
132-
&:focus {
133-
background-color: #fff;
134-
box-shadow: 0 0 0 size.$edge-large color.$brand-primary-lighter;
135-
}
136-
137-
&[readonly]:not(:disabled) {
138-
background-color: transparent;
139-
border-color: transparent;
140-
color: inherit;
141-
}
142-
143-
&:disabled {
144-
background-color: var(--theme-color-background-input-disabled);
145-
border-color: var(--theme-color-border-input-disabled);
146-
cursor: not-allowed;
147-
}
148-
149-
/**
150-
* 1. We set `-webkit-text-fill-color` on the root element so that Safari
151-
* would respect our disabled text color. But that also resets the
152-
* `::placeholder` color, so we have to specify our own so it will be
153-
* distinct from a normal value while maintaining reasonable high color
154-
* contrast.
155-
* 2. Firefox uses `opacity` instead of a lightened text color, appearing
156-
* lighter than other browsers unless we reset it here.
157-
*/
158-
159-
&::placeholder {
160-
color: color.$text-dark-muted; /* 1 */
161-
opacity: 1; /* 2 */
162-
-webkit-text-fill-color: color.$text-dark-muted; /* 1 */
163-
}
4+
@include input.default;
1645
}

0 commit comments

Comments
 (0)