Skip to content

Commit

Permalink
fix: ssr playground error (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmartinezmedia authored May 21, 2024
1 parent 13464ad commit b889206
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
3 changes: 3 additions & 0 deletions apps/web-demo/src/app/converter/_preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import * as components from 'katcn';
import { getStyles } from 'katcn/getStyles';
import * as React from 'react';

const componentNames = Object.keys(components).join(', ');
Expand All @@ -9,6 +10,7 @@ export function Preview({ code }: { code: string }) {
const fnString = new Function(`
return function ({
React,
getStyles,
${componentNames}
}) {
${code}
Expand All @@ -18,6 +20,7 @@ export function Preview({ code }: { code: string }) {

const Comp = fnString({
React,
getStyles,
...components,
});

Expand Down
34 changes: 12 additions & 22 deletions apps/web-demo/src/app/playground/[id]/preview/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
'use client';

import { PlaygroundDataContext } from '@/lib/context';
import {
Avatar,
Box,
HStack,
Icon,
Image,
Pressable,
Text,
TextInput,
VStack,
} from 'katcn';
import * as components from 'katcn';
import { getStyles } from 'katcn/getStyles';
import { useContext } from 'react';
import * as React from 'react';
import { jsxDEV } from 'react/jsx-dev-runtime';
import { jsx } from 'react/jsx-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';

const componentNames = Object.keys(components).join(', ');

export default function Page() {
const { css, js } = useContext(PlaygroundDataContext);

if (!css || !js) {
return null;
}

const fnString = new Function(`
function renderComp({ jsx, jsxDEV, getStyles, Box, HStack, VStack, Icon, Image, Pressable, Text, TextInput, Avatar }) {
function renderComp({ jsx, jsxDEV, jsxs, React, getStyles, ${componentNames} }) {
${js}
return Example;
}
Expand All @@ -33,17 +28,12 @@ export default function Page() {
const Comp = fnString({
jsx,
jsxDEV,
jsxs,
React,
getStyles,
Box,
HStack,
VStack,
Icon,
Image,
Pressable,
Text,
TextInput,
Avatar,
...components,
});

return (
<div>
<style>{css}</style>
Expand Down
1 change: 0 additions & 1 deletion apps/web-demo/src/ui/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ function HueShade({
.getPropertyValue('background-color');

const oklchMatch = oklchRegex.exec(oklchString);
console.log('oklchMatch', oklchMatch);
if (oklchMatch) {
const lightness = Number.parseFloat(oklchMatch[1]);
const chroma = Number.parseFloat(oklchMatch[2]);
Expand Down

0 comments on commit b889206

Please sign in to comment.