Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nervous-worms-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compai/css-gui': patch
---

Add HTML codegen
58 changes: 31 additions & 27 deletions apps/docs/pages/html-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ const initialValue: any = {
style: {
color: 'primary',
fontSize: [
{
value: 4,
unit: 'rem',
},
{
value: 6,
unit: 'rem',
},
{
value: 10,
unit: 'rem',
},
{
value: 4,
unit: 'rem',
},
{
value: 6,
unit: 'rem',
},
{
value: 10,
unit: 'rem',
},
],
fontWeight: 900,
fontFamily: 'Inter',
Expand Down Expand Up @@ -218,25 +218,29 @@ export default function HtmlEditorExample() {
const [html, setHtml] = useState(initialValue)

return (
<HtmlEditorProvider value={html}>
<div sx={{
display: 'grid',
<HtmlEditorProvider value={html}>
<div
sx={{
display: 'grid',
gridTemplateAreas: '"nav content"',
gridTemplateColumns: 'auto 1fr',
gridTemplateRows: 'auto',
height: 'calc(100vh - 64px)',
}}>
<div sx={{
gridArea: 'nav',
maxheight: 'calc(100vh - 64px)',
overflow: 'auto',
}}>
<HtmlEditor onChange={setHtml} />
</div>
<div sx={{ overflow: 'auto', width: '100%', gridArea: 'content', }}>
<HtmlRenderer value={html} />
</div>
}}
>
<div
sx={{
gridArea: 'nav',
maxheight: 'calc(100vh - 64px)',
overflow: 'auto',
}}
>
<HtmlEditor onChange={setHtml} />
</div>
<div sx={{ overflow: 'auto', width: '100%', gridArea: 'content' }}>
<HtmlRenderer value={html} />
</div>
</HtmlEditorProvider>
</div>
</HtmlEditorProvider>
)
}
14 changes: 14 additions & 0 deletions packages/gui/src/lib/codegen/html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { HtmlNode } from '../../components/html/types'

export const html = async (node: HtmlNode) => {
const res = await fetch('https://components.ai/api/v1/gui/export/html', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ html: node }),
})

const docHtml: string = await res.text()
return docHtml
}
2 changes: 2 additions & 0 deletions packages/gui/src/lib/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { isNestedSelector, isNestedSelectorWithSyntax } from '../util'
import { stringifyCSSObject } from './stringify-css-object'
import { toCSSObject } from './to-css-object'

export { html } from './html'

const DEFAULT_BREAKPOINTS_COUNT = 3

const getStylesByBreakpoint = (obj: any, breakpoint: number): any => {
Expand Down