@vaadin/vaadin-form-layout 22.0.0-alpha6 → 22.0.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,10 +1,29 @@
1
1
  {
2
2
  "name": "@vaadin/vaadin-form-layout",
3
- "version": "22.0.0-alpha6",
3
+ "version": "22.0.0-beta1",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "Web component providing configurable responsive layout for form elements",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/vaadin/web-components.git",
12
+ "directory": "packages/vaadin-form-layout"
13
+ },
14
+ "author": "Vaadin Ltd",
15
+ "homepage": "https://vaadin.com/components",
16
+ "bugs": {
17
+ "url": "https://github.com/vaadin/vaadin-form-layout/issues"
18
+ },
5
19
  "main": "vaadin-form-layout.js",
6
20
  "module": "vaadin-form-layout.js",
7
- "repository": "vaadin/vaadin-form-layout",
21
+ "files": [
22
+ "src",
23
+ "theme",
24
+ "vaadin-*.d.ts",
25
+ "vaadin-*.js"
26
+ ],
8
27
  "keywords": [
9
28
  "Vaadin",
10
29
  "form-layout",
@@ -12,34 +31,8 @@
12
31
  "web-component",
13
32
  "polymer"
14
33
  ],
15
- "author": "Vaadin Ltd",
16
- "license": "Apache-2.0",
17
- "bugs": {
18
- "url": "https://github.com/vaadin/vaadin-form-layout/issues"
19
- },
20
- "homepage": "https://vaadin.com/components",
21
- "files": [
22
- "vaadin-*.d.ts",
23
- "vaadin-*.js",
24
- "src",
25
- "theme"
26
- ],
27
34
  "dependencies": {
28
- "@polymer/iron-resizable-behavior": "^3.0.0",
29
- "@polymer/polymer": "^3.0.0",
30
- "@vaadin/vaadin-element-mixin": "^22.0.0-alpha6",
31
- "@vaadin/vaadin-lumo-styles": "^22.0.0-alpha6",
32
- "@vaadin/vaadin-material-styles": "^22.0.0-alpha6",
33
- "@vaadin/vaadin-themable-mixin": "^22.0.0-alpha6"
34
- },
35
- "devDependencies": {
36
- "@esm-bundle/chai": "^4.3.4",
37
- "@vaadin/testing-helpers": "^0.3.0",
38
- "@vaadin/vaadin-text-field": "^22.0.0-alpha6",
39
- "sinon": "^9.2.1"
40
- },
41
- "publishConfig": {
42
- "access": "public"
35
+ "@vaadin/form-layout": "22.0.0-beta1"
43
36
  },
44
- "gitHead": "4b136b1c7da8942960e7255f40c27859125b3a45"
37
+ "gitHead": "4cf8a9d0504994200c610e44b3676114fef49c1e"
45
38
  }
@@ -1,103 +1,18 @@
1
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { FormItem } from '@vaadin/form-layout/src/vaadin-form-item.js';
2
7
 
3
8
  /**
4
- * `<vaadin-form-item>` is a Web Component providing labelled form item wrapper
5
- * for using inside `<vaadin-form-layout>`.
6
- *
7
- * `<vaadin-form-item>` accepts any number of children as the input content,
8
- * and also has a separate named `label` slot:
9
- *
10
- * ```html
11
- * <vaadin-form-item>
12
- * <label slot="label">Label aside</label>
13
- * <input>
14
- * </vaadin-form-item>
15
- * ```
16
- *
17
- * Any content can be used. For instance, you can have multiple input elements
18
- * with surrounding text. The label can be an element of any type:
19
- *
20
- * ```html
21
- * <vaadin-form-item>
22
- * <span slot="label">Date of Birth</span>
23
- * <input placeholder="YYYY" size="4"> -
24
- * <input placeholder="MM" size="2"> -
25
- * <input placeholder="DD" size="2"><br>
26
- * <em>Example: 1900-01-01</em>
27
- * </vaadin-form-item>
28
- * ```
29
- *
30
- * The label is optional and can be omitted:
31
- *
32
- * ```html
33
- * <vaadin-form-item>
34
- * <input type="checkbox"> Subscribe to our Newsletter
35
- * </vaadin-form-item>
36
- * ```
37
- *
38
- * By default, the `label` slot content is displayed aside of the input content.
39
- * When `label-position="top"` is set, the `label` slot content is displayed on top:
40
- *
41
- * ```html
42
- * <vaadin-form-item label-position="top">
43
- * <label slot="label">Label on top</label>
44
- * <input>
45
- * </vaadin-form-item>
46
- * ```
47
- *
48
- * **Note:** Normally, `<vaadin-form-item>` is used as a child of
49
- * a `<vaadin-form-layout>` element. Setting `label-position` is unnecessary,
50
- * because the `label-position` attribute is triggered automatically by the parent
51
- * `<vaadin-form-layout>`, depending on its width and responsive behavior.
52
- *
53
- * ### Input Width
54
- *
55
- * By default, `<vaadin-form-item>` does not manipulate the width of the slotted
56
- * input elements. Optionally you can stretch the child input element to fill
57
- * the available width for the input content by adding the `full-width` class:
58
- *
59
- * ```html
60
- * <vaadin-form-item>
61
- * <label slot="label">Label</label>
62
- * <input class="full-width">
63
- * </vaadin-form-item>
64
- * ```
65
- *
66
- * ### Styling
67
- *
68
- * The `label-position` host attribute can be used to target the label on top state:
69
- *
70
- * ```
71
- * :host([label-position="top"]) {
72
- * padding-top: 0.5rem;
73
- * }
74
- * ```
75
- *
76
- * The following shadow DOM parts are available for styling:
77
- *
78
- * Part name | Description
79
- * ---|---
80
- * label | The label slot container
81
- *
82
- * ### Custom CSS Properties Reference
83
- *
84
- * The following custom CSS properties are available on the `<vaadin-form-item>`
85
- * element:
86
- *
87
- * Custom CSS property | Description | Default
88
- * ---|---|---
89
- * `--vaadin-form-item-label-width` | Width of the label column when the labels are aside | `8em`
90
- * `--vaadin-form-item-label-spacing` | Spacing between the label column and the input column when the labels are aside | `1em`
91
- * `--vaadin-form-item-row-spacing` | Height of the spacing between the form item elements | `1em`
92
- *
93
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
9
+ * @deprecated Import `FormItem` from `@vaadin/form-layout/vaadin-form-item` instead.
94
10
  */
95
- declare class FormItemElement extends ThemableMixin(HTMLElement) {}
11
+ export type FormItemElement = FormItem;
96
12
 
97
- declare global {
98
- interface HTMLElementTagNameMap {
99
- 'vaadin-form-item': FormItemElement;
100
- }
101
- }
13
+ /**
14
+ * @deprecated Import `FormItem` from `@vaadin/form-layout/vaadin-form-item` instead.
15
+ */
16
+ export const FormItemElement: typeof FormItem;
102
17
 
103
- export { FormItemElement };
18
+ export * from '@vaadin/form-layout/src/vaadin-form-item.js';
@@ -3,181 +3,11 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
7
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
+ import { FormItem } from '@vaadin/form-layout/src/vaadin-form-item.js';
8
7
 
9
8
  /**
10
- * `<vaadin-form-item>` is a Web Component providing labelled form item wrapper
11
- * for using inside `<vaadin-form-layout>`.
12
- *
13
- * `<vaadin-form-item>` accepts any number of children as the input content,
14
- * and also has a separate named `label` slot:
15
- *
16
- * ```html
17
- * <vaadin-form-item>
18
- * <label slot="label">Label aside</label>
19
- * <input>
20
- * </vaadin-form-item>
21
- * ```
22
- *
23
- * Any content can be used. For instance, you can have multiple input elements
24
- * with surrounding text. The label can be an element of any type:
25
- *
26
- * ```html
27
- * <vaadin-form-item>
28
- * <span slot="label">Date of Birth</span>
29
- * <input placeholder="YYYY" size="4"> -
30
- * <input placeholder="MM" size="2"> -
31
- * <input placeholder="DD" size="2"><br>
32
- * <em>Example: 1900-01-01</em>
33
- * </vaadin-form-item>
34
- * ```
35
- *
36
- * The label is optional and can be omitted:
37
- *
38
- * ```html
39
- * <vaadin-form-item>
40
- * <input type="checkbox"> Subscribe to our Newsletter
41
- * </vaadin-form-item>
42
- * ```
43
- *
44
- * By default, the `label` slot content is displayed aside of the input content.
45
- * When `label-position="top"` is set, the `label` slot content is displayed on top:
46
- *
47
- * ```html
48
- * <vaadin-form-item label-position="top">
49
- * <label slot="label">Label on top</label>
50
- * <input>
51
- * </vaadin-form-item>
52
- * ```
53
- *
54
- * **Note:** Normally, `<vaadin-form-item>` is used as a child of
55
- * a `<vaadin-form-layout>` element. Setting `label-position` is unnecessary,
56
- * because the `label-position` attribute is triggered automatically by the parent
57
- * `<vaadin-form-layout>`, depending on its width and responsive behavior.
58
- *
59
- * ### Input Width
60
- *
61
- * By default, `<vaadin-form-item>` does not manipulate the width of the slotted
62
- * input elements. Optionally you can stretch the child input element to fill
63
- * the available width for the input content by adding the `full-width` class:
64
- *
65
- * ```html
66
- * <vaadin-form-item>
67
- * <label slot="label">Label</label>
68
- * <input class="full-width">
69
- * </vaadin-form-item>
70
- * ```
71
- *
72
- * ### Styling
73
- *
74
- * The `label-position` host attribute can be used to target the label on top state:
75
- *
76
- * ```
77
- * :host([label-position="top"]) {
78
- * padding-top: 0.5rem;
79
- * }
80
- * ```
81
- *
82
- * The following shadow DOM parts are available for styling:
83
- *
84
- * Part name | Description
85
- * ---|---
86
- * label | The label slot container
87
- *
88
- * ### Custom CSS Properties Reference
89
- *
90
- * The following custom CSS properties are available on the `<vaadin-form-item>`
91
- * element:
92
- *
93
- * Custom CSS property | Description | Default
94
- * ---|---|---
95
- * `--vaadin-form-item-label-width` | Width of the label column when the labels are aside | `8em`
96
- * `--vaadin-form-item-label-spacing` | Spacing between the label column and the input column when the labels are aside | `1em`
97
- * `--vaadin-form-item-row-spacing` | Height of the spacing between the form item elements | `1em`
98
- *
99
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
100
- *
101
- * @extends HTMLElement
102
- * @mixes ThemableMixin
9
+ * @deprecated Import `FormItem` from `@vaadin/form-layout/vaadin-form-item` instead.
103
10
  */
104
- class FormItemElement extends ThemableMixin(PolymerElement) {
105
- static get template() {
106
- return html`
107
- <style>
108
- :host {
109
- display: inline-flex;
110
- flex-direction: row;
111
- align-items: baseline;
11
+ export const FormItemElement = FormItem;
112
12
 
113
- /* CSS API for host */
114
- --vaadin-form-item-label-width: 8em;
115
- --vaadin-form-item-label-spacing: 1em;
116
- --vaadin-form-item-row-spacing: 1em;
117
-
118
- margin: calc(0.5 * var(--vaadin-form-item-row-spacing)) 0;
119
- }
120
-
121
- :host([label-position='top']) {
122
- flex-direction: column;
123
- align-items: stretch;
124
- }
125
-
126
- :host([hidden]) {
127
- display: none !important;
128
- }
129
-
130
- #label {
131
- width: var(--vaadin-form-item-label-width);
132
- flex: 0 0 auto;
133
- }
134
-
135
- :host([label-position='top']) #label {
136
- width: auto;
137
- }
138
-
139
- #spacing {
140
- width: var(--vaadin-form-item-label-spacing);
141
- flex: 0 0 auto;
142
- }
143
-
144
- #content {
145
- flex: 1 1 auto;
146
- }
147
-
148
- #content ::slotted(.full-width) {
149
- box-sizing: border-box;
150
- width: 100%;
151
- min-width: 0;
152
- }
153
- </style>
154
- <div id="label" part="label" on-click="_onLabelClick">
155
- <slot name="label" id="labelSlot"></slot>
156
- </div>
157
- <div id="spacing"></div>
158
- <div id="content">
159
- <slot id="contentSlot"></slot>
160
- </div>
161
- `;
162
- }
163
-
164
- static get is() {
165
- return 'vaadin-form-item';
166
- }
167
-
168
- /** @private */
169
- _onLabelClick() {
170
- const firstContentElementChild = Array.prototype.find.call(
171
- this.$.contentSlot.assignedNodes(),
172
- (e) => e.nodeType === Node.ELEMENT_NODE
173
- );
174
- if (firstContentElementChild) {
175
- firstContentElementChild.focus();
176
- firstContentElementChild.click();
177
- }
178
- }
179
- }
180
-
181
- customElements.define(FormItemElement.is, FormItemElement);
182
-
183
- export { FormItemElement };
13
+ export * from '@vaadin/form-layout/src/vaadin-form-item.js';
@@ -1,149 +1,18 @@
1
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
2
-
3
- import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.js';
4
-
5
- import { FormLayoutResponsiveStep } from './interfaces';
6
-
7
1
  /**
8
- * `<vaadin-form-layout>` is a Web Component providing configurable responsive
9
- * layout for form elements.
10
- *
11
- * ```html
12
- * <vaadin-form-layout>
13
- *
14
- * <vaadin-form-item>
15
- * <label slot="label">First Name</label>
16
- * <input class="full-width" value="Jane">
17
- * </vaadin-form-item>
18
- *
19
- * <vaadin-form-item>
20
- * <label slot="label">Last Name</label>
21
- * <input class="full-width" value="Doe">
22
- * </vaadin-form-item>
23
- *
24
- * <vaadin-form-item>
25
- * <label slot="label">Email</label>
26
- * <input class="full-width" value="jane.doe@example.com">
27
- * </vaadin-form-item>
28
- *
29
- * </vaadin-form-layout>
30
- * ```
31
- *
32
- * It supports any child elements as layout items.
33
- *
34
- * By default, it makes a layout of two columns if the element width is equal or
35
- * wider than 40em, and a single column layout otherwise.
36
- *
37
- * The number of columns and the responsive behavior are customizable with
38
- * the `responsiveSteps` property.
39
- *
40
- * ### Spanning Items on Multiple Columns
41
- *
42
- * You can use `colspan` attribute on the items.
43
- * In the example below, the first text field spans on two columns:
44
- *
45
- * ```html
46
- * <vaadin-form-layout>
47
- *
48
- * <vaadin-form-item colspan="2">
49
- * <label slot="label">Address</label>
50
- * <input class="full-width">
51
- * </vaadin-form-item>
52
- *
53
- * <vaadin-form-item>
54
- * <label slot="label">First Name</label>
55
- * <input class="full-width" value="Jane">
56
- * </vaadin-form-item>
57
- *
58
- * <vaadin-form-item>
59
- * <label slot="label">Last Name</label>
60
- * <input class="full-width" value="Doe">
61
- * </vaadin-form-item>
62
- *
63
- * </vaadin-form-layout>
64
- * ```
65
- *
66
- * ### Explicit New Row
67
- *
68
- * Use the `<br>` line break element to wrap the items on a new row:
69
- *
70
- * ```html
71
- * <vaadin-form-layout>
72
- *
73
- * <vaadin-form-item>
74
- * <label slot="label">Email</label>
75
- * <input class="full-width">
76
- * </vaadin-form-item>
77
- *
78
- * <br>
79
- *
80
- * <vaadin-form-item>
81
- * <label slot="label">Confirm Email</label>
82
- * <input class="full-width">
83
- * </vaadin-form-item>
84
- *
85
- * </vaadin-form-layout>
86
- * ```
87
- *
88
- * ### CSS Properties Reference
89
- *
90
- * The following custom CSS properties are available on the `<vaadin-form-layout>`
91
- * element:
92
- *
93
- * Custom CSS property | Description | Default
94
- * ---|---|---
95
- * `--vaadin-form-layout-column-spacing` | Length of the spacing between columns | `2em`
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
96
5
  */
97
- declare class FormLayoutElement extends ElementMixin(ThemableMixin(HTMLElement)) {
98
- /**
99
- * Allows specifying a responsive behavior with the number of columns
100
- * and the label position depending on the layout width.
101
- *
102
- * Format: array of objects, each object defines one responsive step
103
- * with `minWidth` CSS length, `columns` number, and optional
104
- * `labelsPosition` string of `"aside"` or `"top"`. At least one item is required.
105
- *
106
- * #### Examples
107
- *
108
- * ```javascript
109
- * formLayout.responsiveSteps = [{columns: 1}];
110
- * // The layout is always a single column, labels aside.
111
- * ```
112
- *
113
- * ```javascript
114
- * formLayout.responsiveSteps = [
115
- * {minWidth: 0, columns: 1},
116
- * {minWidth: '40em', columns: 2}
117
- * ];
118
- * // Sets two responsive steps:
119
- * // 1. When the layout width is < 40em, one column, labels aside.
120
- * // 2. Width >= 40em, two columns, labels aside.
121
- * ```
122
- *
123
- * ```javascript
124
- * formLayout.responsiveSteps = [
125
- * {minWidth: 0, columns: 1, labelsPosition: 'top'},
126
- * {minWidth: '20em', columns: 1},
127
- * {minWidth: '40em', columns: 2}
128
- * ];
129
- * // Default value. Three responsive steps:
130
- * // 1. Width < 20em, one column, labels on top.
131
- * // 2. 20em <= width < 40em, one column, labels aside.
132
- * // 3. Width >= 40em, two columns, labels aside.
133
- * ```
134
- */
135
- responsiveSteps: FormLayoutResponsiveStep[];
6
+ import { FormLayout } from '@vaadin/form-layout/src/vaadin-form-layout.js';
136
7
 
137
- /**
138
- * Set custom CSS property values and update the layout.
139
- */
140
- updateStyles(properties?: { [key: string]: string }): void;
141
- }
8
+ /**
9
+ * @deprecated Import `FormLayout` from `@vaadin/form-layout` instead.
10
+ */
11
+ export type FormLayoutElement = FormLayout;
142
12
 
143
- declare global {
144
- interface HTMLElementTagNameMap {
145
- 'vaadin-form-layout': FormLayoutElement;
146
- }
147
- }
13
+ /**
14
+ * @deprecated Import `FormLayout` from `@vaadin/form-layout` instead.
15
+ */
16
+ export const FormLayoutElement: typeof FormLayout;
148
17
 
149
- export { FormLayoutElement };
18
+ export * from '@vaadin/form-layout/src/vaadin-form-layout.js';
@@ -3,527 +3,11 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
7
- import { beforeNextRender } from '@polymer/polymer/lib/utils/render-status.js';
8
- import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
9
- import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
10
- import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-resizable-behavior.js';
11
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
- import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.js';
6
+ import { FormLayout } from '@vaadin/form-layout/src/vaadin-form-layout.js';
13
7
 
14
8
  /**
15
- * `<vaadin-form-layout>` is a Web Component providing configurable responsive
16
- * layout for form elements.
17
- *
18
- * ```html
19
- * <vaadin-form-layout>
20
- *
21
- * <vaadin-form-item>
22
- * <label slot="label">First Name</label>
23
- * <input class="full-width" value="Jane">
24
- * </vaadin-form-item>
25
- *
26
- * <vaadin-form-item>
27
- * <label slot="label">Last Name</label>
28
- * <input class="full-width" value="Doe">
29
- * </vaadin-form-item>
30
- *
31
- * <vaadin-form-item>
32
- * <label slot="label">Email</label>
33
- * <input class="full-width" value="jane.doe@example.com">
34
- * </vaadin-form-item>
35
- *
36
- * </vaadin-form-layout>
37
- * ```
38
- *
39
- * It supports any child elements as layout items.
40
- *
41
- * By default, it makes a layout of two columns if the element width is equal or
42
- * wider than 40em, and a single column layout otherwise.
43
- *
44
- * The number of columns and the responsive behavior are customizable with
45
- * the `responsiveSteps` property.
46
- *
47
- * ### Spanning Items on Multiple Columns
48
- *
49
- * You can use `colspan` attribute on the items.
50
- * In the example below, the first text field spans on two columns:
51
- *
52
- * ```html
53
- * <vaadin-form-layout>
54
- *
55
- * <vaadin-form-item colspan="2">
56
- * <label slot="label">Address</label>
57
- * <input class="full-width">
58
- * </vaadin-form-item>
59
- *
60
- * <vaadin-form-item>
61
- * <label slot="label">First Name</label>
62
- * <input class="full-width" value="Jane">
63
- * </vaadin-form-item>
64
- *
65
- * <vaadin-form-item>
66
- * <label slot="label">Last Name</label>
67
- * <input class="full-width" value="Doe">
68
- * </vaadin-form-item>
69
- *
70
- * </vaadin-form-layout>
71
- * ```
72
- *
73
- * ### Explicit New Row
74
- *
75
- * Use the `<br>` line break element to wrap the items on a new row:
76
- *
77
- * ```html
78
- * <vaadin-form-layout>
79
- *
80
- * <vaadin-form-item>
81
- * <label slot="label">Email</label>
82
- * <input class="full-width">
83
- * </vaadin-form-item>
84
- *
85
- * <br>
86
- *
87
- * <vaadin-form-item>
88
- * <label slot="label">Confirm Email</label>
89
- * <input class="full-width">
90
- * </vaadin-form-item>
91
- *
92
- * </vaadin-form-layout>
93
- * ```
94
- *
95
- * ### CSS Properties Reference
96
- *
97
- * The following custom CSS properties are available on the `<vaadin-form-layout>`
98
- * element:
99
- *
100
- * Custom CSS property | Description | Default
101
- * ---|---|---
102
- * `--vaadin-form-layout-column-spacing` | Length of the spacing between columns | `2em`
103
- *
104
- * @extends HTMLElement
105
- * @mixes ElementMixin
106
- * @mixes ThemableMixin
9
+ * @deprecated Import `FormLayout` from `@vaadin/form-layout` instead.
107
10
  */
108
- class FormLayoutElement extends ElementMixin(ThemableMixin(mixinBehaviors([IronResizableBehavior], PolymerElement))) {
109
- static get template() {
110
- return html`
111
- <style>
112
- :host {
113
- display: block;
114
- max-width: 100%;
115
- animation: 1ms vaadin-form-layout-appear;
116
- /* CSS API for host */
117
- --vaadin-form-layout-column-spacing: 2em; /* (default) */
118
- align-self: stretch;
119
- }
11
+ export const FormLayoutElement = FormLayout;
120
12
 
121
- @keyframes vaadin-form-layout-appear {
122
- to {
123
- opacity: 1 !important; /* stylelint-disable-line keyframe-declaration-no-important */
124
- }
125
- }
126
-
127
- :host([hidden]) {
128
- display: none !important;
129
- }
130
-
131
- #layout {
132
- display: flex;
133
-
134
- align-items: baseline; /* default \`stretch\` is not appropriate */
135
-
136
- flex-wrap: wrap; /* the items should wrap */
137
- }
138
-
139
- #layout ::slotted(*) {
140
- /* Items should neither grow nor shrink. */
141
- flex-grow: 0;
142
- flex-shrink: 0;
143
-
144
- /* Margins make spacing between the columns */
145
- margin-left: calc(0.5 * var(--vaadin-form-layout-column-spacing));
146
- margin-right: calc(0.5 * var(--vaadin-form-layout-column-spacing));
147
- }
148
-
149
- #layout ::slotted(br) {
150
- display: none;
151
- }
152
- </style>
153
- <div id="layout">
154
- <slot id="slot"></slot>
155
- </div>
156
- `;
157
- }
158
-
159
- static get is() {
160
- return 'vaadin-form-layout';
161
- }
162
-
163
- static get properties() {
164
- return {
165
- /**
166
- * @typedef FormLayoutResponsiveStep
167
- * @type {object}
168
- * @property {string} minWidth - The threshold value for this step in CSS length units.
169
- * @property {number} columns - Number of columns. Only natural numbers are valid.
170
- * @property {string} labelsPosition - Labels position option, valid values: `"aside"` (default), `"top"`.
171
- */
172
-
173
- /**
174
- * Allows specifying a responsive behavior with the number of columns
175
- * and the label position depending on the layout width.
176
- *
177
- * Format: array of objects, each object defines one responsive step
178
- * with `minWidth` CSS length, `columns` number, and optional
179
- * `labelsPosition` string of `"aside"` or `"top"`. At least one item is required.
180
- *
181
- * #### Examples
182
- *
183
- * ```javascript
184
- * formLayout.responsiveSteps = [{columns: 1}];
185
- * // The layout is always a single column, labels aside.
186
- * ```
187
- *
188
- * ```javascript
189
- * formLayout.responsiveSteps = [
190
- * {minWidth: 0, columns: 1},
191
- * {minWidth: '40em', columns: 2}
192
- * ];
193
- * // Sets two responsive steps:
194
- * // 1. When the layout width is < 40em, one column, labels aside.
195
- * // 2. Width >= 40em, two columns, labels aside.
196
- * ```
197
- *
198
- * ```javascript
199
- * formLayout.responsiveSteps = [
200
- * {minWidth: 0, columns: 1, labelsPosition: 'top'},
201
- * {minWidth: '20em', columns: 1},
202
- * {minWidth: '40em', columns: 2}
203
- * ];
204
- * // Default value. Three responsive steps:
205
- * // 1. Width < 20em, one column, labels on top.
206
- * // 2. 20em <= width < 40em, one column, labels aside.
207
- * // 3. Width >= 40em, two columns, labels aside.
208
- * ```
209
- *
210
- * @type {!Array<!FormLayoutResponsiveStep>}
211
- */
212
- responsiveSteps: {
213
- type: Array,
214
- value: function () {
215
- return [
216
- { minWidth: 0, columns: 1, labelsPosition: 'top' },
217
- { minWidth: '20em', columns: 1 },
218
- { minWidth: '40em', columns: 2 }
219
- ];
220
- },
221
- observer: '_responsiveStepsChanged'
222
- },
223
-
224
- /**
225
- * Current number of columns in the layout
226
- * @private
227
- */
228
- _columnCount: {
229
- type: Number
230
- },
231
-
232
- /**
233
- * Indicates that labels are on top
234
- * @private
235
- */
236
- _labelsOnTop: {
237
- type: Boolean
238
- }
239
- };
240
- }
241
-
242
- static get observers() {
243
- return ['_invokeUpdateStyles(_columnCount, _labelsOnTop)'];
244
- }
245
-
246
- /** @protected */
247
- ready() {
248
- // Here we create and attach a style element that we use for validating
249
- // CSS values in `responsiveSteps`. We can’t add this to the `<template>`,
250
- // because Polymer will throw it away. We need to create this before
251
- // `super.ready()`, because `super.ready()` invokes property observers,
252
- // and the observer for `responsiveSteps` does CSS value validation.
253
- this._styleElement = document.createElement('style');
254
- this.root.appendChild(this._styleElement);
255
- // Ensure there is a child text node in the style element
256
- this._styleElement.textContent = ' ';
257
-
258
- super.ready();
259
-
260
- this.addEventListener('iron-resize', this._selectResponsiveStep);
261
- this.addEventListener('animationend', this.__onAnimationEnd);
262
- }
263
-
264
- /** @protected */
265
- connectedCallback() {
266
- super.connectedCallback();
267
-
268
- beforeNextRender(this, this._selectResponsiveStep);
269
- beforeNextRender(this, this.updateStyles);
270
-
271
- this._observeChildrenColspanChange();
272
- }
273
-
274
- /** @protected */
275
- disconnectedCallback() {
276
- super.disconnectedCallback();
277
-
278
- this.__mutationObserver.disconnect();
279
- this.__childObserver.disconnect();
280
- }
281
-
282
- /** @private */
283
- _observeChildrenColspanChange() {
284
- // Observe changes in form items' `colspan` attribute and update styles
285
- const mutationObserverConfig = { attributes: true };
286
-
287
- this.__mutationObserver = new MutationObserver((mutationRecord) => {
288
- mutationRecord.forEach((mutation) => {
289
- if (
290
- mutation.type === 'attributes' &&
291
- (mutation.attributeName === 'colspan' || mutation.attributeName === 'hidden')
292
- ) {
293
- this.updateStyles();
294
- }
295
- });
296
- });
297
-
298
- this.__childObserver = new FlattenedNodesObserver(this, (info) => {
299
- const addedNodes = this._getObservableNodes(info.addedNodes);
300
- const removedNodes = this._getObservableNodes(info.removedNodes);
301
-
302
- addedNodes.forEach((child) => {
303
- this.__mutationObserver.observe(child, mutationObserverConfig);
304
- });
305
-
306
- if (addedNodes.length > 0 || removedNodes.length > 0) {
307
- this.updateStyles();
308
- }
309
- });
310
- }
311
-
312
- /** @private */
313
- _getObservableNodes(nodeList) {
314
- const ignore = ['template', 'style', 'dom-repeat', 'dom-if'];
315
- return Array.from(nodeList).filter(
316
- (node) => node.nodeType === Node.ELEMENT_NODE && ignore.indexOf(node.localName.toLowerCase()) === -1
317
- );
318
- }
319
-
320
- /** @private */
321
- _naturalNumberOrOne(n) {
322
- if (typeof n === 'number' && n >= 1 && n < Infinity) {
323
- return Math.floor(n);
324
- }
325
- return 1;
326
- }
327
-
328
- /** @private */
329
- _isValidCSSLength(value) {
330
- // Let us choose a CSS property for validating CSS <length> values:
331
- // - `border-spacing` accepts `<length> | inherit`, it’s the best! But
332
- // it does not disallow invalid values at all in MSIE :-(
333
- // - `letter-spacing` and `word-spacing` accept
334
- // `<length> | normal | inherit`, and disallows everything else, like
335
- // `<percentage>`, `auto` and such, good enough.
336
- // - `word-spacing` is used since its shorter.
337
-
338
- // Disallow known keywords allowed as the `word-spacing` value
339
- if (value === 'inherit' || value === 'normal') {
340
- return false;
341
- }
342
-
343
- // Use the value in a stylesheet and check the parsed value. Invalid
344
- // input value results in empty parsed value.
345
- this._styleElement.firstChild.nodeValue = `#styleElement { word-spacing: ${value}; }`;
346
-
347
- if (!this._styleElement.sheet) {
348
- // Stylesheet is not ready, probably not attached to the document yet.
349
- return true;
350
- }
351
-
352
- // Safari 9 sets invalid CSS rules' value to `null`
353
- return ['', null].indexOf(this._styleElement.sheet.cssRules[0].style.getPropertyValue('word-spacing')) < 0;
354
- }
355
-
356
- /** @private */
357
- _responsiveStepsChanged(responsiveSteps, oldResponsiveSteps) {
358
- try {
359
- if (!Array.isArray(responsiveSteps)) {
360
- throw new Error('Invalid "responsiveSteps" type, an Array is required.');
361
- }
362
-
363
- if (responsiveSteps.length < 1) {
364
- throw new Error('Invalid empty "responsiveSteps" array, at least one item is required.');
365
- }
366
-
367
- responsiveSteps.forEach((step) => {
368
- if (this._naturalNumberOrOne(step.columns) !== step.columns) {
369
- throw new Error(`Invalid 'columns' value of ${step.columns}, a natural number is required.`);
370
- }
371
-
372
- if (step.minWidth !== undefined && !this._isValidCSSLength(step.minWidth)) {
373
- throw new Error(`Invalid 'minWidth' value of ${step.minWidth}, a valid CSS length required.`);
374
- }
375
-
376
- if (step.labelsPosition !== undefined && ['aside', 'top'].indexOf(step.labelsPosition) === -1) {
377
- throw new Error(
378
- `Invalid 'labelsPosition' value of ${step.labelsPosition}, 'aside' or 'top' string is required.`
379
- );
380
- }
381
- });
382
- } catch (e) {
383
- if (oldResponsiveSteps && oldResponsiveSteps !== responsiveSteps) {
384
- console.warn(`${e.message} Using previously set 'responsiveSteps' instead.`);
385
- this.responsiveSteps = oldResponsiveSteps;
386
- } else {
387
- console.warn(`${e.message} Using default 'responsiveSteps' instead.`);
388
- this.responsiveSteps = [
389
- { minWidth: 0, columns: 1, labelsPosition: 'top' },
390
- { minWidth: '20em', columns: 1 },
391
- { minWidth: '40em', columns: 2 }
392
- ];
393
- }
394
- }
395
-
396
- this._selectResponsiveStep();
397
- }
398
-
399
- /** @private */
400
- __onAnimationEnd(e) {
401
- if (e.animationName.indexOf('vaadin-form-layout-appear') === 0) {
402
- this._selectResponsiveStep();
403
- }
404
- }
405
-
406
- /** @private */
407
- _selectResponsiveStep() {
408
- // Iterate through responsiveSteps and choose the step
409
- let selectedStep;
410
- const tmpStyleProp = 'background-position';
411
- this.responsiveSteps.forEach((step) => {
412
- // Convert minWidth to px units for comparison
413
- this.$.layout.style.setProperty(tmpStyleProp, step.minWidth);
414
- const stepMinWidthPx = parseFloat(getComputedStyle(this.$.layout).getPropertyValue(tmpStyleProp));
415
-
416
- // Compare step min-width with the host width, select the passed step
417
- if (stepMinWidthPx <= this.offsetWidth) {
418
- selectedStep = step;
419
- }
420
- });
421
- this.$.layout.style.removeProperty(tmpStyleProp);
422
-
423
- // Sometimes converting units is not possible, e.g, when element is
424
- // not connected. Then the `selectedStep` stays `undefined`.
425
- if (selectedStep) {
426
- // Apply the chosen responsive step’s properties
427
- this._columnCount = selectedStep.columns;
428
- this._labelsOnTop = selectedStep.labelsPosition === 'top';
429
- }
430
- }
431
-
432
- /** @private */
433
- _invokeUpdateStyles() {
434
- this.updateStyles();
435
- }
436
-
437
- /**
438
- * Set custom CSS property values and update the layout.
439
- * @param {Object<string, string>=} properties
440
- * @protected
441
- */
442
- updateStyles(properties) {
443
- super.updateStyles(properties);
444
-
445
- /*
446
- The item width formula:
447
-
448
- itemWidth = colspan / columnCount * 100% - columnSpacing
449
-
450
- We have to subtract columnSpacing, because the column spacing space is taken
451
- by item margins of 1/2 * spacing on both sides
452
- */
453
-
454
- const style = getComputedStyle(this);
455
- const columnSpacing = style.getPropertyValue('--vaadin-form-layout-column-spacing');
456
-
457
- const direction = style.direction;
458
- const marginStartProp = 'margin-' + (direction === 'ltr' ? 'left' : 'right');
459
- const marginEndProp = 'margin-' + (direction === 'ltr' ? 'right' : 'left');
460
-
461
- const containerWidth = this.offsetWidth;
462
-
463
- let col = 0;
464
- Array.from(this.children)
465
- .filter((child) => child.localName === 'br' || getComputedStyle(child).display !== 'none')
466
- .forEach((child, index, children) => {
467
- if (child.localName === 'br') {
468
- // Reset column count on line break
469
- col = 0;
470
- return;
471
- }
472
-
473
- let colspan;
474
- colspan = this._naturalNumberOrOne(parseFloat(child.getAttribute('colspan')));
475
-
476
- // Never span further than the number of columns
477
- colspan = Math.min(colspan, this._columnCount);
478
-
479
- const childRatio = colspan / this._columnCount;
480
-
481
- // Note: using 99.9% for 100% fixes rounding errors in MS Edge
482
- // (< v16), otherwise the items might wrap, resizing is wobbly.
483
- child.style.width = `calc(${childRatio * 99.9}% - ${1 - childRatio} * ${columnSpacing})`;
484
-
485
- if (col + colspan > this._columnCount) {
486
- // Too big to fit on this row, let’s wrap it
487
- col = 0;
488
- }
489
-
490
- // At the start edge
491
- if (col === 0) {
492
- child.style.setProperty(marginStartProp, '0px');
493
- } else {
494
- child.style.removeProperty(marginStartProp);
495
- }
496
-
497
- const nextIndex = index + 1;
498
- const nextLineBreak = nextIndex < children.length && children[nextIndex].localName === 'br';
499
-
500
- // At the end edge
501
- if (col + colspan === this._columnCount) {
502
- child.style.setProperty(marginEndProp, '0px');
503
- } else if (nextLineBreak) {
504
- const colspanRatio = (this._columnCount - col - colspan) / this._columnCount;
505
- child.style.setProperty(
506
- marginEndProp,
507
- `calc(${colspanRatio * containerWidth}px + ${colspanRatio} * ${columnSpacing})`
508
- );
509
- } else {
510
- child.style.removeProperty(marginEndProp);
511
- }
512
-
513
- // Move the column counter
514
- col = (col + colspan) % this._columnCount;
515
-
516
- if (child.localName === 'vaadin-form-item') {
517
- if (this._labelsOnTop) {
518
- child.setAttribute('label-position', 'top');
519
- } else {
520
- child.removeAttribute('label-position');
521
- }
522
- }
523
- });
524
- }
525
- }
526
-
527
- customElements.define(FormLayoutElement.is, FormLayoutElement);
528
-
529
- export { FormLayoutElement };
13
+ export * from '@vaadin/form-layout/src/vaadin-form-layout.js';
@@ -1,2 +1 @@
1
- import './vaadin-form-item-styles.js';
2
- import '../../src/vaadin-form-item.js';
1
+ import '@vaadin/form-layout/theme/lumo/vaadin-form-item.js';
@@ -1,2 +1 @@
1
- import './vaadin-form-layout-styles.js';
2
- import '../../src/vaadin-form-layout.js';
1
+ import '@vaadin/form-layout/theme/lumo/vaadin-form-layout.js';
@@ -1,2 +1 @@
1
- import './vaadin-form-item-styles.js';
2
- import '../../src/vaadin-form-item.js';
1
+ import '@vaadin/form-layout/theme/material/vaadin-form-item.js';
@@ -1 +1 @@
1
- import '../../src/vaadin-form-layout.js';
1
+ import '@vaadin/form-layout/theme/material/vaadin-form-layout.js';
@@ -1,2 +1 @@
1
1
  export * from './src/vaadin-form-layout.js';
2
- export * from './src/interfaces';
@@ -1,7 +0,0 @@
1
- export type FormLayoutLabelsPosition = 'aside' | 'top';
2
-
3
- export type FormLayoutResponsiveStep = {
4
- minWidth?: string | 0;
5
- columns: number;
6
- labelsPosition?: FormLayoutLabelsPosition;
7
- };
@@ -1,28 +0,0 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import '@vaadin/vaadin-lumo-styles/color.js';
3
- import '@vaadin/vaadin-lumo-styles/spacing.js';
4
- import '@vaadin/vaadin-lumo-styles/style.js';
5
- import '@vaadin/vaadin-lumo-styles/typography.js';
6
-
7
- registerStyles(
8
- 'vaadin-form-item',
9
- css`
10
- :host {
11
- --vaadin-form-item-row-spacing: 0;
12
- }
13
-
14
- /* font-weight, margin-bottom, transition and line-height same as for part label in text-field */
15
- [part='label'] {
16
- color: var(--lumo-secondary-text-color);
17
- font-family: var(--lumo-font-family);
18
- font-size: var(--lumo-font-size-s);
19
- font-weight: 500;
20
- margin-top: var(--lumo-space-m);
21
- margin-left: calc(var(--lumo-border-radius-m) / 4);
22
- margin-bottom: var(--lumo-space-xs);
23
- transition: color 0.4s;
24
- line-height: 1.333;
25
- }
26
- `,
27
- { moduleId: 'lumo-form-item' }
28
- );
@@ -1,12 +0,0 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import '@vaadin/vaadin-lumo-styles/spacing.js';
3
-
4
- registerStyles(
5
- 'vaadin-form-layout',
6
- css`
7
- :host {
8
- --vaadin-form-layout-column-spacing: var(--lumo-space-l);
9
- }
10
- `,
11
- { moduleId: 'lumo-form-layout' }
12
- );
@@ -1,19 +0,0 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import '@vaadin/vaadin-material-styles/color.js';
3
- import '@vaadin/vaadin-material-styles/typography.js';
4
-
5
- registerStyles(
6
- 'vaadin-form-item',
7
- css`
8
- [part='label'] {
9
- font-family: var(--material-font-family);
10
- font-size: var(--material-small-font-size);
11
- color: var(--material-secondary-text-color);
12
- line-height: 16px;
13
- font-weight: 400;
14
- margin-top: 16px;
15
- margin-bottom: 8px;
16
- }
17
- `,
18
- { moduleId: 'material-form-item' }
19
- );