Skip to content

Commit 9f44213

Browse files
committed
fix Jest tests
1 parent c83d0eb commit 9f44213

File tree

14 files changed

+35
-32
lines changed

14 files changed

+35
-32
lines changed

packages/editor/src/ColorPicker.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const Picker = CustomPicker<CustomPickerForwardedProps>(
143143
Hue
144144
<Input
145145
{...props}
146-
value={round(props.hsl.h)}
146+
value={props.hsl ? Math.round(props.hsl.h) : ''}
147147
name="hue"
148148
label="h"
149149
// We need to cast to any because @types/react-color does not define types correctly
@@ -156,7 +156,7 @@ export const Picker = CustomPicker<CustomPickerForwardedProps>(
156156
Saturation
157157
<Input
158158
{...props}
159-
value={round(props.hsl.s * 100)}
159+
value={props.hsl ? Math.round(props.hsl.s * 100) : ''}
160160
name="saturation"
161161
label="s"
162162
// We need to cast to any because @types/react-color does not define types correctly
@@ -169,7 +169,7 @@ export const Picker = CustomPicker<CustomPickerForwardedProps>(
169169
Lightness
170170
<Input
171171
{...props}
172-
value={round(props.hsl.l * 100)}
172+
value={props.hsl ? Math.round(props.hsl.l * 100) : ''}
173173
name="lightness"
174174
label="l"
175175
// We need to cast to any because @types/react-color does not define types correctly

packages/editor/src/Combobox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Chevron = () => (
2020
</svg>
2121
)
2222

23-
const keys = {
23+
const keys: { [k: number]: string } = {
2424
38: 'up',
2525
40: 'down',
2626
27: 'escape',
@@ -121,7 +121,7 @@ const Combobox: <T extends string | number>(
121121
const val = options[i]
122122
if (val) onChange(val)
123123
setOpen(false)
124-
input.current.select()
124+
input.current && input.current.select()
125125
}
126126

127127
return (

packages/editor/src/Styles.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EditorContextValue } from './types'
66

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

1111
const style = styles[tag] || {}
1212

@@ -24,7 +24,11 @@ export default ({ tag = 'root' }) => {
2424
return (
2525
<Fragment>
2626
<b>theme.styles.{tag}</b>
27-
<Sx.Typography value={style} onChange={setStyle} theme={context.theme} />
27+
<Sx.Typography
28+
value={style}
29+
onChange={setStyle}
30+
theme={context.theme || undefined}
31+
/>
2832
<Sx.Margin value={style} onChange={setStyle} />
2933
<Sx.Colors value={style} onChange={setStyle} />
3034
</Fragment>

packages/editor/src/Sx/ThemeColorPicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const ThemeColorPicker = ({
2323
// const { colors } = theme || context.theme || {}
2424
const _theme = theme || context.theme || {}
2525
const colors = _theme.colors || {}
26-
const value = colors[props.value] || props.value
26+
const value = props.value && (colors[props.value] || props.value)
2727
const options = [
2828
'transparent',
2929
...Object.keys(colors)
@@ -67,7 +67,7 @@ export const ThemeColorPicker = ({
6767
{...popover}
6868
aria-label="Choose Color"
6969
style={{
70-
zIndex: popover.visible ? 1 : null,
70+
zIndex: popover.visible ? 1 : undefined,
7171
}}>
7272
<GithubPicker
7373
colors={options}

packages/editor/src/Theme/Colors.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @jsx jsx */
22
import { jsx, useThemeUI } from 'theme-ui'
3+
// @ts-ignore: Remove @ts-ignore after @theme-ui/style-guide was transformed to TypeScript
34
import { ColorPalette } from '@theme-ui/style-guide'
45
import ColorPicker from '../ColorPicker'
56
import { EditorContextValue } from '../types'
@@ -18,7 +19,7 @@ const Colors = (props: ColorsProps) => {
1819
const context = useThemeUI() as EditorContextValue
1920
// TODO: Remove any after @theme-ui/color-mode was transformed to TypeScript
2021
const mode = (context as any).colorMode
21-
const { colors } = context.theme
22+
const { colors } = context.theme || {}
2223

2324
const onChange = (key: string) => (val: { hex: string }) => {
2425
let next = {}

packages/editor/src/Theme/FontSizes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EditorContextValue } from '../types'
66

77
const FontSizes = () => {
88
const context = useThemeUI() as EditorContextValue
9-
const { fontSizes = [] } = context.theme
9+
const { fontSizes = [] } = context.theme || {}
1010

1111
const onChange = (key: string) => (
1212
e: React.ChangeEvent<HTMLInputElement>

packages/editor/src/Theme/FontWeights.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const weights = [100, 200, 300, 400, 500, 600, 700, 800, 900]
99

1010
const FontWeights = () => {
1111
const context = useThemeUI() as EditorContextValue
12-
const { fontWeights = {} } = context.theme
12+
const { fontWeights = {} } = context.theme || {}
1313

1414
const onChange = (key: string) => (val: string | number) => {
1515
context.setTheme({

packages/editor/src/Theme/Fonts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const defaultFonts = [
3030

3131
const Fonts = ({ options = defaultFonts }) => {
3232
const context = useThemeUI() as EditorContextValue
33-
const { fonts = {} } = context.theme
33+
const { fonts = {} } = context.theme || {}
3434

3535
const onChange = (key: string) => (val: CSS.FontFamilyProperty) => {
3636
context.setTheme({

packages/editor/src/Theme/LineHeights.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EditorContextValue } from '../types'
66

77
export default () => {
88
const context = useThemeUI() as EditorContextValue
9-
const { lineHeights = {} } = context.theme
9+
const { lineHeights = {} } = context.theme || {}
1010

1111
const onChange = (key: string) => (
1212
e: React.ChangeEvent<HTMLInputElement>

packages/editor/src/Theme/Space.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const defaultSpace = [0, 4, 8, 16, 32, 64, 128, 256, 512]
88

99
const Space = () => {
1010
const context = useThemeUI() as EditorContextValue
11-
const { space = defaultSpace } = context.theme
11+
const { space = defaultSpace } = context.theme || {}
1212

1313
const onChange = (key: string) => (
1414
e: React.ChangeEvent<HTMLInputElement>

0 commit comments

Comments
 (0)