Skip to content

Commit 312cf94

Browse files
committed
Migrate CSS to vanilla-extract
1 parent 6ee8f2f commit 312cf94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1372
-1439
lines changed

src/ui/components/BooksWidget/index.tsx

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@ import { h, FunctionComponent } from 'preact'
22
import shuffle from 'lodash/shuffle'
33
import { useMemo, useState } from 'preact/hooks'
44
import { books } from './constants'
5-
import {
6-
Container,
7-
Badge,
8-
BadgeLabel,
9-
BadgeNext,
10-
Cover,
11-
Text,
12-
Header,
13-
Title,
14-
Description,
15-
Link,
16-
} from './style.css'
5+
import * as styles from './styles.css'
176

187
export const BooksWidget: FunctionComponent = () => {
198
const shuffledBooks = useMemo(() => shuffle(books), [])
@@ -22,29 +11,29 @@ export const BooksWidget: FunctionComponent = () => {
2211

2312
return (
2413
<div>
25-
<Container
26-
tag="a"
14+
<a
15+
class={styles.container}
2716
href={book.url}
2817
target="_blank"
2918
rel="noopener noreferrer"
3019
>
31-
<Cover tag="img" src={book.cover} />
20+
<img class={styles.cover} src={book.cover} />
3221

33-
<Text>
34-
<Header>
35-
<Title>{book.title}</Title>
36-
<Description>{book.description}</Description>
37-
</Header>
22+
<div class={styles.text}>
23+
<div class={styles.header}>
24+
<div class={styles.title}>{book.title}</div>
25+
<div class={styles.description}>{book.description}</div>
26+
</div>
3827

39-
<Link tag="button">Get the book</Link>
40-
</Text>
41-
</Container>
28+
<button class={styles.link}>Get the book</button>
29+
</div>
30+
</a>
4231

43-
<Badge>
44-
<BadgeLabel>☝️ Support date-fns, buy a book 🙏</BadgeLabel>
32+
<div class={styles.badge}>
33+
<div class={styles.badgeLabel}>☝️ Support date-fns, buy a book 🙏</div>
4534

46-
<BadgeNext
47-
tag="button"
35+
<button
36+
class={styles.badgeNext}
4837
onClick={() => {
4938
let newIndex = bookIndex + 1
5039
if (newIndex > books.length - 1) {
@@ -54,8 +43,8 @@ export const BooksWidget: FunctionComponent = () => {
5443
}}
5544
>
5645
Next book
57-
</BadgeNext>
58-
</Badge>
46+
</button>
47+
</div>
5948
</div>
6049
)
6150
}

src/ui/components/BooksWidget/style.css

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/ui/components/BooksWidget/style.css.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { style, globalStyle } from '@vanilla-extract/css'
2+
3+
export const badge = style({
4+
background: '#9a0f98',
5+
padding: '0.25rem',
6+
display: 'flex',
7+
justifyContent: 'space-between',
8+
alignItems: 'center',
9+
})
10+
11+
export const badgeLabel = style({
12+
color: 'white',
13+
fontWeight: '600',
14+
})
15+
16+
export const badgeNext = style({
17+
background: 'transparent',
18+
color: 'white',
19+
border: '1px solid white',
20+
borderRadius: '0.25rem',
21+
cursor: 'pointer',
22+
23+
':hover': {
24+
color: '#9a0f98',
25+
background: 'white',
26+
},
27+
})
28+
29+
export const cover = style({
30+
width: '6rem',
31+
flexShrink: '0',
32+
})
33+
34+
export const description = style({
35+
lineHeight: '1.4',
36+
fontSize: '0.9rem',
37+
color: '#fdf4dc',
38+
})
39+
40+
export const container = style({
41+
padding: '0.5rem',
42+
background: '#39065a',
43+
color: '#fff6f6',
44+
display: 'flex',
45+
alignItems: 'flex-start',
46+
textDecoration: 'none',
47+
transition: 'background 150ms ease-out',
48+
49+
':hover': {
50+
background: '#6a0572',
51+
},
52+
})
53+
54+
globalStyle(`${container} > *:not(:last-child)`, {
55+
marginRight: '0.75rem',
56+
})
57+
58+
export const header = style({})
59+
60+
globalStyle(`${header} > *:not(:last-child)`, {
61+
marginBottom: '0.125rem',
62+
})
63+
64+
export const link = style({
65+
background: '#ea0599',
66+
padding: '0.25rem 0.5rem',
67+
display: 'inline-block',
68+
color: 'white',
69+
fontSize: '1rem',
70+
fontWeight: '500',
71+
borderRadius: '0.25rem',
72+
transition: 'background 150ms ease-out',
73+
border: 'none',
74+
cursor: 'pointer',
75+
selectors: {
76+
[`${container}:hover &`]: {
77+
background: '#ff00a5',
78+
},
79+
},
80+
})
81+
82+
export const text = style({
83+
lineHeight: '1.2',
84+
})
85+
86+
globalStyle(`${text} > *:not(:last-child)`, {
87+
marginBottom: '0.5rem',
88+
})
89+
90+
export const title = style({
91+
fontWeight: '600',
92+
fontSize: '1.25rem',
93+
color: '#ead7af',
94+
selectors: {
95+
[`${container}:hover &`]: {
96+
textDecoration: 'underline',
97+
},
98+
},
99+
})

src/ui/components/Code/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { h, FunctionComponent, Fragment } from 'preact'
1+
import { FunctionComponent, h } from 'preact'
22
import Prism from 'prismjs'
33
import 'prismjs/themes/prism.css?global'
44
import './global.css?global'
5-
import { Pre, Code as StyledCode } from './style.css'
5+
import * as styles from './styles.css'
66

77
interface CodeProps {
88
value: string
99
}
1010
export const Code: FunctionComponent<CodeProps> = ({ value }) => {
1111
const html = Prism.highlight(value, Prism.languages.javascript, 'javascript')
12+
1213
return (
13-
<>
14-
<Pre tag="pre">
15-
<StyledCode tag="code" dangerouslySetInnerHTML={{ __html: html }} />
16-
</Pre>
17-
</>
14+
<pre class={styles.pre}>
15+
<code class={styles.code} dangerouslySetInnerHTML={{ __html: html }} />
16+
</pre>
1817
)
1918
}

src/ui/components/Code/style.css

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/ui/components/Code/style.css.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { style } from '@vanilla-extract/css'
2+
3+
export const code = style({
4+
display: 'block',
5+
color: '#5d583b',
6+
backgroundColor: '#fffffe',
7+
font: "13px Consolas, 'Liberation Mono', Menlo, Courier, monospace",
8+
'::after': {
9+
display: 'none',
10+
},
11+
'::before': {
12+
display: 'none',
13+
},
14+
})
15+
16+
export const pre = style({
17+
overflowX: 'auto',
18+
border: '1px solid #b9a2b2',
19+
backgroundColor: '#fffffe',
20+
padding: '4px 8px',
21+
})

src/ui/components/DocExamples/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { h, FunctionComponent } from 'preact'
22
import { Code } from '~/ui/components/Code'
33
import { DocHeaderAnchor } from '~/ui/components/DocHeaderAnchor'
4-
import { CodeContainer } from './style.css'
54
import isArray from 'lodash/isArray'
65
import { Markdown } from '~/ui/components/Markdown'
6+
import * as styles from './styles.css'
77

88
interface Props {
99
examples: string[] | string
@@ -17,13 +17,11 @@ export const DocExamples: FunctionComponent<Props> = ({ examples }) => (
1717
</h2>
1818

1919
{isArray(examples) ? (
20-
examples.map((example, index) => {
21-
return (
22-
<CodeContainer key={index}>
23-
<Code value={example} />
24-
</CodeContainer>
25-
)
26-
})
20+
examples.map((example, index) => (
21+
<div class={styles.codeContainer} key={index}>
22+
<Code value={example} />
23+
</div>
24+
))
2725
) : (
2826
<Markdown value={examples} />
2927
)}

src/ui/components/DocExamples/style.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)