Skip to content

Commit 161ae5b

Browse files
authored
Merge pull request #620 from components-ai/style-string-and-attrs
Use a style string rather than object
2 parents d917e6a + 8db9856 commit 161ae5b

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

.changeset/strong-cheetahs-tap.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+
Use style string and don't destructure slots as attrs

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isCSSClass } from '../classes'
33
import { isElement } from '../elements'
44
import { isPseudo } from '../pseudos'
55

6-
const objectToDecls = (obj: any): string => {
6+
export const objectToDecls = (obj: any): string => {
77
return Object.entries(obj)
88
.map(([key, value]: [string, any]) => {
99
return ` ${kebabCase(key)}: ${value};`

packages/gui/src/lib/codegen/stringify-hast-node-as-html.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isArray, isNumber, isObject, kebabCase } from 'lodash-es'
22
import escapeHtml from 'escape-html'
33
import { isElement, isVoidElement } from '../elements'
44
import { getSlots, isSlot } from './util'
5+
import { objectToDecls } from './stringify-css-object'
56

67
// TODO: This can, and should, be done at the AST level in the future
78
export const formatTagName = (node: any) => {
@@ -23,6 +24,10 @@ export const stringifyHastNode = (node: any) => {
2324
return node.value || node
2425
}
2526

27+
if (node.props.style) {
28+
node.props.style = objectToDecls(node.props.style).trim()
29+
}
30+
2631
if (isVoidElement(node.tagName)) {
2732
return `<${formatTagName(node)} ${stringifyProps(node.props)} />`
2833
}

packages/gui/src/lib/codegen/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export const stringifySlotInProp = (value: any, outerProps: any) => {
5555
export const isText = (value: HtmlNode) => value?.type === 'text'
5656
export const isSlot = (value: HtmlNode) => value?.type === 'slot'
5757

58+
// TODO: This should find attr slots only
5859
export const getAttrSyntax = (value: HtmlNode) => {
60+
return ''
5961
const slots = getSlots(value)
6062

6163
if (!slots.length) {

0 commit comments

Comments
 (0)