Skip to content

Commit

Permalink
Bootstrap dynamic imports POC
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Oct 16, 2023
1 parent d327c81 commit d4ed5e0
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 189 deletions.
4 changes: 3 additions & 1 deletion _dev/css/theme/utility/_dynamic-import-fix.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
}

//FIX TO TOAST, opacity by default
.toast {
.toast:not(.show),
.fade:not(.show) {
opacity: 0;
display: none;
}
160 changes: 109 additions & 51 deletions _dev/js/theme/components/dynamic-bootstrap-components.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,138 @@
import $ from 'jquery';
import DynamicImportHandler from '@js/theme/utils/DynamicImportHandler';
import DOMReady from "../utils/DOMReady";
import useBootstrapComponentDynamicImport from '../utils/dynamicImports/useBootstrapComponentDynamicImport';

$(() => {
DOMReady(() => {
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "import" }] */

const importModal = new DynamicImportHandler({
jqueryPluginCover: 'modal',
DOMEvents: 'click',
DOMEventsSelector: '[data-bs-toggle="modal"]',
DOMEventsPreventDefault: true,
files: () => [
const { init: initDynamicImportForModal } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/modal'),
import('@css/dynamic/modal/_index.scss'),
],
});

const importOffcanvas = new DynamicImportHandler({
jqueryPluginCover: 'offcanvas',
DOMEvents: 'click',
DOMEventsSelector: '[data-bs-toggle="offcanvas"]',
DOMEventsPreventDefault: true,
files: () => [
{
events: [
{
name: 'click',
selector: '[data-bs-toggle="modal"]',
},
],
componentName: 'Modal',
},
);

initDynamicImportForModal();

// const modal = new bootstrap.Modal('#testModal', {
// keyboard: false,
// });
//
// const handleTestModal = () => {
// modal.toggle();
// console.log('toggle');
// setTimeout(handleTestModal, 4000);
// }
//
// handleTestModal();

const { init: initDynamicImportForOffcanvas } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/offcanvas'),
import('@css/dynamic/offcanvas/_index.scss'),
],
});

const importDropdown = new DynamicImportHandler({
jqueryPluginCover: 'dropdown',
DOMEvents: 'click',
DOMEventsSelector: '[data-bs-toggle="dropdown"]',
DOMEventsPreventDefault: true,
files: () => [
{
events: [
{
name: 'click',
selector: '[data-bs-toggle="offcanvas"]',
},
],
componentName: 'Offcanvas',
},
);

initDynamicImportForOffcanvas();

const { init: initDynamicImportForDropdown } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/dropdown'),
import('@css/dynamic/dropdown/_index.scss'),
],
});

const importCollapse = new DynamicImportHandler({
jqueryPluginCover: 'collapse',
DOMEvents: 'click',
DOMEventsSelector: '[data-bs-toggle="collapse"]',
DOMEventsPreventDefault: true,
files: () => [
{
events: [
{
name: 'click',
selector: '[data-bs-toggle="dropdown"]',
},
],
componentName: 'Dropdown',
},
);

initDynamicImportForDropdown();

const { init: initDynamicImportForCollapse } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/collapse'),
],
});
{
events: [
{
name: 'click',
selector: '[data-bs-toggle="collapse"]',
},
],
componentName: 'Collapse',
},
);

initDynamicImportForCollapse();

const importPopover = new DynamicImportHandler({
jqueryPluginCover: 'popover',
files: () => [
const { init: initDynamicImportForPopover } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/popover'),
import('@css/dynamic/popover/_index.scss'),
],
});
{
componentName: 'Popover',
events: [
{
name: 'click',
selector: '[data-bs-toggle="popover"]',
},
],
},
);

const importScrollspy = new DynamicImportHandler({
jqueryPluginCover: 'scrollspy',
files: () => [
import('bootstrap/js/src/scrollspy'),
],
});
initDynamicImportForPopover();

const importToast = new DynamicImportHandler({
jqueryPluginCover: 'toast',
files: () => [
const { init: initDynamicImportForToast } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/toast'),
import('@css/dynamic/toast/_index.scss'),
],
});
{
componentName: 'Toast',
},
);

const importTooltip = new DynamicImportHandler({
jqueryPluginCover: 'tooltip',
files: () => [
initDynamicImportForToast();

const { init: initDynamicImportForTooltip } = useBootstrapComponentDynamicImport(
() => [
import('bootstrap/js/src/tooltip'),
import('@css/dynamic/tooltip/_index.scss'),
],
});
{
componentName: 'Tooltip',
events: [
{
name: 'mouseenter',
selector: '[data-bs-toggle="tooltip"]',
},
],
},
);

initDynamicImportForTooltip();
});
42 changes: 0 additions & 42 deletions _dev/js/theme/utils/DynamicImportDOMEvents.js

This file was deleted.

51 changes: 0 additions & 51 deletions _dev/js/theme/utils/DynamicImportHandler.js

This file was deleted.

41 changes: 0 additions & 41 deletions _dev/js/theme/utils/DynamicImportJqueryPlugin.js

This file was deleted.

Loading

0 comments on commit d4ed5e0

Please sign in to comment.