-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[polaris.shopify.com] Add playroom prototype #7032
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
409f579
Polaris sandbox implementation based on playroom.
gwyneplaine e11fe2a
revert change to floating-ui tooltip config
gwyneplaine b499349
remove darkmode button
gwyneplaine 8dbecb4
Change CopyButton to be more explicit CopyURL
gwyneplaine 13d19c7
update header copy in sandbox to use status badge
gwyneplaine ba33716
fix ts error in SandboxHeader component
gwyneplaine 362731d
minor copy consistency tweaks
gwyneplaine d668c15
update eslintrc to reflect change to playroom build folder
gwyneplaine f3fcb3a
changeset
gwyneplaine 0aa4f5d
Update Sandbox 1-liner on homepage
jesstelford 8a826f2
Sandbox header has distinct title + header with link to help
jesstelford 1948535
Support passing a className prop to buttons on docs site
jesstelford 82a4e7b
Support all css sizes for icons on docs site
jesstelford 7228eac
<StableButton> allows changing button text without the width jumping …
jesstelford a9db423
Restyle Sandbox header to be clearer
jesstelford b39ff26
Rework Sandbox help dialog for better flow and content
jesstelford b91b7b5
Show Sandbox onboarding for firsttime visitors
jesstelford 2d0524f
Add a 320px breakpoint to Playroom Sandbox
jesstelford 91f01bc
Ask Typescript politely to stop being silly
jesstelford bac53ea
Update polaris.shopify.com/src/components/SandboxHelpDialog/SandboxDi…
gwyneplaine 3b63e2b
remove unused styles
gwyneplaine 2e5ea13
minor updates to sandbox CTA to accommodate new website ux updates
gwyneplaine 788e756
remove icons from .gitignore
gwyneplaine 714fda2
remove unused spread argument, remove playroom specific scripts in pk…
gwyneplaine aae80f7
[polaris.shopify.com] Improve design of sandbox (#7366)
martenbjork be05091
Fix up some comments in the playroom config
jesstelford b4703b8
Name a magic number & tweak some comments
jesstelford c5ce2a1
fix inconsistent file naming
gwyneplaine fef8b2f
remove videoRef and initialFocus prop as this was breaking a11y for t…
gwyneplaine db2c33f
Resolve conflicting yarn.lock
jesstelford e4eb0b3
create SandboxContainer component, and replace markup in sandbox.tsx …
gwyneplaine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'polaris.shopify.com': patch | ||
| --- | ||
|
|
||
| Improved the design of the Sandbox feature. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'polaris.shopify.com': minor | ||
| --- | ||
|
|
||
| Added Playroom integration to Polaris docs site. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ dist | |
| node_modules | ||
| /polaris-react/build | ||
| /polaris-react/build-internal | ||
| /polaris.shopify.com/public/sandbox | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| diff --git a/node_modules/playroom/README.md b/node_modules/playroom/README.md | ||
| index 6c82bbe..f05b80b 100644 | ||
| --- a/node_modules/playroom/README.md | ||
| +++ b/node_modules/playroom/README.md | ||
| @@ -160,6 +160,12 @@ export { themeB } from './themeB'; | ||
| // etc... | ||
| ``` | ||
|
|
||
| +## Additional Code Transformations | ||
| + | ||
| +A hook into the internal processing of code is available via the `processCode` option, which is a path to a file that exports a function that receives the code as entered into the editor, and returns the new code to be rendered. | ||
| + | ||
| +One example is [wrapping code in an IIFE for state support](https://github.com/seek-oss/playroom/issues/66). | ||
| + | ||
| ## TypeScript Support | ||
|
|
||
| If a `tsconfig.json` file is present in your project, static prop types are parsed using [react-docgen-typescript](https://github.com/styleguidist/react-docgen-typescript) to provide better autocompletion in the Playroom editor. | ||
| diff --git a/node_modules/playroom/lib/defaultModules/processCode.js b/node_modules/playroom/lib/defaultModules/processCode.js | ||
| new file mode 100644 | ||
| index 0000000..36a436c | ||
| --- /dev/null | ||
| +++ b/node_modules/playroom/lib/defaultModules/processCode.js | ||
| @@ -0,0 +1 @@ | ||
| +export default code => code; | ||
| diff --git a/node_modules/playroom/lib/makeWebpackConfig.js b/node_modules/playroom/lib/makeWebpackConfig.js | ||
| index 56defa7..1e7cf3b 100644 | ||
| --- a/node_modules/playroom/lib/makeWebpackConfig.js | ||
| +++ b/node_modules/playroom/lib/makeWebpackConfig.js | ||
| @@ -54,6 +54,9 @@ module.exports = async (playroomConfig, options) => { | ||
| __PLAYROOM_ALIAS__USE_SCOPE__: playroomConfig.scope | ||
| ? relativeResolve(playroomConfig.scope) | ||
| : require.resolve('./defaultModules/useScope'), | ||
| + __PLAYROOM_ALIAS__PROCESS_CODE__: playroomConfig.processCode | ||
| + ? relativeResolve(playroomConfig.processCode) | ||
| + : require.resolve('./defaultModules/processCode'), | ||
| }, | ||
| }, | ||
| module: { | ||
| diff --git a/node_modules/playroom/src/utils/compileJsx.ts b/node_modules/playroom/src/utils/compileJsx.ts | ||
| index dadea77..82d080c 100644 | ||
| --- a/node_modules/playroom/src/utils/compileJsx.ts | ||
| +++ b/node_modules/playroom/src/utils/compileJsx.ts | ||
| @@ -1,9 +1,18 @@ | ||
| import { transform } from '@babel/standalone'; | ||
| +/* eslint-disable-next-line import/no-unresolved */ | ||
| +import processCode from '__PLAYROOM_ALIAS__PROCESS_CODE__'; | ||
|
|
||
| -export const compileJsx = (code: string) => | ||
| - transform(`<React.Fragment>${code.trim() || ''}</React.Fragment>`, { | ||
| +export const compileJsx = (code: string) => { | ||
| + const processedCode = processCode(code); | ||
| + | ||
| + if (typeof processedCode !== 'string') { | ||
| + throw new Error('processCode function must return a string of code.'); | ||
| + } | ||
| + | ||
| + return transform(`<React.Fragment>${processedCode.trim()}</React.Fragment>`, { | ||
| presets: ['react'], | ||
| }).code; | ||
| +} | ||
|
|
||
| export const validateCode = (code: string) => { | ||
| try { | ||
| diff --git a/node_modules/playroom/src/utils/formatting.ts b/node_modules/playroom/src/utils/formatting.ts | ||
| index a1819bf..70ac15c 100644 | ||
| --- a/node_modules/playroom/src/utils/formatting.ts | ||
| +++ b/node_modules/playroom/src/utils/formatting.ts | ||
| @@ -133,10 +133,10 @@ export const formatAndInsert = ({ | ||
| snippet, | ||
| }); | ||
|
|
||
| - return formatCode({ | ||
| + return { | ||
| code: newCode, | ||
| cursor: updatedCursor, | ||
| - }); | ||
| + }; | ||
| }; | ||
|
|
||
| export const formatForInsertion = ({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| module.exports = { | ||
| root: true, | ||
| extends: ['next/core-web-vitals'], | ||
| ignorePatterns: ['public/playroom'], | ||
| rules: {}, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Not a TS file because our playroom.config.js needs to access it also, and can't understand ts imports. | ||
| module.exports = { | ||
| playroom: { | ||
| baseUrl: '/playroom/', | ||
| }, | ||
| }; | ||
gwyneplaine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import {useEffect, useRef, useState} from 'react'; | ||
| import type {InferGetServerSidePropsType, GetServerSideProps} from 'next'; | ||
| import {useRouter} from 'next/router'; | ||
|
|
||
| import SandboxHeader from '../src/components/SandboxHeader'; | ||
| import SandboxHelpDialog from '../src/components/SandboxHelpDialog'; | ||
| import SandboxContainer from '../src/components/SandboxContainer'; | ||
|
|
||
| export const getServerSideProps: GetServerSideProps = async ({query}) => { | ||
| // We need to pass initial query param to our nested iframe | ||
gwyneplaine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const initialSearchParams = new URLSearchParams( | ||
| query as Record<string, string>, | ||
| ).toString(); | ||
| return { | ||
| props: { | ||
| initialSearchParams: `?${initialSearchParams}`, | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| const MS_DELAY_BEFORE_SHOW_ONBOARDING = 500; | ||
|
|
||
| export default function Sandbox({ | ||
| initialSearchParams, | ||
| }: InferGetServerSidePropsType<typeof getServerSideProps>) { | ||
| const iframeRef = useRef<HTMLIFrameElement>(null); | ||
| const router = useRouter(); | ||
| const searchValue = useRef(''); | ||
| const [isHelpOpen, setHelpIsOpen] = useState(false); | ||
|
|
||
| // After the page has rendered at least once, we might show the help dialog | ||
| // (so it animates onto the screen nicely) | ||
| useEffect(() => { | ||
| const helpTimeout = setTimeout(() => { | ||
| const hasAlreadyBeenOnboarded = localStorage.getItem('onboarded'); | ||
| if (hasAlreadyBeenOnboarded) { | ||
| return; | ||
| } | ||
| localStorage.setItem('onboarded', 'true'); | ||
| setHelpIsOpen(true); | ||
| }, MS_DELAY_BEFORE_SHOW_ONBOARDING); | ||
| return () => clearTimeout(helpTimeout); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| /** | ||
| * We want to mirror the iframes url in the parent (aka browser) to support URL sharing. | ||
| * the iframes onload handler isn't invoked when the iframes url changes so we're polling here instead. | ||
| */ | ||
| const iframeUrlPoll = setInterval(() => { | ||
| if ( | ||
| iframeRef?.current?.contentWindow && | ||
| iframeRef.current.contentWindow.location.search !== searchValue.current | ||
| ) { | ||
| searchValue.current = iframeRef.current.contentWindow.location.search; | ||
| const iframeQueryObj = Object.fromEntries( | ||
| new URLSearchParams(searchValue.current), | ||
| ); | ||
|
|
||
| router.replace( | ||
| { | ||
| query: iframeQueryObj, | ||
| }, | ||
| undefined, | ||
| { | ||
| shallow: true, | ||
| }, | ||
| ); | ||
| } | ||
| }, 200); | ||
| return () => clearInterval(iframeUrlPoll); | ||
| }, [router]); | ||
|
|
||
| return ( | ||
| <SandboxContainer> | ||
| <SandboxHeader | ||
| setHelpIsOpen={setHelpIsOpen} | ||
| url={typeof window !== 'undefined' ? window.location.href : ''} | ||
| /> | ||
| <SandboxHelpDialog {...{isOpen: isHelpOpen, setIsOpen: setHelpIsOpen}} /> | ||
| <iframe | ||
| id="main" | ||
| ref={iframeRef} | ||
| style={{ | ||
| border: 0, | ||
| padding: 0, | ||
| margin: 0, | ||
| }} | ||
| src={`/playroom${initialSearchParams}`} | ||
| width="100%" | ||
| height="100%" | ||
| /> | ||
| </SandboxContainer> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.