File tree Expand file tree Collapse file tree 3 files changed +27
-12
lines changed
Expand file tree Collapse file tree 3 files changed +27
-12
lines changed Original file line number Diff line number Diff line change 1- import { Theme } from './config'
2- import multiThemePlugin from '.'
3- import { MultiThemePluginOptions } from './utils/optionsUtils'
4- import { defaultThemeName } from './utils/optionsUtils'
5- import { PluginAPI } from 'tailwindcss/types/config'
61import { mock } from 'jest-mock-extended'
2+ import { PluginAPI } from 'tailwindcss/types/config'
3+ import multiThemePlugin from '.'
4+ import { Theme } from './config'
5+ import { MultiThemePluginOptions , defaultThemeName } from './utils/optionsUtils'
76
87describe ( 'multiThemePlugin' , ( ) => {
98 describe ( 'handler' , ( ) => {
@@ -25,6 +24,9 @@ describe('multiThemePlugin', () => {
2524 colors : {
2625 primary : 'another' ,
2726 secondary : 'something'
27+ } ,
28+ spacing : {
29+ '0.5' : '10px'
2830 }
2931 }
3032 }
@@ -65,7 +67,8 @@ describe('multiThemePlugin', () => {
6567 expect ( api . addBase ) . toHaveBeenCalledWith ( {
6668 [ `.escaped-${ theme . name } ` ] : {
6769 '--colors-primary' : 'another' ,
68- '--colors-secondary' : 'something'
70+ '--colors-secondary' : 'something' ,
71+ '--spacing-0\\.5' : '10px'
6972 }
7073 } )
7174 }
Original file line number Diff line number Diff line change 11import { isColor , toRgb , withOpacity } from './colorUtils'
22
3+ /**
4+ * Code copied from the tailwind official codebase
5+ * @link https://github.com/tailwindlabs/tailwindcss/blob/fbbba6f67f73c3a4f9571649c3fc27006446d8f4/src/lib/regex.js#L70
6+ */
7+ const REGEX_SPECIAL = / [ \\ ^ $ . * + ? ( ) [ \] { } | ] / g
8+ const REGEX_HAS_SPECIAL = RegExp ( REGEX_SPECIAL . source )
9+ export const escape = ( string ?: string ) : string => {
10+ return string && REGEX_HAS_SPECIAL . test ( string )
11+ ? string . replace ( REGEX_SPECIAL , '\\$&' )
12+ : string || ''
13+ }
14+
315/**
416 * @param value - a custom prop value
517 * @return the value converted to a string of its rgb components comma separated if it is a color else it returns the value unaltered
@@ -27,9 +39,9 @@ export const toCustomPropName = (valuePath: string[]): string => {
2739 ) } "`
2840 )
2941 }
30- return `-- ${ valuePath
31- . filter ( step => step . toLowerCase ( ) !== 'default' )
32- . join ( '-' ) } `
42+ return escape (
43+ `-- ${ valuePath . filter ( step => step . toLowerCase ( ) !== 'default' ) . join ( '-' ) } `
44+ )
3345}
3446
3547/**
Original file line number Diff line number Diff line change 1+ import { mock } from 'jest-mock-extended'
2+ import { PluginAPI } from 'tailwindcss/types/config'
3+ import { PluginUtils , TailwindExtension , Theme } from '../config'
14import {
25 resolveThemeExtensionAsCustomProps ,
36 resolveThemeExtensionsAsTailwindExtension
47} from './themeUtils'
5- import { PluginUtils , TailwindExtension , Theme } from '../config'
6- import { PluginAPI } from 'tailwindcss/types/config'
7- import { mock } from 'jest-mock-extended'
88
99describe ( 'themeUtils' , ( ) => {
1010 let pluginUtils : PluginUtils
You can’t perform that action at this time.
0 commit comments