Storybook: How to import jQuery into global namespace (for Semantic UI)

Created on 22 Jul 2016  ·  3Comments  ·  Source: storybookjs/storybook

Hi. I'm trying to use Semantic UI and I'm fading all css from it. The problem is that Semantic UI expects jQuery in the global namespace. I tried following to import it, but I still get 'jQuery' is not defined.

//file: config.js

import jquery from 'jquery';

global.$ = jquery;
global.jQuery = jquery;

import './semanticui'

Any idea how can this be achieved ?

Most helpful comment

Thanks for this @tomitrescak

I decided to npm install semantic-ui-css --save-dev package and import the files directly from it like so

// config.js
import jquery from 'jquery';
global.$ = jquery;
global.jQuery =  jquery;
require('semantic-ui-css/semantic.css');
require('semantic-ui-css/semantic.js');

All 3 comments

Ok, this seemed to do a trick, when I put this code into my main .stories/index file.

import jquery from 'jquery';
global.$ = jquery;
global.jQuery = jquery;
require('./semanticui');

Thanks for this @tomitrescak

I decided to npm install semantic-ui-css --save-dev package and import the files directly from it like so

// config.js
import jquery from 'jquery';
global.$ = jquery;
global.jQuery =  jquery;
require('semantic-ui-css/semantic.css');
require('semantic-ui-css/semantic.js');

I've had issues integrating jQueryUI, so here's how I did it. It uses the jquery-ui module.

// config.js
import jquery from "jquery";
import jQueryAutocomplete from "jquery-ui/ui/widgets/autocomplete";
import jQueryDatepicker from "jquery-ui/ui/widgets/datepicker";

jquery.autocomplete = jQueryAutocomplete;
jquery.datepicker = jQueryDatepicker;
global.$ = jquery;
global.jQuery =  jquery;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpersaud picture rpersaud  ·  3Comments

ericterpstra picture ericterpstra  ·  3Comments

zvictor picture zvictor  ·  3Comments

miljan-aleksic picture miljan-aleksic  ·  3Comments

dnlsandiego picture dnlsandiego  ·  3Comments