@vaadin/horizontal-layout 24.7.0-alpha1 → 24.7.0-alpha10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/horizontal-layout",
3
- "version": "24.7.0-alpha1",
3
+ "version": "24.7.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,19 +36,20 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/component-base": "24.7.0-alpha1",
40
- "@vaadin/vaadin-lumo-styles": "24.7.0-alpha1",
41
- "@vaadin/vaadin-material-styles": "24.7.0-alpha1",
42
- "@vaadin/vaadin-themable-mixin": "24.7.0-alpha1",
39
+ "@vaadin/component-base": "24.7.0-alpha10",
40
+ "@vaadin/vaadin-lumo-styles": "24.7.0-alpha10",
41
+ "@vaadin/vaadin-material-styles": "24.7.0-alpha10",
42
+ "@vaadin/vaadin-themable-mixin": "24.7.0-alpha10",
43
43
  "lit": "^3.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@vaadin/chai-plugins": "24.7.0-alpha1",
47
- "@vaadin/testing-helpers": "^1.0.0"
46
+ "@vaadin/chai-plugins": "24.7.0-alpha10",
47
+ "@vaadin/test-runner-commands": "24.7.0-alpha10",
48
+ "@vaadin/testing-helpers": "^1.1.0"
48
49
  },
49
50
  "web-types": [
50
51
  "web-types.json",
51
52
  "web-types.lit.json"
52
53
  ],
53
- "gitHead": "04be941c9a7b659871c97f31b9cc3ffd7528087b"
54
+ "gitHead": "c0f8933df2a6a40648d3fb9cfbae6bbf86a8aa90"
54
55
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+
8
+ export declare function HorizontalLayoutMixin<T extends Constructor<HTMLElement>>(base: T): T;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { isEmptyTextNode } from '@vaadin/component-base/src/dom-utils.js';
7
+ import { SlotObserver } from '@vaadin/component-base/src/slot-observer.js';
8
+
9
+ /**
10
+ * @polymerMixin
11
+ */
12
+ export const HorizontalLayoutMixin = (superClass) =>
13
+ class extends superClass {
14
+ /** @protected */
15
+ ready() {
16
+ super.ready();
17
+
18
+ const startSlot = this.shadowRoot.querySelector('slot:not([name])');
19
+ this.__startSlotObserver = new SlotObserver(startSlot, ({ currentNodes, removedNodes }) => {
20
+ if (removedNodes.length) {
21
+ this.__clearAttribute(removedNodes, 'last-start-child');
22
+ }
23
+
24
+ const children = currentNodes.filter((node) => node.nodeType === Node.ELEMENT_NODE);
25
+ this.__updateAttributes(children, 'start', false, true);
26
+
27
+ const nodes = currentNodes.filter((node) => !isEmptyTextNode(node));
28
+ this.toggleAttribute('has-start', nodes.length > 0);
29
+ });
30
+
31
+ const endSlot = this.shadowRoot.querySelector('[name="end"]');
32
+ this.__endSlotObserver = new SlotObserver(endSlot, ({ currentNodes, removedNodes }) => {
33
+ if (removedNodes.length) {
34
+ this.__clearAttribute(removedNodes, 'first-end-child');
35
+ }
36
+
37
+ this.__updateAttributes(currentNodes, 'end', true, false);
38
+
39
+ this.toggleAttribute('has-end', currentNodes.length > 0);
40
+ });
41
+
42
+ const middleSlot = this.shadowRoot.querySelector('[name="middle"]');
43
+ this.__middleSlotObserver = new SlotObserver(middleSlot, ({ currentNodes, removedNodes }) => {
44
+ if (removedNodes.length) {
45
+ this.__clearAttribute(removedNodes, 'first-middle-child');
46
+ this.__clearAttribute(removedNodes, 'last-middle-child');
47
+ }
48
+
49
+ this.__updateAttributes(currentNodes, 'middle', true, true);
50
+
51
+ this.toggleAttribute('has-middle', currentNodes.length > 0);
52
+ });
53
+ }
54
+
55
+ /** @private */
56
+ __clearAttribute(nodes, attr) {
57
+ const el = nodes.find((node) => node.nodeType === Node.ELEMENT_NODE && node.hasAttribute(attr));
58
+ if (el) {
59
+ el.removeAttribute(attr);
60
+ }
61
+ }
62
+
63
+ /** @private */
64
+ __updateAttributes(nodes, slot, setFirst, setLast) {
65
+ nodes.forEach((child, idx) => {
66
+ if (setFirst) {
67
+ const attr = `first-${slot}-child`;
68
+ if (idx === 0) {
69
+ child.setAttribute(attr, '');
70
+ } else if (child.hasAttribute(attr)) {
71
+ child.removeAttribute(attr);
72
+ }
73
+ }
74
+
75
+ if (setLast) {
76
+ const attr = `last-${slot}-child`;
77
+ if (idx === nodes.length - 1) {
78
+ child.setAttribute(attr, '');
79
+ } else if (child.hasAttribute(attr)) {
80
+ child.removeAttribute(attr);
81
+ }
82
+ }
83
+ });
84
+ }
85
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { CSSResult } from 'lit';
7
+
8
+ export const horizontalLayoutStyles: CSSResult[];
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
+
8
+ export const baseStyles = css`
9
+ :host {
10
+ display: flex;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ :host([hidden]) {
15
+ display: none !important;
16
+ }
17
+
18
+ /* Theme variations */
19
+ :host([theme~='margin']) {
20
+ margin: 1em;
21
+ }
22
+
23
+ :host([theme~='padding']) {
24
+ padding: 1em;
25
+ }
26
+
27
+ :host([theme~='spacing']) {
28
+ gap: 1em;
29
+ }
30
+
31
+ :host([has-end]:not([has-middle])) ::slotted([last-start-child]) {
32
+ margin-inline-end: auto;
33
+ }
34
+
35
+ ::slotted([first-middle-child]) {
36
+ margin-inline-start: auto;
37
+ }
38
+
39
+ ::slotted([last-middle-child]) {
40
+ margin-inline-end: auto;
41
+ }
42
+
43
+ :host([has-start]:not([has-middle])) ::slotted([first-end-child]) {
44
+ margin-inline-start: auto;
45
+ }
46
+ `;
47
+
48
+ // Layout improvements are part of a feature for Flow users where children that have been configured to use full size
49
+ // using `HasSize.setSizeFull()` and others, get additional styles so that they effectively take the remaining space in
50
+ // the layout, rather than explicitly use 100% width/height. The respective data attributes are set by Flow's `HasSize`
51
+ // class.
52
+ const enableLayoutImprovements = window.Vaadin.featureFlags.layoutComponentImprovements;
53
+ const layoutImprovementStyles = css`
54
+ ::slotted([data-width-full]) {
55
+ flex: 1;
56
+ }
57
+
58
+ ::slotted(vaadin-horizontal-layout[data-width-full]),
59
+ ::slotted(vaadin-vertical-layout[data-width-full]) {
60
+ min-width: 0;
61
+ }
62
+ `;
63
+
64
+ export const horizontalLayoutStyles = enableLayoutImprovements ? [baseStyles, layoutImprovementStyles] : [baseStyles];
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
7
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+ import { HorizontalLayoutMixin } from './vaadin-horizontal-layout-mixin.js';
8
9
 
9
10
  /**
10
11
  * `<vaadin-horizontal-layout>` provides a simple way to horizontally align your HTML elements.
@@ -26,8 +27,18 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
26
27
  * `theme="padding"` | Applies the default amount of CSS padding for the host element (specified by the theme)
27
28
  * `theme="spacing"` | Applies the default amount of CSS margin between items (specified by the theme)
28
29
  * `theme="wrap"` | Items wrap to the next row when they exceed the layout width
30
+ *
31
+ * ### Component's slots
32
+ *
33
+ * The following slots are available to be set:
34
+ *
35
+ * Slot name | Description
36
+ * -------------------|---------------
37
+ * no name | Default slot
38
+ * `middle` | Slot for the content placed in the middle
39
+ * `end` | Slot for the content placed at the end
29
40
  */
30
- declare class HorizontalLayout extends ThemableMixin(ElementMixin(HTMLElement)) {}
41
+ declare class HorizontalLayout extends HorizontalLayoutMixin(ThemableMixin(ElementMixin(HTMLElement))) {}
31
42
 
32
43
  declare global {
33
44
  interface HTMLElementTagNameMap {
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
+ import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+ import { HorizontalLayoutMixin } from './vaadin-horizontal-layout-mixin.js';
11
+ import { horizontalLayoutStyles } from './vaadin-horizontal-layout-styles.js';
12
+
13
+ registerStyles('vaadin-horizontal-layout', horizontalLayoutStyles, { moduleId: 'vaadin-horizontal-layout-styles' });
10
14
 
11
15
  /**
12
16
  * `<vaadin-horizontal-layout>` provides a simple way to horizontally align your HTML elements.
@@ -29,39 +33,28 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
29
33
  * `theme="spacing"` | Applies the default amount of CSS margin between items (specified by the theme)
30
34
  * `theme="wrap"` | Items wrap to the next row when they exceed the layout width
31
35
  *
36
+ * ### Component's slots
37
+ *
38
+ * The following slots are available to be set:
39
+ *
40
+ * Slot name | Description
41
+ * -------------------|---------------
42
+ * no name | Default slot
43
+ * `middle` | Slot for the content placed in the middle
44
+ * `end` | Slot for the content placed at the end
45
+ *
32
46
  * @customElement
33
47
  * @extends HTMLElement
34
48
  * @mixes ThemableMixin
35
49
  * @mixes ElementMixin
50
+ * @mixes HorizontalLayoutMixin
36
51
  */
37
- class HorizontalLayout extends ElementMixin(ThemableMixin(PolymerElement)) {
52
+ class HorizontalLayout extends HorizontalLayoutMixin(ElementMixin(ThemableMixin(PolymerElement))) {
38
53
  static get template() {
39
54
  return html`
40
- <style>
41
- :host {
42
- display: flex;
43
- box-sizing: border-box;
44
- }
45
-
46
- :host([hidden]) {
47
- display: none !important;
48
- }
49
-
50
- /* Theme variations */
51
- :host([theme~='margin']) {
52
- margin: 1em;
53
- }
54
-
55
- :host([theme~='padding']) {
56
- padding: 1em;
57
- }
58
-
59
- :host([theme~='spacing']) {
60
- gap: 1em;
61
- }
62
- </style>
63
-
64
55
  <slot></slot>
56
+ <slot name="middle"></slot>
57
+ <slot name="end"></slot>
65
58
  `;
66
59
  }
67
60
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  export * from './vaadin-horizontal-layout.js';
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2017 - 2024 Vaadin Ltd.
3
+ * Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { css, html, LitElement } from 'lit';
6
+ import { html, LitElement } from 'lit';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
9
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10
10
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
+ import { HorizontalLayoutMixin } from './vaadin-horizontal-layout-mixin.js';
12
+ import { horizontalLayoutStyles } from './vaadin-horizontal-layout-styles.js';
11
13
 
12
14
  /**
13
15
  * LitElement based version of `<vaadin-horizontal-layout>` web component.
@@ -18,39 +20,22 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
18
20
  * There is no ETA regarding specific Vaadin version where it'll land.
19
21
  * Feel free to try this code in your apps as per Apache 2.0 license.
20
22
  */
21
- class HorizontalLayout extends ThemableMixin(ElementMixin(PolylitMixin(LitElement))) {
22
- static get styles() {
23
- return css`
24
- :host {
25
- display: flex;
26
- box-sizing: border-box;
27
- }
28
-
29
- :host([hidden]) {
30
- display: none !important;
31
- }
32
-
33
- /* Theme variations */
34
- :host([theme~='margin']) {
35
- margin: 1em;
36
- }
37
-
38
- :host([theme~='padding']) {
39
- padding: 1em;
40
- }
41
-
42
- :host([theme~='spacing']) {
43
- gap: 1em;
44
- }
45
- `;
46
- }
47
-
23
+ class HorizontalLayout extends HorizontalLayoutMixin(ThemableMixin(ElementMixin(PolylitMixin(LitElement)))) {
48
24
  static get is() {
49
25
  return 'vaadin-horizontal-layout';
50
26
  }
51
27
 
28
+ static get styles() {
29
+ return horizontalLayoutStyles;
30
+ }
31
+
32
+ /** @protected */
52
33
  render() {
53
- return html`<slot></slot>`;
34
+ return html`
35
+ <slot></slot>
36
+ <slot name="middle"></slot>
37
+ <slot name="end"></slot>
38
+ `;
54
39
  }
55
40
  }
56
41
 
package/web-types.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/horizontal-layout",
4
- "version": "24.7.0-alpha1",
4
+ "version": "24.7.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
8
8
  "elements": [
9
9
  {
10
10
  "name": "vaadin-horizontal-layout",
11
- "description": "`<vaadin-horizontal-layout>` provides a simple way to horizontally align your HTML elements.\n\n```\n<vaadin-horizontal-layout>\n <div>Item 1</div>\n <div>Item 2</div>\n</vaadin-horizontal-layout>\n```\n\n### Built-in Theme Variations\n\n`<vaadin-horizontal-layout>` supports the following theme variations:\n\nTheme variation | Description\n---|---\n`theme=\"margin\"` | Applies the default amount of CSS margin for the host element (specified by the theme)\n`theme=\"padding\"` | Applies the default amount of CSS padding for the host element (specified by the theme)\n`theme=\"spacing\"` | Applies the default amount of CSS margin between items (specified by the theme)\n`theme=\"wrap\"` | Items wrap to the next row when they exceed the layout width",
11
+ "description": "`<vaadin-horizontal-layout>` provides a simple way to horizontally align your HTML elements.\n\n```\n<vaadin-horizontal-layout>\n <div>Item 1</div>\n <div>Item 2</div>\n</vaadin-horizontal-layout>\n```\n\n### Built-in Theme Variations\n\n`<vaadin-horizontal-layout>` supports the following theme variations:\n\nTheme variation | Description\n---|---\n`theme=\"margin\"` | Applies the default amount of CSS margin for the host element (specified by the theme)\n`theme=\"padding\"` | Applies the default amount of CSS padding for the host element (specified by the theme)\n`theme=\"spacing\"` | Applies the default amount of CSS margin between items (specified by the theme)\n`theme=\"wrap\"` | Items wrap to the next row when they exceed the layout width\n\n### Component's slots\n\nThe following slots are available to be set:\n\nSlot name | Description\n-------------------|---------------\nno name | Default slot\n`middle` | Slot for the content placed in the middle\n`end` | Slot for the content placed at the end",
12
12
  "attributes": [
13
13
  {
14
14
  "name": "theme",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/horizontal-layout",
4
- "version": "24.7.0-alpha1",
4
+ "version": "24.7.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -16,7 +16,7 @@
16
16
  "elements": [
17
17
  {
18
18
  "name": "vaadin-horizontal-layout",
19
- "description": "`<vaadin-horizontal-layout>` provides a simple way to horizontally align your HTML elements.\n\n```\n<vaadin-horizontal-layout>\n <div>Item 1</div>\n <div>Item 2</div>\n</vaadin-horizontal-layout>\n```\n\n### Built-in Theme Variations\n\n`<vaadin-horizontal-layout>` supports the following theme variations:\n\nTheme variation | Description\n---|---\n`theme=\"margin\"` | Applies the default amount of CSS margin for the host element (specified by the theme)\n`theme=\"padding\"` | Applies the default amount of CSS padding for the host element (specified by the theme)\n`theme=\"spacing\"` | Applies the default amount of CSS margin between items (specified by the theme)\n`theme=\"wrap\"` | Items wrap to the next row when they exceed the layout width",
19
+ "description": "`<vaadin-horizontal-layout>` provides a simple way to horizontally align your HTML elements.\n\n```\n<vaadin-horizontal-layout>\n <div>Item 1</div>\n <div>Item 2</div>\n</vaadin-horizontal-layout>\n```\n\n### Built-in Theme Variations\n\n`<vaadin-horizontal-layout>` supports the following theme variations:\n\nTheme variation | Description\n---|---\n`theme=\"margin\"` | Applies the default amount of CSS margin for the host element (specified by the theme)\n`theme=\"padding\"` | Applies the default amount of CSS padding for the host element (specified by the theme)\n`theme=\"spacing\"` | Applies the default amount of CSS margin between items (specified by the theme)\n`theme=\"wrap\"` | Items wrap to the next row when they exceed the layout width\n\n### Component's slots\n\nThe following slots are available to be set:\n\nSlot name | Description\n-------------------|---------------\nno name | Default slot\n`middle` | Slot for the content placed in the middle\n`end` | Slot for the content placed at the end",
20
20
  "extension": true,
21
21
  "attributes": []
22
22
  }