File tree Expand file tree Collapse file tree 4 files changed +27
-5
lines changed Expand file tree Collapse file tree 4 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -175,5 +175,26 @@ describe('#style', () => {
175175 fontFamily : 'arial' ,
176176 } )
177177 } )
178+
179+ describe ( 'mixins' , ( ) => {
180+ const fontSize = style ( {
181+ prop : 'fontSize' ,
182+ key : 'fontSizes' ,
183+ } )
184+ const text = style ( {
185+ prop : 'text' ,
186+ key : 'texts' ,
187+ cssProperty : ( value ) => fontSize . apply ( { fontSize : value } ) ,
188+ } )
189+
190+ it ( 'supports functions' , ( ) => {
191+ const theme = {
192+ fontSizes : { xs : '0.8rem' } ,
193+ texts : { xs : 2 } ,
194+ }
195+
196+ expect ( text ( { theme, text : 'xs' } ) ) . toEqual ( { fontSize : 2 } )
197+ } )
198+ } )
178199 } )
179200} )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 identity ,
1111 merge ,
1212 assign ,
13+ cascade ,
1314} from '@xstyled/util'
1415import { getBreakpoints , getBreakpointMin , mediaMinWidth } from './media'
1516import { defaultStates } from './defaultStates'
@@ -193,7 +194,7 @@ function styleFromValue(
193194 if ( obj ( value ) ) return null
194195 if ( cache . has ( value ) ) return cache . get ( value )
195196 const computedValue = themeGet ( value ) ( props )
196- const style = mixin ( computedValue )
197+ const style = cascade ( mixin ( computedValue ) , props )
197198 cache . set ( value , style )
198199 return style
199200}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export interface BackgroundProps<T extends ITheme = Theme> {
3636export const background = style ( {
3737 prop : 'background' ,
3838 cssProperty : ( value ) => ( {
39- background : gradientBackgrounds [ value ] || value ,
39+ background : gradientBackgrounds [ value as string ] || value ,
4040 } ) ,
4141} )
4242
@@ -112,7 +112,7 @@ export interface BackgroundImageProps<T extends ITheme = Theme> {
112112export const backgroundImage = style ( {
113113 prop : 'backgroundImage' ,
114114 cssProperty : ( value ) => ( {
115- backgroundImage : gradientBackgrounds [ value ] || value ,
115+ backgroundImage : gradientBackgrounds [ value as string ] || value ,
116116 } ) ,
117117} )
118118
Original file line number Diff line number Diff line change @@ -38,12 +38,12 @@ export type IStyles = Record<string, unknown>
3838export type IBreakpoints = Record < string | number , number >
3939export type IPropsWithTheme < TTheme extends ITheme > = IProps & { theme : TTheme }
4040
41- export type Mixin = ( value : any ) => IStyles | null | undefined
42-
4341export interface StyleGetter {
4442 ( props : IProps ) : any
4543}
4644
45+ export type Mixin = ( value : unknown ) => IStyles | null | undefined | StyleGetter
46+
4747export type Breakpoints < TTheme extends ITheme > = TTheme extends {
4848 breakpoints : IBreakpoints
4949}
You can’t perform that action at this time.
0 commit comments