Skip to content

Commit 517fc35

Browse files
committed
Fix packages/editor types and use CSS.Properties instead of Fallback
1 parent 9dce7ba commit 517fc35

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

packages/css/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as CSS from 'csstype'
77

8-
type StandardCSSProperties = CSS.PropertiesFallback<number | string>
8+
type StandardCSSProperties = CSS.Properties<number | string>
99

1010
/**
1111
* The `css` function accepts arrays as values for mobile-first responsive styles.

packages/editor/src/Styles.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/** @jsx jsx */
2-
import { jsx, useThemeUI } from 'theme-ui'
2+
import { jsx, useThemeUI, AllThemeUICSSProperties } from 'theme-ui'
33
import { Fragment } from 'react'
44
import Sx from './Sx'
55
import { EditorContextValue } from './types'
66

7-
export default ({ tag = 'root' }) => {
7+
export default function Styles({ tag = 'root' }) {
88
const context = useThemeUI() as EditorContextValue
99
const { styles = {} } = context.theme || {}
1010

11-
const style = styles[tag] || {}
11+
// unsafe
12+
const style = (styles[tag] || {}) as AllThemeUICSSProperties
1213

1314
const setStyle = next => {
1415
context.setTheme({

packages/editor/src/Sx/Space.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
/** @jsx jsx */
2-
import { jsx, Theme, SxStyleProp } from 'theme-ui'
2+
import { jsx, SxStyleProp, AllThemeUICSSProperties } from 'theme-ui'
33
import { useState, useEffect } from 'react'
44
import { Field, Label, Checkbox } from '@theme-ui/components'
55

66
export interface SpaceProps {
77
tag?: string
88
property?: 'margin' | 'padding'
9-
value?: Theme['space']
9+
value?: Partial<
10+
Pick<
11+
AllThemeUICSSProperties,
12+
| 'paddingTop'
13+
| 'marginTop'
14+
| 'paddingBottom'
15+
| 'marginBottom'
16+
| 'paddingLeft'
17+
| 'marginLeft'
18+
| 'paddingRight'
19+
| 'marginRight'
20+
| 'paddingX'
21+
| 'paddingY'
22+
| 'marginX'
23+
| 'marginY'
24+
| 'mt'
25+
| 'pt'
26+
| 'mb'
27+
| 'pb'
28+
| 'ml'
29+
| 'pl'
30+
| 'mr'
31+
| 'pr'
32+
| 'px'
33+
| 'py'
34+
| 'mx'
35+
| 'my'
36+
>
37+
>
1038
onChange: (sx: SxStyleProp) => void
1139
}
1240

packages/editor/src/Sx/ThemeColorPicker.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ export const ThemeColorPicker = ({
2323
// const { colors } = theme || context.theme || {}
2424
const _theme = theme || context.theme || {}
2525
const colors = _theme.colors || {}
26-
const value = props.value && (colors[props.value] || props.value)
26+
// bug: only supports flat color scales
27+
const value = String(props.value && (colors[props.value] || props.value))
2728
const options = [
2829
'transparent',
2930
...Object.keys(colors)
3031
.map((key) => colors[key])
31-
.filter((color) => typeof color === 'string')
32+
.filter((color): color is string => typeof color === 'string')
3233
.filter((color) => /^#/.test(color)),
3334
]
3435
const onChange = (color: ColorState) => {

packages/editor/src/Sx/Typography.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ import { Fragment } from 'react'
44
import { Field } from '@theme-ui/components'
55
import Combobox from '../Combobox'
66

7-
type OnChangeArg =
8-
| { fontFamily: string }
9-
| { fontSize: number }
10-
| { fontWeight: string }
11-
| { lineHeight: string }
7+
type TypographyPropsValue = {
8+
fontFamily?: string
9+
fontSize?: string | number
10+
fontWeight?: string | number
11+
lineHeight?: string | number
12+
}
13+
14+
type OnChangeArg = {
15+
[P in keyof TypographyPropsValue]: {
16+
[K in P]: Exclude<TypographyPropsValue[P], undefined>
17+
}
18+
}[keyof TypographyPropsValue]
19+
1220
export interface TypographyProps {
1321
tag?: string
14-
value?: {
15-
fontFamily?: string
16-
fontSize?: string | number
17-
fontWeight?: string
18-
lineHeight?: string
19-
}
22+
value?: TypographyPropsValue
2023
theme?: Theme
2124
onChange: (arg: OnChangeArg) => void
2225
}
@@ -40,7 +43,7 @@ export const SxTypography = ({
4043
name={prefixName('fontFamily')}
4144
label="Font Family"
4245
value={fontFamily || ''}
43-
onChange={(fontFamily) => {
46+
onChange={fontFamily => {
4447
onChange({ fontFamily })
4548
}}
4649
options={['inherit', ...Object.keys(fonts)]}
@@ -56,7 +59,7 @@ export const SxTypography = ({
5659
label="Font Size"
5760
value={fontSize || ''}
5861
type="number"
59-
onChange={(e) => {
62+
onChange={e => {
6063
const fontSize = Number(e.target.value)
6164
onChange({ fontSize })
6265
}}
@@ -65,7 +68,7 @@ export const SxTypography = ({
6568
name={prefixName('fontWeight')}
6669
label="Font Weight"
6770
value={fontWeight || ''}
68-
onChange={(fontWeight) => {
71+
onChange={fontWeight => {
6972
onChange({ fontWeight })
7073
}}
7174
options={['inherit', ...Object.keys(fontWeights)]}
@@ -74,7 +77,7 @@ export const SxTypography = ({
7477
name={prefixName('lineHeight')}
7578
label="Line Height"
7679
value={lineHeight || ''}
77-
onChange={(lineHeight) => {
80+
onChange={lineHeight => {
7881
onChange({ lineHeight })
7982
}}
8083
options={['inherit', ...Object.keys(lineHeights)]}

packages/editor/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Theme, ContextValue } from 'theme-ui'
22

3-
export type EditorContextValue = ContextValue & {
3+
export interface EditorContextValue extends ContextValue {
44
setTheme: React.Dispatch<Theme>
55
}

packages/theme-ui/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export {
2222
CSSProperties,
2323
CSSPseudoSelectorProps,
2424
ResponsiveStyleValue,
25-
SystemCssProperties,
25+
AllThemeUICSSProperties,
26+
ThemeUIRecursiveCSSProperties,
2627
SystemStyleObject,
2728
Theme,
2829
TLengthStyledSystem,

0 commit comments

Comments
 (0)