File tree Expand file tree Collapse file tree
react-strict-dom/src/native/css Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,8 +11,33 @@ const { createSuite } = require('../helpers');
1111const { css } = require ( '../react-strict-dom' ) ;
1212const { styles } = require ( '../fixtures' ) ;
1313
14+ function cloneStyle ( style ) {
15+ const result = { } ;
16+ for ( const propName in style ) {
17+ const value = style [ propName ] ;
18+ result [ propName ] =
19+ value != null && typeof value === 'object' && ! Array . isArray ( value )
20+ ? { ...value }
21+ : value ;
22+ }
23+ return result ;
24+ }
25+
1426function runSuite ( options ) {
1527 const { suite, test } = createSuite ( 'css.create' , options ) ;
28+ const dynamicStyles = css . create ( {
29+ small : ( width ) => ( {
30+ ...styles . small ,
31+ width
32+ } ) ,
33+ complex : ( width ) => ( {
34+ ...styles . complex ,
35+ width : {
36+ ...styles . complex . width ,
37+ default : width
38+ }
39+ } )
40+ } ) ;
1641
1742 test ( 'small' , ( ) => {
1843 css . create ( {
@@ -63,6 +88,26 @@ function runSuite(options) {
6388 } ) ;
6489 } ) ;
6590
91+ test ( 'fresh small with units' , ( ) => {
92+ css . create ( {
93+ smallWithUnits : cloneStyle ( styles . smallWithUnits )
94+ } ) ;
95+ } ) ;
96+
97+ test ( 'fresh complex' , ( ) => {
98+ css . create ( {
99+ complex : cloneStyle ( styles . complex )
100+ } ) ;
101+ } ) ;
102+
103+ test ( 'dynamic small' , ( ) => {
104+ dynamicStyles . small ( 1000 ) ;
105+ } ) ;
106+
107+ test ( 'dynamic complex' , ( ) => {
108+ dynamicStyles . complex ( 300 ) ;
109+ } ) ;
110+
66111 suite . run ( ) ;
67112}
68113
Original file line number Diff line number Diff line change @@ -50,15 +50,18 @@ function _create<S extends { +[string]: { +[string]: unknown } }>(styles: S): {
5050}
5151export const create : IStyleX [ 'create '] = _create as $FlowFixMe ;
5252
53- const RE_CAPTURE_VAR_NAME = / ^ v a r \ (- - ( . * ) \) $ / ;
53+ const VAR_FUNCTION_PREFIX = ' var(--' ;
5454export const createTheme = (
5555 baseTokens : Tokens ,
5656 overrides : CustomProperties
5757) : CustomProperties => {
5858 const result : MutableCustomProperties = { $$theme : 'theme' } ;
5959 for ( const key in baseTokens ) {
6060 const varName : string = baseTokens [ key ] ;
61- const normalizedKey = varName . replace ( RE_CAPTURE_VAR_NAME , '$1' ) ;
61+ const normalizedKey =
62+ varName . startsWith ( VAR_FUNCTION_PREFIX ) && varName . endsWith ( ')' )
63+ ? varName . slice ( VAR_FUNCTION_PREFIX . length , - 1 )
64+ : varName ;
6265 result [ normalizedKey ] = overrides [ key ] ;
6366 }
6467 return result ;
You can’t perform that action at this time.
0 commit comments