From cd032f3e8542a2c30dbc66191b2995194431cbc7 Mon Sep 17 00:00:00 2001 From: igor_przybysz Date: Fri, 30 Jun 2023 12:29:29 +0200 Subject: [PATCH 1/3] Add autoinits for tooltips & popover --- .../standard/components/popover/a-ss.html | 3 ++ .../docs/standard/components/popover/a.html | 39 ++++++++++++++++++ .../standard/components/popover/index-js.html | 11 ----- .../standard/components/popover/index.html | 13 ++++-- .../standard/components/tooltip/a-ss.html | 3 ++ .../docs/standard/components/tooltip/a.html | 41 +++++++++++++++++++ .../standard/components/tooltip/index.html | 25 ++++++++--- .../partials/footer/footer-scripts.html | 10 ----- src/js/autoinit/autoinitCallbacks.js | 21 ++++++++++ src/js/autoinit/index.js | 14 +++++++ 10 files changed, 149 insertions(+), 31 deletions(-) delete mode 100644 site/content/docs/standard/components/popover/index-js.html diff --git a/site/content/docs/standard/components/popover/a-ss.html b/site/content/docs/standard/components/popover/a-ss.html index b51813ad0..3a1053ecf 100644 --- a/site/content/docs/standard/components/popover/a-ss.html +++ b/site/content/docs/standard/components/popover/a-ss.html @@ -2,6 +2,9 @@ ---
  • + Import +
  • +
  • Usage
  • diff --git a/site/content/docs/standard/components/popover/a.html b/site/content/docs/standard/components/popover/a.html index b889b8479..009e9ad5d 100644 --- a/site/content/docs/standard/components/popover/a.html +++ b/site/content/docs/standard/components/popover/a.html @@ -3,6 +3,45 @@
    + +
    + +

    + Import +

    + +

    + Importing components depends on how your application works. If you intend + to use the Tailwind Elements ES format, you must first import + the component and then initialize it with the initTE method. + If you are going to use the UMD format, just import the + tw-elements package. +

    + + + {{< twsnippet/no-demo id="api-example41" >}} + + +
    + +
    diff --git a/site/content/docs/standard/components/popover/index-js.html b/site/content/docs/standard/components/popover/index-js.html deleted file mode 100644 index 9abf50d39..000000000 --- a/site/content/docs/standard/components/popover/index-js.html +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - diff --git a/site/content/docs/standard/components/popover/index.html b/site/content/docs/standard/components/popover/index.html index 8ba288715..d3d9cde20 100644 --- a/site/content/docs/standard/components/popover/index.html +++ b/site/content/docs/standard/components/popover/index.html @@ -12,6 +12,7 @@ menu: components: name: "Popover" +autoinits: "Popover" --- @@ -66,11 +67,12 @@ {{< twsnippet/code lang="js" >}} // Initialization for ES Users import { + Popover, Ripple, initTE, } from "tw-elements"; - initTE({ Ripple }); + initTE({ Popover, Ripple }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} @@ -460,11 +462,12 @@ {{< twsnippet/code lang="js" >}} // Initialization for ES Users import { + Popover, Ripple, initTE, } from "tw-elements"; - initTE({ Ripple }); + initTE({ Popover, Ripple }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} @@ -528,11 +531,12 @@ {{< twsnippet/code lang="js" >}} // Initialization for ES Users import { + Popover, Ripple, initTE, } from "tw-elements"; - initTE({ Ripple }); + initTE({ Popover, Ripple }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} @@ -598,11 +602,12 @@ {{< twsnippet/code lang="js" >}} // Initialization for ES Users import { + Popover, Ripple, initTE, } from "tw-elements"; - initTE({ Ripple }); + initTE({ Popover, Ripple }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} diff --git a/site/content/docs/standard/components/tooltip/a-ss.html b/site/content/docs/standard/components/tooltip/a-ss.html index b51813ad0..3a1053ecf 100644 --- a/site/content/docs/standard/components/tooltip/a-ss.html +++ b/site/content/docs/standard/components/tooltip/a-ss.html @@ -2,6 +2,9 @@ ---
  • + Import +
  • +
  • Usage
  • diff --git a/site/content/docs/standard/components/tooltip/a.html b/site/content/docs/standard/components/tooltip/a.html index b5d19fcee..4ea612669 100644 --- a/site/content/docs/standard/components/tooltip/a.html +++ b/site/content/docs/standard/components/tooltip/a.html @@ -3,6 +3,47 @@
    + +
    + +

    + Import +

    + +

    + Importing components depends on how your application works. If you intend + to use the Tailwind Elements ES format, you must first import + the component and then initialize it with the initTE method. + If you are going to use the UMD format, just import the + tw-elements package. +

    + + + {{< twsnippet/no-demo id="api-example41" >}} + + +
    + + +
    +
    diff --git a/site/content/docs/standard/components/tooltip/index.html b/site/content/docs/standard/components/tooltip/index.html index c130426a8..b56bd2dbc 100644 --- a/site/content/docs/standard/components/tooltip/index.html +++ b/site/content/docs/standard/components/tooltip/index.html @@ -12,6 +12,7 @@ menu: components: name: "Tooltip" +autoinits: "Tooltip" --- @@ -65,8 +66,13 @@ {{< /twsnippet/code >}} {{< twsnippet/code lang="js" >}} - const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-te-toggle="tooltip"]')); - tooltipTriggerList.map((tooltipTriggerEl) => new te.Tooltip(tooltipTriggerEl)); + // Initialization for ES Users + import { + Tooltip, + initTE, + } from "tw-elements"; + + initTE({ Tooltip }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} @@ -453,10 +459,11 @@ // Initialization for ES Users import { Ripple, + Tooltip, initTE, } from "tw-elements"; - initTE({ Ripple }); + initTE({ Ripple, Tooltip }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} @@ -513,10 +520,11 @@ // Initialization for ES Users import { Ripple, + Tooltip, initTE, } from "tw-elements"; - initTE({ Ripple }); + initTE({ Ripple, Tooltip }); {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} @@ -574,8 +582,13 @@ {{< /twsnippet/code >}} {{< twsnippet/code lang="js" >}} - const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-te-toggle="tooltip"]')); - tooltipTriggerList.map((tooltipTriggerEl) => new te.Tooltip(tooltipTriggerEl)); + // Initialization for ES Users + import { + Tooltip, + initTE, + } from "tw-elements"; + + initTE({ Tooltip }) {{< /twsnippet/code >}} {{< /twsnippet/wrapper >}} diff --git a/site/layouts/partials/footer/footer-scripts.html b/site/layouts/partials/footer/footer-scripts.html index 3eab0c8ab..dcd16caa4 100644 --- a/site/layouts/partials/footer/footer-scripts.html +++ b/site/layouts/partials/footer/footer-scripts.html @@ -566,13 +566,3 @@ } - - diff --git a/src/js/autoinit/autoinitCallbacks.js b/src/js/autoinit/autoinitCallbacks.js index 32e38ca56..17a31aca9 100644 --- a/src/js/autoinit/autoinitCallbacks.js +++ b/src/js/autoinit/autoinitCallbacks.js @@ -163,6 +163,25 @@ const collapseCallback = (component, initSelector) => { ); }; +const tooltipsCallback = (component, initSelector) => { + const tooltipTriggerList = [].slice.call( + document.querySelectorAll(initSelector) + ); + tooltipTriggerList.map(function (tooltipTriggerEl) { + return new component(tooltipTriggerEl); + }); +}; + +const popoverCallback = (component, initSelector) => { + console.log("hello"); + const popoverTriggerList = [].slice.call( + document.querySelectorAll(initSelector) + ); + popoverTriggerList.map(function (popoverTriggerEl) { + return new component(popoverTriggerEl); + }); +}; + export { dropdownCallback, tabCallback, @@ -171,4 +190,6 @@ export { modalCallback, rippleCallback, collapseCallback, + tooltipsCallback, + popoverCallback, }; diff --git a/src/js/autoinit/index.js b/src/js/autoinit/index.js index 3d3d7f546..976ece491 100644 --- a/src/js/autoinit/index.js +++ b/src/js/autoinit/index.js @@ -8,6 +8,8 @@ import { modalCallback, rippleCallback, collapseCallback, + tooltipsCallback, + popoverCallback, } from "./autoinitCallbacks"; import { chartsCallback } from "./chartsInit"; @@ -82,6 +84,12 @@ const defaultInitSelectors = { selector: "[data-te-toast-init]", isToggler: false, }, + tooltip: { + name: "Tooltip", + selector: "[data-te-toggle='tooltip']", + isToggler: false, + callback: tooltipsCallback, + }, // advancedInits chart: { @@ -135,6 +143,12 @@ const defaultInitSelectors = { isToggler: true, callback: tabCallback, }, + popover: { + name: "Popover", + selector: "[data-te-toggle='popover']", + isToggler: true, + callback: popoverCallback, + }, }; const getComponentData = (component) => { From be7946357dde2f94ab6b7182fd3ff95b8d67f6a1 Mon Sep 17 00:00:00 2001 From: igor_przybysz Date: Fri, 30 Jun 2023 12:30:11 +0200 Subject: [PATCH 2/3] Add autoinits for tooltips & popover --- src/js/autoinit/autoinitCallbacks.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/autoinit/autoinitCallbacks.js b/src/js/autoinit/autoinitCallbacks.js index 17a31aca9..cb224b95f 100644 --- a/src/js/autoinit/autoinitCallbacks.js +++ b/src/js/autoinit/autoinitCallbacks.js @@ -173,7 +173,6 @@ const tooltipsCallback = (component, initSelector) => { }; const popoverCallback = (component, initSelector) => { - console.log("hello"); const popoverTriggerList = [].slice.call( document.querySelectorAll(initSelector) ); From 5a67bd1f47556ccff622f07b59e36490ce16011d Mon Sep 17 00:00:00 2001 From: igor_przybysz Date: Mon, 3 Jul 2023 12:53:23 +0200 Subject: [PATCH 3/3] Add autoinits - demo sites --- demo/sites/components/popover.html | 25 ++++++++----------------- demo/sites/components/tooltip.html | 27 +++++++++------------------ 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/demo/sites/components/popover.html b/demo/sites/components/popover.html index 6ea10a835..7421e518d 100644 --- a/demo/sites/components/popover.html +++ b/demo/sites/components/popover.html @@ -59,7 +59,7 @@