diff --git a/example/storybook/src/api/Specificity/Specificity.tsx b/example/storybook/src/api/Specificity/Specificity.tsx index c3fe0e0ec..0c4e89df0 100644 --- a/example/storybook/src/api/Specificity/Specificity.tsx +++ b/example/storybook/src/api/Specificity/Specificity.tsx @@ -57,11 +57,16 @@ export function Specificity({ ...args }) { variant="redbox" states={{ hover: true }} bg="$red500" - // sx={{ - // _dark: { - // bg: '$amber900', - // }, - // }} + sx={{ + '_dark': { + bg: '$blue500', + }, + '@md': { + _dark: { + bg: '$green400', + }, + }, + }} // sx={{ style: { bg: '$amber400' } }} > bluebox - sm diff --git a/packages/react/src/utils/cssify/utils/common.ts b/packages/react/src/utils/cssify/utils/common.ts index b0cbc94f3..fe7b65a3d 100644 --- a/packages/react/src/utils/cssify/utils/common.ts +++ b/packages/react/src/utils/cssify/utils/common.ts @@ -14,20 +14,26 @@ const createCssRule = ( prefixColorMode: string ) => { let rule; - const dataMediaSelector = prefixClassName - ? `.${prefixClassName} [data-${dataType}~="${stringHash}"]` - : `[data-${dataType}~="${stringHash}"]`; + const dataMediaSelector = `[data-${dataType}~="${stringHash}"]`; if (isMedia(mediaQuery) && isColorScheme(colorSchemeQuery)) { // rule = `${mediaQuery} {${colorSchemeQuery} {${dataMediaSelector} ${css}} .${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}}`; - rule = `${mediaQuery} {.${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}}`; + rule = prefixClassName + ? `${mediaQuery} {.${prefixClassName}.${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}}` + : `${mediaQuery} {.${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}}`; } else if (isMedia(mediaQuery)) { - rule = `${mediaQuery} {${dataMediaSelector} ${css}}`; + rule = prefixClassName + ? `${mediaQuery} {.${prefixClassName} ${dataMediaSelector} ${css}}` + : `${mediaQuery} {${dataMediaSelector} ${css}}`; } else if (isColorScheme(colorSchemeQuery)) { // rule = `${colorSchemeQuery} {${dataMediaSelector} ${css}} .${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}`; - rule = `.${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}`; + rule = prefixClassName + ? `.${prefixClassName}.${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}` + : `.${prefixColorMode}${colorMode} ${dataMediaSelector} ${css}`; } else { - rule = `${dataMediaSelector}${mediaQuery} ${css}`; + rule = prefixClassName + ? `.${prefixClassName} ${dataMediaSelector}${mediaQuery} ${css}` + : `${dataMediaSelector}${mediaQuery} ${css}`; } return rule;