chocolatedonut

chocolatedonut

How to include a 3rd party CSS?

The library in my case is vex. I ran npm install vex and followed vex’s installation docs by adding below to app.js:

import vex from 'vex-js'
vex.registerPlugin(require('vex-dialog'))
vex.defaultOptions.className = 'vex-theme-default'

I found this library in Phoenix.Component docs, in the Overriding the default confirm behaviour section, also in app.js:

// listen on document.body, so it's executed before the default of
// phoenix_html, which is listening on the window object
document.body.addEventListener('phoenix.link.click', function (e) {
  // Prevent default implementation
  e.stopPropagation();
  // Introduce alternative implementation
  var message = e.target.getAttribute("data-confirm");
  if(!message){ return true; }
  vex.dialog.confirm({
    message: message,
    callback: function (value) {
      if (value == false) { e.preventDefault(); }
    }
  })
}, false);

Using data-confirm attribute, above confirm() gets called, but its CSS is missing. I’ve copied vex.css and vex-theme-default.css to assets/vendor/vex/. Where and how do I now include these two files? Like so, in app.js?

import '../vendor/vex/vex.css'
import '../vendor/vex/vex-theme-default.css'

Doh, I just need to import them from app.css:

@import "../vendor/vex.css";
@import "../vendor/vex-theme-default.css";

Let me know if there’s a better way to import the CSS. I presume assets/css is meant for an app’s own CSS and vendor/ is a better place for this case, for vex.


Phoenix 1.7.2
LV 0.18.18

Marked As Solved

chocolatedonut

chocolatedonut

Doh, I just need to import them from app.css:

@import "../vendor/vex.css";
@import "../vendor/vex-theme-default.css";

Let me know if there’s a better way to import the CSS. I presume assets/css is meant for an app’s own CSS and vendor/ is a better place for this case, for vex.

Last Post!

sodapopcan

sodapopcan

Yep! What you have looks good. At least, it’s exactly how I would do it—take that how you will :sweat_smile:

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement