Skip to content

Commit

Permalink
Properly handle pseudos when stringifying CSS object
Browse files Browse the repository at this point in the history
  • Loading branch information
johno committed Sep 29, 2022
1 parent c05e7b0 commit debd3b8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-kangaroos-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compai/css-gui': patch
---

Properly handle pseudos when stringifying CSS object
6 changes: 3 additions & 3 deletions packages/gui/src/lib/codegen/stringify-css-object.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isEmpty, kebabCase } from 'lodash-es'
import { isCSSClass } from '../classes'
import { isElement } from '../elements'
import { isPseudo } from '../pseudos'
import { addPseudoSyntax, hasPseudoSyntax, isPseudo } from '../pseudos'

export const objectToDecls = (obj: any): string => {
return Object.entries(obj)
Expand All @@ -28,8 +28,8 @@ const flattenCSSObject = (
...flattenedGroups,
}
return
} else if (isPseudo(key)) {
const fullSelector = selector + key
} else if (isPseudo(key) || hasPseudoSyntax(key)) {
const fullSelector = selector + addPseudoSyntax(key)
const flattenedGroups = flattenCSSObject(value, fullSelector)
cssDeclGroups = {
...cssDeclGroups,
Expand Down
4 changes: 4 additions & 0 deletions packages/gui/src/lib/pseudos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const stringifySelectorFunction = (
}

export const addPseudoSyntax = (str: string): string => {
if (hasPseudoSyntax(str)) {
return str
}

if (isPseudoClass(str) || isSelectorFunction(str)) {
return ':' + str
} else if (isPseudoElement(str)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const inlineStylesToStyleElement = (

delete node.properties.style

console.log(options)
styleMap[selector] = stringifyCSSObject(
toCSSObject(style, options?.theme),
addCSSClassSyntax(selector)
Expand Down

1 comment on commit debd3b8

@vercel
Copy link

@vercel vercel bot commented on debd3b8 Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

css-gui – ./

css-gui.vercel.app
css-gui-git-main-components-ai.vercel.app
css-gui-components-ai.vercel.app

Please sign in to comment.