Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add playground #404

Closed
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
25 changes: 25 additions & 0 deletions components/ContentTemplates/FormsTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import dynamic from "next/dynamic"
import { formsPageNavigation } from "../../data/pageNavigationLists"
import { CodeBlock } from "../CodeBlock/CodeBlock"
import { NavPage } from "../NavPage/NavPage"
import { PageUpdated } from "../PageUpdated/PageUpdated"
import { TemplateSection } from "../TemplateSection/TemplateSection"
import { formatCss, formatHtml } from "../../utils"

const Playground = dynamic(() => import("../Playground/Playground"), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason this needs to be dynamic? Why can't it be server side rendered like the rest of the content on the page?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, sandpack provides client-side rendering. When not imported dynamically like above where I set ssr: false, it was causing Hydration problem. To avoid it, I used dynamic rendering as a first step. But it's possible to server render . More on it

I need your opinion here, whether I should use server side rendering here or go ahead with default client side?

ssr: false,
})

export const FormsTemplate = () => {
return (
Expand Down Expand Up @@ -216,6 +222,25 @@ export const FormsTemplate = () => {
screen reader user.
</p>
</TemplateSection>
<TemplateSection sectionName="playground" title="Playground">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs adding to the in-page navigation

<Playground
files={{
"/index.html": {
active: true,
code: formatHtml(`
<form>
<label for="phone">Phone Number (XXX-XXX-XXXX):</label>
<input type="tel" id="phone" name="phone">
</form>

`),
},
"/Wrapper.css": {
code: formatCss(`form{ color:blue;} `),
},
}}
/>
</TemplateSection>
<TemplateSection sectionName="WCAGCriteria" title="WCAG Criteria">
<ul className="list">
<li>
Expand Down
3 changes: 3 additions & 0 deletions components/Playground/Playground.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container {
margin-top: 16px;
}
25 changes: 25 additions & 0 deletions components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Sandpack, SandpackFile } from "@codesandbox/sandpack-react"

import styles from "./Playground.module.css"

type FileType = {
[fileName: string]: SandpackFile
}

type Props = {
files: FileType
}

/**
* Playground component
* @returns Ui for playground
*/
const Playground = (props: Props) => {
return (
<div className={styles.container}>
<Sandpack theme="auto" template="static" files={{ ...props.files }} />
</div>
)
}

export default Playground
Loading