Skip to content

Commit cad552e

Browse files
committed
feat: fix typings for functions
1 parent 40c1662 commit cad552e

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

example/src/examples/Extreme.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const stylesheet = createStyles(theme => ({
3838
},
3939
{
4040
translateX: {
41-
sm: 10
41+
sm: 10,
42+
md: 20
4243
}
4344
}
4445
]

example/src/examples/MinimalWithCreateStyles.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const stylesheet = createStyles({
2626
text: {
2727
borderWidth: 1,
2828
borderColor: 'purple',
29-
padding: 20
29+
padding: 20,
30+
flex: {
31+
xs: 2,
32+
md: 1
33+
}
3034
}
3135
})

src/createUnistyles.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ export const createUnistyles = <B extends Record<string, number>, T = {}>(breakp
88
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints)
99

1010
return {
11-
createStyles: <S extends CustomNamedStyles<S, B>>(styles: S | CustomNamedStyles<S, B> | CreateStylesFactory<S, T>) => styles as S,
11+
createStyles: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
12+
if (typeof styles === 'function') {
13+
return styles as X
14+
}
15+
16+
return styles as S
17+
},
1218
useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T>) => {
1319
const theme = useContext(UnistylesContext) as T
1420
const dimensions = useDimensions()

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type ScreenSize = {
2020
height: number
2121
}
2222

23-
export type CreateStylesFactory<T, Theme> = (theme: Theme) => T
23+
export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
2424

2525
type StyleProperty<T, B extends Record<string, number>> = {
2626
[K in keyof T]: {

0 commit comments

Comments
 (0)