-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Playground-local stylesheets #290
Comments
Hey @derekstavis you can use the new
You can see more info about |
@pedronauck Could you please expand on how this I've updated my doczrc.js export default {
indexHtml: './src/documentation/index.html',
htmlContext: {
head: {
links: [
{ rel: 'stylesheet', href: '/build/main.css' }
]
}
}
}; ./src/documentation/index.html <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="{{ description }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{ title }}</title>
{{ head }}
</head>
<body>
<div id="root" />
{{ footer }}
</body>
</html> |
@pedronauck I believe the issue he is mentioning is applying the css only to the previewer.
So he is able to load the styles globally but it messes up the Docz theme itself. Is there a workaround for that? |
@donifer Hi, i'm also getting the same error (404) when trying to append a custom .css file. Maybe i'm putting the css file in the wrong place? I put it along with the doczrc.js file |
@donifer, what you can do is pass some class just to playground, but some css that just act in the playground isn't possible 😕 |
@pedronauck So even a global style.css isn't possible? Or at least, style the html? Maybe add some custom styles like fonts, colors, etc |
You can put styles using |
Ok, thank you very much! :) |
i also get 404.
|
@pedronauck Do you have any objection to using iframes to load each Playground? I see this issue coming up quite often and iframes seem to be the way to go for similar component docs generator tools. Without style isolation, there's no way to safely use Docz. |
@Dobby89 I don't have any objections, to be honest, I really think is the best solution since with an iframe we can simulate viewport and be able to work more effectively with responsive queries. But, I tried to transform playground render using iframes, but I didn't get success. I'll try again on v1. |
You can do the following in case you don't want to commit
|
@giulianok That's useful, thanks. Now I'm stuck by docz overriding the styles I inlined, since the styles added to 'htmlContext' become the first style tag in the document...any ideas? Specifically, I'm attempting to define the font-family for the document, and docz is overriding it as Source Sans Pro in a later style tag |
Hey 👋
I'm migrating the docs from
Vanilla Form
, my form state/validation management library. Currently I'm using Styleguidist, so migrating to Docz is pretty easy as all documentation and examples are already in Markdown.Background
As the documentation examples are using plain HTML elements, I've used Styleguidist's
require
configuration option to apply Milligram styles for better-looking components in playground. This basically requires applies Milligram globally in the docs page.For the Docz migration I followed the same idea, but using the CSS plugin to achieve it. I could make it work and all playground examples now have Milligram styles, but as a side-effect, Docz theme is completely screwed up, as Milligram uses global CSS.
Playground Isolation
I like a lot that both Styleguidist and Docz render playgrounds inline (no funky iframes), even understanding that conflicts ranging from HTML IDs to CSS could happen. On the other hand, I've come to believe that having at least styles isolation inside playgrounds is an important thing, because not all libraries are using fancy CSS systems (emotion, styled, css-modules, ...), so their styles could interfere with Docz's own theme.
Possible solution
Trying to avoid using
iframe
, it seems that Shadow DOM could be a thing here. By Shadow DOM-ing playground's preview and injecting style tags inside the playground we could get the desired styles isolation.EDIT:: After some tinkering, I came with this component to Shadow DOM the example. The only downside is that it breaks HTML preview (for obvious reasons):
I had to match
\.css$
and usefile-loader
in the pipeline to achieve the desired effect.Even if this is already sufficient for me, having to repeat the theme wrapper every demo makes the demos clunky.
The text was updated successfully, but these errors were encountered: