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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shrilakshmishastry
Copy link

@shrilakshmishastry shrilakshmishastry commented Aug 10, 2024

Describe your changes

Introduce a playground where users can interact with code and look at live demos. The idea is to introduce playground initially and later maybe convert it into a challenge ground, like we have in reactdev

what is Playground?

  • A final code of the accessibility best practice that is described throughout the pattern template. This allows the user to interact with code, see the output, and open the code in codesandbox.

There are 4-5 options available to embed editor, I have listed them here.

I am currently using sandpack-react. An open source, well-documented library with a lot of functionality out of the box.

I have tried out this in the form component. Need opinion and corrections to improve.

Screenshots

Screen.Recording.2024-08-10.at.4.55.32.PM.mov

image

Link to issue

Closes # issue-403

Checklist before requesting a review

  • I have performed a self-review of my code.
  • Followed the repository's Contributing Guidelines.
  • I ran the app and tested it locally to verify that it works as expected.
  • I have checked my code with an automatic accessibility tool such as Axe Dev Tools or Wave
    and it shows no errors.

Copy link

Hello @shrilakshmishastry, thanks for raising a pull request in this project. The maintainers of this project are volunteers so please be understanding if it takes time before you get a response. We still appreciate your help with creating pull requests!

Copy link
Member

@EmmaDawsonDev EmmaDawsonDev left a comment

Choose a reason for hiding this comment

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

Some nice work so far. Things I'm concerned about:

  1. The current colours in the sandbox do not meet colour contrast thresholds of 4.5:1. Is there a way to update the theme to find one that has good colour contrast and also matches the current site theme in light/dark mode?
  2. The component is not keyboard accessible meaning anyone using a keyboard is unable to edit the code. Is there something that can be done about this?
  3. How does it work with JS?
  4. I tried making edits to the code and nothing happened. Then after about 3 minutes the preview crashed. I would expect if it was an interactive playground that any edits I make would be reflected in place without me having to go to open the sandbox in full.

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?

@@ -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

@shrilakshmishastry
Copy link
Author

shrilakshmishastry commented Aug 13, 2024

Some nice work so far. Things I'm concerned about:

  1. The current colours in the sandbox do not meet colour contrast thresholds of 4.5:1. Is there a way to update the theme to find one that has good colour contrast and also matches the current site theme in light/dark mode?
  1. The component is not keyboard accessible meaning anyone using a keyboard is unable to edit the code. Is there something that can be done about this?
  1. How does it work with JS?
  2. I tried making edits to the code and nothing happened. Then after about 3 minutes the preview crashed. I would expect if it was an interactive playground that any edits I make would be reflected in place without me having to go to open the sandbox in full.

Hey @EmmaDawsonDev 👋

(Answering to above points according to their numbers)

  1. Yes, There are themes available. Here is the link to theme. Can you please help me here to select the one that suits the site theme and matches color contrast thresholds? Also can you please tell me how did you test color contrast?

  2. I will check and come back on keyboard accessibility of editor.

  3. This supports vanilla js and all framework of js. You need to pass the required template to SandPack or SandpackProvider

  <SandpackProvider template="react">
    <SandpackLayout>
      <SandpackPreview />
      <SandpackCodeEditor />
    </SandpackLayout>
  </SandpackProvider>

Replace the react with the template you require. More about templates.

  1. Can you please provide more details on error (screen shot of error), the node, yarn version? also screen recording ? So I can reproduce. As you can see in above video it worked well for me 😬

@shrilakshmishastry
Copy link
Author

Some nice work so far. Things I'm concerned about:

  1. The current colours in the sandbox do not meet colour contrast thresholds of 4.5:1. Is there a way to update the theme to find one that has good colour contrast and also matches the current site theme in light/dark mode?
  2. The component is not keyboard accessible meaning anyone using a keyboard is unable to edit the code. Is there something that can be done about this?
  3. How does it work with JS?
  4. I tried making edits to the code and nothing happened. Then after about 3 minutes the preview crashed. I would expect if it was an interactive playground that any edits I make would be reflected in place without me having to go to open the sandbox in full.

Hey @EmmaDawsonDev 👋

(Answering to above points according to their numbers)

  1. Yes, There are themes available. Here is the link to theme. Can you please help me here to select the one that suits site theme and matches color contrast thresholds?
  2. I will check and come back on keyboard accessibility of editor.
  3. This supports vanilla js and all framework of js. You need to pass the required template to SandPack or SandpackProvider like
  <SandpackProvider template="react">
    <SandpackLayout>
      <SandpackPreview />
      <SandpackCodeEditor />
    </SandpackLayout>
  </SandpackProvider>

Replace the react with the template you require. More about templates.

  1. Can you please provide more details on error (screen shot of error), the node, yarn version? also screen recording ? So I can reproduce. As you can see in above video it worked well for me 😬

reported accessibility issue in sandpack codesandbox/sandpack#1173

@shrilakshmishastry
Copy link
Author

I have noticed few things here,

  1. for voice-over that reads all the tags, the editor is available, and it's possible to edit the code.
  2. The top buttons have the role of tab. But they do not follow the tab accessibility pattern.
  3. I guess you might have missed, editor is accessible via the tab, when focused, you need to explicitly click on enter key to activate it and esc key to come out of it
image

@shrilakshmishastry
Copy link
Author

Solving editor accessibility here codesandbox/sandpack#1184

@EmmaDawsonDev
Copy link
Member

Apologies for not getting to this very quickly! I've just started a new job so I've been a bit overwhelmed with new information and will also be away quite a bit in the next couple of weeks travelling.

@EmmaDawsonDev
Copy link
Member

Here's a screenshot of the sandbox when I open it. My system is set automatically to lightmode but the sandbox doesn't seem to change even when I switch the page to darkmode. The html tags in green are too light and the grey icons/text on the grey buttons don't have enough contrast either
Sandbox in lightmode with axe dev tools showing 13 contrast issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants