@vaadin/horizontal-layout 24.7.0-alpha8 → 24.7.0-beta1

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-alpha8",
3
+ "version": "24.7.0-beta1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,20 +36,20 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/component-base": "24.7.0-alpha8",
40
- "@vaadin/vaadin-lumo-styles": "24.7.0-alpha8",
41
- "@vaadin/vaadin-material-styles": "24.7.0-alpha8",
42
- "@vaadin/vaadin-themable-mixin": "24.7.0-alpha8",
39
+ "@vaadin/component-base": "24.7.0-beta1",
40
+ "@vaadin/vaadin-lumo-styles": "24.7.0-beta1",
41
+ "@vaadin/vaadin-material-styles": "24.7.0-beta1",
42
+ "@vaadin/vaadin-themable-mixin": "24.7.0-beta1",
43
43
  "lit": "^3.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@vaadin/chai-plugins": "24.7.0-alpha8",
47
- "@vaadin/test-runner-commands": "24.7.0-alpha8",
46
+ "@vaadin/chai-plugins": "24.7.0-beta1",
47
+ "@vaadin/test-runner-commands": "24.7.0-beta1",
48
48
  "@vaadin/testing-helpers": "^1.1.0"
49
49
  },
50
50
  "web-types": [
51
51
  "web-types.json",
52
52
  "web-types.lit.json"
53
53
  ],
54
- "gitHead": "d015035192480fcc8cc9df5d00a950f177b83c32"
54
+ "gitHead": "4043c518ef9b915cde612d2907ddc9bd10e5af17"
55
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
+ };
@@ -27,6 +27,22 @@ export const baseStyles = css`
27
27
  :host([theme~='spacing']) {
28
28
  gap: 1em;
29
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
+ }
30
46
  `;
31
47
 
32
48
  // Layout improvements are part of a feature for Flow users where children that have been configured to use full size
@@ -5,6 +5,7 @@
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 {
@@ -7,6 +7,7 @@ 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
9
  import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+ import { HorizontalLayoutMixin } from './vaadin-horizontal-layout-mixin.js';
10
11
  import { horizontalLayoutStyles } from './vaadin-horizontal-layout-styles.js';
11
12
 
12
13
  registerStyles('vaadin-horizontal-layout', horizontalLayoutStyles, { moduleId: 'vaadin-horizontal-layout-styles' });
@@ -32,14 +33,29 @@ registerStyles('vaadin-horizontal-layout', horizontalLayoutStyles, { moduleId: '
32
33
  * `theme="spacing"` | Applies the default amount of CSS margin between items (specified by the theme)
33
34
  * `theme="wrap"` | Items wrap to the next row when they exceed the layout width
34
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
+ *
35
46
  * @customElement
36
47
  * @extends HTMLElement
37
48
  * @mixes ThemableMixin
38
49
  * @mixes ElementMixin
50
+ * @mixes HorizontalLayoutMixin
39
51
  */
40
- class HorizontalLayout extends ElementMixin(ThemableMixin(PolymerElement)) {
52
+ class HorizontalLayout extends HorizontalLayoutMixin(ElementMixin(ThemableMixin(PolymerElement))) {
41
53
  static get template() {
42
- return html`<slot></slot>`;
54
+ return html`
55
+ <slot></slot>
56
+ <slot name="middle"></slot>
57
+ <slot name="end"></slot>
58
+ `;
43
59
  }
44
60
 
45
61
  static get is() {
@@ -8,6 +8,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';
11
12
  import { horizontalLayoutStyles } from './vaadin-horizontal-layout-styles.js';
12
13
 
13
14
  /**
@@ -19,7 +20,7 @@ import { horizontalLayoutStyles } from './vaadin-horizontal-layout-styles.js';
19
20
  * There is no ETA regarding specific Vaadin version where it'll land.
20
21
  * Feel free to try this code in your apps as per Apache 2.0 license.
21
22
  */
22
- class HorizontalLayout extends ThemableMixin(ElementMixin(PolylitMixin(LitElement))) {
23
+ class HorizontalLayout extends HorizontalLayoutMixin(ThemableMixin(ElementMixin(PolylitMixin(LitElement)))) {
23
24
  static get is() {
24
25
  return 'vaadin-horizontal-layout';
25
26
  }
@@ -30,7 +31,11 @@ class HorizontalLayout extends ThemableMixin(ElementMixin(PolylitMixin(LitElemen
30
31
 
31
32
  /** @protected */
32
33
  render() {
33
- return html`<slot></slot>`;
34
+ return html`
35
+ <slot></slot>
36
+ <slot name="middle"></slot>
37
+ <slot name="end"></slot>
38
+ `;
34
39
  }
35
40
  }
36
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-alpha8",
4
+ "version": "24.7.0-beta1",
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-alpha8",
4
+ "version": "24.7.0-beta1",
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
  }