Skip to content

Commit 5d5108d

Browse files
authored
Merge pull request #807 from beerose/feat/style-guide-ts
feat(@theme-ui/style-guide): convert to typescript
2 parents e4787a5 + f616b01 commit 5d5108d

17 files changed

+158
-97
lines changed

packages/style-guide/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.4.0-alpha.1",
44
"main": "dist/index.js",
55
"module": "dist/index.esm.js",
6+
"types": "dist/index.d.ts",
7+
"source": "src/index.ts",
68
"author": "Brent Jackson",
79
"license": "MIT",
810
"scripts": {
@@ -17,10 +19,14 @@
1719
"dependencies": {
1820
"@theme-ui/presets": "^0.4.0-alpha.1",
1921
"color": "^3.1.2",
22+
"@types/color": "3.0.1",
2023
"lodash.get": "^4.4.2"
2124
},
2225
"publishConfig": {
2326
"access": "public"
2427
},
25-
"gitHead": "bfd026cae085f377ca537de897dc43233d50f5d5"
28+
"gitHead": "bfd026cae085f377ca537de897dc43233d50f5d5",
29+
"devDependencies": {
30+
"@types/color": "^3.0.1"
31+
}
2632
}

packages/style-guide/src/Card.js

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

packages/style-guide/src/Card.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @jsx jsx */
2+
import { ComponentProps } from 'react'
3+
import { jsx } from 'theme-ui'
4+
5+
export interface CardProps extends ComponentProps<'div'> {}
6+
export const Card: React.FC<CardProps> = props => (
7+
<div
8+
{...props}
9+
sx={{
10+
variant: 'styles.Card',
11+
}}
12+
/>
13+
)
14+
15+
export default Card

packages/style-guide/src/ColorPalette.js renamed to packages/style-guide/src/ColorPalette.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
/** @jsx jsx */
22
import { jsx } from 'theme-ui'
33
import { useTheme } from './context'
4-
import ColorSwatch from './ColorSwatch'
4+
import ColorSwatch, { ColorSwatchProps } from './ColorSwatch'
55

6-
const join = (...args) => args.filter(Boolean).join('.')
6+
const join = (...args: unknown[]) => args.filter(Boolean).join('.')
77

8+
type Colors = Record<string, string | { [key: string]: Colors }>
9+
export interface ColorRowProps extends Omit<ColorSwatchProps, 'color'> {
10+
colors: Colors
11+
name?: string
12+
omit?: string[]
13+
render?: (value: {
14+
swatch: React.ReactElement
15+
color: string
16+
key: string
17+
name: string
18+
}) => React.ReactNode
19+
size?: number | string
20+
}
821
export const ColorRow = ({
922
colors,
1023
name,
1124
omit = ['modes'],
1225
render,
1326
size,
1427
...props
15-
}) => {
28+
}: ColorRowProps) => {
1629
return (
1730
<div>
1831
<div
@@ -31,7 +44,7 @@ export const ColorRow = ({
3144
{...props}
3245
key={key}
3346
name={id}
34-
colors={color}
47+
colors={color as Colors}
3548
omit={omit}
3649
/>
3750
)
@@ -63,16 +76,16 @@ export const ColorRow = ({
6376
)
6477
}
6578

66-
export const ColorPalette = ({
67-
omit,
68-
mode,
69-
...props
70-
}) => {
79+
export interface ColorPaletteProps extends Omit<ColorRowProps, 'colors'> {
80+
omit?: string[]
81+
mode?: string
82+
}
83+
export const ColorPalette = ({ omit, mode, ...props }: ColorPaletteProps) => {
7184
const theme = useTheme()
72-
let colors = theme.colors
85+
let colors = theme!.colors
7386

74-
if (mode && colors.modes) {
75-
colors = colors.modes[mode] || colors
87+
if (mode && colors!.modes) {
88+
colors = colors!.modes[mode] || colors
7689
}
7790

7891
return (
@@ -81,7 +94,7 @@ export const ColorPalette = ({
8194
marginLeft: -8,
8295
marginRight: -8,
8396
}}>
84-
<ColorRow {...props} omit={omit} colors={colors} />
97+
<ColorRow {...props} omit={omit} colors={colors as Colors} />
8598
</div>
8699
)
87100
}

packages/style-guide/src/ColorSwatch.js renamed to packages/style-guide/src/ColorSwatch.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
/** @jsx jsx */
2-
import { jsx, get } from 'theme-ui'
3-
import { toHex, toHSL } from './color'
2+
import { ComponentProps } from 'react'
3+
import { jsx, get, ResponsiveStyleValue } from 'theme-ui'
4+
import { toHex } from './color'
45
import { useTheme } from './context'
56

7+
export interface ColorSwatchProps extends ComponentProps<'div'> {
8+
color: string
9+
name?: React.ReactNode
10+
size?: ResponsiveStyleValue<string | number>
11+
label?: boolean
12+
}
613
export const ColorSwatch = ({
714
color,
815
name,
916
size = 128,
1017
label = true,
1118
...props
12-
}) => {
13-
const { colors } = useTheme()
14-
const value = get(colors, color)
19+
}: ColorSwatchProps) => {
20+
const { colors } = useTheme()!
21+
const value = get(colors!, color)
1522
return (
1623
<div {...props} title={`${toHex(value)}`}>
1724
<div

packages/style-guide/src/FontFamily.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { get } from 'theme-ui'
2+
import { useTheme } from './context'
3+
4+
export const FontFamily = ({ name }: { name: string }) => {
5+
const { fonts } = useTheme()!
6+
return get(fonts!, name)
7+
}

packages/style-guide/src/HeadingStyle.js renamed to packages/style-guide/src/HeadingStyle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @jsx jsx */
22
import { jsx } from 'theme-ui'
3-
import TypeStyle from './TypeStyle'
3+
import TypeStyle, { TypeStyleProps } from './TypeStyle'
44

5-
export const HeadingStyle = props => (
5+
export const HeadingStyle = (props: TypeStyleProps) => (
66
<TypeStyle
77
fontFamily="heading"
88
fontWeight="heading"

packages/style-guide/src/ThemeCard.js renamed to packages/style-guide/src/ThemeCard.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/** @jsx jsx */
2-
import { jsx, useThemeUI } from 'theme-ui'
3-
import Card from './Card'
2+
import { jsx } from 'theme-ui'
3+
import Card, { CardProps } from './Card'
44
import ColorPalette from './ColorPalette'
55
import TypeStyle from './TypeStyle'
66

7-
export const ThemeCard = props => {
8-
const { theme } = useThemeUI()
9-
7+
export interface ThemeCardProps extends CardProps {}
8+
export const ThemeCard: React.FC<ThemeCardProps> = props => {
109
return (
1110
<Card
1211
{...props}
@@ -15,10 +14,7 @@ export const ThemeCard = props => {
1514
bg: 'background',
1615
}}>
1716
<TypeStyle />
18-
<ColorPalette
19-
label={false}
20-
size={32}
21-
/>
17+
<ColorPalette label={false} size={32} />
2218
</Card>
2319
)
2420
}

packages/style-guide/src/TypeScale.js

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

0 commit comments

Comments
 (0)