Skip to content

Commit da68914

Browse files
fktesseralis
andauthored
chore(www): Refactor homepage-newsletter (#25350)
* chore(www): Refactor to `sx` * ☀️ * 🌻 * no need to `calc`, fix and rm stray `rhythm` * no need for literal * mv `NewsletterFormOrnament` styles inline * combine imports * func-y * Update www/src/components/homepage/homepage-newsletter.js Co-authored-by: Nat Alison <[email protected]> * don't use shorthand for `border` * ditch "functional value" for border color * `border: 1` doesn't work, we need `borderStyle: solid`, thus went for the explicit `borderWidth` Co-authored-by: Nat Alison <[email protected]>
1 parent 2394276 commit da68914

File tree

1 file changed

+78
-89
lines changed

1 file changed

+78
-89
lines changed
Lines changed: 78 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,100 @@
1-
import React from "react"
2-
import styled from "@emotion/styled"
1+
/** @jsx jsx */
2+
import { jsx, Flex } from "theme-ui"
33

44
import HomepageSection from "./homepage-section"
55
import EmailCaptureForm from "../email-capture-form"
66

77
import { NewsletterFormOrnament } from "../../assets/ornaments"
88

9-
import { rhythm } from "../../utils/typography"
109
import { mediaQueries } from "gatsby-design-tokens/dist/theme-gatsbyjs-org"
1110

1211
const stripedBorderHeight = 1
1312

14-
const Container = styled(`div`)`
15-
background: ${p => p.theme.colors.newsletter.background};
16-
border: 1px solid ${p => p.theme.colors.newsletter.border};
17-
border-radius: ${p => p.theme.radii[2]};
18-
display: flex;
19-
flex-direction: column;
20-
margin-bottom: ${p => p.theme.space[8]};
21-
padding: calc(${p => p.theme.space[8]} * 1.2);
22-
padding-bottom: calc(
23-
${props => rhythm(props.theme.space[8] * 1.2)} +
24-
${p => p.theme.space[stripedBorderHeight]}
25-
);
26-
position: relative;
13+
const containerStyles = {
14+
bg: `newsletter.background`,
15+
borderColor: `newsletter.border`,
16+
borderStyle: `solid`,
17+
borderWidth: 1,
18+
borderRadius: 2,
19+
flexDirection: `column`,
20+
mb: 8,
21+
p: 9,
22+
pb: t => `calc(${t.space[9]} + ${t.space[stripedBorderHeight]})`,
23+
position: `relative`,
2724

28-
:after {
29-
border-radius: 0 0 ${p => p.theme.radii[2]} ${p => p.theme.radii[2]};
30-
background: ${p => p.theme.colors.newsletter.background}
25+
":after": {
26+
borderBottomLeftRadius: 2,
27+
borderBottomRightRadius: 2,
28+
background: t => `${t.colors.newsletter.background}
3129
repeating-linear-gradient(
3230
135deg,
33-
${p => p.theme.colors.newsletter.stripeColorA},
34-
${p => p.theme.colors.newsletter.stripeColorA} 20px,
31+
${t.colors.newsletter.stripeColorA},
32+
${t.colors.newsletter.stripeColorA} 20px,
3533
transparent 20px,
3634
transparent 40px,
37-
${p => p.theme.colors.newsletter.stripeColorB} 40px,
38-
${p => p.theme.colors.newsletter.stripeColorB} 60px,
35+
${t.colors.newsletter.stripeColorB} 40px,
36+
${t.colors.newsletter.stripeColorB} 60px,
3937
transparent 60px,
4038
transparent 80px
41-
);
42-
bottom: 0;
43-
content: "";
44-
height: ${p => p.theme.space[stripedBorderHeight]};
45-
left: 0;
46-
right: 0;
47-
position: absolute;
48-
}
39+
)`,
40+
bottom: 0,
41+
content: `""`,
42+
height: t => t.space[stripedBorderHeight],
43+
left: 0,
44+
right: 0,
45+
position: `absolute`,
46+
},
4947

50-
${mediaQueries.lg} {
51-
flex-direction: row;
52-
justify-content: space-between;
48+
[mediaQueries.lg]: {
49+
flexDirection: `row`,
50+
justifyContent: `space-between`,
5351

54-
> * {
55-
flex-basis: 50%;
56-
}
57-
}
58-
`
52+
"> *": {
53+
flexBasis: `50%`,
54+
},
55+
},
56+
}
5957

60-
const Ornament = styled(`span`)`
61-
left: -${p => p.theme.space[1]};
62-
position: absolute;
63-
top: -${p => p.theme.space[2]};
64-
`
58+
const nameStyles = {
59+
color: `textMuted`,
60+
fontFamily: `heading`,
61+
fontSize: 1,
62+
fontWeight: `body`,
63+
letterSpacing: `tracked`,
64+
m: 0,
65+
textTransform: `uppercase`,
66+
}
6567

66-
const Name = styled(`h3`)`
67-
color: ${p => p.theme.colors.textMuted};
68-
font-family: ${p => p.theme.fonts.heading};
69-
font-size: ${p => p.theme.fontSizes[1]};
70-
font-weight: ${p => p.theme.fontWeights.body};
71-
letter-spacing: ${p => p.theme.letterSpacings.tracked};
72-
margin: 0;
73-
text-transform: uppercase;
74-
`
68+
const titleStyles = {
69+
color: `newsletter.heading`,
70+
fontSize: 4,
71+
fontWeight: `heading`,
72+
lineHeight: `dense`,
73+
m: 0,
74+
mt: 1,
75+
}
7576

76-
const Title = styled(`h1`)`
77-
color: ${p => p.theme.colors.newsletter.heading};
78-
font-size: ${p => p.theme.fontSizes[4]};
79-
font-weight: ${p => p.theme.fontWeights.heading};
80-
line-height: ${p => p.theme.lineHeights.dense};
81-
margin: 0;
82-
margin-top: ${p => p.theme.space[1]};
83-
`
84-
85-
const Form = styled(EmailCaptureForm)`
86-
margin-top: ${p => p.theme.space[5]};
87-
88-
${mediaQueries.lg} {
89-
margin-top: 0;
90-
}
91-
`
92-
93-
const HomepageNewsletter = () => (
94-
<HomepageSection>
95-
<Container>
96-
<Ornament>
97-
<NewsletterFormOrnament />
98-
</Ornament>
99-
<header>
100-
<Name>The Gatsby Newsletter</Name>
101-
<Title>Keep up with the latest things Gatsby!</Title>
102-
</header>
103-
<Form
104-
isHomepage={true}
105-
confirmMessage="Success! You have been subscribed to the Gatsby newsletter. Expect to see a newsletter in your inbox each Wednesday (or the equivalent of US Wednesday in your time zone)!"
106-
/>
107-
</Container>
108-
</HomepageSection>
109-
)
110-
111-
export default HomepageNewsletter
77+
export default function HomepageNewsletter() {
78+
return (
79+
<HomepageSection>
80+
<Flex sx={containerStyles}>
81+
<NewsletterFormOrnament
82+
sx={{
83+
left: -1,
84+
position: `absolute`,
85+
top: -2,
86+
}}
87+
/>
88+
<header>
89+
<h3 sx={nameStyles}>The Gatsby Newsletter</h3>
90+
<h1 sx={titleStyles}>Keep up with the latest things Gatsby!</h1>
91+
</header>
92+
<EmailCaptureForm
93+
isHomepage
94+
confirmMessage="Success! You have been subscribed to the Gatsby newsletter. Expect to see a newsletter in your inbox each Wednesday (or the equivalent of US Wednesday in your time zone)!"
95+
sx={{ mt: [5, null, null, null, 0] }}
96+
/>
97+
</Flex>
98+
</HomepageSection>
99+
)
100+
}

0 commit comments

Comments
 (0)