Skip to content

Commit 3205a79

Browse files
authored
Merge pull request #890 from cyrilchapon/ts-typography
@theme-ui/typography => Typescript
2 parents 8dc72b2 + fc01946 commit 3205a79

File tree

12 files changed

+392
-364
lines changed

12 files changed

+392
-364
lines changed

packages/docs/src/components/theme-scales.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { jsx } from 'theme-ui'
33
import { scales, multiples } from '@theme-ui/css'
44
import { Styled } from 'theme-ui'
55

6-
const camelDash = string =>
7-
string.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`)
6+
const camelDash = (string) =>
7+
string.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`)
88

99
const alphabeticSort = (a, b) =>
1010
a.localeCompare(b, undefined, {
1111
sensitivity: 'base',
1212
})
1313

14-
export default props => {
14+
export default (props) => {
1515
const exclude = Object.keys(multiples)
1616
const table = Object.keys(scales).reduce((acc, curr) => {
1717
if (!Array.isArray(acc[scales[curr]])) {
@@ -35,7 +35,7 @@ export default props => {
3535
<tbody>
3636
{Object.keys(table)
3737
.sort(alphabeticSort)
38-
.map(key => (
38+
.map((key) => (
3939
<tr>
4040
<td>
4141
<Styled.inlineCode>{key}</Styled.inlineCode>
@@ -44,7 +44,10 @@ export default props => {
4444
{table[key].map((property, index) => (
4545
<Styled.inlineCode>
4646
{!!index && ', '}
47-
<Styled.a href={`https://developer.mozilla.org/en-US/docs/Web/CSS/${property}`}>{property}</Styled.a>
47+
<Styled.a
48+
href={`https://developer.mozilla.org/en-US/docs/Web/CSS/${property}`}>
49+
{property}
50+
</Styled.a>
4851
</Styled.inlineCode>
4952
))}
5053
</td>

packages/typography/package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
"version": "0.4.0-rc.1",
44
"main": "dist/index.js",
55
"module": "dist/index.esm.js",
6+
"source": "src/index.ts",
7+
"types": "dist/index.d.ts",
68
"author": "Brent Jackson <jxnblk@gmail.com>",
79
"license": "MIT",
810
"scripts": {
9-
"prepare": "microbundle --no-compress",
10-
"watch": "microbundle watch --no-compress"
11+
"prepare": "microbundle --no-compress --tsconfig tsconfig.json",
12+
"watch": "microbundle watch --no-compress --tsconfig tsconfig.json"
1113
},
1214
"dependencies": {
15+
"@theme-ui/css": "^0.4.0-rc.1",
16+
"@types/compass-vertical-rhythm": "^1.4.1",
17+
"@types/modularscale": "^2.0.0",
18+
"@types/typography": "^0.16.3",
1319
"compass-vertical-rhythm": "^1.4.5",
20+
"csstype": "^2.6.10",
1421
"modularscale": "^2.0.1",
15-
"object-assign": "^4.1.1"
22+
"type-fest": "^0.13.1"
1623
},
1724
"devDependencies": {
1825
"typography": "^0.16.19",

packages/typography/src/index.js

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

packages/typography/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { toTheme } from './to-theme'
2+
export { styles } from './styles'
3+
export { CustomTypographyOptions, ThemeTypographyRhythm as CustomVerticalRhythm } from './to-theme'
Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
import { ThemeStyles } from '@theme-ui/css'
2+
13
// theme.styles object for use with typography.js-generated theme object
24
// similar to typography.js style output, with these differences
35
// - only includes styles for markdown elements
46
// - does not include color styles
57
// - does not include responsive styles
68

7-
import assign from 'object-assign'
8-
99
const heading = {
1010
fontFamily: 'heading',
1111
lineHeight: 'heading',
1212
fontWeight: 'heading',
1313
}
1414

15-
export const styles = {
15+
const baseStyles: ThemeStyles = {
1616
root: {
1717
fontFamily: 'body',
1818
fontSize: 2,
@@ -22,42 +22,30 @@ export const styles = {
2222
img: {
2323
maxWidth: '100%',
2424
},
25-
h1: assign(
26-
{
27-
fontSize: 5,
28-
},
29-
heading
30-
),
31-
h2: assign(
32-
{
33-
fontSize: 4,
34-
},
35-
heading
36-
),
37-
h3: assign(
38-
{
39-
fontSize: 3,
40-
},
41-
heading
42-
),
43-
h4: assign(
44-
{
45-
fontSize: 2,
46-
},
47-
heading
48-
),
49-
h5: assign(
50-
{
51-
fontSize: 1,
52-
},
53-
heading
54-
),
55-
h6: assign(
56-
{
57-
fontSize: 0,
58-
},
59-
heading
60-
),
25+
h1: {
26+
fontSize: 5,
27+
...heading,
28+
},
29+
h2: {
30+
fontSize: 4,
31+
...heading,
32+
},
33+
h3: {
34+
fontSize: 3,
35+
...heading,
36+
},
37+
h4: {
38+
fontSize: 2,
39+
...heading,
40+
},
41+
h5: {
42+
fontSize: 1,
43+
...heading,
44+
},
45+
h6: {
46+
fontSize: 0,
47+
...heading,
48+
},
6149
ul: {
6250
listStylePosition: 'outside',
6351
listStyleImage: 'none',
@@ -137,7 +125,7 @@ export const styles = {
137125
},
138126
}
139127

140-
const headings = ['h6', 'h5', 'h4', 'h3', 'h2', 'h1']
128+
const headings = ['h6', 'h5', 'h4', 'h3', 'h2', 'h1'] as const
141129
const blockElements = [
142130
...headings,
143131
'ul',
@@ -148,19 +136,22 @@ const blockElements = [
148136
'blockquote',
149137
'img',
150138
'hr',
151-
]
139+
] as const
152140

153-
blockElements.forEach(tag => {
154-
assign(styles, {
155-
[tag]: assign(
156-
{
141+
export const styles: ThemeStyles = {
142+
...baseStyles,
143+
...blockElements.reduce(
144+
(style, tag) => ({
145+
...style,
146+
[tag]: {
157147
padding: 0,
158148
margin: 0,
159149
marginBottom: 3,
150+
...baseStyles[tag],
160151
},
161-
styles[tag]
162-
),
163-
})
164-
})
152+
}),
153+
{}
154+
),
155+
}
165156

166157
export default styles

packages/typography/src/to-theme.js

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

0 commit comments

Comments
 (0)