Skip to content

Commit debd3b8

Browse files
committed
Properly handle pseudos when stringifying CSS object
1 parent c05e7b0 commit debd3b8

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

.changeset/clever-kangaroos-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compai/css-gui': patch
3+
---
4+
5+
Properly handle pseudos when stringifying CSS object

packages/gui/src/lib/codegen/stringify-css-object.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isEmpty, kebabCase } from 'lodash-es'
22
import { isCSSClass } from '../classes'
33
import { isElement } from '../elements'
4-
import { isPseudo } from '../pseudos'
4+
import { addPseudoSyntax, hasPseudoSyntax, isPseudo } from '../pseudos'
55

66
export const objectToDecls = (obj: any): string => {
77
return Object.entries(obj)
@@ -28,8 +28,8 @@ const flattenCSSObject = (
2828
...flattenedGroups,
2929
}
3030
return
31-
} else if (isPseudo(key)) {
32-
const fullSelector = selector + key
31+
} else if (isPseudo(key) || hasPseudoSyntax(key)) {
32+
const fullSelector = selector + addPseudoSyntax(key)
3333
const flattenedGroups = flattenCSSObject(value, fullSelector)
3434
cssDeclGroups = {
3535
...cssDeclGroups,

packages/gui/src/lib/pseudos.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export const stringifySelectorFunction = (
4242
}
4343

4444
export const addPseudoSyntax = (str: string): string => {
45+
if (hasPseudoSyntax(str)) {
46+
return str
47+
}
48+
4549
if (isPseudoClass(str) || isSelectorFunction(str)) {
4650
return ':' + str
4751
} else if (isPseudoElement(str)) {

packages/gui/src/lib/transformers/inline-styles-to-style-element.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const inlineStylesToStyleElement = (
3131

3232
delete node.properties.style
3333

34-
console.log(options)
3534
styleMap[selector] = stringifyCSSObject(
3635
toCSSObject(style, options?.theme),
3736
addCSSClassSyntax(selector)

0 commit comments

Comments
 (0)