diff --git a/.changeset/nervous-worms-confess.md b/.changeset/nervous-worms-confess.md new file mode 100644 index 00000000..d9c755e0 --- /dev/null +++ b/.changeset/nervous-worms-confess.md @@ -0,0 +1,5 @@ +--- +'@compai/css-gui': patch +--- + +Add HTML codegen diff --git a/apps/docs/pages/html-editor.tsx b/apps/docs/pages/html-editor.tsx index 33da30f4..a048cb36 100644 --- a/apps/docs/pages/html-editor.tsx +++ b/apps/docs/pages/html-editor.tsx @@ -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', @@ -218,25 +218,29 @@ export default function HtmlEditorExample() { const [html, setHtml] = useState(initialValue) return ( - -
+
-
- -
-
- -
+ }} + > +
+ +
+
+
- +
+ ) } diff --git a/packages/gui/src/lib/codegen/html.ts b/packages/gui/src/lib/codegen/html.ts new file mode 100644 index 00000000..2b3096b6 --- /dev/null +++ b/packages/gui/src/lib/codegen/html.ts @@ -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 +} diff --git a/packages/gui/src/lib/codegen/index.ts b/packages/gui/src/lib/codegen/index.ts index 0aafb28f..2526e4c1 100644 --- a/packages/gui/src/lib/codegen/index.ts +++ b/packages/gui/src/lib/codegen/index.ts @@ -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 => {