Closed kitten closed 5 years ago
@kitten @sofiapoh This looks great! A few questions and comments though:
transformOutput
the same as transformCode
from the current API?transformError
passes the error message down as a string? does this mean any sort of manipulation has to happen by using regex? I believe this is the current behavior and can be suboptimal.. is having an object representation of the error possible? 🤔 .prism-code
class. For now the only workaround I found was doing something similar to what react-live using dangerouslySetInnerHTML
.noInline
as a prop, are we getting rid of this? If we are not can we change this to be called inline
or some other prop name? I think generally speaking avoiding boolean values that are negative by default is cleaner since then you don't have to negate a false boolean value. Would this prop still involve wrapping the components to be rendered by a render(<Component />)
function?Live.DefaultLayout
do and how is this different than just wrapping Live.Editor
, Live.Preview
and Live.Error
by different divs with flexbox etc. and creating a custom layout from that. What's the benefit? Is it just cleaner?withLive
as an HoC?Editor
takes a language prop what languages would we support? js
, ts
(we need buble for this)? js
already works with jsx
so is this neccesary? specially since this is a react playground, meaning most people will be using jsx already? does this just change the prism language highlight?noInline
it could be interesting to have fake import statements for all components in scope
to replicate a more editor like experience and pinpoint what components are being used e.g from what library etc.These are some things that first come to mind (I'll let you know if I can think of anything else). I know this is a draft but think it might be nice to clarify what the PropType of each prop is and go into more detail on what the behavior of each of this prop is, similar to the table in the react-live README.
I am very excited for this, let me know if there's any other way I can help, happy to help writing code and/or docs 😄
@alejandrogarciasalas These are some great questions :) Let me try to go through them one by one
Live
as a new render prop-based component that can be customised, but the core would still be broken out into separate components; This enables customisation at every single point and it's make it easy to get started easilyjs
which is probably initially the only one we're still interested inHope this answers everything :)
tl;dr Take a look at prism-react-renderer and react-simple-code-editor to get an idea of the future Editor component, which are both published and ready for prod use today individually :)
https://github.com/FormidableLabs/prism-react-renderer https://github.com/satya164/react-simple-code-editor
Regarding Bable/Babel. If Buble isn't swapped out then it probably makes sense to contribute back to it on a few key tickets that follow some pretty commonly used features in the react/babel community that don't currently work in react-live:
https://github.com/Rich-Harris/buble/issues/123 https://github.com/Rich-Harris/buble/pull/125
One feedback regarding the API, renderEditor={Live.Editor}
should probably be editor={Live.Editor}
or editorComponent={Live.Editor}
to distinguish it from a render callback, or renderEditor={props => <Live.Editor {...props} />}
I would like to be able have editors not map 1:1 onto previews. E.g. have one editor and multiple previews. The editor shows the code for the most recently clicked preview. That way code can be shown in another pane (e.g. storybook) without needing loads of providers . The code in the code pane may change depending on scroll position, focus or button press.
function ThreePreviewsOneEditor() {
const [activeId, setActive] = useState("a")
return <LiveProvider>
<Live.Code id="a" code="<div>A</div>" /> /* render null*/
<Live.Code id="b" code="<div>B</div>" />
<Live.Code id="c" code="<div>C</div>" />
<Live.Editor fileName={activeId} />
<Live.Preview activeId="a" onFocus={() => setActive("a")} />
<Live.Preview activeId="b" onFocus={() => setActive("b")} />
<Live.Preview activeId="c" onFocus={() => setActive("c")} />
</LiveProvider>
}
do we want to necessarily stick with bublé? I think having the option to use Babel would be nice since you can have custom presets that match your company best practices, this would also allow us to support superscripts of JS like TypeScript (not sure what the TS support is for bublé). Sadly babel is not as lightweight but IMO it's not that much of a compromise specially if we support this as an alternate option.
+1 for TypeScript support! I can't use this project currently but I so wish I could.
Perfect-world-wishful-thinking-optimal-API: