@trilogy-ds/vanilla 0.0.1-alpha-prompt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +82 -0
- package/.prettierrc.js +12 -0
- package/README.md +18 -0
- package/examples/tabs.html +43 -0
- package/lib/trilogy-ds-vanilla.js +6 -0
- package/package.json +28 -0
- package/src/app.ts +138 -0
- package/src/components/autocomplete.ts +133 -0
- package/src/components/chips.ts +28 -0
- package/src/components/countdown.ts +40 -0
- package/src/components/font-variant.ts +42 -0
- package/src/components/input-gauge.ts +111 -0
- package/src/components/input-icon.ts +36 -0
- package/src/components/modal.ts +104 -0
- package/src/components/progress-radial.ts +45 -0
- package/src/components/range.ts +48 -0
- package/src/components/segmented-control.ts +16 -0
- package/src/components/select.ts +48 -0
- package/src/components/sticky.ts +14 -0
- package/src/components/table-expansion.ts +11 -0
- package/src/components/tabs.ts +68 -0
- package/src/components/textarea.ts +27 -0
- package/src/utils/intersectionObserver.ts +13 -0
- package/tsconfig.json +10 -0
- package/vite.config.js +23 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
env: {
|
|
5
|
+
node: true,
|
|
6
|
+
},
|
|
7
|
+
plugins: ['@typescript-eslint', 'import', 'jest', 'react', 'react-hooks'],
|
|
8
|
+
extends: [
|
|
9
|
+
'eslint:recommended',
|
|
10
|
+
'plugin:@typescript-eslint/recommended',
|
|
11
|
+
'plugin:import/errors',
|
|
12
|
+
'plugin:import/warnings',
|
|
13
|
+
'plugin:import/typescript',
|
|
14
|
+
'plugin:jest/recommended',
|
|
15
|
+
'plugin:react/recommended',
|
|
16
|
+
'plugin:react-hooks/recommended',
|
|
17
|
+
],
|
|
18
|
+
parserOptions: {
|
|
19
|
+
ecmaFeatures: {
|
|
20
|
+
jsx: true,
|
|
21
|
+
tsx: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
rules: {
|
|
25
|
+
'arrow-spacing': 2,
|
|
26
|
+
'block-spacing': 1,
|
|
27
|
+
'brace-style': 1,
|
|
28
|
+
camelcase: ['error', { properties: 'always' }],
|
|
29
|
+
'comma-spacing': 1,
|
|
30
|
+
'comma-style': 1,
|
|
31
|
+
'default-case': 'error',
|
|
32
|
+
'dot-location': ['warn', 'property'],
|
|
33
|
+
'eol-last': 2,
|
|
34
|
+
'func-call-spacing': 2,
|
|
35
|
+
'import/export': 0,
|
|
36
|
+
'jsx-quotes': ['warn', 'prefer-single'],
|
|
37
|
+
'key-spacing': 1,
|
|
38
|
+
'keyword-spacing': 1,
|
|
39
|
+
'lines-between-class-members': 1,
|
|
40
|
+
'max-len': ['error', { code: 170 }],
|
|
41
|
+
'no-alert': 0,
|
|
42
|
+
'no-confusing-arrow': 1,
|
|
43
|
+
'no-console': 0,
|
|
44
|
+
'no-duplicate-imports': 1,
|
|
45
|
+
'no-eval': 2,
|
|
46
|
+
'no-extend-native': 2,
|
|
47
|
+
'no-multiple-empty-lines': [1, { max: 1 }],
|
|
48
|
+
'no-trailing-spaces': 1,
|
|
49
|
+
'no-unneeded-ternary': 1,
|
|
50
|
+
'no-unused-expressions': 0,
|
|
51
|
+
'no-use-before-define': 0,
|
|
52
|
+
'react-hooks/exhaustive-deps': 'off',
|
|
53
|
+
'no-useless-constructor': 1,
|
|
54
|
+
'no-var': 1,
|
|
55
|
+
'object-curly-spacing': [1, 'always'],
|
|
56
|
+
'prefer-const': 1,
|
|
57
|
+
'prefer-destructuring': ['warn', { array: true, object: true }],
|
|
58
|
+
'prefer-rest-params': 1,
|
|
59
|
+
'prefer-spread': 1,
|
|
60
|
+
'prefer-template': 1,
|
|
61
|
+
indent: 'off',
|
|
62
|
+
quotes: 'off',
|
|
63
|
+
'quote-props': ['warn', 'as-needed'],
|
|
64
|
+
'react/display-name': 2,
|
|
65
|
+
'react/jsx-key': 2,
|
|
66
|
+
'react/jsx-no-duplicate-props': 2,
|
|
67
|
+
'react/jsx-no-useless-fragment': 1,
|
|
68
|
+
'react/jsx-no-target-blank': 2,
|
|
69
|
+
'react/prop-types': 0,
|
|
70
|
+
'rest-spread-spacing': 2,
|
|
71
|
+
semi: ['error', 'never', { beforeStatementContinuationChars: 'always' }],
|
|
72
|
+
'spaced-comment': ['warn', 'always'],
|
|
73
|
+
'switch-colon-spacing': 1,
|
|
74
|
+
},
|
|
75
|
+
settings: {
|
|
76
|
+
react: {
|
|
77
|
+
pragma: 'React',
|
|
78
|
+
version: 'detect',
|
|
79
|
+
},
|
|
80
|
+
'import/ignore': ['react-native'],
|
|
81
|
+
},
|
|
82
|
+
}
|
package/.prettierrc.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
bracketSpacing: true,
|
|
3
|
+
jsxBracketSameLine: true,
|
|
4
|
+
jsxSingleQuote: true,
|
|
5
|
+
singleQuote: true,
|
|
6
|
+
trailingComma: 'all',
|
|
7
|
+
semi: false,
|
|
8
|
+
printWidth: 120,
|
|
9
|
+
tabWidth: 2,
|
|
10
|
+
importOrder: ["^react$", "^[A-Za-z-\/]+$", "^[@]", "^[~]", "^[./]",],
|
|
11
|
+
importOrderSeparation: true,
|
|
12
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Trilogy DS Vanilla
|
|
2
|
+
|
|
3
|
+
___
|
|
4
|
+
|
|
5
|
+
This repository contains all the necessary Javascript components to integrate Trilogy Design System in an HTML setting.
|
|
6
|
+
|
|
7
|
+
___
|
|
8
|
+
|
|
9
|
+
## CDN
|
|
10
|
+
|
|
11
|
+
For a faster setup, you can utilize the JSDelivr CDN to include Trilogy Vanilla in your project's HTML:
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<!-- ... -->
|
|
15
|
+
<link href="https://cdn.jsdelivr.net/npm/@trilogy-ds/vanilla" rel="stylesheet" />
|
|
16
|
+
<!-- ... -->
|
|
17
|
+
```
|
|
18
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Tab List with Arrows</title>
|
|
6
|
+
<link rel="stylesheet" href="../../styles/dist/default/trilogy.css" />
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
|
|
10
|
+
<div class="tabs">
|
|
11
|
+
<div data-tablist class="tab-list is-aligned-start is-arrows" id="tablist">
|
|
12
|
+
<span data-arrow-prev class="icon is-medium arrow-prev hidden">←</span>
|
|
13
|
+
<button aria-selected="true" data-tab-navigation="" class="tab is-active" role="tab" data-index="0"><div>Tab 1</div></button>
|
|
14
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="1"><div>Tab 2</div></button>
|
|
15
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="2"><div>Tab 3</div></button>
|
|
16
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="3"><div>Tab 4</div></button>
|
|
17
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="4"><div>Tab 5</div></button>
|
|
18
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="5"><div>Tab 6</div></button>
|
|
19
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="6"><div>Tab 7</div></button>
|
|
20
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="7"><div>Tab 8</div></button>
|
|
21
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="8"><div>Tab 9</div></button>
|
|
22
|
+
<button aria-selected="false" data-tab-navigation="" class="tab" role="tab" data-index="9"><div>Tab 10</div></button>
|
|
23
|
+
<span data-arrow-next class="icon is-medium arrow-next">→</span>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div class="tab-panels">
|
|
27
|
+
<div data-tab-panel class="tab-panel is-active" data-index="0"><p>Tab 1 content</p></div>
|
|
28
|
+
<div data-tab-panel class="tab-panel" data-index="1"><p>Tab 2 content</p></div>
|
|
29
|
+
<div data-tab-panel class="tab-panel" data-index="2"><p>Tab 3 content</p></div>
|
|
30
|
+
<div data-tab-panel class="tab-panel" data-index="3"><p>Tab 4 content</p></div>
|
|
31
|
+
<div data-tab-panel class="tab-panel" data-index="4"><p>Tab 5 content</p></div>
|
|
32
|
+
<div data-tab-panel class="tab-panel" data-index="5"><p>Tab 6 content</p></div>
|
|
33
|
+
<div data-tab-panel class="tab-panel" data-index="6"><p>Tab 7 content</p></div>
|
|
34
|
+
<div data-tab-panel class="tab-panel" data-index="7"><p>Tab 8 content</p></div>
|
|
35
|
+
<div data-tab-panel class="tab-panel" data-index="8"><p>Tab 9 content</p></div>
|
|
36
|
+
<div data-tab-panel class="tab-panel" data-index="9"><p>Tab 10 content</p></div>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<script src="../lib/trilogy-ds-vanilla.js"></script>
|
|
41
|
+
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(v){typeof define=="function"&&define.amd?define(v):v()})(function(){"use strict";const v=()=>{let r=document.querySelectorAll("[data-modal-context]");for(let s=0;s<r.length;s++){let e=r[s],a=e.querySelectorAll("[data-modal-open]"),o=e.querySelector("[data-modal]"),u=e.querySelectorAll("[data-modal-close]"),l=e.querySelectorAll('iframe[src*="www.youtube.com"], iframe[src*="player.vimeo.com"], video');for(let d=0;d<a.length;d++){let m=a[d],g=l[d];m.addEventListener("click",function(){if(i(o),g){if(g.tagName.toLowerCase()==="video"){g.play();return}g.src=g.src+(g.src.indexOf("?")<0?"?":"&")+"autoplay=1"}else return})}for(let d=0;d<u.length;d++)u[d].addEventListener("click",function(){c(o)});t(o);const n=e.querySelector(".modal-background");n&&(n.onclick=function(){c(o)}),e.setAttribute("data-modal-initialized","true")}function t(s){document.addEventListener("keyup",function(e){e=e||window.event;var a=!1;"key"in e?a=e.key==="Escape"||e.key==="Esc":a=e.keyCode===27,a&&c(s)}),document.addEventListener("click",function(e){const a=e.target;let o=a.closest("[data-modal-content]"),u=a.classList.contains("modal");o===null&&u==!0&&c(s)})}const i=s=>{s.classList.add("is-active"),document.body.style.overflow="hidden"},c=s=>{let e=s.querySelector('iframe[src*="youtube"], iframe[src*="vimeo"], video');if(e){if(e.tagName.toLowerCase()==="video"){e.pause();return}e.src=e.src.replace("&autoplay=1","").replace("?autoplay=1","")}s.classList.remove("is-active"),document.body.style.overflow=null}},C=()=>{let r=document.querySelectorAll('[data-variant="auto"]');const t=function(i){let c=0,s=i.length,e=0;if(s>0)for(;e<s;)c=(c<<5)-c+i.charCodeAt(e++)|0;return c};for(let i=0;i<r.length;i++){let c=r[i];const s=c.textContent,e=["b","g","o","q"],a=[];if(s.toLowerCase().split("").map((o,u)=>(e.indexOf(o)>-1&&a.push(u),o)),a.length){const o=t(s),u=Math.abs(o%a.length),l=s.charAt(a[u]),n=s.substring(0,a[u]),d=s.substring(a[u]+1);c.innerHTML=`${n}<span class="has-variant">${l}</span>${d}`}c.setAttribute("data-fontVariant-initialized","true")}},k=()=>{document.querySelectorAll("[data-countdown]").forEach(t=>{let a=t,o=new Date(a.dataset.date).getTime(),u=a.querySelector("[data-days]"),l=a.querySelector("[data-hours]"),n=a.querySelector("[data-minutes]"),d=a.querySelector("[data-seconds]"),m=setInterval(()=>{let g=new Date().getTime(),y=0;o-g>0&&(y=o-g),y<=0&&clearInterval(m),u.innerText=Math.floor(y/864e5).toString(),l.innerText=Math.floor(y%864e5/36e5).toString(),n.innerText=Math.floor(y%36e5/6e4).toString(),d.innerText=Math.floor(y%6e4/1e3).toString()},1e3);a.setAttribute("data-countdown-initialized","true")})},z=()=>{let r=document.querySelectorAll("[data-expandable-row]");for(let t=0;t<r.length;t++){let i=r[t];i.querySelector("[data-expandable-trigger]").addEventListener("click",function(){i.classList.toggle("is-expanded")}),i.setAttribute("data-tableexpansion-initialized","true")}},N=()=>{const r=document.querySelector("[data-tablist]"),t=r.querySelectorAll("[data-tab-navigation]"),i=r.querySelector("[data-arrow-prev]"),c=r.querySelector("[data-arrow-next]"),s=()=>{if(!i||!c)return;const a=r.scrollLeft,o=r.scrollWidth,u=r.clientWidth;i.classList.toggle("hidden",a<=0),c.classList.toggle("hidden",o<=a+u)},e=a=>{const o=Array.from(t),u=r.scrollLeft;let l;a===1?l=o.find(n=>n.offsetLeft>u):l=o.slice().reverse().find(n=>n.offsetLeft<u),l?r.scrollTo({left:l.offsetLeft,behavior:"smooth"}):a===-1&&r.scrollTo({left:0,behavior:"smooth"}),s()};i&&i.addEventListener("click",()=>{e(-1)}),c&&c.addEventListener("click",()=>{e(1)}),t.forEach((a,o)=>{a.addEventListener("click",()=>{t.forEach(n=>n.classList.remove("is-active")),a.classList.add("is-active"),document.querySelectorAll("[data-tab-panel]").forEach(n=>n.classList.remove("is-active"));const l=document.querySelector(`[data-tab-panel][data-index="${o}"]`);l&&l.classList.add("is-active")})}),r.addEventListener("scroll",s),window.addEventListener("resize",s),s()},I=()=>{document.querySelectorAll("[data-autocomplete-context]").forEach(t=>{const i=t.querySelector("[data-autocomplete-input]"),c=t.querySelector("[data-autocomplete-menu]"),s=c.querySelectorAll(".autocomplete-item");let e=-1,a="";const o=()=>{e=-1,document.body.classList.remove("autocomplete-close"),t.classList.remove("is-active"),i.blur(),s.forEach(l=>{l.removeAttribute("data-autocomplete-item-hover")})};c.querySelectorAll(".autocomplete-item").forEach((l,n)=>{l.setAttribute("data-autocomplete-item-index",String(n))}),i.addEventListener("focus",l=>{l.stopPropagation(),t.closest(".is-autocomplete").classList.add("is-active"),document.body.classList.add("autocomplete-close");const n=[];s.forEach(d=>{d.textContent.trim().toLocaleLowerCase().includes(i.value.trim().toLocaleLowerCase())?(d.style.display="block",n.push(d)):d.style.display="none",d.removeAttribute("data-autocomplete-item-index")}),n.forEach((d,m)=>{d.setAttribute("data-autocomplete-item-index",String(m))})}),s.forEach(l=>{l.addEventListener("mousemove",()=>{s.forEach(d=>{d.removeAttribute("data-autocomplete-item-hover")});const n=l.getAttribute("data-autocomplete-item-index");e=Number(n),l.setAttribute("data-autocomplete-item-hover","true"),a=""}),l.addEventListener("mouseout",()=>{l.removeAttribute("data-autocomplete-item-hover")}),l.addEventListener("click",n=>{const d=n.target;i.value=d.textContent,o()})}),i.addEventListener("input",l=>{const n=l.target;e!==-1&&(e=-1);const d=[];s.forEach(m=>{m.textContent.trim().toLocaleLowerCase().includes(n.value.trim().toLocaleLowerCase())?(m.style.display="block",d.push(m)):m.style.display="none",m.removeAttribute("data-autocomplete-item-index"),m.removeAttribute("data-autocomplete-item-hover")}),d.forEach((m,g)=>{m.setAttribute("data-autocomplete-item-index",String(g))})}),i.addEventListener("keydown",l=>{const n=c.querySelectorAll("[data-autocomplete-item-index]");l.key==="ArrowDown"&&(e=e+1,e===n.length&&(e=0)),l.key==="ArrowUp"&&(e=e-1,e<0&&(e=n.length-1)),["ArrowDown","ArrowUp"].includes(l.key)&&(n.forEach(d=>{d.removeAttribute("data-autocomplete-item-hover")}),n[e].setAttribute("data-autocomplete-item-hover","true"),a=n[e].textContent),l.key==="Enter"&&a.trim().length>0&&(i.value=a,o())}),i.addEventListener("blur",()=>{setTimeout(()=>o(),100)}),t.setAttribute("data-autocomplete-initialized","true")})},M=()=>{document.querySelectorAll(".segmented-control-item").forEach(t=>{t.addEventListener("click",function(){this.parentElement.querySelector(".is-active").classList.remove("is-active"),t.classList.contains("is-active")||t.classList.add("is-active")}),t.setAttribute("data-segmentedControl-initialized","true")})},O=()=>{document.querySelectorAll(".textarea-wrapper").forEach(t=>{if(!t.getAttribute("data-textarea-initialized")){const s=t.querySelector("textarea.textarea"),e=s.getAttribute("maxlength");if(e){var c=0;const a=document.createElement("div");a.classList.add("counter"),a.innerHTML=`${c}/${e}`,t.appendChild(a),s.addEventListener("input",function(o){c=this.value.length,a.innerHTML=`${c}/${e}`,c===10&&o.preventDefault()})}t.setAttribute("data-textarea-initialized","true")}})},D=r=>{r.forEach(t=>{t.classList.remove("is-active")})},T=()=>{document.querySelectorAll(".chips-list").forEach(t=>{if(!t.getAttribute("data-chips-initialized")){const c=t.querySelectorAll(".chips"),s=t.classList.contains("is-multiple");c.forEach(e=>{e.classList.contains("is-disabled")||e.addEventListener("click",function(){s||D(c),e.classList.toggle("is-active")})}),t.setAttribute("data-chips-initialized","true")}})},H=r=>{if(!r.getAttribute("data-progress-radial-initialized")){let i=Number(r.getAttribute("data-progress-radial-first-value")),c=Number(r.getAttribute("data-progress-radial-second-value")),s="",e=0,a=0;if(c===0){const o=setInterval(()=>{e!==i?e+=1:clearInterval(o),s=`radial-gradient(white 58%, transparent 51%),
|
|
2
|
+
conic-gradient(#0C7B91 0deg ${360*(e/100)}deg,
|
|
3
|
+
gainsboro ${360*(e/100)}deg 360deg)`,r.style.background=s},13)}else{c+=i;const o=setInterval(()=>{e<i&&(e+=1),a<c?a+=1:clearInterval(o),s=`radial-gradient(white 58%, transparent 51%),
|
|
4
|
+
conic-gradient(#0C7B91 0deg ${360*(e/100)}deg,
|
|
5
|
+
#25465f ${360*(e/100)}deg ${360*(a/100)}deg,
|
|
6
|
+
gainsboro ${360*(a/100)}deg 360deg)`,r.style.background=s},13)}r.setAttribute("data-progress-radial-initialized","true")}},F=r=>{let t=r.querySelector(".range-cursor-min"),i=r.querySelector(".range-cursor-max"),c=r.querySelector(".range-track"),s=r.querySelector(".range-value-min"),e=r.querySelector(".range-value-max"),a=t.max,o=0;const u=()=>{let l=Number(t.value)/Number(a)*100,n=Number(i.value)/Number(a)*100;c.style.background=`linear-gradient(to right, #E1E1E1 ${l}% , #0C7B91 ${l}% , #0C7B91 ${n}%, #E1E1E1 ${n}%) `};u(),t.addEventListener("input",l=>{const n=l.target;Number(n.value)<Number(i.value)-o?t.value=n.value:t.value=String(Number(i.value)-o),s.textContent=n.value,u()}),i.addEventListener("input",l=>{const n=l.target;Number(n.value)>Number(t.value)+o?i.value=n.value:i.value=String(Number(t.value)+o),e.textContent=n.value,u()}),r.setAttribute("data-ranges-initialized","true")},R=(r,t)=>{new IntersectionObserver(c=>{c.forEach(s=>{s.isIntersecting&&t(s.target)})}).observe(r)},$=()=>{const r=document.querySelectorAll("[data-select-name]");r&&r.forEach(t=>{const i=t.querySelector("label");if(!t.classList.contains("select-disabled")){const c=t.parentNode;let s=c.querySelector("[data-is-open-options]");t.addEventListener("click",()=>{const a=s.getAttribute("data-is-open-options");a==="true"&&s.setAttribute("data-is-open-options","false"),a==="false"&&s.setAttribute("data-is-open-options","true")}),t.addEventListener("blur",()=>{s.setAttribute("data-is-open-options","false")});const e=s.querySelectorAll("[data-option-name]");e.forEach(a=>{a.classList.contains("select-options-option-disabled")||a.addEventListener("mousedown",()=>{e.forEach(u=>u.classList.remove("select-options-option-activated")),a.classList.add("select-options-option-activated");let o=t.querySelector("[data-option-selected]");o||(o=document.createElement("span"),o.classList.add("select-value"),(!i||i===null)&&o.classList.add("no-label"),t.appendChild(o)),t.setAttribute("data-option-selected",a.getAttribute("data-option-name")),o.setAttribute("data-option-selected",a.getAttribute("data-option-name")),o.textContent=a.getAttribute("data-option-name"),c.classList.add("has-dynamic-placeholder")})})}t.setAttribute("data-selects-initialized","true")})},V=()=>{const r=document.querySelectorAll("[data-has-gauge]");r&&r.forEach(t=>{var A,x;const i="#007B52",c="#707070",s="#D42D02",e="#FFBB33",a=t.querySelector("input"),o=t.querySelector("[data-gauge]"),u=(A=t.querySelector("[data-length-min]"))==null?void 0:A.getAttribute("data-length-min"),l=(x=t.querySelector("[data-length-max]"))==null?void 0:x.getAttribute("data-length-max"),n={},d={fn:f=>l&&!u?f.length>0&&f.length<=Number(l):u&&!l?f.length>=Number(u):l&&u?f.length>=Number(u)&&f.length<=Number(l):!1,ref:t.querySelector("[data-security-length]")},m={fn:f=>/[^\w\*]/.test(f),ref:t.querySelector("[data-security-special-chars]")},g={fn:f=>/[0-9]/.test(f),ref:t.querySelector("[data-security-number]")},y={fn:f=>/[A-Z]/.test(f),ref:t.querySelector("[data-security-uppercase]")},h={fn:f=>/[a-z]/.test(f),ref:t.querySelector("[data-security-lowercase]")};g.ref&&Object.assign(n,{numberVerify:g}),d.ref&&Object.assign(n,{lengthVerify:d}),h.ref&&Object.assign(n,{lowercaseVerify:h}),y.ref&&Object.assign(n,{uppercaseVerify:y}),m.ref&&Object.assign(n,{specialCharsverify:m}),Object.keys(n).length;const S=f=>{const p=[];return Object.keys(n).map(b=>{const E=n[b].fn(f),L=n[b].ref.querySelector("[data-icon-securities]").querySelector("i");p.push(E),E?(L.classList.remove("tri-times-circle"),L.classList.add("tri-check-circle","is-success")):(L.classList.remove("tri-check-circle","is-success"),L.classList.add("tri-times-circle"))}),p.filter(b=>b).length},w=f=>{const p=Number((f/Object.keys(n).length*100).toFixed(0));p<=50&&p>0?(o.style.width="50%",o.style.backgroundColor=s):p<=99&&p>50?(o.style.width="75%",o.style.backgroundColor=e):p===100?(o.style.width="100%",o.style.backgroundColor=i):(o.style.width="0%",o.style.backgroundColor=c)},q=f=>{const p=f.target.value,b=S(p);w(b)};a.addEventListener("input",q),t.setAttribute("data-gauges-initialized","true")})},B=()=>{const r=document.querySelectorAll("[data-show-pwd]");r&&r.forEach(t=>{const i=e=>{e.classList.contains("tri-eye")?(e.classList.remove("tri-eye"),e.classList.add("tri-eye-slash")):(e.classList.remove("tri-eye-slash"),e.classList.add("tri-eye"))},c=e=>{const a=e.parentNode.parentNode;let o=a.querySelector("input");o||(o=a.parentNode.querySelector("input")),o.type==="password"?o.type="text":o.type="password"},s=e=>{const a=e.target;i(a),c(a)};t.addEventListener("click",s),t.setAttribute("data-iconsShowPwd-initialized","true")})},P=()=>{N(),v(),C(),k(),z(),I(),M(),O(),T(),$(),V(),B()};let j=!1;j||document.addEventListener("DOMContentLoaded",function(){P(),j=!0;const r={attributes:!0,childList:!0,subtree:!0};new MutationObserver(function(i){i.forEach(function(c){const s=c.target;if(s){const e=s.querySelectorAll("[data-modal-context]"),a=s.querySelectorAll(".accordions"),o=s.querySelectorAll(".countdown"),u=s.querySelectorAll("[data-tabs-context]"),l=s.querySelectorAll("[data-autocomplete-context]"),n=s.querySelectorAll('[data-variant="auto"]'),d=s.querySelectorAll(".segmented-control-item"),m=document.querySelectorAll(".textarea"),g=document.querySelectorAll(".progress-radial"),y=document.querySelectorAll(".range-container"),h=document.querySelectorAll(".chips-list"),S=s.querySelectorAll("[data-select-name]"),w=document.querySelectorAll("[data-has-gauge]"),q=document.querySelectorAll("[data-show-pwd]"),A=s.querySelectorAll("[data-expandable-row]");[{modal:e},{accordion:a},{tab:u},{countdown:o},{autocomplete:l},{fontVariant:n},{segmentedControl:d},{textareas:m},{ranges:y},{progressRadials:g},{chips:h},{selects:S},{gauges:w},{iconsShowPwd:q},{tableexpansion:A}].forEach(f=>{const p=Object.keys(f)[0];f[p].length&&f[p].forEach(b=>{if(b.getAttribute(`data-${p}-initialized`)!=="true")switch(b.setAttribute(`data-${p}-initialized`,"true"),p){case"modal":return v();case"tab":return N();case"countdown":return k();case"autocomplete":return I();case"fontVariant":return C();case"segmentedControl":return M();case"textareas":return O();case"chips":return T();case"selects":return $();case"ranges":return F(b);case"progressRadials":return R(b,H);case"gauges":return V();case"iconsShowPwd":return B();case"tableexpansion":return z();default:return P()}})})}})}).observe(document.documentElement,r)})});
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trilogy-ds/vanilla",
|
|
3
|
+
"version": "0.0.1-alpha-prompt",
|
|
4
|
+
"author": "Bouygues Telecom",
|
|
5
|
+
"main": "lib/trilogy-ds-vanilla.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "webpack --watch",
|
|
8
|
+
"build": "rimraf ./lib && vite --config vite.config.js build",
|
|
9
|
+
"serve": "npm run build && npx http-server -p 8090 ./lib"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/BouyguesTelecom/trilogy",
|
|
14
|
+
"directory": "packages/vanilla"
|
|
15
|
+
},
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"http-server": "^14.1.1",
|
|
19
|
+
"ts-loader": "^8.0.17",
|
|
20
|
+
"typescript": "^4.1.5",
|
|
21
|
+
"vite": "^4.5.2",
|
|
22
|
+
"vite-tsconfig-paths": "^4.3.1",
|
|
23
|
+
"@storybook/builder-webpack5": "8.1.10",
|
|
24
|
+
"eslint": "^9.5.0",
|
|
25
|
+
"fork-ts-checker-webpack-plugin": "^6.1.0",
|
|
26
|
+
"rimraf": "^3.0.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { initModals } from './components/modal'
|
|
2
|
+
import { initVariant } from './components/font-variant'
|
|
3
|
+
import { initCountdowns } from './components/countdown'
|
|
4
|
+
import { initTableExpansion } from './components/table-expansion'
|
|
5
|
+
import { initTabs } from './components/tabs'
|
|
6
|
+
import { initAutocomplete } from './components/autocomplete'
|
|
7
|
+
import { initSegmentedControl } from './components/segmented-control'
|
|
8
|
+
import { initTextarea } from './components/textarea'
|
|
9
|
+
import { initChips } from './components/chips'
|
|
10
|
+
import { initProgressRadial } from './components/progress-radial'
|
|
11
|
+
import { initRange } from './components/range'
|
|
12
|
+
import { intersectionObserver } from './utils/intersectionObserver'
|
|
13
|
+
import { initSelects } from './components/select'
|
|
14
|
+
import { initInputGauge } from './components/input-gauge'
|
|
15
|
+
import { initInputIcon } from './components/input-icon'
|
|
16
|
+
|
|
17
|
+
const loadVanilla = () => {
|
|
18
|
+
initTabs()
|
|
19
|
+
initModals()
|
|
20
|
+
initVariant()
|
|
21
|
+
initCountdowns()
|
|
22
|
+
initTableExpansion()
|
|
23
|
+
initAutocomplete()
|
|
24
|
+
initSegmentedControl()
|
|
25
|
+
initTextarea()
|
|
26
|
+
initChips()
|
|
27
|
+
initSelects()
|
|
28
|
+
initInputGauge()
|
|
29
|
+
initInputIcon()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let isInitialized = false
|
|
33
|
+
|
|
34
|
+
if (!isInitialized) {
|
|
35
|
+
// when DOM is loaded
|
|
36
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
37
|
+
loadVanilla()
|
|
38
|
+
|
|
39
|
+
// Assign variable to true
|
|
40
|
+
isInitialized = true
|
|
41
|
+
|
|
42
|
+
// Observer config
|
|
43
|
+
const observerConfig = {
|
|
44
|
+
attributes: true,
|
|
45
|
+
childList: true,
|
|
46
|
+
subtree: true,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Checking mutations
|
|
50
|
+
const mutationObserver = new MutationObserver(function (mutations: MutationRecord[]) {
|
|
51
|
+
mutations.forEach(function (mutation: MutationRecord) {
|
|
52
|
+
const mutationTarget = mutation.target as HTMLElement
|
|
53
|
+
|
|
54
|
+
if (mutationTarget) {
|
|
55
|
+
const modals = mutationTarget.querySelectorAll('[data-modal-context]')
|
|
56
|
+
const accordions = mutationTarget.querySelectorAll('.accordions')
|
|
57
|
+
const countdowns = mutationTarget.querySelectorAll('.countdown')
|
|
58
|
+
const tabs = mutationTarget.querySelectorAll('[data-tabs-context]')
|
|
59
|
+
const autocomplete = mutationTarget.querySelectorAll('[data-autocomplete-context]')
|
|
60
|
+
const fontVariant = mutationTarget.querySelectorAll('[data-variant="auto"]')
|
|
61
|
+
const segmentedControl = mutationTarget.querySelectorAll('.segmented-control-item')
|
|
62
|
+
const textareas = document.querySelectorAll('.textarea')
|
|
63
|
+
const progressRadials = document.querySelectorAll('.progress-radial')
|
|
64
|
+
const ranges = document.querySelectorAll('.range-container')
|
|
65
|
+
const chips = document.querySelectorAll('.chips-list')
|
|
66
|
+
const selects = mutationTarget.querySelectorAll('[data-select-name]')
|
|
67
|
+
const gauges = document.querySelectorAll<HTMLElement>('[data-has-gauge]')
|
|
68
|
+
const iconsShowPwd = document.querySelectorAll<HTMLElement>('[data-show-pwd]')
|
|
69
|
+
const tableexpansion = mutationTarget.querySelectorAll('[data-expandable-row]')
|
|
70
|
+
|
|
71
|
+
const elements = [
|
|
72
|
+
{ modal: modals },
|
|
73
|
+
{ accordion: accordions },
|
|
74
|
+
{ tab: tabs },
|
|
75
|
+
{ countdown: countdowns },
|
|
76
|
+
{ autocomplete: autocomplete },
|
|
77
|
+
{ fontVariant: fontVariant },
|
|
78
|
+
{ segmentedControl: segmentedControl },
|
|
79
|
+
{ textareas: textareas },
|
|
80
|
+
{ ranges: ranges },
|
|
81
|
+
{ progressRadials: progressRadials },
|
|
82
|
+
{ chips: chips },
|
|
83
|
+
{ selects: selects },
|
|
84
|
+
{ gauges: gauges },
|
|
85
|
+
{ iconsShowPwd: iconsShowPwd },
|
|
86
|
+
{ tableexpansion: tableexpansion },
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
elements.forEach((element: any) => {
|
|
90
|
+
const key = Object.keys(element)[0]
|
|
91
|
+
if (element[key].length) {
|
|
92
|
+
element[key].forEach((htmlElement: HTMLElement) => {
|
|
93
|
+
const initialized = htmlElement.getAttribute(`data-${key}-initialized`)
|
|
94
|
+
if (initialized !== 'true') {
|
|
95
|
+
htmlElement.setAttribute(`data-${key}-initialized`, 'true')
|
|
96
|
+
switch (key) {
|
|
97
|
+
case 'modal':
|
|
98
|
+
return initModals()
|
|
99
|
+
case 'tab':
|
|
100
|
+
return initTabs()
|
|
101
|
+
case 'countdown':
|
|
102
|
+
return initCountdowns()
|
|
103
|
+
case 'autocomplete':
|
|
104
|
+
return initAutocomplete()
|
|
105
|
+
case 'fontVariant':
|
|
106
|
+
return initVariant()
|
|
107
|
+
case 'segmentedControl':
|
|
108
|
+
return initSegmentedControl()
|
|
109
|
+
case 'textareas':
|
|
110
|
+
return initTextarea()
|
|
111
|
+
case 'chips':
|
|
112
|
+
return initChips()
|
|
113
|
+
case 'selects':
|
|
114
|
+
return initSelects()
|
|
115
|
+
case 'ranges':
|
|
116
|
+
return initRange(htmlElement)
|
|
117
|
+
case 'progressRadials':
|
|
118
|
+
return intersectionObserver(htmlElement, initProgressRadial)
|
|
119
|
+
case 'gauges':
|
|
120
|
+
return initInputGauge()
|
|
121
|
+
case 'iconsShowPwd':
|
|
122
|
+
return initInputIcon()
|
|
123
|
+
case 'tableexpansion':
|
|
124
|
+
return initTableExpansion()
|
|
125
|
+
default:
|
|
126
|
+
return loadVanilla()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
mutationObserver.observe(document.documentElement, observerConfig)
|
|
137
|
+
})
|
|
138
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export const initAutocomplete = () => {
|
|
2
|
+
const autocompleteContainer = document.querySelectorAll('[data-autocomplete-context]')
|
|
3
|
+
|
|
4
|
+
autocompleteContainer.forEach((autocompleteConainterElmt: HTMLDivElement) => {
|
|
5
|
+
const inputAutocomplete: HTMLInputElement = autocompleteConainterElmt.querySelector('[data-autocomplete-input]')
|
|
6
|
+
const autocompleteMenu: HTMLDivElement = autocompleteConainterElmt.querySelector('[data-autocomplete-menu]')
|
|
7
|
+
const autocompleteItems = autocompleteMenu.querySelectorAll('.autocomplete-item')
|
|
8
|
+
|
|
9
|
+
let currentItems = -1
|
|
10
|
+
let itemSelected = ''
|
|
11
|
+
|
|
12
|
+
const onBlur = () => {
|
|
13
|
+
currentItems = -1
|
|
14
|
+
document.body.classList.remove('autocomplete-close')
|
|
15
|
+
autocompleteConainterElmt.classList.remove('is-active')
|
|
16
|
+
inputAutocomplete.blur()
|
|
17
|
+
autocompleteItems.forEach((item: HTMLDivElement) => {
|
|
18
|
+
item.removeAttribute('data-autocomplete-item-hover')
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// add data attributte on items
|
|
23
|
+
const itemsList = autocompleteMenu.querySelectorAll('.autocomplete-item')
|
|
24
|
+
itemsList.forEach((item: HTMLDivElement, index: number) => {
|
|
25
|
+
item.setAttribute('data-autocomplete-item-index', String(index))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Open suggestions
|
|
29
|
+
inputAutocomplete.addEventListener('focus', (eventFocus: FocusEvent) => {
|
|
30
|
+
eventFocus.stopPropagation()
|
|
31
|
+
autocompleteConainterElmt.closest('.is-autocomplete').classList.add('is-active')
|
|
32
|
+
document.body.classList.add('autocomplete-close')
|
|
33
|
+
const items: HTMLDivElement[] = []
|
|
34
|
+
|
|
35
|
+
// open with suggestions filtered
|
|
36
|
+
autocompleteItems.forEach((item: HTMLDivElement) => {
|
|
37
|
+
if (item.textContent.trim().toLocaleLowerCase().includes(inputAutocomplete.value.trim().toLocaleLowerCase())) {
|
|
38
|
+
item.style.display = 'block'
|
|
39
|
+
items.push(item)
|
|
40
|
+
} else {
|
|
41
|
+
item.style.display = 'none'
|
|
42
|
+
}
|
|
43
|
+
item.removeAttribute('data-autocomplete-item-index')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
items.forEach((item: HTMLDivElement, index: number) => {
|
|
47
|
+
item.setAttribute('data-autocomplete-item-index', String(index))
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// on hover and blur item
|
|
52
|
+
autocompleteItems.forEach((autocompleteItem: HTMLDivElement) => {
|
|
53
|
+
autocompleteItem.addEventListener('mousemove', () => {
|
|
54
|
+
autocompleteItems.forEach((i: HTMLDivElement) => {
|
|
55
|
+
i.removeAttribute('data-autocomplete-item-hover')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const index = autocompleteItem.getAttribute('data-autocomplete-item-index')
|
|
59
|
+
currentItems = Number(index)
|
|
60
|
+
autocompleteItem.setAttribute('data-autocomplete-item-hover', 'true')
|
|
61
|
+
itemSelected = ''
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
autocompleteItem.addEventListener('mouseout', () => {
|
|
65
|
+
autocompleteItem.removeAttribute('data-autocomplete-item-hover')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
autocompleteItem.addEventListener('click', (eventClick: MouseEvent) => {
|
|
69
|
+
const targetItem = eventClick.target as HTMLInputElement
|
|
70
|
+
inputAutocomplete.value = targetItem.textContent
|
|
71
|
+
onBlur()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// filter suggestions
|
|
76
|
+
inputAutocomplete.addEventListener('input', (eventInput: InputEvent) => {
|
|
77
|
+
const target = eventInput.target as HTMLInputElement
|
|
78
|
+
if (currentItems !== -1) currentItems = -1
|
|
79
|
+
const items: HTMLDivElement[] = []
|
|
80
|
+
|
|
81
|
+
autocompleteItems.forEach((item: HTMLDivElement) => {
|
|
82
|
+
if (item.textContent.trim().toLocaleLowerCase().includes(target.value.trim().toLocaleLowerCase())) {
|
|
83
|
+
item.style.display = 'block'
|
|
84
|
+
items.push(item)
|
|
85
|
+
} else {
|
|
86
|
+
item.style.display = 'none'
|
|
87
|
+
}
|
|
88
|
+
item.removeAttribute('data-autocomplete-item-index')
|
|
89
|
+
item.removeAttribute('data-autocomplete-item-hover')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
items.forEach((item: HTMLDivElement, index: number) => {
|
|
93
|
+
item.setAttribute('data-autocomplete-item-index', String(index))
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// on select items with keyboard
|
|
98
|
+
inputAutocomplete.addEventListener('keydown', (eventKeyboard: KeyboardEvent) => {
|
|
99
|
+
const itemsList = autocompleteMenu.querySelectorAll('[data-autocomplete-item-index]')
|
|
100
|
+
|
|
101
|
+
if (eventKeyboard.key === 'ArrowDown') {
|
|
102
|
+
currentItems = currentItems + 1
|
|
103
|
+
if (currentItems === itemsList.length) currentItems = 0
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (eventKeyboard.key === 'ArrowUp') {
|
|
107
|
+
currentItems = currentItems - 1
|
|
108
|
+
if (currentItems < 0) currentItems = itemsList.length - 1
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (['ArrowDown', 'ArrowUp'].includes(eventKeyboard.key)) {
|
|
112
|
+
itemsList.forEach((item: HTMLDivElement) => {
|
|
113
|
+
item.removeAttribute('data-autocomplete-item-hover')
|
|
114
|
+
})
|
|
115
|
+
itemsList[currentItems].setAttribute('data-autocomplete-item-hover', 'true')
|
|
116
|
+
itemSelected = itemsList[currentItems].textContent
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (eventKeyboard.key === 'Enter' && itemSelected.trim().length > 0) {
|
|
120
|
+
inputAutocomplete.value = itemSelected
|
|
121
|
+
onBlur()
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
// on blur
|
|
126
|
+
// set timeout for click item before blur input
|
|
127
|
+
inputAutocomplete.addEventListener('blur', () => {
|
|
128
|
+
setTimeout(() => onBlur(), 100)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
autocompleteConainterElmt.setAttribute(`data-autocomplete-initialized`, 'true')
|
|
132
|
+
})
|
|
133
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const _resetChips = (chipsList: any) => {
|
|
2
|
+
chipsList.forEach((chips: any) => {
|
|
3
|
+
chips.classList.remove('is-active');
|
|
4
|
+
})
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const initChips = () => {
|
|
8
|
+
const allChipsLists = document.querySelectorAll(".chips-list");
|
|
9
|
+
|
|
10
|
+
allChipsLists.forEach((chipsList: any) => {
|
|
11
|
+
const isInitialized = chipsList.getAttribute('data-chips-initialized');
|
|
12
|
+
if (!isInitialized) {
|
|
13
|
+
const chips = chipsList.querySelectorAll('.chips');
|
|
14
|
+
const isMultiple = chipsList.classList.contains('is-multiple');
|
|
15
|
+
chips.forEach((chip: HTMLElement) => {
|
|
16
|
+
if (!chip.classList.contains('is-disabled')) {
|
|
17
|
+
chip.addEventListener("click", function () {
|
|
18
|
+
if (!isMultiple) {
|
|
19
|
+
_resetChips(chips);
|
|
20
|
+
}
|
|
21
|
+
chip.classList.toggle('is-active');
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
chipsList.setAttribute('data-chips-initialized', 'true');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const initCountdowns = () => {
|
|
2
|
+
|
|
3
|
+
let countdowns: NodeListOf<HTMLElement> = document.querySelectorAll('[data-countdown]');
|
|
4
|
+
|
|
5
|
+
countdowns.forEach((countdown: HTMLElement) => {
|
|
6
|
+
const second = 1000,
|
|
7
|
+
minute = second * 60,
|
|
8
|
+
hour = minute * 60,
|
|
9
|
+
day = hour * 24;
|
|
10
|
+
|
|
11
|
+
let countdownElements = countdown;
|
|
12
|
+
let countDown = new Date(countdownElements.dataset.date).getTime();
|
|
13
|
+
let numbersDays: HTMLElement = countdownElements.querySelector('[data-days]');
|
|
14
|
+
let numbersHours: HTMLElement = countdownElements.querySelector('[data-hours]');
|
|
15
|
+
let numbersMinutes: HTMLElement = countdownElements.querySelector('[data-minutes]');
|
|
16
|
+
let numbersSeconds: HTMLElement = countdownElements.querySelector('[data-seconds]');
|
|
17
|
+
|
|
18
|
+
let timer = setInterval(() => {
|
|
19
|
+
|
|
20
|
+
let now = new Date().getTime();
|
|
21
|
+
let distance = 0;
|
|
22
|
+
if ((countDown - now) > 0) {
|
|
23
|
+
distance = (countDown - now);
|
|
24
|
+
}
|
|
25
|
+
if (distance <= 0) {
|
|
26
|
+
clearInterval(timer);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
numbersDays.innerText = Math.floor(distance / (day)).toString(),
|
|
30
|
+
numbersHours.innerText = Math.floor((distance % (day)) / (hour)).toString(),
|
|
31
|
+
numbersMinutes.innerText = Math.floor((distance % (hour)) / (minute)).toString(),
|
|
32
|
+
numbersSeconds.innerText = Math.floor((distance % (minute)) / second).toString();
|
|
33
|
+
|
|
34
|
+
}, second)
|
|
35
|
+
countdownElements.setAttribute(`data-countdown-initialized`, 'true')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default initCountdowns;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const initVariant = () => {
|
|
2
|
+
let titres = document.querySelectorAll('[data-variant="auto"]');
|
|
3
|
+
|
|
4
|
+
const hashCode = function (string: string) {
|
|
5
|
+
let hashNumbers = 0;
|
|
6
|
+
let hashLength = string.length;
|
|
7
|
+
let i = 0;
|
|
8
|
+
|
|
9
|
+
if (hashLength > 0) {
|
|
10
|
+
while (i < hashLength) {
|
|
11
|
+
hashNumbers = (hashNumbers << 5) - hashNumbers + string.charCodeAt(i++) | 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return hashNumbers;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < titres.length; i++) {
|
|
18
|
+
let titre = titres[i];
|
|
19
|
+
const content = titre.textContent;
|
|
20
|
+
const charsArray = ['b', 'g', 'o', 'q'];
|
|
21
|
+
const charsIndexes: number[] = [];
|
|
22
|
+
|
|
23
|
+
content.toLowerCase().split('').map((i, j) => {
|
|
24
|
+
if (charsArray.indexOf(i) > -1) {
|
|
25
|
+
charsIndexes.push(j);
|
|
26
|
+
}
|
|
27
|
+
return i;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (charsIndexes.length) {
|
|
31
|
+
const hashContent = hashCode(content);
|
|
32
|
+
const position = Math.abs(hashContent % charsIndexes.length);
|
|
33
|
+
const char = content.charAt(charsIndexes[position]);
|
|
34
|
+
const beforeChar = content.substring(0, charsIndexes[position]);
|
|
35
|
+
const afterChar = content.substring(charsIndexes[position] + 1);
|
|
36
|
+
titre.innerHTML = `${beforeChar}<span class="has-variant">${char}</span>${afterChar}`;
|
|
37
|
+
}
|
|
38
|
+
titre.setAttribute(`data-fontVariant-initialized`, 'true')
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default initVariant;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
interface IVerifies {
|
|
2
|
+
[key: string]: { fn: (e: string) => boolean; ref: HTMLElement };
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const initInputGauge = () => {
|
|
6
|
+
const pwdInput = document.querySelectorAll<HTMLElement>("[data-has-gauge]");
|
|
7
|
+
|
|
8
|
+
if (pwdInput) {
|
|
9
|
+
pwdInput.forEach((htmlElement: HTMLElement) => {
|
|
10
|
+
const green: string = "#007B52";
|
|
11
|
+
const grey: string = "#707070";
|
|
12
|
+
const red: string = "#D42D02";
|
|
13
|
+
const yellow: string = "#FFBB33";
|
|
14
|
+
|
|
15
|
+
const input = htmlElement.querySelector("input") as HTMLElement;
|
|
16
|
+
const gauge = htmlElement.querySelector("[data-gauge]") as HTMLElement;
|
|
17
|
+
const min = htmlElement.querySelector("[data-length-min]")?.getAttribute("data-length-min");
|
|
18
|
+
const max = htmlElement.querySelector("[data-length-max]")?.getAttribute("data-length-max");
|
|
19
|
+
const dataVerifies: IVerifies = {};
|
|
20
|
+
let nbVerified = 0;
|
|
21
|
+
|
|
22
|
+
const lengthVerify = {
|
|
23
|
+
fn: (e: string) => {
|
|
24
|
+
if (max && !min) {
|
|
25
|
+
return e.length > 0 && e.length <= Number(max);
|
|
26
|
+
}
|
|
27
|
+
if (min && !max) {
|
|
28
|
+
return e.length >= Number(min);
|
|
29
|
+
}
|
|
30
|
+
if (max && min) {
|
|
31
|
+
return e.length >= Number(min) && e.length <= Number(max);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
},
|
|
35
|
+
ref: htmlElement.querySelector("[data-security-length]") as HTMLElement,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const specialCharsverify = {
|
|
39
|
+
fn: (e: string) => /[^\w\*]/.test(e),
|
|
40
|
+
ref: htmlElement.querySelector("[data-security-special-chars]") as HTMLElement,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const numberVerify = {
|
|
44
|
+
fn: (e: string) => /[0-9]/.test(e),
|
|
45
|
+
ref: htmlElement.querySelector("[data-security-number]") as HTMLElement,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const uppercaseVerify = {
|
|
49
|
+
fn: (e: string) => /[A-Z]/.test(e),
|
|
50
|
+
ref: htmlElement.querySelector("[data-security-uppercase]") as HTMLElement,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const lowercaseVerify = {
|
|
54
|
+
fn: (e: string) => /[a-z]/.test(e),
|
|
55
|
+
ref: htmlElement.querySelector("[data-security-lowercase]") as HTMLElement,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (numberVerify.ref) Object.assign(dataVerifies, { numberVerify });
|
|
59
|
+
if (lengthVerify.ref) Object.assign(dataVerifies, { lengthVerify });
|
|
60
|
+
if (lowercaseVerify.ref) Object.assign(dataVerifies, { lowercaseVerify });
|
|
61
|
+
if (uppercaseVerify.ref) Object.assign(dataVerifies, { uppercaseVerify });
|
|
62
|
+
if (specialCharsverify.ref) Object.assign(dataVerifies, { specialCharsverify });
|
|
63
|
+
nbVerified = Object.keys(dataVerifies).length;
|
|
64
|
+
|
|
65
|
+
const handleChangeIconsVerify = (e: string): number => {
|
|
66
|
+
const verifiesTests: boolean[] = [];
|
|
67
|
+
|
|
68
|
+
Object.keys(dataVerifies).map((key: string) => {
|
|
69
|
+
const test = dataVerifies[key].fn(e);
|
|
70
|
+
const icon = dataVerifies[key].ref.querySelector("[data-icon-securities]").querySelector("i");
|
|
71
|
+
verifiesTests.push(test);
|
|
72
|
+
|
|
73
|
+
if (test) {
|
|
74
|
+
icon.classList.remove("tri-times-circle");
|
|
75
|
+
icon.classList.add("tri-check-circle", "is-success");
|
|
76
|
+
} else {
|
|
77
|
+
icon.classList.remove("tri-check-circle", "is-success");
|
|
78
|
+
icon.classList.add("tri-times-circle");
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return verifiesTests.filter((item) => item).length;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleChangeGauge = (points: number) => {
|
|
85
|
+
const calc = Number(((points / Object.keys(dataVerifies).length) * 100).toFixed(0));
|
|
86
|
+
if (calc <= 50 && calc > 0) {
|
|
87
|
+
gauge.style.width = "50%";
|
|
88
|
+
gauge.style.backgroundColor = red;
|
|
89
|
+
} else if (calc <= 99 && calc > 50) {
|
|
90
|
+
gauge.style.width = "75%";
|
|
91
|
+
gauge.style.backgroundColor = yellow;
|
|
92
|
+
} else if (calc === 100) {
|
|
93
|
+
gauge.style.width = "100%";
|
|
94
|
+
gauge.style.backgroundColor = green;
|
|
95
|
+
} else {
|
|
96
|
+
gauge.style.width = "0%";
|
|
97
|
+
gauge.style.backgroundColor = grey;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const onInput = (e: InputEvent) => {
|
|
102
|
+
const value = (e.target as HTMLInputElement).value;
|
|
103
|
+
const points = handleChangeIconsVerify(value);
|
|
104
|
+
handleChangeGauge(points);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
input.addEventListener("input", onInput);
|
|
108
|
+
htmlElement.setAttribute(`data-gauges-initialized`, 'true')
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const initInputIcon = () => {
|
|
2
|
+
const iconsShowPwd = document.querySelectorAll<HTMLElement>("[data-show-pwd]");
|
|
3
|
+
|
|
4
|
+
if (iconsShowPwd) {
|
|
5
|
+
iconsShowPwd.forEach((htmlElement: HTMLElement) => {
|
|
6
|
+
const changeIcon = (icon: HTMLElement) => {
|
|
7
|
+
if (icon.classList.contains("tri-eye")) {
|
|
8
|
+
icon.classList.remove("tri-eye");
|
|
9
|
+
icon.classList.add("tri-eye-slash");
|
|
10
|
+
} else {
|
|
11
|
+
icon.classList.remove("tri-eye-slash");
|
|
12
|
+
icon.classList.add("tri-eye");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const changeTypeInput = (icon: HTMLElement) => {
|
|
17
|
+
const parent = icon.parentNode.parentNode;
|
|
18
|
+
let input = parent.querySelector("input");
|
|
19
|
+
if (!input) input = parent.parentNode.querySelector("input");
|
|
20
|
+
if (input.type === "password") {
|
|
21
|
+
input.type = "text";
|
|
22
|
+
} else {
|
|
23
|
+
input.type = "password";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const handleClickIcon = (e: Event) => {
|
|
28
|
+
const target = e.target as HTMLElement;
|
|
29
|
+
changeIcon(target);
|
|
30
|
+
changeTypeInput(target);
|
|
31
|
+
};
|
|
32
|
+
htmlElement.addEventListener("click", handleClickIcon);
|
|
33
|
+
htmlElement.setAttribute(`data-iconsShowPwd-initialized`, 'true')
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export const initModals = () => {
|
|
2
|
+
|
|
3
|
+
let modalContexts: NodeListOf<HTMLElement> = document.querySelectorAll('[data-modal-context]');
|
|
4
|
+
|
|
5
|
+
for (let i = 0; i < modalContexts.length; i++) {
|
|
6
|
+
let modalContext: HTMLElement = modalContexts[i];
|
|
7
|
+
|
|
8
|
+
let modalOpenButtons: NodeListOf<HTMLElement> = modalContext.querySelectorAll('[data-modal-open]');
|
|
9
|
+
let modalElement: HTMLElement = modalContext.querySelector('[data-modal]');
|
|
10
|
+
let modalCloseButtons: NodeListOf<HTMLElement> = modalContext.querySelectorAll('[data-modal-close]');
|
|
11
|
+
let modalVideos: NodeListOf<HTMLVideoElement> = modalContext.querySelectorAll('iframe[src*="www.youtube.com"], iframe[src*="player.vimeo.com"], video');
|
|
12
|
+
|
|
13
|
+
for (let j = 0; j < modalOpenButtons.length; j++) {
|
|
14
|
+
let modalOpenButton = modalOpenButtons[j];
|
|
15
|
+
let modalVideo: HTMLVideoElement = modalVideos[j];
|
|
16
|
+
|
|
17
|
+
modalOpenButton.addEventListener('click', function () {
|
|
18
|
+
makeModalActive(modalElement);
|
|
19
|
+
if (!modalVideo) {
|
|
20
|
+
return;
|
|
21
|
+
} else {
|
|
22
|
+
if (modalVideo.tagName.toLowerCase() === 'video') {
|
|
23
|
+
modalVideo.play();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
modalVideo.src = modalVideo.src + (modalVideo.src.indexOf('?') < 0 ? '?' : '&') + 'autoplay=1';
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (let j = 0; j < modalCloseButtons.length; j++) {
|
|
32
|
+
let modalCloseButton = modalCloseButtons[j];
|
|
33
|
+
modalCloseButton.addEventListener('click', function () {
|
|
34
|
+
makeModalInactive(modalElement);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
initClosingListeners(modalElement);
|
|
39
|
+
|
|
40
|
+
// TODO: supprimer en 1.0.0
|
|
41
|
+
// rétrocompatibilité : fermeture de la modal en cliquant n'importe où
|
|
42
|
+
const background: HTMLElement = modalContext.querySelector('.modal-background');
|
|
43
|
+
if (background) {
|
|
44
|
+
background.onclick = function () {
|
|
45
|
+
makeModalInactive(modalElement);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
modalContext.setAttribute(`data-modal-initialized`, 'true')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initialise l'écoute des événements permettant de fermer une modale
|
|
53
|
+
*/
|
|
54
|
+
function initClosingListeners(modalElement: HTMLElement) {
|
|
55
|
+
document.addEventListener('keyup', function (e: any) {
|
|
56
|
+
e = e || window.event;
|
|
57
|
+
var isEscape = false;
|
|
58
|
+
if ('key' in e) {
|
|
59
|
+
isEscape = (e.key === 'Escape' || e.key === 'Esc');
|
|
60
|
+
} else {
|
|
61
|
+
isEscape = (e.keyCode === 27);
|
|
62
|
+
}
|
|
63
|
+
if (isEscape) {
|
|
64
|
+
makeModalInactive(modalElement);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
document.addEventListener('click', function (e: MouseEvent) {
|
|
69
|
+
const target = e.target as HTMLInputElement
|
|
70
|
+
let modalContent = target.closest('[data-modal-content]');
|
|
71
|
+
let isModal = target.classList.contains('modal');
|
|
72
|
+
if (modalContent === null && isModal == true) {
|
|
73
|
+
makeModalInactive(modalElement);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Make an element active
|
|
80
|
+
* @param { Element } modalElementToMakeActive element to be made active
|
|
81
|
+
*/
|
|
82
|
+
const makeModalActive = (modalElementToMakeActive: HTMLElement) => {
|
|
83
|
+
modalElementToMakeActive.classList.add('is-active');
|
|
84
|
+
document.body.style.overflow = 'hidden';
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Make an element inactive
|
|
89
|
+
* @param { Element } modalElementToMakeInactive element to be made inactive
|
|
90
|
+
*/
|
|
91
|
+
const makeModalInactive = (modalElementToMakeInactive: HTMLElement) => {
|
|
92
|
+
let video: HTMLVideoElement = modalElementToMakeInactive.querySelector('iframe[src*="youtube"], iframe[src*="vimeo"], video');
|
|
93
|
+
if (video) {
|
|
94
|
+
if (video.tagName.toLowerCase() === 'video') {
|
|
95
|
+
video.pause();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
video.src = video.src.replace('&autoplay=1', '').replace('?autoplay=1', '');
|
|
99
|
+
}
|
|
100
|
+
modalElementToMakeInactive.classList.remove('is-active');
|
|
101
|
+
document.body.style.overflow = null;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const initProgressRadial = (progressRadial: HTMLElement) => {
|
|
2
|
+
const isInitialized = progressRadial.getAttribute('data-progress-radial-initialized');
|
|
3
|
+
if (!isInitialized) {
|
|
4
|
+
let firstProgressValueMax: number = Number(progressRadial.getAttribute('data-progress-radial-first-value'));
|
|
5
|
+
let secondProgressValueMax: number = Number(progressRadial.getAttribute('data-progress-radial-second-value'));
|
|
6
|
+
let backgroundStyle: string = '';
|
|
7
|
+
|
|
8
|
+
let firstProgressCurrentValue: number = 0;
|
|
9
|
+
let secondProgressCurrentValue: number = 0;
|
|
10
|
+
|
|
11
|
+
// If second value does not exist
|
|
12
|
+
if (secondProgressValueMax === 0) {
|
|
13
|
+
const animation = setInterval(() => {
|
|
14
|
+
if (firstProgressCurrentValue !== firstProgressValueMax) {
|
|
15
|
+
firstProgressCurrentValue += 1;
|
|
16
|
+
} else {
|
|
17
|
+
clearInterval(animation);
|
|
18
|
+
}
|
|
19
|
+
backgroundStyle = `radial-gradient(white 58%, transparent 51%),
|
|
20
|
+
conic-gradient(#0C7B91 0deg ${(360 * (firstProgressCurrentValue / 100))}deg,
|
|
21
|
+
gainsboro ${(360 * (firstProgressCurrentValue / 100))}deg 360deg)`;
|
|
22
|
+
progressRadial.style.background = backgroundStyle;
|
|
23
|
+
}, 13);
|
|
24
|
+
} else {
|
|
25
|
+
secondProgressValueMax += firstProgressValueMax;
|
|
26
|
+
const animation = setInterval(() => {
|
|
27
|
+
if (firstProgressCurrentValue < firstProgressValueMax) {
|
|
28
|
+
firstProgressCurrentValue += 1;
|
|
29
|
+
}
|
|
30
|
+
if (secondProgressCurrentValue < secondProgressValueMax) {
|
|
31
|
+
secondProgressCurrentValue += 1;
|
|
32
|
+
} else {
|
|
33
|
+
clearInterval(animation);
|
|
34
|
+
}
|
|
35
|
+
backgroundStyle = `radial-gradient(white 58%, transparent 51%),
|
|
36
|
+
conic-gradient(#0C7B91 0deg ${(360 * (firstProgressCurrentValue / 100))}deg,
|
|
37
|
+
#25465f ${(360 * (firstProgressCurrentValue / 100))}deg ${(360 * (secondProgressCurrentValue / 100))}deg,
|
|
38
|
+
gainsboro ${(360 * (secondProgressCurrentValue / 100))}deg 360deg)`;
|
|
39
|
+
progressRadial.style.background = backgroundStyle;
|
|
40
|
+
}, 13);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
progressRadial.setAttribute('data-progress-radial-initialized', 'true');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const initRange = (rangeContainer: HTMLElement) => {
|
|
2
|
+
|
|
3
|
+
let HTMLInputRangeMin: HTMLInputElement = rangeContainer.querySelector(".range-cursor-min");
|
|
4
|
+
let HTMLInputRangeMax: HTMLInputElement = rangeContainer.querySelector(".range-cursor-max");
|
|
5
|
+
let track: HTMLDivElement = rangeContainer.querySelector(".range-track");
|
|
6
|
+
let valueMin: HTMLHtmlElement = rangeContainer.querySelector(".range-value-min");
|
|
7
|
+
let valueMax: HTMLHtmlElement = rangeContainer.querySelector(".range-value-max");
|
|
8
|
+
|
|
9
|
+
let maxValue = HTMLInputRangeMin.max;
|
|
10
|
+
let gap = 0;
|
|
11
|
+
|
|
12
|
+
const setColor = () => {
|
|
13
|
+
let percent1 =
|
|
14
|
+
(Number(HTMLInputRangeMin.value) / Number(maxValue)) * 100;
|
|
15
|
+
let percent2 =
|
|
16
|
+
(Number(HTMLInputRangeMax.value) / Number(maxValue)) * 100;
|
|
17
|
+
track.style.background = `linear-gradient(to right, #E1E1E1 ${percent1}% , #0C7B91 ${percent1}% , #0C7B91 ${percent2}%, #E1E1E1 ${percent2}%) `;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
setColor();
|
|
21
|
+
|
|
22
|
+
HTMLInputRangeMin.addEventListener("input", (e: InputEvent) => {
|
|
23
|
+
const event = e.target as HTMLInputElement;
|
|
24
|
+
if (Number(event.value) < Number(HTMLInputRangeMax.value) - gap) {
|
|
25
|
+
HTMLInputRangeMin.value = event.value;
|
|
26
|
+
} else {
|
|
27
|
+
HTMLInputRangeMin.value = String(
|
|
28
|
+
Number(HTMLInputRangeMax.value) - gap
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
valueMin.textContent = event.value;
|
|
32
|
+
setColor();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
HTMLInputRangeMax.addEventListener("input", (e: InputEvent) => {
|
|
36
|
+
const event = e.target as HTMLInputElement;
|
|
37
|
+
if (Number(event.value) > Number(HTMLInputRangeMin.value) + gap) {
|
|
38
|
+
HTMLInputRangeMax.value = event.value;
|
|
39
|
+
} else {
|
|
40
|
+
HTMLInputRangeMax.value = String(
|
|
41
|
+
Number(HTMLInputRangeMin.value) + gap
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
valueMax.textContent = event.value;
|
|
45
|
+
setColor();
|
|
46
|
+
});
|
|
47
|
+
rangeContainer.setAttribute(`data-ranges-initialized`, 'true')
|
|
48
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const initSegmentedControl = () => {
|
|
2
|
+
const HTMLButtons = document.querySelectorAll(".segmented-control-item");
|
|
3
|
+
|
|
4
|
+
HTMLButtons.forEach((button: HTMLButtonElement) => {
|
|
5
|
+
button.addEventListener("click", function () {
|
|
6
|
+
this.parentElement
|
|
7
|
+
.querySelector(".is-active")
|
|
8
|
+
.classList.remove("is-active");
|
|
9
|
+
|
|
10
|
+
if (!button.classList.contains("is-active")) {
|
|
11
|
+
button.classList.add("is-active");
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
button.setAttribute(`data-segmentedControl-initialized`, 'true')
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const initSelects = () => {
|
|
2
|
+
const HTMLSelects = document.querySelectorAll('[data-select-name]')
|
|
3
|
+
|
|
4
|
+
if (HTMLSelects) {
|
|
5
|
+
HTMLSelects.forEach((HTMLSelect: HTMLDivElement) => {
|
|
6
|
+
const HTMLLabel = HTMLSelect.querySelector('label')
|
|
7
|
+
if (!HTMLSelect.classList.contains('select-disabled')) {
|
|
8
|
+
const HTMLParentOfSelect = HTMLSelect.parentNode as HTMLElement
|
|
9
|
+
let HTMLOptions = HTMLParentOfSelect.querySelector('[data-is-open-options]')
|
|
10
|
+
|
|
11
|
+
HTMLSelect.addEventListener('click', () => {
|
|
12
|
+
const isOpenOptions = HTMLOptions.getAttribute('data-is-open-options')
|
|
13
|
+
if (isOpenOptions === 'true') HTMLOptions.setAttribute('data-is-open-options', 'false')
|
|
14
|
+
if (isOpenOptions === 'false') HTMLOptions.setAttribute('data-is-open-options', 'true')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
HTMLSelect.addEventListener('blur', () => {
|
|
18
|
+
HTMLOptions.setAttribute('data-is-open-options', 'false')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const options = HTMLOptions.querySelectorAll('[data-option-name]')
|
|
22
|
+
options.forEach((option: HTMLElement) => {
|
|
23
|
+
if (!option.classList.contains('select-options-option-disabled')) {
|
|
24
|
+
option.addEventListener('mousedown', () => {
|
|
25
|
+
// select option
|
|
26
|
+
options.forEach((opt: HTMLElement) => opt.classList.remove('select-options-option-activated'))
|
|
27
|
+
option.classList.add('select-options-option-activated')
|
|
28
|
+
|
|
29
|
+
// insert/update otp
|
|
30
|
+
let HTMLSpan: HTMLSpanElement = HTMLSelect.querySelector('[data-option-selected]')
|
|
31
|
+
if (!HTMLSpan) {
|
|
32
|
+
HTMLSpan = document.createElement('span')
|
|
33
|
+
HTMLSpan.classList.add('select-value')
|
|
34
|
+
if (!HTMLLabel || HTMLLabel === null) HTMLSpan.classList.add('no-label')
|
|
35
|
+
HTMLSelect.appendChild(HTMLSpan)
|
|
36
|
+
}
|
|
37
|
+
HTMLSelect.setAttribute('data-option-selected', option.getAttribute('data-option-name'))
|
|
38
|
+
HTMLSpan.setAttribute('data-option-selected', option.getAttribute('data-option-name'))
|
|
39
|
+
HTMLSpan.textContent = option.getAttribute('data-option-name')
|
|
40
|
+
HTMLParentOfSelect.classList.add('has-dynamic-placeholder')
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
HTMLSelect.setAttribute(`data-selects-initialized`, 'true')
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const initSticky = () => {
|
|
2
|
+
const navbar = document.querySelector('.navbar');
|
|
3
|
+
|
|
4
|
+
const myObserverCallback: any = (event: any) => {
|
|
5
|
+
navbar.classList.toggle('enable-transition', event.intersectionRatio < 1);
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
event.target.parentNode.classList.toggle('is-sticky', event.intersectionRatio < 1)
|
|
8
|
+
}, 100);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
let observer = new IntersectionObserver(myObserverCallback, { threshold: 1 });
|
|
12
|
+
observer.observe(navbar);
|
|
13
|
+
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const initTableExpansion = () => {
|
|
2
|
+
let expandableRows: NodeListOf<HTMLElement> = document.querySelectorAll('[data-expandable-row]');
|
|
3
|
+
for (let i = 0; i < expandableRows.length; i++) {
|
|
4
|
+
let expandableRow: HTMLElement = expandableRows[i];
|
|
5
|
+
let trigger: HTMLElement = expandableRow.querySelector('[data-expandable-trigger]');
|
|
6
|
+
trigger.addEventListener('click', function () {
|
|
7
|
+
expandableRow.classList.toggle('is-expanded');
|
|
8
|
+
});
|
|
9
|
+
expandableRow.setAttribute(`data-tableexpansion-initialized`, 'true')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const initTabs = (): void => {
|
|
2
|
+
const tabList = document.querySelector('[data-tablist]') as HTMLDivElement;
|
|
3
|
+
const tabs = tabList.querySelectorAll<HTMLButtonElement>('[data-tab-navigation]');
|
|
4
|
+
const arrowPrev = tabList.querySelector<HTMLSpanElement>('[data-arrow-prev]');
|
|
5
|
+
const arrowNext = tabList.querySelector<HTMLSpanElement>('[data-arrow-next]');
|
|
6
|
+
|
|
7
|
+
const updateArrows = (): void => {
|
|
8
|
+
if (!arrowPrev || !arrowNext) return;
|
|
9
|
+
|
|
10
|
+
const scrollLeft = tabList.scrollLeft;
|
|
11
|
+
const scrollWidth = tabList.scrollWidth;
|
|
12
|
+
const clientWidth = tabList.clientWidth;
|
|
13
|
+
|
|
14
|
+
arrowPrev.classList.toggle('hidden', scrollLeft <= 0);
|
|
15
|
+
arrowNext.classList.toggle('hidden', scrollWidth <= scrollLeft + clientWidth);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const scrollTabsToNext = (direction: 1 | -1): void => {
|
|
19
|
+
const tabsArray = Array.from(tabs);
|
|
20
|
+
const currentScrollLeft = tabList.scrollLeft;
|
|
21
|
+
let targetTab: HTMLButtonElement | undefined;
|
|
22
|
+
|
|
23
|
+
if (direction === 1) {
|
|
24
|
+
targetTab = tabsArray.find(tab => tab.offsetLeft > currentScrollLeft);
|
|
25
|
+
} else {
|
|
26
|
+
targetTab = tabsArray.slice().reverse().find(tab => tab.offsetLeft < currentScrollLeft);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (targetTab) {
|
|
30
|
+
tabList.scrollTo({ left: targetTab.offsetLeft, behavior: 'smooth' });
|
|
31
|
+
} else if (direction === -1) {
|
|
32
|
+
// If we're scrolling left and no targetTab found, scroll to the very start
|
|
33
|
+
tabList.scrollTo({ left: 0, behavior: 'smooth' });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
updateArrows();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (arrowPrev) {
|
|
40
|
+
arrowPrev.addEventListener('click', () => {
|
|
41
|
+
scrollTabsToNext(-1);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (arrowNext) {
|
|
46
|
+
arrowNext.addEventListener('click', () => {
|
|
47
|
+
scrollTabsToNext(1);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
tabs.forEach((tab, index) => {
|
|
52
|
+
tab.addEventListener('click', () => {
|
|
53
|
+
tabs.forEach(t => t.classList.remove('is-active'));
|
|
54
|
+
tab.classList.add('is-active');
|
|
55
|
+
|
|
56
|
+
const panels = document.querySelectorAll<HTMLDivElement>('[data-tab-panel]');
|
|
57
|
+
panels.forEach(panel => panel.classList.remove('is-active'));
|
|
58
|
+
const activePanel = document.querySelector<HTMLDivElement>(`[data-tab-panel][data-index="${index}"]`);
|
|
59
|
+
if (activePanel) activePanel.classList.add('is-active');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
tabList.addEventListener('scroll', updateArrows);
|
|
64
|
+
|
|
65
|
+
window.addEventListener('resize', updateArrows);
|
|
66
|
+
|
|
67
|
+
updateArrows();
|
|
68
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const initTextarea = () => {
|
|
2
|
+
const textareaWrappers = document.querySelectorAll(".textarea-wrapper");
|
|
3
|
+
textareaWrappers.forEach((textareaWrapper: HTMLElement) => {
|
|
4
|
+
const isInitialized = textareaWrapper.getAttribute('data-textarea-initialized');
|
|
5
|
+
if(!isInitialized) {
|
|
6
|
+
const textarea: HTMLTextAreaElement = textareaWrapper.querySelector('textarea.textarea');
|
|
7
|
+
|
|
8
|
+
const counterMaxLength = textarea.getAttribute('maxlength');
|
|
9
|
+
if (counterMaxLength) {
|
|
10
|
+
var currentLength = 0;
|
|
11
|
+
const counter = document.createElement('div');
|
|
12
|
+
counter.classList.add('counter');
|
|
13
|
+
counter.innerHTML = `${currentLength}/${counterMaxLength}`;
|
|
14
|
+
textareaWrapper.appendChild(counter);
|
|
15
|
+
|
|
16
|
+
textarea.addEventListener("input", function (e) {
|
|
17
|
+
currentLength = this.value.length;
|
|
18
|
+
counter.innerHTML = `${currentLength}/${counterMaxLength}`;
|
|
19
|
+
if(currentLength === 10) {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
textareaWrapper.setAttribute('data-textarea-initialized', 'true');
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type functionToPlayType = (htmlElement: HTMLElement) => void;
|
|
2
|
+
|
|
3
|
+
export const intersectionObserver = (elementToObserve: HTMLElement, functionToPlay: functionToPlayType) => {
|
|
4
|
+
const observer = new IntersectionObserver((entries) => {
|
|
5
|
+
entries.forEach((entry: any) => {
|
|
6
|
+
if (entry.isIntersecting) {
|
|
7
|
+
functionToPlay(entry.target);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
observer.observe(elementToObserve);
|
|
13
|
+
}
|
package/tsconfig.json
ADDED
package/vite.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import { resolve } from 'path'
|
|
3
|
+
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [tsconfigPaths()],
|
|
7
|
+
root: resolve(__dirname, 'src/'),
|
|
8
|
+
base: './',
|
|
9
|
+
mode: 'production',
|
|
10
|
+
build: {
|
|
11
|
+
outDir: '../lib',
|
|
12
|
+
lib: {
|
|
13
|
+
entry: resolve(__dirname, 'src/app.ts'),
|
|
14
|
+
name: 'trilogy-ds-vanilla',
|
|
15
|
+
fileName: () => `trilogy-ds-vanilla.js`,
|
|
16
|
+
},
|
|
17
|
+
rollupOptions: {
|
|
18
|
+
input: {
|
|
19
|
+
main: resolve(__dirname, 'src/app.ts'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
})
|