wj-elements 0.1.252 → 0.1.253

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.
@@ -17,6 +17,18 @@
17
17
  * getHsl('test', 50, 70);
18
18
  */
19
19
  export function getHsl(text: string, s?: number, l?: number): string;
20
+ /**
21
+ * Generates background and text HSL colors for avatars based on input text.
22
+ * The text color is a darker, more saturated variant of the background color
23
+ * to ensure sufficient contrast while keeping the same hue.
24
+ *
25
+ * @param {string} text The input text (e.g. initials or name).
26
+ * @returns {{ background: string, color: string }}
27
+ */
28
+ export function getAvatarColors(text: string): {
29
+ background: string;
30
+ color: string;
31
+ };
20
32
  /**
21
33
  * Generates initials from a given string.
22
34
  * @param {string} string The input string, typically a full name.
@@ -18,6 +18,8 @@ export default class TabGroup extends WJElement {
18
18
  * @returns {CSSStyleSheet}
19
19
  */
20
20
  static get cssStyleSheet(): CSSStyleSheet;
21
+ _lastNavWidth: any;
22
+ _initialized: boolean;
21
23
  /**
22
24
  * Sets the value for the 'variant' attribute of the element.
23
25
  * @param {string} value The value to set for the 'variant' attribute.
@@ -67,12 +69,7 @@ export default class TabGroup extends WJElement {
67
69
  * @returns {void} Does not return a value.
68
70
  */
69
71
  afterDraw(): void;
70
- /**
71
- * Checks if the tabs within a navigation bar overflow the available space.
72
- * Moves overflowing tabs into a dropdown menu and updates their state accordingly.
73
- * @returns {void} This method does not return a value.
74
- */
75
- checkOverflow(): void;
72
+ _resizeObserver: ResizeObserver;
76
73
  /**
77
74
  * Removes the 'active' class from all panel and tab elements.
78
75
  * @returns {void} This method does not return a value.
@@ -108,6 +105,22 @@ export default class TabGroup extends WJElement {
108
105
  * @returns {void} Does not return a value.
109
106
  */
110
107
  toggleMoreVisibility(): void;
108
+ /**
109
+ * Initializes metrics for tabs within the component. Assigns each tab to the navigation slot
110
+ * and calculates their dimensions for further operations.
111
+ * @returns {void} Does not return any value.
112
+ */
113
+ initTabMetrics(): void;
114
+ _tabMetrics: {
115
+ el: Element;
116
+ width: number;
117
+ }[];
118
+ /**
119
+ * Checks if the tabs within a navigation bar overflow the available space.
120
+ * Moves overflowing tabs into a dropdown menu and updates their state accordingly.
121
+ * @returns {void} This method does not return a value.
122
+ */
123
+ checkOverflow(): void;
111
124
  /**
112
125
  * Toggles the "dropdown-active" class on the element based on its "active" status
113
126
  * and the value of its "slot" attribute.
@@ -0,0 +1 @@
1
+ export {};
@@ -2,14 +2,20 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import WJElement from "./wje-element.js";
5
- function getHsl(text, s = 40, l = 65) {
6
- let str = text;
5
+ function getAvatarColors(text) {
7
6
  let hash = 0;
8
- for (let i = 0; i < (str == null ? void 0 : str.length); i++) {
9
- hash = str.charCodeAt(i) + hash * 31;
7
+ for (let i = 0; i < (text == null ? void 0 : text.length); i++) {
8
+ hash = text.charCodeAt(i) + hash * 31;
10
9
  }
11
- let h = hash % 360;
12
- return `hsl(${h}, ${s}%, ${l}%)`;
10
+ const h = Math.abs(hash) % 360;
11
+ const bgS = 30;
12
+ const bgL = 88;
13
+ const textS = 50;
14
+ const textL = 48;
15
+ return {
16
+ background: `hsl(${h}, ${bgS}%, ${bgL}%)`,
17
+ color: `hsl(${h}, ${textS}%, ${textL}%)`
18
+ };
13
19
  }
14
20
  function getInitials(string, length = 2) {
15
21
  let names = string.split(" ");
@@ -110,7 +116,9 @@ class Avatar extends WJElement {
110
116
  element.appendChild(slot);
111
117
  if (this.initials) {
112
118
  let initials = getInitials(this.label);
113
- this.setAttribute("style", `--wje-avatar-background-color: ${getHsl(initials)}`);
119
+ const { background, color } = getAvatarColors(initials);
120
+ this.style.setProperty("--wje-avatar-background-color", background);
121
+ this.style.setProperty("--wje-avatar-color", color);
114
122
  element.innerText = initials;
115
123
  } else {
116
124
  let slotIcon = document.createElement("slot");
@@ -1 +1 @@
1
- {"version":3,"file":"wje-avatar.js","sources":["../packages/wje-avatar/service/service.js","../packages/wje-avatar/avatar.element.js","../packages/wje-avatar/avatar.js"],"sourcesContent":["/**\n * Generates an HSL color value based on the input text.\n * @param {string} text The input text to generate the HSL color.\n * @param {number} [s] The saturation value (in percentage) for the HSL color.\n * @param {number} [l] The lightness value (in percentage) for the HSL color.\n * @returns {string} - The HSL color string in the format `hsl(h, s%, l%)`.\n * @description\n * This function computes a hash from the input text and uses it to generate\n * a hue value. The hue is combined with the provided saturation and lightness\n * values to create an HSL color. This can be useful for consistently assigning\n * colors based on text input, such as for avatars or tags.\n * @example\n * // Returns 'hsl(180, 40%, 65%)'\n * getHsl('example');\n * @example\n * // Returns 'hsl(300, 50%, 70%)'\n * getHsl('test', 50, 70);\n */\nexport function getHsl(text, s = 40, l = 65) {\n let str = text;\n let hash = 0;\n\n for (let i = 0; i < str?.length; i++) {\n hash = str.charCodeAt(i) + hash * 31;\n }\n\n let h = hash % 360;\n\n return `hsl(${h}, ${s}%, ${l}%)`;\n}\n\n/**\n * Generates initials from a given string.\n * @param {string} string The input string, typically a full name.\n * @param {number} [length] The desired number of initials (default is 2).\n * @returns {string} - The generated initials in uppercase.\n * @description\n * This function takes a string, splits it by spaces, and generates initials.\n * It always includes the first character of the first word. If the input string\n * contains more than one word and the `length` parameter is greater than 1, it\n * also includes the first character of the last word.\n * @example\n * // Returns 'JD'\n * getInitials('John Doe');\n * @example\n * // Returns 'J'\n * getInitials('John');\n * @example\n * // Returns 'JM'\n * getInitials('John Michael Doe', 2);\n */\nexport function getInitials(string, length = 2) {\n let names = string.split(' ');\n let initials = names[0].substring(0, 1).toUpperCase();\n\n if (names.length > 1 && length > 1) {\n initials += names[names.length - 1].substring(0, 1).toUpperCase();\n }\n return initials;\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport { getHsl, getInitials } from './service/service.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This class represents an Avatar element, extending the WJElement class.\n * @documentation https://elements.webjet.sk/components/avatar\n * @status stable\n * @augments WJElement\n * @slot - The avatar main content.\n * @csspart native - The component's native wrapper.\n * @cssproperty --wje-avatar-width;\n * @cssproperty --wje-avatar-height;\n * @cssproperty --wje-avatar-font-size;\n * @cssproperty --wje-avatar-font-weight;\n * @cssproperty --wje-avatar-color;\n * @cssproperty --wje-avatar-background-color;\n * @cssproperty --wje-avatar-border-radius;\n * @cssproperty --wje-avatar-border-color;\n * @cssproperty --wje-avatar-border-width;\n * @cssproperty --wje-avatar-border-style;\n * @tag wje-avatar\n */\nexport default class Avatar extends WJElement {\n /**\n * Avatar class constructor.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the value of the 'label' attribute for the element.\n * @param {string} value The new value to be set for the 'label' attribute.\n */\n set label(value) {\n this.setAttribute('label', value);\n }\n\n /**\n * Retrieves the value of the 'label' attribute for the element.\n * If the attribute is not set, it defaults to an empty string.\n * @returns {string} The value of the 'label' attribute or an empty string if not defined.\n */\n get label() {\n return this.getAttribute('label') || '';\n }\n\n /**\n * Sets the value of initials for the element by updating\n * the 'initials' attribute with the provided value.\n * @param {string} value The value to be set as the initials.\n */\n set initials(value) {\n this.setAttribute('initials', '');\n }\n\n /**\n * Retrieves the value of the 'initials' attribute if it exists.\n * @returns {boolean} Returns true if the 'initials' attribute is present, otherwise false.\n */\n get initials() {\n return this.hasAttribute('initials') || false;\n }\n\n /**\n * Sets the size attribute for the element.\n * @param {string | number} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the size attribute of the element. If the size attribute\n * is not defined, it returns the default value 'medium'.\n * @returns {string} The size value of the element or 'medium' if not specified.\n */\n get size() {\n return this.getAttribute('size') || 'medium';\n }\n\n /**\n * Class name for the Avatar element.\n */\n className = 'Avatar';\n\n /**\n * Getter for cssStyleSheet.\n * @returns {string} styles\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['initials'];\n }\n\n /**\n * Method to setup attributes.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Method to draw the avatar element and return a document fragment.\n * @returns {object} fragment - The document fragment\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let element = document.createElement('div');\n element.setAttribute('part', 'native');\n element.classList.add('native-avatar');\n\n let slot = document.createElement('slot');\n\n element.appendChild(slot);\n\n if (this.initials) {\n let initials = getInitials(this.label);\n\n this.setAttribute('style', `--wje-avatar-background-color: ${getHsl(initials)}`);\n element.innerText = initials;\n } else {\n let slotIcon = document.createElement('slot');\n slotIcon.setAttribute('name', 'icon');\n\n element.appendChild(slotIcon);\n }\n\n let status = document.createElement('slot');\n status.setAttribute('name', 'status');\n status.setAttribute('part', 'status');\n\n let secondary = document.createElement('slot');\n secondary.setAttribute('name', 'secondary');\n secondary.setAttribute('part', 'secondary');\n\n element.appendChild(status);\n element.appendChild(secondary);\n\n fragment.appendChild(element);\n\n return fragment;\n }\n\n /**\n * Method to check if the avatar is an image.\n * @returns {boolean} - True if the avatar is an image, false otherwise\n */\n isImage() {\n return this.getElementsByTagName('wje-img').length > 0;\n }\n}\n","import Avatar from './avatar.element.js';\n\nexport default Avatar;\n\nAvatar.define('wje-avatar', Avatar);\n"],"names":[],"mappings":";;;;AAkBO,SAAS,OAAO,MAAM,IAAI,IAAI,IAAI,IAAI;AACzC,MAAI,MAAM;AACV,MAAI,OAAO;AAEX,WAAS,IAAI,GAAG,KAAI,2BAAK,SAAQ,KAAK;AAClC,WAAO,IAAI,WAAW,CAAC,IAAI,OAAO;AAAA,EAC1C;AAEI,MAAI,IAAI,OAAO;AAEf,SAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;AAChC;AAsBO,SAAS,YAAY,QAAQ,SAAS,GAAG;AAC5C,MAAI,QAAQ,OAAO,MAAM,GAAG;AAC5B,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AEhD,QAAI,UAAU,SAAS,cAAc,KAAK;AAC1C,YAAQ,aAAa,QAAQ,QAAQ;AACrC,YAAQ,UAAU,IAAI,eAAe;AAErC,QAAI,OAAO,SAAS,cAAc,MAAM;AAExC,YAAQ,YAAY,IAAI;AAExB,QAAI,KAAK,UAAU;AACf,UAAI,WAAW,YAAY,KAAK,KAAK;AAErC,WAAK,aAAa,SAAS,kCAAkC,OAAO,QAAQ,CAAC,EAAE;AAC/E,cAAQ,YAAY;AAAA,IAChC,OAAe;AACH,UAAI,WAAW,SAAS,cAAc,MAAM;AAC5C,eAAS,aAAa,QAAQ,MAAM;AAEpC,cAAQ,YAAY,QAAQ;AAAA,IACxC;AAEQ,QAAI,SAAS,SAAS,cAAc,MAAM;AAC1C,WAAO,aAAa,QAAQ,QAAQ;AACpC,WAAO,aAAa,QAAQ,QAAQ;AAEpC,QAAI,YAAY,SAAS,cAAc,MAAM;AAC7C,cAAU,aAAa,QAAQ,WAAW;AAC1C,cAAU,aAAa,QAAQ,WAAW;AAE1C,YAAQ,YAAY,MAAM;AAC1B,YAAQ,YAAY,SAAS;AAE7B,aAAS,YAAY,OAAO;AAE5B,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,UAAU;AACN,WAAO,KAAK,qBAAqB,SAAS,EAAE,SAAS;AAAA,EAC7D;AACA;AC7JA,OAAO,OAAO,cAAc,MAAM;"}
1
+ {"version":3,"file":"wje-avatar.js","sources":["../packages/wje-avatar/service/service.js","../packages/wje-avatar/avatar.element.js","../packages/wje-avatar/avatar.js"],"sourcesContent":["/**\n * Generates an HSL color value based on the input text.\n * @param {string} text The input text to generate the HSL color.\n * @param {number} [s] The saturation value (in percentage) for the HSL color.\n * @param {number} [l] The lightness value (in percentage) for the HSL color.\n * @returns {string} - The HSL color string in the format `hsl(h, s%, l%)`.\n * @description\n * This function computes a hash from the input text and uses it to generate\n * a hue value. The hue is combined with the provided saturation and lightness\n * values to create an HSL color. This can be useful for consistently assigning\n * colors based on text input, such as for avatars or tags.\n * @example\n * // Returns 'hsl(180, 40%, 65%)'\n * getHsl('example');\n * @example\n * // Returns 'hsl(300, 50%, 70%)'\n * getHsl('test', 50, 70);\n */\nexport function getHsl(text, s = 40, l = 75) {\n let str = text;\n let hash = 0;\n\n for (let i = 0; i < str?.length; i++) {\n hash = str.charCodeAt(i) + hash * 31;\n }\n\n let h = hash % 360;\n\n return `hsl(${h}, ${s}%, ${l}%)`;\n}\n\n/**\n * Generates background and text HSL colors for avatars based on input text.\n * The text color is a darker, more saturated variant of the background color\n * to ensure sufficient contrast while keeping the same hue.\n *\n * @param {string} text The input text (e.g. initials or name).\n * @returns {{ background: string, color: string }}\n */\nexport function getAvatarColors(text) {\n let hash = 0;\n for (let i = 0; i < text?.length; i++) {\n hash = text.charCodeAt(i) + hash * 31;\n }\n\n const h = Math.abs(hash) % 360;\n\n // 👇 Figma-like pastel background\n const bgS = 30;\n const bgL = 88;\n\n // 👇 Softer text color (same hue)\n const textS = 50;\n const textL = 48;\n\n return {\n background: `hsl(${h}, ${bgS}%, ${bgL}%)`,\n color: `hsl(${h}, ${textS}%, ${textL}%)`\n };\n}\n\n/**\n * Generates initials from a given string.\n * @param {string} string The input string, typically a full name.\n * @param {number} [length] The desired number of initials (default is 2).\n * @returns {string} - The generated initials in uppercase.\n * @description\n * This function takes a string, splits it by spaces, and generates initials.\n * It always includes the first character of the first word. If the input string\n * contains more than one word and the `length` parameter is greater than 1, it\n * also includes the first character of the last word.\n * @example\n * // Returns 'JD'\n * getInitials('John Doe');\n * @example\n * // Returns 'J'\n * getInitials('John');\n * @example\n * // Returns 'JM'\n * getInitials('John Michael Doe', 2);\n */\nexport function getInitials(string, length = 2) {\n let names = string.split(' ');\n let initials = names[0].substring(0, 1).toUpperCase();\n\n if (names.length > 1 && length > 1) {\n initials += names[names.length - 1].substring(0, 1).toUpperCase();\n }\n return initials;\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport { getHsl, getInitials, getAvatarColors } from './service/service.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This class represents an Avatar element, extending the WJElement class.\n * @documentation https://elements.webjet.sk/components/avatar\n * @status stable\n * @augments WJElement\n * @slot - The avatar main content.\n * @csspart native - The component's native wrapper.\n * @cssproperty --wje-avatar-width;\n * @cssproperty --wje-avatar-height;\n * @cssproperty --wje-avatar-font-size;\n * @cssproperty --wje-avatar-font-weight;\n * @cssproperty --wje-avatar-color;\n * @cssproperty --wje-avatar-background-color;\n * @cssproperty --wje-avatar-border-radius;\n * @cssproperty --wje-avatar-border-color;\n * @cssproperty --wje-avatar-border-width;\n * @cssproperty --wje-avatar-border-style;\n * @tag wje-avatar\n */\nexport default class Avatar extends WJElement {\n /**\n * Avatar class constructor.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the value of the 'label' attribute for the element.\n * @param {string} value The new value to be set for the 'label' attribute.\n */\n set label(value) {\n this.setAttribute('label', value);\n }\n\n /**\n * Retrieves the value of the 'label' attribute for the element.\n * If the attribute is not set, it defaults to an empty string.\n * @returns {string} The value of the 'label' attribute or an empty string if not defined.\n */\n get label() {\n return this.getAttribute('label') || '';\n }\n\n /**\n * Sets the value of initials for the element by updating\n * the 'initials' attribute with the provided value.\n * @param {string} value The value to be set as the initials.\n */\n set initials(value) {\n this.setAttribute('initials', '');\n }\n\n /**\n * Retrieves the value of the 'initials' attribute if it exists.\n * @returns {boolean} Returns true if the 'initials' attribute is present, otherwise false.\n */\n get initials() {\n return this.hasAttribute('initials') || false;\n }\n\n /**\n * Sets the size attribute for the element.\n * @param {string | number} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the size attribute of the element. If the size attribute\n * is not defined, it returns the default value 'medium'.\n * @returns {string} The size value of the element or 'medium' if not specified.\n */\n get size() {\n return this.getAttribute('size') || 'medium';\n }\n\n /**\n * Class name for the Avatar element.\n */\n className = 'Avatar';\n\n /**\n * Getter for cssStyleSheet.\n * @returns {string} styles\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['initials'];\n }\n\n /**\n * Method to setup attributes.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Method to draw the avatar element and return a document fragment.\n * @returns {object} fragment - The document fragment\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let element = document.createElement('div');\n element.setAttribute('part', 'native');\n element.classList.add('native-avatar');\n\n let slot = document.createElement('slot');\n\n element.appendChild(slot);\n\n if (this.initials) {\n let initials = getInitials(this.label);\n const { background, color } = getAvatarColors(initials);\n\n this.style.setProperty('--wje-avatar-background-color', background);\n this.style.setProperty('--wje-avatar-color', color);\n\n element.innerText = initials;\n } else {\n let slotIcon = document.createElement('slot');\n slotIcon.setAttribute('name', 'icon');\n\n element.appendChild(slotIcon);\n }\n\n let status = document.createElement('slot');\n status.setAttribute('name', 'status');\n status.setAttribute('part', 'status');\n\n let secondary = document.createElement('slot');\n secondary.setAttribute('name', 'secondary');\n secondary.setAttribute('part', 'secondary');\n\n element.appendChild(status);\n element.appendChild(secondary);\n\n fragment.appendChild(element);\n\n return fragment;\n }\n\n /**\n * Method to check if the avatar is an image.\n * @returns {boolean} - True if the avatar is an image, false otherwise\n */\n isImage() {\n return this.getElementsByTagName('wje-img').length > 0;\n }\n}\n","import Avatar from './avatar.element.js';\n\nexport default Avatar;\n\nAvatar.define('wje-avatar', Avatar);\n"],"names":[],"mappings":";;;;AAuCO,SAAS,gBAAgB,MAAM;AAClC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,KAAI,6BAAM,SAAQ,KAAK;AACnC,WAAO,KAAK,WAAW,CAAC,IAAI,OAAO;AAAA,EAC3C;AAEI,QAAM,IAAI,KAAK,IAAI,IAAI,IAAI;AAG3B,QAAM,MAAM;AACZ,QAAM,MAAM;AAGZ,QAAM,QAAQ;AACd,QAAM,QAAQ;AAEd,SAAO;AAAA,I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Content":["import { default as WJElement, event } from '../wje-element/element.js';\nimport '../wje-button/button.element.js';\nimport '../wje-icon/icon.element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Dialog` is a custom web component that represents a dialog.\n * @summary This element represents a dialog.\n * @documentation https://elements.webjet.sk/components/dialog\n * @status stable\n * @augments {WJElement}\n * @slot header - Slot for the header content.\n * @slot body - Slot for the body content.\n * @slot footer - Slot for the footer content.\n * @csspart dialog - The dialog wrapper.\n * @csspart header - The header of the dialog.\n * @csspart body - The body of the dialog.\n * @csspart footer - The footer of the dialog.\n * @csspart close - The close button of the dialog.\n * @cssproperty [--wje-dialog-background=var(--wje-background-color)] - Specifies the background color of the dialog.\n * @cssproperty [--wje-dialog-color=var(--wje-text-color)] - Defines the text color within the dialog.\n * @cssproperty [--wje-dialog-padding=1rem] - Controls the padding inside the dialog.\n * @cssproperty [--wje-dialog-border-radius=0.5rem] - Sets the border radius for the dialog's corners.\n * @cssproperty [--wje-dialog-box-shadow=0 2px 10px rgba(0, 0, 0, 0.1)] - Applies a shadow effect to the dialog.\n * @tag wje-dialog\n */\n\nexport default class Dialog extends WJElement {\n /**\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the value of the 'headline' attribute.\n * @param {string} value The new value for the 'headline' attribute.\n */\n set headline(value) {\n this.setAttribute('headline', value);\n }\n\n /**\n * Retrieves the value of the \"headline\" attribute from the element.\n * If the \"headline\" attribute is not present, returns an empty string.\n * @returns {string} The headline attribute value or an empty string if not set.\n */\n get headline() {\n return this.getAttribute('headline') || '';\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set placement(value) {\n this.setAttribute('placement', value);\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {string|string}\n */\n get placement() {\n return this.getAttribute('placement') || 'slide-up';\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set async(value) {\n this.setAttribute('async', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get async() {\n return this.hasAttribute('async');\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set closeHidden(value) {\n if (value) this.setAttribute('close-hidden', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get closeHidden() {\n return !!this.hasAttribute('close-hidden');\n }\n\n set hiddenHeader(value) {\n if (value) this.setAttribute('hidden-header', '');\n }\n\n get hiddenHeader() {\n return !!this.hasAttribute('hidden-header');\n }\n\n set hiddenFooter(value) {\n if (value) this.setAttribute('hidden-footer', '');\n }\n\n get hiddenFooter() {\n return !!this.hasAttribute('hidden-footer');\n }\n\n /**\n * Sets the headline of the dialog.\n * @type {string}\n */\n className = 'Dialog';\n\n /**\n * Returns the CSS styles for the component.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {*[]}\n */\n static get observedAttributes() {\n return [];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('fade', this.placement, params.size);\n\n let dialog = document.createElement('dialog');\n dialog.setAttribute('part', 'dialog');\n dialog.classList.add('modal-dialog');\n\n fragment.appendChild(dialog);\n\n this.dialog = dialog;\n\n return fragment;\n }\n\n /**\n * Draws the component after it has been drawn.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n */\n afterDraw(context, store, params) {\n if (params.trigger) {\n event.addListener(document, params.trigger, null, this.onOpen);\n }\n\n //this.dialog.addEventListener('close', this.onClose);\n }\n\n /**\n * Creates the dialog body.\n * @param dialog\n */\n htmlDialogBody(dialog) {\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'x');\n icon.setAttribute('slot', 'icon-only');\n\n let close = document.createElement('wje-button');\n close.setAttribute('fill', 'link');\n close.setAttribute('size', 'small');\n close.setAttribute('part', 'close');\n close.addEventListener('click', (e) => {\n this.close(e);\n });\n\n let header = document.createElement('div');\n header.setAttribute('part', 'header');\n header.classList.add('dialog-header');\n if (this.hasAttribute('headline'))\n header.innerHTML = `<span part=\"headline\">${this.headline}</span>`;\n\n let slotHeader = document.createElement('slot');\n slotHeader.setAttribute('name', 'header');\n\n const headerActions = document.createElement('div');\n headerActions.classList.add('header-actions');\n headerActions.setAttribute('part', 'header-actions');\n headerActions.appendChild(slotHeader);\n\n let contentSlot = document.createElement('slot');\n\n let body = document.createElement('div');\n body.setAttribute('part', 'body');\n body.classList.add('dialog-content');\n\n let footer = document.createElement('div');\n footer.setAttribute('part', 'footer');\n footer.classList.add('dialog-footer');\n footer.innerHTML = '';\n\n let slotFooter = document.createElement('slot');\n slotFooter.setAttribute('name', 'footer');\n\n close.appendChild(icon);\n\n if (!this.closeHidden) header.appendChild(close);\n\n header.appendChild(headerActions);\n body.appendChild(contentSlot);\n footer.appendChild(slotFooter);\n\n if (!this.hiddenHeader) dialog.appendChild(header);\n dialog.appendChild(body);\n if (!this.hiddenFooter) dialog.appendChild(footer);\n }\n\n /**\n * Closes the dialog.\n * @param e\n */\n close(e) {\n this.onClose(e);\n }\n\n /**\n * Before the component is disconnected.\n */\n beforeDisconnect() {\n if (this.params?.trigger) {\n event.removeListener(document, this.params?.trigger, null, this.onOpen);\n }\n\n //this.dialog.removeEventListener('close', this.onClose);\n }\n\n /**\n * Before the dialog opens.\n */\n beforeOpen(dialog, trigger) {\n // Hook for extending behavior before the dialog opens\n }\n\n /**\n * After the dialog opens.\n */\n afterOpen(dialog, trigger) {\n // Hook for extending behavior after the dialog opens\n }\n\n /**\n * Before the dialog closes.\n */\n beforeClose(dialog, trigger) {\n // Hook for extending behavior before the dialog closes\n }\n\n /**\n * After the dialog closes.\n */\n afterClose(dialog, trigger) {\n // Hook for extending behavior after the dialog closes\n }\n\n /**\n * Opens the dialog.\n * @param e\n */\n onOpen = (e) => {\n if (this.dialog) {\n this.dialog.innerHTML = '';\n }\n\n setTimeout(() => {\n Promise.resolve(this.beforeOpen(this, e)).then((res) => {\n this.htmlDialogBody(this.dialog);\n\n this.dialog.showModal(); // Now open the dialog\n\n if (this.dialog.open) {\n Promise.resolve(this.afterOpen(this, e));\n }\n });\n }, 0);\n }\n\n /**\n * Closes the dialog.\n * @param {object} e\n */\n onClose = (e) => {\n Promise.resolve(this.beforeClose(this, e)).then((res) => {\n this.dialog.close(); // Now close the dialog\n\n if (!this.dialog.open) {\n Promise.resolve(this.afterClose(this, e));\n }\n });\n };\n\n /**\n * Registers an event listener on the provided button that triggers a blocking UI element\n * and executes a given promise when the button is clicked.\n * @param {HTMLElement} button The button element to attach the event listener to.\n * @param {Function} promise A function that returns a promise to be executed when the button is clicked.\n */\n registerBlockingEvent(button, promise) {\n button.addEventListener('wje-button:click', async (e) => {\n let blockingElement = document.createElement('div');\n blockingElement.classList.add('blocking-element');\n\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'loader-2');\n icon.setAttribute('size', '2x-large');\n\n blockingElement.appendChild(icon);\n\n let scrollOffset = this.dialog.scrollTop;\n blockingElement.style.top = `${scrollOffset}px`;\n blockingElement.style.bottom = `-${scrollOffset}px`;\n\n this.dialog.appendChild(blockingElement);\n\n await promise()\n .then((res) => {\n this.close();\n blockingElement.remove();\n })\n .catch((err) => {\n console.error(err);\n blockingElement.remove();\n });\n });\n }\n}\n","import Dialog from './dialog.element.js';\n\nexport default Dialog;\n\nDialog.define('wje-dialog', Dialog);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAe,KAAK,OAAO;AAC/B,sBAAgB,MAAM,MAAM,GAAG,YAAY;AAC3C,sBAAgB,MAAM,SAAS,IAAI,YAAY;AAE/C,WAAK,OAAO,YAAY,eAAe;AAEvC,YAAM,QAAO,EACR,KAAK,CAAC,QAAQ;AACX,aAAK,MAAO;AACZ,wBAAgB,OAAQ;AAAA,MAC3B,CAAA,EACA,MAAM,CAAC,QAAQ;AACZ,gBAAQ,MAAM,GAAG;AACjB,wBAAgB,OAAQ;AAAA,MAC5C,CAAiB;AAAA,IACjB,CAAS;AAAA,EACT;AACA;ACjWA,OAAO,OAAO,cAAc,MAAM;"}
1
+ {"version":3,"file":"wje-dialog.js","sources":["../packages/wje-dialog/dialog.element.js","../packages/wje-dialog/dialog.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport '../wje-button/button.element.js';\nimport '../wje-icon/icon.element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Dialog` is a custom web component that represents a dialog.\n * @summary This element represents a dialog.\n * @documentation https://elements.webjet.sk/components/dialog\n * @status stable\n * @augments {WJElement}\n * @slot header - Slot for the header content.\n * @slot body - Slot for the body content.\n * @slot footer - Slot for the footer content.\n * @csspart dialog - The dialog wrapper.\n * @csspart header - The header of the dialog.\n * @csspart body - The body of the dialog.\n * @csspart footer - The footer of the dialog.\n * @csspart close - The close button of the dialog.\n * @cssproperty [--wje-dialog-background=var(--wje-background-color)] - Specifies the background color of the dialog.\n * @cssproperty [--wje-dialog-color=var(--wje-text-color)] - Defines the text color within the dialog.\n * @cssproperty [--wje-dialog-padding=1rem] - Controls the padding inside the dialog.\n * @cssproperty [--wje-dialog-border-radius=0.5rem] - Sets the border radius for the dialog's corners.\n * @cssproperty [--wje-dialog-box-shadow=0 2px 10px rgba(0, 0, 0, 0.1)] - Applies a shadow effect to the dialog.\n * @tag wje-dialog\n */\n\nexport default class Dialog extends WJElement {\n /**\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the value of the 'headline' attribute.\n * @param {string} value The new value for the 'headline' attribute.\n */\n set headline(value) {\n this.setAttribute('headline', value);\n }\n\n /**\n * Retrieves the value of the \"headline\" attribute from the element.\n * If the \"headline\" attribute is not present, returns an empty string.\n * @returns {string} The headline attribute value or an empty string if not set.\n */\n get headline() {\n return this.getAttribute('headline') || '';\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set placement(value) {\n this.setAttribute('placement', value);\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {string|string}\n */\n get placement() {\n return this.getAttribute('placement') || 'slide-up';\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set async(value) {\n this.setAttribute('async', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get async() {\n return this.hasAttribute('async');\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set closeHidden(value) {\n if (value) this.setAttribute('close-hidden', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get closeHidden() {\n return !!this.hasAttribute('close-hidden');\n }\n\n set hiddenHeader(value) {\n if (value) this.setAttribute('hidden-header', '');\n }\n\n get hiddenHeader() {\n return !!this.hasAttribute('hidden-header');\n }\n\n set hiddenFooter(value) {\n if (value) this.setAttribute('hidden-footer', '');\n }\n\n get hiddenFooter() {\n return !!this.hasAttribute('hidden-footer');\n }\n\n /**\n * Sets the headline of the dialog.\n * @type {string}\n */\n className = 'Dialog';\n\n /**\n * Returns the CSS styles for the component.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {*[]}\n */\n static get observedAttributes() {\n return [];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('fade', this.placement, params.size);\n\n let dialog = document.createElement('dialog');\n dialog.setAttribute('part', 'dialog');\n dialog.classList.add('modal-dialog');\n\n fragment.appendChild(dialog);\n\n this.dialog = dialog;\n\n return fragment;\n }\n\n /**\n * Draws the component after it has been drawn.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n */\n afterDraw(context, store, params) {\n if (params.trigger) {\n event.addListener(document, params.trigger, null, this.onOpen);\n }\n }\n\n /**\n * Creates the dialog body.\n * @param dialog\n */\n htmlDialogBody(dialog) {\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'x');\n icon.setAttribute('slot', 'icon-only');\n\n let close = document.createElement('wje-button');\n close.setAttribute('fill', 'link');\n close.setAttribute('size', 'small');\n close.setAttribute('part', 'close');\n close.addEventListener('click', (e) => {\n this.close(e);\n });\n\n let header = document.createElement('div');\n header.setAttribute('part', 'header');\n header.classList.add('dialog-header');\n if (this.hasAttribute('headline'))\n header.innerHTML = `<span part=\"headline\">${this.headline}</span>`;\n\n let slotHeader = document.createElement('slot');\n slotHeader.setAttribute('name', 'header');\n\n const headerActions = document.createElement('div');\n headerActions.classList.add('header-actions');\n headerActions.setAttribute('part', 'header-actions');\n headerActions.appendChild(slotHeader);\n\n let contentSlot = document.createElement('slot');\n\n let body = document.createElement('div');\n body.setAttribute('part', 'body');\n body.classList.add('dialog-content');\n\n let footer = document.createElement('div');\n footer.setAttribute('part', 'footer');\n footer.classList.add('dialog-footer');\n footer.innerHTML = '';\n\n let slotFooter = document.createElement('slot');\n slotFooter.setAttribute('name', 'footer');\n\n close.appendChild(icon);\n\n if (!this.closeHidden) header.appendChild(close);\n\n header.appendChild(headerActions);\n body.appendChild(contentSlot);\n footer.appendChild(slotFooter);\n\n if (!this.hiddenHeader) dialog.appendChild(header);\n dialog.appendChild(body);\n if (!this.hiddenFooter) dialog.appendChild(footer);\n }\n\n /**\n * Closes the dialog.\n * @param e\n */\n close(e) {\n this.onClose(e);\n }\n\n /**\n * Before the component is disconnected.\n */\n beforeDisconnect() {\n if (this.params?.trigger) {\n event.removeListener(document, this.params?.trigger, null, this.onOpen);\n }\n\n //this.dialog.removeEventListener('close', this.onClose);\n }\n\n /**\n * Before the dialog opens.\n */\n beforeOpen(dialog, trigger) {\n // Hook for extending behavior before the dialog opens\n }\n\n /**\n * After the dialog opens.\n */\n afterOpen(dialog, trigger) {\n // Hook for extending behavior after the dialog opens\n }\n\n /**\n * Before the dialog closes.\n */\n beforeClose(dialog, trigger) {\n // Hook for extending behavior before the dialog closes\n }\n\n /**\n * After the dialog closes.\n */\n afterClose(dialog, trigger) {\n // Hook for extending behavior after the dialog closes\n }\n\n /**\n * Opens the dialog.\n * @param e\n */\n onOpen = (e) => {\n if (this.dialog) {\n this.dialog.innerHTML = '';\n }\n\n setTimeout(() => {\n Promise.resolve(this.beforeOpen(this, e)).then((res) => {\n this.htmlDialogBody(this.dialog);\n\n this.dialog.showModal(); // Now open the dialog\n\n if (this.dialog.open) {\n Promise.resolve(this.afterOpen(this, e));\n }\n });\n }, 0);\n }\n\n /**\n * Closes the dialog.\n * @param {object} e\n */\n onClose = (e) => {\n Promise.resolve(this.beforeClose(this, e)).then((res) => {\n this.dialog.close(); // Now close the dialog\n\n if (!this.dialog.open) {\n Promise.resolve(this.afterClose(this, e));\n }\n });\n };\n\n /**\n * Registers an event listener on the provided button that triggers a blocking UI element\n * and executes a given promise when the button is clicked.\n * @param {HTMLElement} button The button element to attach the event listener to.\n * @param {Function} promise A function that returns a promise to be executed when the button is clicked.\n */\n registerBlockingEvent(button, promise) {\n button.addEventListener('wje-button:click', async (e) => {\n let blockingElement = document.createElement('div');\n blockingElement.classList.add('blocking-element');\n\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'loader-2');\n icon.setAttribute('size', '2x-large');\n\n blockingElement.appendChild(icon);\n\n let scrollOffset = this.dialog.scrollTop;\n blockingElement.style.top = `${scrollOffset}px`;\n blockingElement.style.bottom = `-${scrollOffset}px`;\n\n this.dialog.appendChild(blockingElement);\n\n await promise()\n .then((res) => {\n this.close();\n blockingElement.remove();\n })\n .catch((err) => {\n console.error(err);\n blockingElement.remove();\n });\n });\n }\n}\n","import Dialog from './dialog.element.js';\n\nexport default Dialog;\n\nDialog.define('wje-dialog', Dialog);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2Be,MAAM,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA,EAI1C,cAAc;AACV,UAAO;AAwFX;AAAA;AAAA;AAAA;AAAA,qCAAY;AAyKZ;AAAA;AAAA;AAAA;AAAA,kCAAS,CAAC,MAAM;AACZ,UAAI,KAAK,QAAQ;AACb,aAAK,OAAO,YAAY;AAAA,MACpC;AAEQ,iBAAW,MAAM;AACb,gBAAQ,QAAQ,KAAK,WAAW,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ;AACpD,eAAK,eAAe,KAAK,MAAM;AAE/B,eAAK,OAAO;AAEZ,cAAI,KAAK,OAAO,MAAM;AAClB,oBAAQ,QAAQ,KAAK,UAAU,MAAM,CAAC,CAAC;AAAA,UAC3D;AAAA,QACA,CAAa;AAAA,MACJ,GAAE,CAAC;AAAA,IACZ;AAMI;AAAA;AAAA;AAAA;AAAA,mCAAU,CAAC,MAAM;AACb,cAAQ,QAAQ,KAAK,YAAY,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ;AACrD,aAAK,OAAO;AAEZ,YAAI,CAAC,KAAK,OAAO,MA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AAAA;AAAA,EAKI,YAAY,QAAQ,SAAS;AAAA,EAEjC;AAAA;AAAA;AAAA;AAAA,EAKI,WAAW,QAAQ,SAAS;AAAA,EAEhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4CI,sBAAsB,QAAQ,SAAS;AACnC,WAAO,iBAAiB,oBAAoB,OAAO,MAAM;AACrD,UAAI,kBAAkB,SAAS,cAAc,KAAK;AAClD,sBAAgB,UAAU,IAAI,kBAAkB;AAEhD,UAAI,OAAO,SAAS,cAAc,UAAU;AAC5C,WAAK,aAAa,QAAQ,UAAU;AACpC,WAAK,aAAa,QAAQ,UAAU;AAEpC,sBAAgB,YAAY,IAAI;AAEhC,UAAI,eAAe,KAAK,OAAO;AAC/B,sBAAgB,MAAM,MAAM,GAAG,YAAY;AAC3C,sBAAgB,MAAM,SAAS,IAAI,YAAY;AAE/C,WAAK,OAAO,YAAY,eAAe;AAEvC,YAAM,QAAO,EACR,KAAK,CAAC,QAAQ;AACX,aAAK,MAAO;AACZ,wBAAgB,OAAQ;AAAA,MAC3B,CAAA,EACA,MAAM,CAAC,QAAQ;AACZ,gBAAQ,MAAM,GAAG;AACjB,wBAAgB,OAAQ;AAAA,MAC5C,CAAiB;AAAA,IACjB,CAAS;AAAA,EACT;AACA;AC/VA,OAAO,OAAO,cAAc,MAAM;"}
@@ -11,6 +11,8 @@ class TabGroup extends WJElement {
11
11
  constructor() {
12
12
  super();
13
13
  __publicField(this, "className", "TabGroup");
14
+ this._lastNavWidth = null;
15
+ this._initialized = false;
14
16
  }
15
17
  /**
16
18
  * Sets the value for the 'variant' attribute of the element.
@@ -140,9 +142,15 @@ class TabGroup extends WJElement {
140
142
  this.setActiveTab(e.detail.context.panel);
141
143
  });
142
144
  if (this.variant === "top" || this.variant === "bottom") {
143
- this.checkOverflow = this.checkOverflow.bind(this);
144
- window.addEventListener("resize", this.checkOverflow);
145
- requestAnimationFrame(() => this.checkOverflow());
145
+ this.initTabMetrics();
146
+ this._resizeObserver = new ResizeObserver((entries) => {
147
+ const width = entries[0].contentRect.width;
148
+ if (width !== this._lastNavWidth) {
149
+ this._lastNavWidth = width;
150
+ this.checkOverflow();
151
+ }
152
+ });
153
+ this._resizeObserver.observe(this);
146
154
  }
147
155
  }
148
156
  /**
@@ -205,35 +213,49 @@ class TabGroup extends WJElement {
205
213
  * @returns {void} Does not return a value.
206
214
  */
207
215
  toggleMoreVisibility() {
208
- const hasTabsInMore = this.querySelector('wje-tab[slot="more"]');
209
- this.moreDropdown.hidden = !hasTabsInMore;
216
+ const hasTabsInMore = !!this.querySelector('wje-tab[slot="more"]');
217
+ const nextHidden = !hasTabsInMore;
218
+ if (this.moreDropdown.hidden !== nextHidden) {
219
+ this.moreDropdown.hidden = nextHidden;
220
+ }
210
221
  }
211
222
  /**
212
- * Checks if the tabs within a navigation bar overflow the available space.
213
- * Moves overflowing tabs into a dropdown menu and updates their state accordingly.
214
- * @returns {void} This method does not return a value.
223
+ * Initializes metrics for tabs within the component. Assigns each tab to the navigation slot
224
+ * and calculates their dimensions for further operations.
225
+ * @returns {void} Does not return any value.
215
226
  */
216
- checkOverflow() {
217
- const nav = this.nav;
218
- const moreBtn = this.moreDropdown;
219
- const moreWidth = moreBtn.offsetWidth || 48;
227
+ initTabMetrics() {
220
228
  const tabs = Array.from(this.querySelectorAll("wje-tab"));
221
229
  tabs.forEach((tab) => tab.setAttribute("slot", "nav"));
222
230
  requestAnimationFrame(() => {
223
- const navRight = nav.getBoundingClientRect().right;
224
- let overflowStarted = false;
225
- for (const tab of tabs) {
226
- const tabRect = tab.getBoundingClientRect();
227
- const fits = tabRect.right + moreWidth <= navRight;
228
- if (!fits || overflowStarted) {
229
- tab.setAttribute("slot", "more");
230
- this.dropdownActive(tab);
231
- overflowStarted = true;
232
- }
233
- }
234
- this.toggleMoreVisibility();
231
+ this._tabMetrics = tabs.map((tab) => ({
232
+ el: tab,
233
+ width: tab.getBoundingClientRect().width
234
+ }));
235
+ this._initialized = true;
236
+ this.checkOverflow();
237
+ this._lastNavWidth = this.nav.getBoundingClientRect().width;
235
238
  });
236
239
  }
240
+ /**
241
+ * Checks if the tabs within a navigation bar overflow the available space.
242
+ * Moves overflowing tabs into a dropdown menu and updates their state accordingly.
243
+ * @returns {void} This method does not return a value.
244
+ */
245
+ checkOverflow() {
246
+ if (!this._initialized) return;
247
+ const navWidth = this.nav.getBoundingClientRect().width;
248
+ const moreWidth = this.moreDropdown.offsetWidth || 48;
249
+ let used = 0;
250
+ let overflowStarted = false;
251
+ for (const { el, width } of this._tabMetrics) {
252
+ used += width;
253
+ const shouldOverflow = used + moreWidth > navWidth;
254
+ el.setAttribute("slot", shouldOverflow || overflowStarted ? "more" : "nav");
255
+ overflowStarted || (overflowStarted = shouldOverflow);
256
+ }
257
+ this.toggleMoreVisibility();
258
+ }
237
259
  /**
238
260
  * Toggles the "dropdown-active" class on the element based on its "active" status
239
261
  * and the value of its "slot" attribute.
@@ -248,6 +270,11 @@ class TabGroup extends WJElement {
248
270
  this.moreDropdown.classList.remove("dropdown-active");
249
271
  }
250
272
  }
273
+ disconnectedCallback() {
274
+ var _a, _b;
275
+ (_a = super.disconnectedCallback) == null ? void 0 : _a.call(this);
276
+ (_b = this._resizeObserver) == null ? void 0 : _b.disconnect();
277
+ }
251
278
  }
252
279
  TabGroup.define("wje-tab-group", TabGroup);
253
280
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"wje-tab-group.js","sources":["../packages/wje-tab-group/tab-group.element.js","../packages/wje-tab-group/tab-group.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `TabGroup` is a custom web component that represents a group of tabs.\n * @summary This element represents a group of tabs.\n * @documentation https://elements.webjet.sk/components/tab-group\n * @status stable\n * @augments WJElement\n * @param {string} type The type of the tab group. Can be either 'panel' or 'route'.\n * @slot - The default slot for the tab group.\n * @slot nav - Slot for the navigation of the tab group.\n * @cssproperty [--wje-tab-group-padding=1rem] - Specifies the padding inside the tab group. This property defines the space between the content of the tab group and its outer boundary. Accepts any valid CSS length unit (e.g., `px`, `rem`, `em`, `%`).\n * @tag wje-tab-group\n */\n\nexport default class TabGroup extends WJElement {\n /**\n * Creates an instance of TabGroup.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the value for the 'variant' attribute of the element.\n * @param {string} value The value to set for the 'variant' attribute.\n */\n set variant(value) {\n this.setAttribute('variant', value);\n }\n\n /**\n * Gets the value of the 'variant' attribute.\n * If the attribute is not set, it defaults to 'top'.\n * @returns {string} The value of the 'variant' attribute or the default value 'top' if not set.\n */\n get variant() {\n return this.getAttribute('variant') || 'top';\n }\n\n /**\n * Sets the 'type' attribute of the element to the specified value.\n * @param {string} value The value to set for the 'type' attribute.\n */\n set type(value) {\n this.setAttribute('type', value);\n }\n\n /**\n * Retrieves the `type` attribute of the element.\n * If the `type` attribute is not set, it defaults to `'panel'`.\n * @returns {string} The value of the `type` attribute or the default value `'panel'`.\n */\n get type() {\n return this.getAttribute('type') || 'panel';\n }\n\n className = 'TabGroup';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Sets up the event listeners before the component is drawn.\n * This method is called before the component is drawn.\n * It is used to set up event listeners.\n */\n beforeDraw() {\n let activeTabName = location.hash.replace('#', '');\n\n // skontrolujeme ci sa nachadza v paneloch\n if (this.getPanelAllName().includes(activeTabName)) {\n window.addEventListener('load', (e) => {\n this.setActiveTab(activeTabName);\n });\n }\n }\n\n /**\n * Creates and returns a document fragment containing a structured layout for a tab group.\n * The tab group layout includes a `header` section with navigational elements,\n * a `section` element for tab panels, and slots for customization such as additional navigation items,\n * dropdowns, and more.\n * The structure comprises:\n * - A `div` container with relevant styling and part attributes.\n * - A `header` for tabs, including a slot for navigation (`nav`) and additional tabs in a dropdown (`moreDropdown`).\n * - A `section` for tab panels with a customizable `slot`.\n * This function also initializes the `nav` and `moreDropdown` properties for external use.\n * @returns {DocumentFragment} The completed document fragment containing the tab group layout.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-tab-group');\n\n let header = document.createElement('header');\n header.setAttribute('part', 'tabs');\n header.classList.add('scroll-snap-x');\n\n let nav = document.createElement('nav');\n nav.setAttribute('part', 'nav');\n\n let section = document.createElement('section');\n section.setAttribute('part', 'panels');\n\n let slot = document.createElement('slot');\n\n let slotNav = document.createElement('slot');\n slotNav.setAttribute('name', 'nav');\n\n // More dropdown\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'dots');\n\n let button = document.createElement('wje-button');\n button.setAttribute('slot', 'trigger');\n button.setAttribute('fill', 'link');\n\n let menu = document.createElement('wje-menu');\n menu.setAttribute('variant', 'context');\n\n let slotMore = document.createElement('slot');\n slotMore.setAttribute('name', 'more');\n\n let moreDropdown = document.createElement('wje-dropdown');\n moreDropdown.setAttribute('placement', 'bottom-end');\n moreDropdown.setAttribute('collapsible', '');\n moreDropdown.classList.add('more-tabs');\n\n // APPEND\n button.append(icon);\n\n menu.append(slotMore);\n\n moreDropdown.append(button);\n moreDropdown.append(menu);\n\n header.append(nav);\n\n nav.append(slotNav);\n\n if(this.variant === 'top' || this.variant === 'bottom') {\n nav.append(moreDropdown);\n }\n\n section.append(slot);\n\n native.append(header);\n native.append(section);\n\n fragment.append(native);\n\n this.nav = nav;\n this.moreDropdown = moreDropdown;\n\n return fragment;\n }\n\n /**\n * Executes necessary initializations and attaches event listeners after a drawing operation.\n * Handles active tab selection, 'wje-tab:change' event binding, and window resize event for overflow checking.\n * @returns {void} Does not return a value.\n */\n afterDraw() {\n let activeTab = this.getActiveTab();\n let activeTabName = activeTab ? activeTab[0][this.type] : this.getTabAll()[0][this.type];\n\n this.setActiveTab(activeTabName);\n\n this.addEventListener('wje-tab:change', (e) => {\n if (e.detail.context.hasAttribute('disabled')) return;\n this.setActiveTab(e.detail.context.panel);\n });\n\n if(this.variant === 'top' || this.variant === 'bottom') {\n this.checkOverflow = this.checkOverflow.bind(this);\n\n window.addEventListener('resize', this.checkOverflow);\n\n requestAnimationFrame(() => this.checkOverflow());\n }\n }\n\n /**\n * Removes the 'active' class from all panel and tab elements.\n * @returns {void} This method does not return a value.\n */\n removeActiveTab() {\n this.getPanelAll().forEach((el) => {\n el.classList.remove('active');\n });\n\n this.getTabAll().forEach((el) => {\n el.classList.remove('active');\n });\n }\n\n /**\n * Sets the active tab and panel.\n * @param {string} tab The name of the tab to set as active.\n */\n setActiveTab(tab) {\n this.removeActiveTab();\n\n const el = this.querySelector(`[${this.type}=\"${tab}\"]`)\n el?.classList.add('active');\n\n if(this.type === 'panel')\n this.querySelector(`[name=\"${tab}\"]`)?.classList.add('active');\n\n if(el)\n this.dropdownActive(el);\n }\n\n /**\n * Returns the currently active tab.\n * @returns {Element|null} The active tab, or null if no tab is active.\n */\n getActiveTab() {\n let activeTabs = Array.from(this.querySelectorAll('wje-tab.active'));\n return activeTabs.length > 0 ? activeTabs : null;\n }\n\n /**\n * Returns all tabs.\n * @returns {Array<Element>} An array of all tabs.\n */\n getTabAll() {\n return this.context.querySelector('[name=\"nav\"]').assignedElements();\n }\n\n /**\n * Returns all panels.\n * @returns {Array<Element>} An array of all panels.\n */\n getPanelAll() {\n return Array.from(this.querySelectorAll('wje-tab-panel'));\n }\n\n /**\n * Returns the names of all tabs.\n * @returns {Array<string>} An array of all tab names.\n */\n getPanelAllName() {\n return this.getPanelAll().map((el) => el.getAttribute('name'));\n }\n\n /**\n * Toggles the visibility of the \"more\" dropdown based on the presence of tabs in the \"more\" slot.\n * @returns {void} Does not return a value.\n */\n toggleMoreVisibility() {\n const hasTabsInMore = this.querySelector('wje-tab[slot=\"more\"]');\n this.moreDropdown.hidden = !hasTabsInMore;\n }\n\n /**\n * Checks if the tabs within a navigation bar overflow the available space.\n * Moves overflowing tabs into a dropdown menu and updates their state accordingly.\n * @returns {void} This method does not return a value.\n */\n checkOverflow() {\n const nav = this.nav;\n const moreBtn = this.moreDropdown;\n const moreWidth = moreBtn.offsetWidth || 48; // fallback ak ešte nie je vykreslený\n\n const tabs = Array.from(this.querySelectorAll('wje-tab'));\n\n // Reset: presunieme všetky taby naspäť do nav slotu\n tabs.forEach(tab => tab.setAttribute('slot', 'nav'));\n\n // Vykreslíme nanovo, aby sa more button správne umiestnil\n requestAnimationFrame(() => {\n const navRight = nav.getBoundingClientRect().right;\n let overflowStarted = false;\n\n for (const tab of tabs) {\n const tabRect = tab.getBoundingClientRect();\n\n // Ak by pretekal vrátane rezervy na more, presunieme ho\n const fits = tabRect.right + moreWidth <= navRight;\n\n if (!fits || overflowStarted) {\n tab.setAttribute('slot', 'more');\n this.dropdownActive(tab);\n overflowStarted = true;\n }\n }\n\n this.toggleMoreVisibility();\n });\n }\n\n /**\n * Toggles the \"dropdown-active\" class on the element based on its \"active\" status\n * and the value of its \"slot\" attribute.\n * @param {HTMLElement} el The HTML element to evaluate and apply the toggle logic.\n * @returns {void} This method does not return any value.\n */\n dropdownActive(el) {\n if(el.classList.contains('active')) {\n if(el.getAttribute('slot') === 'more')\n this.moreDropdown.classList.add('dropdown-active');\n else\n this.moreDropdown.classList.remove('dropdown-active');\n }\n }\n}\n","import TabGroup from './tab-group.element.js';\n\nexport default TabGroup;\n\nTabGroup.define('wje-tab-group', TabGroup);\n"],"names":[],"mappings":";;;;;AAgBe,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAK5C,cAAc;AACV,UAAO;AAqCX,qCAAY;AAAA,EApChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,QAAQ,OAAO;AACf,SAAK,aAAa,WAAW,KAAK;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,IAAI,UAAU;AACV,WAAO,KAAK,aAAa,SAAS,KAAK;AAAA,EAC/C;AAAA;A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EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,gBAAgB;AACZ,UAAM,MAAM,KAAK;AACjB,UAAM,UAAU,KAAK;AACrB,UAAM,YAAY,QAAQ,eAAe;AAEzC,UAAM,OAAO,MAAM,KAAK,KAAK,iBAAiB,SAAS,CAAC;AAGxD,SAAK,QAAQ,SAAO,IAAI,aAAa,QAAQ,KAAK,CAAC;AAGnD,0BAAsB,MAAM;AACxB,YAAM,WAAW,IAAI,sBAAqB,EAAG;AAC7C,UAAI,kBAAkB;AAEtB,iBAAW,OAAO,MAAM;AACpB,cAAM,UAAU,IAAI,sBAAuB;AAG3C,cAAM,OAAO,QAAQ,QAAQ,aAAa;AAE1C,YAAI,CAAC,QAAQ,iBAAiB;AAC1B,cAAI,aAAa,QAAQ,MAAM;AAC/B,eAAK,eAAe,GAAG;AACvB,4BAAkB;AAAA,QACtC;AAAA,MACA;AAEY,WAAK,qBAAsB;AAAA,IACvC,CAAS;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,eAAe,IAAI;AACf,QAAG,GAAG,UAAU,SAAS,QAAQ,GAAG;AAChC,UAAG,GAAG,aAAa,MAAM,MAAM;AAC3B,aAAK,aAAa,UAAU,IAAI,iBAAiB;AAAA;AAEjD,aAAK,aAAa,UAAU,OAAO,iBAAiB;AAAA,IACpE;AAAA,EACA;AACA;AChUA,SAAS,OAAO,iBAAiB,QAAQ;"}
1
+ {"version":3,"file":"wje-tab-group.js","sources":["../packages/wje-tab-group/tab-group.element.js","../packages/wje-tab-group/tab-group.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `TabGroup` is a custom web component that represents a group of tabs.\n * @summary This element represents a group of tabs.\n * @documentation https://elements.webjet.sk/components/tab-group\n * @status stable\n * @augments WJElement\n * @param {string} type The type of the tab group. Can be either 'panel' or 'route'.\n * @slot - The default slot for the tab group.\n * @slot nav - Slot for the navigation of the tab group.\n * @cssproperty [--wje-tab-group-padding=1rem] - Specifies the padding inside the tab group. This property defines the space between the content of the tab group and its outer boundary. Accepts any valid CSS length unit (e.g., `px`, `rem`, `em`, `%`).\n * @tag wje-tab-group\n */\n\nexport default class TabGroup extends WJElement {\n /**\n * Creates an instance of TabGroup.\n * @class\n */\n constructor() {\n super();\n\n this._lastNavWidth = null;\n this._initialized = false;\n }\n\n /**\n * Sets the value for the 'variant' attribute of the element.\n * @param {string} value The value to set for the 'variant' attribute.\n */\n set variant(value) {\n this.setAttribute('variant', value);\n }\n\n /**\n * Gets the value of the 'variant' attribute.\n * If the attribute is not set, it defaults to 'top'.\n * @returns {string} The value of the 'variant' attribute or the default value 'top' if not set.\n */\n get variant() {\n return this.getAttribute('variant') || 'top';\n }\n\n /**\n * Sets the 'type' attribute of the element to the specified value.\n * @param {string} value The value to set for the 'type' attribute.\n */\n set type(value) {\n this.setAttribute('type', value);\n }\n\n /**\n * Retrieves the `type` attribute of the element.\n * If the `type` attribute is not set, it defaults to `'panel'`.\n * @returns {string} The value of the `type` attribute or the default value `'panel'`.\n */\n get type() {\n return this.getAttribute('type') || 'panel';\n }\n\n className = 'TabGroup';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Sets up the event listeners before the component is drawn.\n * This method is called before the component is drawn.\n * It is used to set up event listeners.\n */\n beforeDraw() {\n let activeTabName = location.hash.replace('#', '');\n\n // skontrolujeme ci sa nachadza v paneloch\n if (this.getPanelAllName().includes(activeTabName)) {\n window.addEventListener('load', (e) => {\n this.setActiveTab(activeTabName);\n });\n }\n }\n\n /**\n * Creates and returns a document fragment containing a structured layout for a tab group.\n * The tab group layout includes a `header` section with navigational elements,\n * a `section` element for tab panels, and slots for customization such as additional navigation items,\n * dropdowns, and more.\n * The structure comprises:\n * - A `div` container with relevant styling and part attributes.\n * - A `header` for tabs, including a slot for navigation (`nav`) and additional tabs in a dropdown (`moreDropdown`).\n * - A `section` for tab panels with a customizable `slot`.\n * This function also initializes the `nav` and `moreDropdown` properties for external use.\n * @returns {DocumentFragment} The completed document fragment containing the tab group layout.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-tab-group');\n\n let header = document.createElement('header');\n header.setAttribute('part', 'tabs');\n header.classList.add('scroll-snap-x');\n\n let nav = document.createElement('nav');\n nav.setAttribute('part', 'nav');\n\n let section = document.createElement('section');\n section.setAttribute('part', 'panels');\n\n let slot = document.createElement('slot');\n\n let slotNav = document.createElement('slot');\n slotNav.setAttribute('name', 'nav');\n\n // More dropdown\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'dots');\n\n let button = document.createElement('wje-button');\n button.setAttribute('slot', 'trigger');\n button.setAttribute('fill', 'link');\n\n let menu = document.createElement('wje-menu');\n menu.setAttribute('variant', 'context');\n\n let slotMore = document.createElement('slot');\n slotMore.setAttribute('name', 'more');\n\n let moreDropdown = document.createElement('wje-dropdown');\n moreDropdown.setAttribute('placement', 'bottom-end');\n moreDropdown.setAttribute('collapsible', '');\n moreDropdown.classList.add('more-tabs');\n\n // APPEND\n button.append(icon);\n\n menu.append(slotMore);\n\n moreDropdown.append(button);\n moreDropdown.append(menu);\n\n header.append(nav);\n\n nav.append(slotNav);\n\n if(this.variant === 'top' || this.variant === 'bottom') {\n nav.append(moreDropdown);\n }\n\n section.append(slot);\n\n native.append(header);\n native.append(section);\n\n fragment.append(native);\n\n this.nav = nav;\n this.moreDropdown = moreDropdown;\n\n return fragment;\n }\n\n /**\n * Executes necessary initializations and attaches event listeners after a drawing operation.\n * Handles active tab selection, 'wje-tab:change' event binding, and window resize event for overflow checking.\n * @returns {void} Does not return a value.\n */\n afterDraw() {\n let activeTab = this.getActiveTab();\n let activeTabName = activeTab ? activeTab[0][this.type] : this.getTabAll()[0][this.type];\n\n this.setActiveTab(activeTabName);\n\n this.addEventListener('wje-tab:change', (e) => {\n if (e.detail.context.hasAttribute('disabled')) return;\n this.setActiveTab(e.detail.context.panel);\n });\n\n if (this.variant === 'top' || this.variant === 'bottom') {\n this.initTabMetrics();\n\n this._resizeObserver = new ResizeObserver(entries => {\n const width = entries[0].contentRect.width;\n\n if (width !== this._lastNavWidth) {\n this._lastNavWidth = width;\n this.checkOverflow();\n }\n });\n\n this._resizeObserver.observe(this);\n }\n }\n\n /**\n * Removes the 'active' class from all panel and tab elements.\n * @returns {void} This method does not return a value.\n */\n removeActiveTab() {\n this.getPanelAll().forEach((el) => {\n el.classList.remove('active');\n });\n\n this.getTabAll().forEach((el) => {\n el.classList.remove('active');\n });\n }\n\n /**\n * Sets the active tab and panel.\n * @param {string} tab The name of the tab to set as active.\n */\n setActiveTab(tab) {\n this.removeActiveTab();\n\n const el = this.querySelector(`[${this.type}=\"${tab}\"]`)\n el?.classList.add('active');\n\n if(this.type === 'panel')\n this.querySelector(`[name=\"${tab}\"]`)?.classList.add('active');\n\n if(el)\n this.dropdownActive(el);\n }\n\n /**\n * Returns the currently active tab.\n * @returns {Element|null} The active tab, or null if no tab is active.\n */\n getActiveTab() {\n let activeTabs = Array.from(this.querySelectorAll('wje-tab.active'));\n return activeTabs.length > 0 ? activeTabs : null;\n }\n\n /**\n * Returns all tabs.\n * @returns {Array<Element>} An array of all tabs.\n */\n getTabAll() {\n return this.context.querySelector('[name=\"nav\"]').assignedElements();\n }\n\n /**\n * Returns all panels.\n * @returns {Array<Element>} An array of all panels.\n */\n getPanelAll() {\n return Array.from(this.querySelectorAll('wje-tab-panel'));\n }\n\n /**\n * Returns the names of all tabs.\n * @returns {Array<string>} An array of all tab names.\n */\n getPanelAllName() {\n return this.getPanelAll().map((el) => el.getAttribute('name'));\n }\n\n /**\n * Toggles the visibility of the \"more\" dropdown based on the presence of tabs in the \"more\" slot.\n * @returns {void} Does not return a value.\n */\n toggleMoreVisibility() {\n const hasTabsInMore = !!this.querySelector('wje-tab[slot=\"more\"]');\n const nextHidden = !hasTabsInMore;\n\n if (this.moreDropdown.hidden !== nextHidden) {\n this.moreDropdown.hidden = nextHidden;\n }\n }\n\n /**\n * Initializes metrics for tabs within the component. Assigns each tab to the navigation slot\n * and calculates their dimensions for further operations.\n * @returns {void} Does not return any value.\n */\n initTabMetrics() {\n const tabs = Array.from(this.querySelectorAll('wje-tab'));\n\n // všetko do nav – LEN RAZ\n tabs.forEach(tab => tab.setAttribute('slot', 'nav'));\n\n requestAnimationFrame(() => {\n this._tabMetrics = tabs.map(tab => ({\n el: tab,\n width: tab.getBoundingClientRect().width\n }));\n\n this._initialized = true;\n this.checkOverflow(); // prvý výpočet\n this._lastNavWidth = this.nav.getBoundingClientRect().width;\n });\n }\n\n /**\n * Checks if the tabs within a navigation bar overflow the available space.\n * Moves overflowing tabs into a dropdown menu and updates their state accordingly.\n * @returns {void} This method does not return a value.\n */\n checkOverflow() {\n if (!this._initialized) return;\n\n const navWidth = this.nav.getBoundingClientRect().width;\n const moreWidth = this.moreDropdown.offsetWidth || 48;\n\n let used = 0;\n let overflowStarted = false;\n\n for (const { el, width } of this._tabMetrics) {\n used += width;\n\n const shouldOverflow = used + moreWidth > navWidth;\n\n el.setAttribute('slot', shouldOverflow || overflowStarted ? 'more' : 'nav');\n overflowStarted ||= shouldOverflow;\n }\n\n this.toggleMoreVisibility();\n }\n\n /**\n * Toggles the \"dropdown-active\" class on the element based on its \"active\" status\n * and the value of its \"slot\" attribute.\n * @param {HTMLElement} el The HTML element to evaluate and apply the toggle logic.\n * @returns {void} This method does not return any value.\n */\n dropdownActive(el) {\n if(el.classList.contains('active')) {\n if(el.getAttribute('slot') === 'more')\n this.moreDropdown.classList.add('dropdown-active');\n else\n this.moreDropdown.classList.remove('dropdown-active');\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback?.();\n this._resizeObserver?.disconnect();\n }\n}\n","import TabGroup from './tab-group.element.js';\n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eAAW,EAAE,IAAI,MAAK,KAAM,KAAK,aAAa;AAC1C,cAAQ;AAER,YAAM,iBAAiB,OAAO,YAAY;AAE1C,SAAG,aAAa,QAAQ,kBAAkB,kBAAkB,SAAS,KAAK;AAC1E,4CAAoB;AAAA,IAChC;AAEQ,SAAK,qBAAsB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,eAAe,IAAI;AACf,QAAG,GAAG,UAAU,SAAS,QAAQ,GAAG;AAChC,UAAG,GAAG,aAAa,MAAM,MAAM;AAC3B,aAAK,aAAa,UAAU,IAAI,iBAAiB;AAAA;AAEjD,aAAK,aAAa,UAAU,OAAO,iBAAiB;AAAA,IACpE;AAAA,EACA;AAAA,EAEI,uBAAuB;;AACnB,gBAAM,yBAAN;AACA,eAAK,oBAAL,mBAAsB;AAAA,EAC9B;AACA;AC/VA,SAAS,OAAO,iBAAiB,QAAQ;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wj-elements",
3
3
  "description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
4
- "version": "0.1.252",
4
+ "version": "0.1.253",
5
5
  "homepage": "https://github.com/lencys/wj-elements",
6
6
  "author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
7
7
  "license": "MIT",
@@ -45,13 +45,15 @@
45
45
  "lint:fix": "eslint packages experimental-packages --max-warnings 0 --fix",
46
46
  "prettier": "prettier --write ./packages ./experimental-packages",
47
47
  "test:animation": "web-test-runner --files packages/wje-animation/animation.test.js",
48
+ "test:avatar": "web-test-runner --files packages/wje-avatar/avatar.test.js",
48
49
  "test:badge": "web-test-runner --files packages/wje-badge/badge.test.js",
49
50
  "test:breadcrumbs": "web-test-runner --files packages/wje-breadcrumbs/breadcrumbs.test.js",
50
51
  "test:button": "web-test-runner --files packages/wje-button/button.test.js",
51
52
  "test:color-picker": "web-test-runner --files packages/wje-color-picker/color-picker.test.js",
52
53
  "test:format-digital": "web-test-runner --files packages/wje-format-digital/format-digital.test.js",
53
54
  "test:relative-time": "web-test-runner --files packages/wje-relative-time/relative-time.test.js",
54
- "test:toast": "web-test-runner --files packages/wje-toast/toast.test.js"
55
+ "test:toast": "web-test-runner --files packages/wje-toast/toast.test.js",
56
+ "test:tab-group": "web-test-runner --files packages/wje-tab-group/tab-group.test.js"
55
57
  },
56
58
  "exports": {
57
59
  ".": {