Last active
April 18, 2023 13:06
-
-
Save amazingrando/df9c1ee90c450e6324d2c84f140df6cc to your computer and use it in GitHub Desktop.
Adding a JS library to an Emulsify Component in Drupal files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Swiper from 'swiper/swiper-bundle'; | |
Drupal.behaviors.carousel = { | |
attach(context) { | |
// Locate the elements to apply swiper to. | |
const carousel = context.getElementsByClassName('swiper'); | |
if (carousel) { | |
// Apply swiper function. | |
const swiper = new Swiper('.swiper', { | |
// carousel settings go here | |
}); | |
swiper.init(); | |
} | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import your component JS. | |
import './carousel'; | |
// Import Swiper library files | |
import 'swiper/swiper-bundle.min'; | |
// import Swiper styles | |
import 'swiper/swiper-bundle.min.css'; | |
// ...storybook code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ attach_library('yourtheme/swiper') }} | |
{{ attach_library('yourtheme/carousel') }} | |
// ...CODE... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
carousel: | |
js: | |
dist/js/03-organisms/carousel/carousel.js: {} | |
dependencies: | |
- core/drupal | |
swiper: | |
css: | |
theme: | |
node_modules/swiper/swiper-bundle.min.css: {} | |
js: | |
node_modules/swiper/swiper-bundle.min.js: {} | |
dependencies: | |
- core/drupal |
I've updated it. Good catch and thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please indent the swiper/js like this: