Skip to content

Commit e116b85

Browse files
committed
Ensure theme is passed to style element stringification
1 parent 8ddcf40 commit e116b85

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.changeset/two-waves-help.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+
Ensure theme is passed to style element stringification

packages/gui/src/lib/codegen/enhance-sfc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const h = (theme: Theme) => (tagName: string, props: any, children?: any[]) => {
2424

2525
export const enhanceSFC = async (node: HtmlNode, options: CodegenOptions) => {
2626
const root = editorSchemaToHast(node, { addSlotTagSyntax: true })
27-
const { node: htmlNode, styles } = inlineStylesToStyleElement(root)
27+
const { node: htmlNode, styles } = inlineStylesToStyleElement(root, options)
2828
// @ts-ignore
2929
const functionBody = stringifyHastNode(toH(h(options?.theme), htmlNode))
3030

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import hash from '../hash'
55
import { stringifyCSSObject } from '../codegen/stringify-css-object'
66
import { toCSSObject } from '../codegen/to-css-object'
77
import { addCSSClassSyntax } from '../classes'
8+
import { CodegenOptions } from '../codegen/types'
89

9-
export const inlineStylesToStyleElement = (node: any) => {
10+
export const inlineStylesToStyleElement = (
11+
node: any,
12+
options: CodegenOptions
13+
) => {
1014
const styleMap: Record<string, any> = {}
1115
const processedTree = unified()
1216
.use(() => (tree) => {
@@ -27,8 +31,9 @@ export const inlineStylesToStyleElement = (node: any) => {
2731

2832
delete node.properties.style
2933

34+
console.log(options)
3035
styleMap[selector] = stringifyCSSObject(
31-
toCSSObject(style),
36+
toCSSObject(style, options?.theme),
3237
addCSSClassSyntax(selector)
3338
)
3439
})

0 commit comments

Comments
 (0)