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

How to render devcards into a HTML element other than #com-rigsomelight-devcards-main? #148

Open
ghost opened this issue Nov 23, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 23, 2018

I would like to render my devcards into a HTML element that is not #com-rigsomelight-devcards-main (but #app-devcards, to use it with figwheel-extra-mains). How do I do that?

It would be nice if I could set :devcards {:target-element :#app-devcards} (instead of :devcards true) in the CLJS compiler options.

@vaz
Copy link

vaz commented Dec 11, 2018

Correct me if I'm wrong but devcards seems to just insert itself as first child of the body element, once it loads the JS script containing start-devcard-ui!. The element it creates and inserts is #com-rigsomelight-devcards-main, yes, but the target element is just the body.

devcards does work with extra mains (it's one of the motivating examples mentioned in the docs you linked). You start the devcards UI in the extra main file. For example declare an extra main in your dev.cljs.edn build, ^{:extra-main-files {:devcards {:main yourapp.devcards}}}, then in yourapp.devcards you require modules with defcard in them and run (devcards.core/start-devcard-ui!) in there as usual. The devcards should be at /figwheel-extra-main/devcards, which should be loading the script /cljs-out/dev-main-devcards.js.

Re-reading the docs you linked and referencing the devcards docs you should be able to sort it out. Also check out this project's README (devcards section) and the project files for an example: https://github.com/onetom/clj-figwheel-main-devcards/blob/master/README.md

@ghost
Copy link
Author

ghost commented Dec 11, 2018

What I saw happening was that the devcards are rendered atop the figwheel-extra-main page instead of into the designated element it reserves for content to be displayed. This creates a really crappy UI. If devcards would support specifying the target element, I could make it render into the appropriate place and figwheel-extra-main and devcards would play well together.

@brianium
Copy link

I am experiencing this also. You end up with this:

screen shot 2019-02-20 at 9 50 59 pm

Not the end of the world, but thought an image might help 🤷‍♂️

@brianium
Copy link

brianium commented Feb 21, 2019

And for anyone who might find it useful, I changed the render function in my devcards main to update the id of the target div to the one devcards is expecting:

(ns ^:figwheel-hooks budget-devcards.core
  (:require [devcards.core]
            [clojure.browser.dom :as dom]
            [budget-devcards.components]))

(defn render []
  (let [element (dom/get-element "app-devcards")]
    (when element
      (-> element
          (. -id)
          (set! "com-rigsomelight-devcards-main")))
    (devcards.core/start-devcard-ui!)))

(defn ^:after-load render-on-reload []
  (render))

(render)

@olymk2
Copy link

olymk2 commented May 14, 2019

anyone find a less hacky way to fix this than deleting the element, seems there must be something in there by default or a way to replace the default html template for devcards ?

@olymk2
Copy link

olymk2 commented May 14, 2019

Shortly after writing that, I found out you just create a html file next to the index file but make sure it includes the generate devcards javascript.

So this for example then just access http://localhost:9500/cards.html not sure why by default it gives you a html page then renders above like in the screenshot but this is good enough for me.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <link href="/css/example.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css"

  </head>
  <body>
    <script src="/cljs-out/dev-main-devcards.js" type="text/javascript"></script>
  </body>
</html>

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

3 participants