Skip to content
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

Can I use Bootstrap inside docz? #267

Closed
itReverie opened this issue Aug 29, 2018 · 6 comments
Closed

Can I use Bootstrap inside docz? #267

itReverie opened this issue Aug 29, 2018 · 6 comments

Comments

@itReverie
Copy link

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.

@mbrochh
Copy link

mbrochh commented Aug 30, 2018

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).

@denisborovikov
Copy link
Contributor

Did you see Custom head tags introduced in 0.10.0?

@mbrochh
Copy link

mbrochh commented Aug 30, 2018

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

@denisborovikov
Copy link
Contributor

denisborovikov commented Aug 30, 2018

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

@itReverie
Copy link
Author

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/codemirror@5.39.2/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>

@pedronauck
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants