docz icon indicating copy to clipboard operation
docz copied to clipboard

Can I use Bootstrap inside docz?

Open itReverie opened this issue 8 years ago • 6 comments

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.

itReverie avatar Aug 29 '18 22:08 itReverie

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 call and then just render {this.props.children} so that I don't have to import Helmet in all my files (and I have other stuff from glamorous that I need to wrap my code in, as well).

mbrochh avatar Aug 30 '18 02:08 mbrochh

Did you see Custom head tags introduced in 0.10.0?

denisborovikov avatar Aug 30 '18 09:08 denisborovikov

@denisborovikov oh awesome! I didn't know about doczrc.js, yet. Seems like htmlContext is not yet documented in the official docs anywhere, right?

mbrochh avatar Aug 30 '18 09:08 mbrochh

Move fast, break things. There're many stuff not documented yet.

denisborovikov avatar Aug 30 '18 09:08 denisborovikov

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>

itReverie avatar Aug 30 '18 18:08 itReverie

Thanks to help us @denisborovikov, I'll work this weekend to make this documentation and release the new version 🙏

pedronauck avatar Aug 31 '18 20:08 pedronauck