@swisspost/design-system-components 1.4.0 → 1.5.1
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/dist/cjs/check-one-of-4c2e8b2e.js +10 -0
- package/dist/cjs/check-one-of-4c2e8b2e.js.map +1 -0
- package/dist/cjs/{check-type-f24cf91d.js → check-type-508a21a5.js} +1 -7
- package/dist/cjs/check-type-508a21a5.js.map +1 -0
- package/dist/cjs/fade-8c6d4fa7.js +12 -0
- package/dist/cjs/fade-8c6d4fa7.js.map +1 -0
- package/dist/cjs/{index-50d7d035.js → index-12cc37c9.js} +107 -5
- package/dist/cjs/index-12cc37c9.js.map +1 -0
- package/dist/cjs/index-f8f6f146.js +28 -0
- package/dist/cjs/index-f8f6f146.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/package-112e1698.js +7 -0
- package/dist/cjs/package-112e1698.js.map +1 -0
- package/dist/cjs/post-alert.cjs.entry.js +105 -0
- package/dist/cjs/post-alert.cjs.entry.js.map +1 -0
- package/dist/cjs/post-collapsible.cjs.entry.js +6 -5
- package/dist/cjs/post-collapsible.cjs.entry.js.map +1 -1
- package/dist/cjs/post-components.cjs.js +2 -2
- package/dist/cjs/post-icon.cjs.entry.js +12 -21
- package/dist/cjs/post-icon.cjs.entry.js.map +1 -1
- package/dist/cjs/post-tab-header.cjs.entry.js +4 -4
- package/dist/cjs/post-tab-header.cjs.entry.js.map +1 -1
- package/dist/cjs/post-tab-panel.cjs.entry.js +2 -2
- package/dist/cjs/post-tabs.cjs.entry.js +31 -17
- package/dist/cjs/post-tabs.cjs.entry.js.map +1 -1
- package/dist/cjs/post-tooltip.cjs.entry.js +5097 -0
- package/dist/cjs/post-tooltip.cjs.entry.js.map +1 -0
- package/dist/collection/collection-manifest.json +3 -1
- package/dist/collection/components/post-alert/alert-types.js +2 -0
- package/dist/collection/components/post-alert/alert-types.js.map +1 -0
- package/dist/collection/components/post-alert/post-alert.css +35 -0
- package/dist/collection/components/post-alert/post-alert.js +255 -0
- package/dist/collection/components/post-alert/post-alert.js.map +1 -0
- package/dist/collection/components/post-collapsible/post-collapsible.css +2 -227
- package/dist/collection/components/post-icon/post-icon.css +1 -102
- package/dist/collection/components/post-tab-header/post-tab-header.css +3 -337
- package/dist/collection/components/post-tab-header/post-tab-header.js +1 -1
- package/dist/collection/components/post-tab-header/post-tab-header.js.map +1 -1
- package/dist/collection/components/post-tab-panel/post-tab-panel.css +1 -3
- package/dist/collection/components/post-tabs/post-tabs.css +1 -148
- package/dist/collection/components/post-tabs/post-tabs.js +26 -7
- package/dist/collection/components/post-tabs/post-tabs.js.map +1 -1
- package/dist/collection/components/post-tooltip/post-tooltip.css +1 -0
- package/dist/collection/components/post-tooltip/post-tooltip.js +338 -0
- package/dist/collection/components/post-tooltip/post-tooltip.js.map +1 -0
- package/dist/collection/components/post-tooltip/types.js +2 -0
- package/dist/collection/components/post-tooltip/types.js.map +1 -0
- package/dist/collection/utils/property-checkers/check-one-of.js.map +1 -1
- package/dist/collection/utils/property-checkers/check-pattern.js +5 -0
- package/dist/collection/utils/property-checkers/check-pattern.js.map +1 -0
- package/dist/collection/utils/property-checkers/index.js +3 -0
- package/dist/collection/utils/property-checkers/index.js.map +1 -1
- package/dist/components/check-one-of.js +8 -0
- package/dist/components/check-one-of.js.map +1 -0
- package/dist/components/check-type.js +1 -6
- package/dist/components/check-type.js.map +1 -1
- package/dist/components/fade.js +9 -0
- package/dist/components/fade.js.map +1 -0
- package/dist/components/package.js +1 -1
- package/dist/components/post-alert.d.ts +11 -0
- package/dist/components/post-alert.js +135 -0
- package/dist/components/post-alert.js.map +1 -0
- package/dist/components/post-collapsible.js +3 -2
- package/dist/components/post-collapsible.js.map +1 -1
- package/dist/components/post-icon.js +1 -135
- package/dist/components/post-icon.js.map +1 -1
- package/dist/components/post-icon2.js +146 -0
- package/dist/components/post-icon2.js.map +1 -0
- package/dist/components/post-tab-header.js +2 -2
- package/dist/components/post-tab-header.js.map +1 -1
- package/dist/components/post-tabs.js +27 -13
- package/dist/components/post-tabs.js.map +1 -1
- package/dist/components/post-tooltip.d.ts +11 -0
- package/dist/components/post-tooltip.js +5118 -0
- package/dist/components/post-tooltip.js.map +1 -0
- package/dist/docs.json +313 -3
- package/dist/esm/check-one-of-ded5e15e.js +8 -0
- package/dist/esm/check-one-of-ded5e15e.js.map +1 -0
- package/dist/esm/{check-type-67411ed3.js → check-type-18ebb4e7.js} +2 -7
- package/dist/esm/check-type-18ebb4e7.js.map +1 -0
- package/dist/esm/fade-671f1489.js +9 -0
- package/dist/esm/fade-671f1489.js.map +1 -0
- package/dist/esm/{index-cc0e53f0.js → index-5611074b.js} +107 -5
- package/dist/esm/index-5611074b.js.map +1 -0
- package/dist/esm/index-7f723686.js +24 -0
- package/dist/esm/index-7f723686.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/package-331628f1.js +5 -0
- package/dist/esm/package-331628f1.js.map +1 -0
- package/dist/esm/post-alert.entry.js +101 -0
- package/dist/esm/post-alert.entry.js.map +1 -0
- package/dist/esm/post-collapsible.entry.js +5 -4
- package/dist/esm/post-collapsible.entry.js.map +1 -1
- package/dist/esm/post-components.js +3 -3
- package/dist/esm/post-icon.entry.js +7 -16
- package/dist/esm/post-icon.entry.js.map +1 -1
- package/dist/esm/post-tab-header.entry.js +4 -4
- package/dist/esm/post-tab-header.entry.js.map +1 -1
- package/dist/esm/post-tab-panel.entry.js +2 -2
- package/dist/esm/post-tabs.entry.js +29 -15
- package/dist/esm/post-tabs.entry.js.map +1 -1
- package/dist/esm/post-tooltip.entry.js +5093 -0
- package/dist/esm/post-tooltip.entry.js.map +1 -0
- package/dist/post-components/p-0d37fe44.entry.js +2 -0
- package/dist/post-components/p-0d37fe44.entry.js.map +1 -0
- package/dist/post-components/p-123bb6fb.entry.js +2 -0
- package/dist/post-components/p-123bb6fb.entry.js.map +1 -0
- package/dist/post-components/p-15fc087f.js +2 -0
- package/dist/post-components/p-15fc087f.js.map +1 -0
- package/dist/post-components/p-65a9d1c2.entry.js +2 -0
- package/dist/post-components/p-7240ae7b.entry.js +2 -0
- package/dist/post-components/p-7240ae7b.entry.js.map +1 -0
- package/dist/post-components/p-75a7b352.js +2 -0
- package/dist/post-components/p-75a7b352.js.map +1 -0
- package/dist/post-components/p-8c386036.entry.js +9 -0
- package/dist/post-components/p-8c386036.entry.js.map +1 -0
- package/dist/post-components/p-97a064da.entry.js +2 -0
- package/dist/post-components/{p-6dad6a8a.entry.js.map → p-97a064da.entry.js.map} +1 -1
- package/dist/post-components/p-bcc705f1.js +2 -0
- package/dist/post-components/p-bcc705f1.js.map +1 -0
- package/dist/post-components/p-ccae1c68.entry.js +2 -0
- package/dist/post-components/p-ccae1c68.entry.js.map +1 -0
- package/dist/post-components/p-d94db268.js +3 -0
- package/dist/post-components/p-d94db268.js.map +1 -0
- package/dist/post-components/p-e5306504.js +2 -0
- package/dist/post-components/p-e5306504.js.map +1 -0
- package/dist/post-components/p-eb3ff4dc.js +2 -0
- package/dist/post-components/post-components.esm.js +1 -1
- package/dist/post-components/post-components.esm.js.map +1 -1
- package/dist/types/components/post-alert/alert-types.d.ts +2 -0
- package/dist/types/components/post-alert/post-alert.d.ts +49 -0
- package/dist/types/components/post-tabs/post-tabs.d.ts +1 -0
- package/dist/types/components/post-tooltip/post-tooltip.d.ts +66 -0
- package/dist/types/components/post-tooltip/types.d.ts +2 -0
- package/dist/types/components.d.ts +115 -0
- package/dist/types/utils/property-checkers/check-one-of.d.ts +1 -1
- package/dist/types/utils/property-checkers/check-pattern.d.ts +1 -0
- package/dist/types/utils/property-checkers/index.d.ts +3 -1
- package/package.json +12 -8
- package/dist/cjs/check-type-f24cf91d.js.map +0 -1
- package/dist/cjs/index-50d7d035.js.map +0 -1
- package/dist/cjs/package-e8a6597e.js +0 -7
- package/dist/cjs/package-e8a6597e.js.map +0 -1
- package/dist/esm/check-type-67411ed3.js.map +0 -1
- package/dist/esm/index-cc0e53f0.js.map +0 -1
- package/dist/esm/package-b514d0f6.js +0 -5
- package/dist/esm/package-b514d0f6.js.map +0 -1
- package/dist/post-components/p-1388585d.entry.js +0 -2
- package/dist/post-components/p-1388585d.entry.js.map +0 -1
- package/dist/post-components/p-58916755.js +0 -2
- package/dist/post-components/p-5b3445dc.entry.js +0 -2
- package/dist/post-components/p-5b3445dc.entry.js.map +0 -1
- package/dist/post-components/p-6341b9b4.js +0 -3
- package/dist/post-components/p-6341b9b4.js.map +0 -1
- package/dist/post-components/p-6dad6a8a.entry.js +0 -2
- package/dist/post-components/p-b95ec099.entry.js +0 -2
- package/dist/post-components/p-cc92afb7.entry.js +0 -2
- package/dist/post-components/p-cc92afb7.entry.js.map +0 -1
- package/dist/post-components/p-f549b3fc.js +0 -2
- package/dist/post-components/p-f549b3fc.js.map +0 -1
- /package/dist/post-components/{p-b95ec099.entry.js.map → p-65a9d1c2.entry.js.map} +0 -0
- /package/dist/post-components/{p-58916755.js.map → p-eb3ff4dc.js.map} +0 -0
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const index = require('./index-
|
|
6
|
-
const _package = require('./package-
|
|
5
|
+
const index = require('./index-12cc37c9.js');
|
|
6
|
+
const _package = require('./package-112e1698.js');
|
|
7
|
+
const fade = require('./fade-8c6d4fa7.js');
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
const fadedOutKeyFrame = { opacity: '0' };
|
|
10
|
-
const fadedInKeyFrame = { opacity: '1' };
|
|
11
|
-
const fadeIn = (el) => el.animate([fadedOutKeyFrame, fadedInKeyFrame], { duration: fadeDuration });
|
|
12
|
-
const fadeOut = (el) => el.animate([fadedInKeyFrame, fadedOutKeyFrame], { duration: fadeDuration });
|
|
13
|
-
|
|
14
|
-
const postTabsCss = ".tabs-wrapper{position:relative;padding-top:1rem;border:0;background-color:#faf9f8}.tabs-wrapper::after{content:\"\";position:absolute;bottom:0;width:100%;height:1px;background-color:hsl(0, 0%, 80%)}.tabs-wrapper .tabs{background-color:transparent !important}@media (forced-colors: active), (-ms-high-contrast: active), (-ms-high-contrast: white-on-black){.tabs-wrapper::after{background-color:ButtonBorder}}.tabs{margin:0;padding:0;list-style:none;display:flex;flex-wrap:nowrap;overflow-x:auto;overscroll-behavior-x:contain;white-space:nowrap}.tabs::after{content:\"\";display:block;flex:1 0 auto;width:1rem}.tab-content{padding-top:1rem;padding-bottom:1rem}.bg-yellow .tabs-wrapper{background-color:#fc0}.bg-light .tabs-wrapper{background-color:#faf9f8}.bg-gray .tabs-wrapper{background-color:#f4f3f1}.bg-dark .tabs-wrapper{background-color:hsl(0, 0%, 20%)}.bg-primary .tabs-wrapper{background-color:hsl(0, 0%, 20%)}.bg-white .tabs-wrapper{background-color:#fff}.bg-black .tabs-wrapper{background-color:#000}.bg-success .tabs-wrapper{background-color:#2c911c}.bg-info .tabs-wrapper{background-color:#cce4ee}.bg-warning .tabs-wrapper{background-color:#f49e00}.bg-danger .tabs-wrapper{background-color:#a51728}.bg-nightblue .tabs-wrapper{background-color:#004976}.bg-nightblue-bright .tabs-wrapper{background-color:#0076a8}.bg-petrol .tabs-wrapper{background-color:#006d68}.bg-petrol-bright .tabs-wrapper{background-color:#00968f}.bg-coral .tabs-wrapper{background-color:#9e2a2f}.bg-coral-bright .tabs-wrapper{background-color:#e03c31}.bg-olive .tabs-wrapper{background-color:#716135}.bg-olive-bright .tabs-wrapper{background-color:#aa9d2e}.bg-purple .tabs-wrapper{background-color:#80276c}.bg-purple-bright .tabs-wrapper{background-color:#c5299b}.bg-aubergine .tabs-wrapper{background-color:#523178}.bg-aubergine-bright .tabs-wrapper{background-color:#7566a0}:host{display:block}";
|
|
9
|
+
const postTabsCss = ".tabs-wrapper{position:relative;padding-top:1rem;border:0;background-color:#faf9f8}.tabs-wrapper::after{content:\"\";position:absolute;bottom:0;width:100%;height:1px;background-color:#ccc}.tabs-wrapper .tabs{background-color:rgba(0,0,0,0) !important}@media (forced-colors: active),(-ms-high-contrast: active),(-ms-high-contrast: white-on-black){.tabs-wrapper::after{background-color:ButtonBorder}}.tabs{margin:0;padding:0;list-style:none;display:flex;flex-wrap:nowrap;overflow-x:auto;overscroll-behavior-x:contain;white-space:nowrap}.tabs::after{content:\"\";display:block;flex:1 0 auto;width:1rem}.tab-content{padding-top:1rem;padding-bottom:1rem}.bg-yellow .tabs-wrapper{background-color:#fc0}.bg-light .tabs-wrapper{background-color:#faf9f8}.bg-gray .tabs-wrapper{background-color:#f4f3f1}.bg-dark .tabs-wrapper{background-color:#333}.bg-primary .tabs-wrapper{background-color:#333}.bg-white .tabs-wrapper{background-color:#fff}.bg-black .tabs-wrapper{background-color:#000}.bg-success .tabs-wrapper{background-color:#2c911c}.bg-info .tabs-wrapper{background-color:#cce4ee}.bg-warning .tabs-wrapper{background-color:#f49e00}.bg-danger .tabs-wrapper{background-color:#a51728}.bg-nightblue .tabs-wrapper{background-color:#004976}.bg-nightblue-bright .tabs-wrapper{background-color:#0076a8}.bg-petrol .tabs-wrapper{background-color:#006d68}.bg-petrol-bright .tabs-wrapper{background-color:#00968f}.bg-coral .tabs-wrapper{background-color:#9e2a2f}.bg-coral-bright .tabs-wrapper{background-color:#e03c31}.bg-olive .tabs-wrapper{background-color:#716135}.bg-olive-bright .tabs-wrapper{background-color:#aa9d2e}.bg-purple .tabs-wrapper{background-color:#80276c}.bg-purple-bright .tabs-wrapper{background-color:#c5299b}.bg-aubergine .tabs-wrapper{background-color:#523178}.bg-aubergine-bright .tabs-wrapper{background-color:#7566a0}:host{display:block}";
|
|
15
10
|
|
|
16
11
|
const PostTabs = class {
|
|
17
12
|
constructor(hostRef) {
|
|
@@ -27,7 +22,7 @@ const PostTabs = class {
|
|
|
27
22
|
this.moveMisplacedTabs();
|
|
28
23
|
this.enableTabs();
|
|
29
24
|
const initiallyActivePanel = this.activePanel || this.tabs.item(0).panel;
|
|
30
|
-
this.show(initiallyActivePanel);
|
|
25
|
+
void this.show(initiallyActivePanel);
|
|
31
26
|
this.isLoaded = true;
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
@@ -84,24 +79,29 @@ const PostTabs = class {
|
|
|
84
79
|
const tabPanel = this.getPanel(tab.panel).shadowRoot.querySelector('.tab-pane');
|
|
85
80
|
tabTitle.setAttribute('aria-controls', tabPanel.id);
|
|
86
81
|
tabPanel.setAttribute('aria-labelledby', tabTitle.id);
|
|
87
|
-
tab.addEventListener('click',
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
tab.addEventListener('click', () => {
|
|
83
|
+
void this.show(tab.panel);
|
|
84
|
+
});
|
|
85
|
+
tab.addEventListener('keydown', ({ key }) => {
|
|
86
|
+
if (key === 'ArrowRight' || key === 'ArrowLeft')
|
|
87
|
+
this.navigateTabs(tab, key);
|
|
90
88
|
});
|
|
91
89
|
});
|
|
92
90
|
// if the currently active tab was removed from the DOM then select the first one
|
|
93
91
|
if (this.activeTab && !this.activeTab.isConnected) {
|
|
94
|
-
this.show(this.tabs.item(0).panel);
|
|
92
|
+
void this.show(this.tabs.item(0).panel);
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
activateTab(tab) {
|
|
98
96
|
if (this.activeTab) {
|
|
99
97
|
const tabTitle = this.activeTab.shadowRoot.querySelector('.tab-title');
|
|
100
98
|
tabTitle.setAttribute('aria-selected', 'false');
|
|
99
|
+
tabTitle.setAttribute('tabindex', '-1');
|
|
101
100
|
tabTitle.classList.remove('active');
|
|
102
101
|
}
|
|
103
102
|
const tabTitle = tab.shadowRoot.querySelector('.tab-title');
|
|
104
103
|
tabTitle.setAttribute('aria-selected', 'true');
|
|
104
|
+
tabTitle.removeAttribute('tabindex');
|
|
105
105
|
tabTitle.classList.add('active');
|
|
106
106
|
this.activeTab = tab;
|
|
107
107
|
}
|
|
@@ -109,7 +109,7 @@ const PostTabs = class {
|
|
|
109
109
|
const previousPanel = this.getPanel(panelName);
|
|
110
110
|
if (!previousPanel)
|
|
111
111
|
return;
|
|
112
|
-
this.hiding = fadeOut(previousPanel);
|
|
112
|
+
this.hiding = fade.fadeOut(previousPanel);
|
|
113
113
|
this.hiding.onfinish = () => {
|
|
114
114
|
previousPanel.style.display = 'none';
|
|
115
115
|
this.hiding = null;
|
|
@@ -121,7 +121,7 @@ const PostTabs = class {
|
|
|
121
121
|
// prevent the initially selected panel from fading in
|
|
122
122
|
if (!this.isLoaded)
|
|
123
123
|
return;
|
|
124
|
-
this.showing = fadeIn(panel);
|
|
124
|
+
this.showing = fade.fadeIn(panel);
|
|
125
125
|
this.showing.onfinish = () => {
|
|
126
126
|
this.showing = null;
|
|
127
127
|
};
|
|
@@ -129,8 +129,22 @@ const PostTabs = class {
|
|
|
129
129
|
getPanel(name) {
|
|
130
130
|
return this.host.querySelector(`post-tab-panel[name=${name}]`);
|
|
131
131
|
}
|
|
132
|
+
navigateTabs(tab, key) {
|
|
133
|
+
const activeTabIndex = Array.from(this.tabs).indexOf(tab);
|
|
134
|
+
let nextTab;
|
|
135
|
+
if (key === 'ArrowRight') {
|
|
136
|
+
nextTab = this.tabs[activeTabIndex + 1] || this.tabs[0];
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
nextTab = this.tabs[activeTabIndex - 1] || this.tabs[this.tabs.length - 1];
|
|
140
|
+
}
|
|
141
|
+
if (!nextTab)
|
|
142
|
+
return;
|
|
143
|
+
const nextTabTitle = nextTab.shadowRoot.querySelector('.tab-title');
|
|
144
|
+
nextTabTitle.focus();
|
|
145
|
+
}
|
|
132
146
|
render() {
|
|
133
|
-
return (index.h(index.Host, { "data-version": _package.version }, index.h("div", { class: "tabs-wrapper" }, index.h("
|
|
147
|
+
return (index.h(index.Host, { "data-version": _package.version }, index.h("div", { class: "tabs-wrapper" }, index.h("div", { class: "tabs", role: "tablist" }, index.h("slot", { name: "tabs", onSlotchange: () => this.enableTabs() }))), index.h("div", { class: "tab-content" }, index.h("slot", { onSlotchange: () => this.moveMisplacedTabs() }))));
|
|
134
148
|
}
|
|
135
149
|
get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IAAI,CAAC,iBAAiB,EAAE,GAAI,CAClD,CACD,EACP;GACH;;;;;;;","names":["h","Host","version"],"sources":["./src/animations/fade.ts","./src/components/post-tabs/post-tabs.scss?tag=post-tabs&encapsulation=shadow","./src/components/post-tabs/post-tabs.tsx"],"sourcesContent":["const fadeDuration = 200;\nconst fadedOutKeyFrame = {opacity: '0'};\nconst fadedInKeyFrame = {opacity: '1'};\n\nexport const fadeIn = (el: Element): Animation => el.animate(\n [ fadedOutKeyFrame, fadedInKeyFrame ],\n { duration: fadeDuration }\n);\n\nexport const fadeOut = (el: Element): Animation => el.animate(\n [ fadedInKeyFrame, fadedOutKeyFrame ],\n { duration: fadeDuration }\n);\n","@use '@swisspost/design-system-styles/components/tabs/tabs-wrapper';\n\n:host {\n display: block;\n}\n","import { Component, Host, h, Element, Method, Event, EventEmitter, Prop } from '@stencil/core';\nimport { version } from '../../../package.json';\nimport { fadeIn, fadeOut } from '../../animations';\n\n@Component({\n tag: 'post-tabs',\n styleUrl: 'post-tabs.scss',\n shadow: true,\n})\nexport class PostTabs {\n private activeTab: HTMLPostTabHeaderElement;\n private showing: Animation;\n private hiding: Animation;\n private isLoaded = false;\n\n private get tabs(): NodeListOf<HTMLPostTabHeaderElement> {\n return this.host.querySelectorAll('post-tab-header');\n }\n\n @Element() host: HTMLPostTabsElement;\n\n /**\n * The name of the panel that is initially shown.\n * If not specified, it defaults to the panel associated with the first tab.\n *\n * **Changing this value after initialization has no effect.**\n */\n @Prop() readonly activePanel: HTMLPostTabPanelElement['name'];\n\n /**\n * An event emitted after the active tab changes, when the fade in transition of its associated panel is finished.\n * The payload is the name of the newly shown panel.\n */\n @Event() tabChange: EventEmitter<HTMLPostTabPanelElement['name']>;\n\n componentDidLoad() {\n this.moveMisplacedTabs();\n this.enableTabs();\n\n const initiallyActivePanel = this.activePanel || this.tabs.item(0).panel;\n this.show(initiallyActivePanel);\n\n this.isLoaded = true;\n }\n\n /**\n * Shows the panel with the given name and selects its associated tab.\n * Any other panel that was previously shown becomes hidden and its associated tab is unselected.\n */\n @Method()\n async show(panelName: string) {\n // do nothing if the tab is already active\n if (panelName === this.activeTab?.panel) {\n return;\n }\n\n const previousTab = this.activeTab;\n const newTab : HTMLPostTabHeaderElement = this.host.querySelector(`post-tab-header[panel=${panelName}]`);\n this.activateTab(newTab);\n\n // if a panel is currently being displayed, remove it from the view and complete the associated animation\n if (this.showing) {\n this.showing.effect['target'].style.display = 'none';\n this.showing.finish();\n }\n\n // hide the currently visible panel only if no other animation is running\n if (previousTab && !this.showing && !this.hiding) {\n this.hidePanel(previousTab.panel);\n }\n\n // wait for any hiding animation to complete before showing the selected tab\n if (this.hiding) {\n await this.hiding.finished;\n }\n\n this.showSelectedPanel();\n\n // wait for any display animation to complete for the returned promise to fully resolve\n if (this.showing) {\n await this.showing.finished;\n }\n\n this.tabChange.emit(this.activeTab.panel);\n }\n private moveMisplacedTabs() {\n if (!this.tabs) return;\n\n this.tabs.forEach(tab => {\n if (tab.getAttribute('slot') === 'tabs') return;\n tab.setAttribute('slot', 'tabs');\n });\n }\n\n private enableTabs() {\n if (!this.tabs) return;\n\n this.tabs.forEach(async tab => {\n await tab.componentOnReady();\n\n const tabTitle = tab.shadowRoot.querySelector('.tab-title');\n\n // if the tab has an \"aria-controls\" attribute it was already linked to its panel: do nothing\n if (tabTitle.getAttribute('aria-controls')) return;\n\n const tabPanel = this.getPanel(tab.panel).shadowRoot.querySelector('.tab-pane');\n tabTitle.setAttribute('aria-controls', tabPanel.id);\n tabPanel.setAttribute('aria-labelledby', tabTitle.id);\n\n tab.addEventListener('click', e => {\n e.preventDefault();\n this.show(tab.panel);\n });\n });\n\n // if the currently active tab was removed from the DOM then select the first one\n if (this.activeTab && !this.activeTab.isConnected) {\n this.show(this.tabs.item(0).panel);\n }\n }\n\n private activateTab(tab: HTMLPostTabHeaderElement) {\n if (this.activeTab) {\n const tabTitle = this.activeTab.shadowRoot.querySelector('.tab-title');\n tabTitle.setAttribute('aria-selected', 'false');\n tabTitle.classList.remove('active');\n }\n\n const tabTitle = tab.shadowRoot.querySelector('.tab-title');\n tabTitle.setAttribute('aria-selected', 'true');\n tabTitle.classList.add('active');\n\n this.activeTab = tab;\n }\n\n private hidePanel(panelName: HTMLPostTabPanelElement['name']) {\n const previousPanel = this.getPanel(panelName);\n\n if (!previousPanel) return;\n\n this.hiding = fadeOut(previousPanel);\n this.hiding.onfinish = () => {\n previousPanel.style.display = 'none';\n this.hiding = null;\n };\n }\n\n private showSelectedPanel() {\n const panel = this.getPanel(this.activeTab.panel);\n panel.style.display = 'block';\n\n // prevent the initially selected panel from fading in\n if (!this.isLoaded) return;\n\n this.showing = fadeIn(panel);\n this.showing.onfinish = () => {\n this.showing = null;\n };\n }\n\n private getPanel(name: string): HTMLPostTabPanelElement {\n return this.host.querySelector(\n `post-tab-panel[name=${name}]`\n );\n }\n\n render() {\n return (\n <Host data-version={version}>\n <div class=\"tabs-wrapper\">\n <ul class=\"tabs nav\" role=\"tablist\">\n <slot name=\"tabs\" onSlotchange={() => this.enableTabs()} />\n </ul>\n </div>\n <div class=\"tab-content\">\n <slot onSlotchange={() => this.moveMisplacedTabs()} />\n </div>\n </Host>\n );\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"post-tabs.entry.cjs.js","mappings":";;;;;;;;AAAA,MAAM,WAAW,GAAG,yzDAAyzD;;MCSh0D,QAAQ;;;;IAIX,aAAQ,GAAG,KAAK,CAAC;;;EAEzB,IAAY,IAAI;IACd,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;GACtD;EAkBD,gBAAgB;IACd,IAAI,CAAC,iBAAiB,EAAE,CAAC;IACzB,IAAI,CAAC,UAAU,EAAE,CAAC;IAElB,MAAM,oBAAoB,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACzE,KAAK,IAAI,CAAC,IAAI,CAAC,oBAAoB,C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;;;;;;","names":["fadeOut","fadeIn","h","Host","version"],"sources":["./src/components/post-tabs/post-tabs.scss?tag=post-tabs&encapsulation=shadow","./src/components/post-tabs/post-tabs.tsx"],"sourcesContent":["@use '@swisspost/design-system-styles/components/tabs/tabs-wrapper';\n\n:host {\n display: block;\n}\n","import { Component, Element, Event, EventEmitter, h, Host, Method, Prop } from '@stencil/core';\nimport { version } from '../../../package.json';\nimport { fadeIn, fadeOut } from '../../animations';\n\n@Component({\n tag: 'post-tabs',\n styleUrl: 'post-tabs.scss',\n shadow: true,\n})\nexport class PostTabs {\n private activeTab: HTMLPostTabHeaderElement;\n private showing: Animation;\n private hiding: Animation;\n private isLoaded = false;\n\n private get tabs(): NodeListOf<HTMLPostTabHeaderElement> {\n return this.host.querySelectorAll('post-tab-header');\n }\n\n @Element() host: HTMLPostTabsElement;\n\n /**\n * The name of the panel that is initially shown.\n * If not specified, it defaults to the panel associated with the first tab.\n *\n * **Changing this value after initialization has no effect.**\n */\n @Prop() readonly activePanel: HTMLPostTabPanelElement['name'];\n\n /**\n * An event emitted after the active tab changes, when the fade in transition of its associated panel is finished.\n * The payload is the name of the newly shown panel.\n */\n @Event() tabChange: EventEmitter<HTMLPostTabPanelElement['name']>;\n\n componentDidLoad() {\n this.moveMisplacedTabs();\n this.enableTabs();\n\n const initiallyActivePanel = this.activePanel || this.tabs.item(0).panel;\n void this.show(initiallyActivePanel);\n\n this.isLoaded = true;\n }\n\n /**\n * Shows the panel with the given name and selects its associated tab.\n * Any other panel that was previously shown becomes hidden and its associated tab is unselected.\n */\n @Method()\n async show(panelName: string) {\n // do nothing if the tab is already active\n if (panelName === this.activeTab?.panel) {\n return;\n }\n\n const previousTab = this.activeTab;\n const newTab: HTMLPostTabHeaderElement = this.host.querySelector(\n `post-tab-header[panel=${panelName}]`,\n );\n this.activateTab(newTab);\n\n // if a panel is currently being displayed, remove it from the view and complete the associated animation\n if (this.showing) {\n this.showing.effect['target'].style.display = 'none';\n this.showing.finish();\n }\n\n // hide the currently visible panel only if no other animation is running\n if (previousTab && !this.showing && !this.hiding) {\n this.hidePanel(previousTab.panel);\n }\n\n // wait for any hiding animation to complete before showing the selected tab\n if (this.hiding) {\n await this.hiding.finished;\n }\n\n this.showSelectedPanel();\n\n // wait for any display animation to complete for the returned promise to fully resolve\n if (this.showing) {\n await this.showing.finished;\n }\n\n this.tabChange.emit(this.activeTab.panel);\n }\n\n private moveMisplacedTabs() {\n if (!this.tabs) return;\n\n this.tabs.forEach(tab => {\n if (tab.getAttribute('slot') === 'tabs') return;\n tab.setAttribute('slot', 'tabs');\n });\n }\n\n private enableTabs() {\n if (!this.tabs) return;\n\n this.tabs.forEach(async tab => {\n await tab.componentOnReady();\n\n const tabTitle = tab.shadowRoot.querySelector('.tab-title');\n\n // if the tab has an \"aria-controls\" attribute it was already linked to its panel: do nothing\n if (tabTitle.getAttribute('aria-controls')) return;\n\n const tabPanel = this.getPanel(tab.panel).shadowRoot.querySelector('.tab-pane');\n tabTitle.setAttribute('aria-controls', tabPanel.id);\n tabPanel.setAttribute('aria-labelledby', tabTitle.id);\n\n tab.addEventListener('click', () => {\n void this.show(tab.panel);\n });\n\n tab.addEventListener('keydown', ({ key }) => {\n if (key === 'ArrowRight' || key === 'ArrowLeft') this.navigateTabs(tab, key);\n });\n });\n\n // if the currently active tab was removed from the DOM then select the first one\n if (this.activeTab && !this.activeTab.isConnected) {\n void this.show(this.tabs.item(0).panel);\n }\n }\n\n private activateTab(tab: HTMLPostTabHeaderElement) {\n if (this.activeTab) {\n const tabTitle = this.activeTab.shadowRoot.querySelector('.tab-title');\n tabTitle.setAttribute('aria-selected', 'false');\n tabTitle.setAttribute('tabindex', '-1');\n tabTitle.classList.remove('active');\n }\n\n const tabTitle = tab.shadowRoot.querySelector('.tab-title');\n tabTitle.setAttribute('aria-selected', 'true');\n tabTitle.removeAttribute('tabindex');\n tabTitle.classList.add('active');\n\n this.activeTab = tab;\n }\n\n private hidePanel(panelName: HTMLPostTabPanelElement['name']) {\n const previousPanel = this.getPanel(panelName);\n\n if (!previousPanel) return;\n\n this.hiding = fadeOut(previousPanel);\n this.hiding.onfinish = () => {\n previousPanel.style.display = 'none';\n this.hiding = null;\n };\n }\n\n private showSelectedPanel() {\n const panel = this.getPanel(this.activeTab.panel);\n panel.style.display = 'block';\n\n // prevent the initially selected panel from fading in\n if (!this.isLoaded) return;\n\n this.showing = fadeIn(panel);\n this.showing.onfinish = () => {\n this.showing = null;\n };\n }\n\n private getPanel(name: string): HTMLPostTabPanelElement {\n return this.host.querySelector(`post-tab-panel[name=${name}]`);\n }\n\n private navigateTabs(tab: HTMLPostTabHeaderElement, key: 'ArrowRight' | 'ArrowLeft') {\n const activeTabIndex = Array.from(this.tabs).indexOf(tab);\n\n let nextTab: HTMLPostTabHeaderElement;\n if (key === 'ArrowRight') {\n nextTab = this.tabs[activeTabIndex + 1] || this.tabs[0];\n } else {\n nextTab = this.tabs[activeTabIndex - 1] || this.tabs[this.tabs.length - 1];\n }\n\n if (!nextTab) return;\n\n const nextTabTitle = nextTab.shadowRoot.querySelector('.tab-title') as HTMLAnchorElement;\n nextTabTitle.focus();\n }\n\n render() {\n return (\n <Host data-version={version}>\n <div class=\"tabs-wrapper\">\n <div class=\"tabs\" role=\"tablist\">\n <slot name=\"tabs\" onSlotchange={() => this.enableTabs()} />\n </div>\n </div>\n <div class=\"tab-content\">\n <slot onSlotchange={() => this.moveMisplacedTabs()} />\n </div>\n </Host>\n );\n }\n}\n"],"version":3}
|