Can I use Bootstrap inside docz?
Question
I am wondering if I can I use Bootstrap inside docz.
Description It is not my choice to use Bootstrap but the repo I will be working on is a legacy and I'm planning to use docz to provide a kind of UI Library hence I need to set the components using bootstrap.
I have tried to install directly bootstrap and try to add another css processor, currently just having css({preprocessor: 'less'}), but when running it seems that I am missing something with my transpiler or build process.
This was the first question I had to ask myself, as well, when I started using docz (10 minutes ago, hehe).
I came up with this super nasty workaround, basically, I'm using Helmet to inject the bootstrap CSS file. Seems to work OK for me:
---
name: MyComponent
---
import { Playground } from 'docz'
import { Helmet } from 'react-helmet'
import MyCompoennt from './MyComponent.js'
# MyComponent
## Basic usage
<Playground>
<Helmet>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
crossOrigin="anonymous"
/>
</Helmet>
<MyComponent />
</Playground>
I guess I will create a <PlaygroundWrapper> component now that has that
Did you see Custom head tags introduced in 0.10.0?
@denisborovikov oh awesome! I didn't know about doczrc.js, yet. Seems like htmlContext is not yet documented in the official docs anywhere, right?
Move fast, break things. There're many stuff not documented yet.
Thanks so much @denisborovikov and @mbrochh. As suggested, using htmlContext Bootstrap is up and running by just adding:
doczrc.js
javascript
htmlContext: {
head: {
links: [{
rel: 'stylesheet',
href: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'
}]
},
body:{},
footer: {
scripts: [
{
src:'https://code.jquery.com/jquery-3.1.1.slim.min.js'
},
{
src:'https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js'
},
{
src:'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js'
}]
}
}
docz/dist/index.html
html
<!doctype html>
<html lang="{{ lang }}">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/codemirror.css"/>
<link href="/static/css/vendors.3ab91c9bbd7c77a236e2.css" rel="stylesheet">
{{ head }}
</head>
<body>
<div id="root"/>
{{ footer }}
<script src="/static/js/runtime~app.3ab91c9bbd7c77a236e2.js"></script><script src="/static/js/vendors.86aa8b62.js"></script><script src="/static/js/app.d04063f9.js">
</script>
</body>
</html>
Thanks to help us @denisborovikov, I'll work this weekend to make this documentation and release the new version 🙏