-
Notifications
You must be signed in to change notification settings - Fork 8
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
Interactive components in playground #139
base: 1.4
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach a lot.
I am wondering how CSS handling will pan out though. Especially because what webpack calls publicPath is trickier for CSS + assets than just vanilla ESM.
How attached are we to JSX Elements being the entirety of a playground? iirc, it's supposed to be sugar to allow designers to get started with a playground without too much knowledge of JSX. A little bit of syntactic salt would make transforming playgrounds into executable code much simpler. The example @mariuswilms has above would be <Card
headline="Headline"
actions={
<ButtonGroup>
<Button>Label</Button>
<Button primary>Label</Button>
</ButtonGroup>
}
>
Content of the card, which is usually a longer description.
</Card> would be a true ES module looking like // This is a little clumsy, but it means that we don't have to do introspection of the playground code.
// It means we can use https://esbuild.github.io/api/#define to rewrite the component library path in question for serving playgrounds
import { Card } from 'component-library'
export default () =>
<Card
headline="Headline"
actions={
<ButtonGroup>
<Button>Label</Button>
<Button primary>Label</Button>
</ButtonGroup>
}
>
Content of the card, which is usually a longer description.
</Card> Because the maintainer of ESBuild isn't too keen on first party support of the automatic JSX transform, we can just inject React's default export.. https://esbuild.github.io/api/#banner allows inserting arbitrary code at the beginning of particular file extensions. However, if we want to allow more full featured state handling (hooks, for example), arbitrarily prepending What default exports allow forBecause the playground is (with the exception of the classic JSX runtime requiring React to be in scope) a self contained example, we bundle it with esbuild directly. Instead of having two potential flows (top level JSX Element) or an ES Module, adding a bit of salt would allow us to just mount a component without DSK introspection. Any build time errors would be from ESBuild. Runtime errors would be through React. Other bitsEspecially for nested components in props like the above example, it might be too naive to insert props in the top level JSX element too. We might make that aspect opt in instead. An example import { useState } from "react"
// This lib might not be the right place for said handlers, but the idea is that it's just a handle for folks to use if they need it
import { defaultHandlers } from "@rundsk/js-sdk"
import { Button } from "component-library"
export default () => {
const [count, setCount] = useState(0)
return (
<Button {...defaultHandlers} onClick={() => setCount(count + 1)}>
{count}
</Button>
)
} |
This comment has been minimized.
This comment has been minimized.
1992b97
to
629149a
Compare
629149a
to
ea9c955
Compare
- Support the `-components` flag on `dsk`, to allow passing a path to a pre-build component bundle output directory. - Provide playground handlers. - Refactor `<Playground>` - Use IFrame in Playground Unrelated: - Deprecate Node.components response property. - Improve routing techniques, by using sub routers and allow us to extract route params. - Rename flag variables. - Pass more parent and current node into documentation components. - Nodes now have an `id` that can be used to adress them. Although not from the outside.
ea9c955
to
414385b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8d57ec9
to
0c57555
Compare
This requires React DOM Server which when build through esbuild requires additional shims.
Otherwise it will be rendered as HTML
As discussed in our call today, these are the things we want to figure out before the PR is ready to be merged: Rename
|
…ot already in a tag
82741e7 has path shimming in it that should resolve this somewhat. Basically, if the COMPONENTS path base doesn't match the "name" field in the @mariuswilms It uses the "write to dist" strategy that playground output used for a bit before d1bd01d. My idea there was that output paths should be stable. Maybe there's a reason for moving to temp dirs though. Ideally we wouldn't have to write to disk at all. |
# Conflicts: # frontend/src/DocumentationComponents/CodeBlock/CodeBlock.jsx
These changes introduce interactive components in playground and is based upon the design outlined in issue #75.
TODOs
nodeLinker: node_modules
.