Skip to content

Commit 32646d1

Browse files
authored
experiment: add LitElement based version of vaadin-form-layout (#8343)
1 parent f8ee0ef commit 32646d1

19 files changed

+137
-8
lines changed

packages/form-layout/src/vaadin-form-layout-mixin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const FormLayoutMixin = (superClass) =>
7171
];
7272
},
7373
observer: '_responsiveStepsChanged',
74+
sync: true,
7475
},
7576

7677
/**
@@ -79,6 +80,7 @@ export const FormLayoutMixin = (superClass) =>
7980
*/
8081
_columnCount: {
8182
type: Number,
83+
sync: true,
8284
},
8385

8486
/**
@@ -87,6 +89,7 @@ export const FormLayoutMixin = (superClass) =>
8789
*/
8890
_labelsOnTop: {
8991
type: Boolean,
92+
sync: true,
9093
},
9194

9295
/** @private */
@@ -102,15 +105,12 @@ export const FormLayoutMixin = (superClass) =>
102105

103106
/** @protected */
104107
ready() {
105-
// Here we create and attach a style element that we use for validating
108+
// Here we attach a style element that we use for validating
106109
// CSS values in `responsiveSteps`. We can't add this to the `<template>`,
107110
// because Polymer will throw it away. We need to create this before
108111
// `super.ready()`, because `super.ready()` invokes property observers,
109112
// and the observer for `responsiveSteps` does CSS value validation.
110-
this._styleElement = document.createElement('style');
111113
this.appendChild(this._styleElement);
112-
// Ensure there is a child text node in the style element
113-
this._styleElement.textContent = ' ';
114114

115115
super.ready();
116116

@@ -120,6 +120,10 @@ export const FormLayoutMixin = (superClass) =>
120120
constructor() {
121121
super();
122122

123+
this._styleElement = document.createElement('style');
124+
// Ensure there is a child text node in the style element
125+
this._styleElement.textContent = ' ';
126+
123127
this.__intersectionObserver = new IntersectionObserver(([entry]) => {
124128
if (!entry.isIntersecting) {
125129
// Prevent possible jump when layout becomes visible
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2024 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
export * from './vaadin-form-item.js';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2024 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { html, LitElement } from 'lit';
7+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
9+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10+
import { FormItemMixin } from './vaadin-form-item-mixin.js';
11+
import { formItemStyles } from './vaadin-form-layout-styles.js';
12+
13+
/**
14+
* LitElement based version of `<vaadin-form-item>` web component.
15+
*
16+
* ## Disclaimer
17+
*
18+
* This component is an experiment and not yet a part of Vaadin platform.
19+
* There is no ETA regarding specific Vaadin version where it'll land.
20+
* Feel free to try this code in your apps as per Apache 2.0 license.
21+
*/
22+
class FormItem extends FormItemMixin(ThemableMixin(PolylitMixin(LitElement))) {
23+
static get is() {
24+
return 'vaadin-form-item';
25+
}
26+
27+
static get styles() {
28+
return formItemStyles;
29+
}
30+
31+
/** @protected */
32+
render() {
33+
return html`
34+
<div id="label" part="label" @click="${this.__onLabelClick}">
35+
<slot name="label" id="labelSlot" @slotchange="${this.__onLabelSlotChange}"></slot>
36+
<span part="required-indicator" aria-hidden="true"></span>
37+
</div>
38+
<div id="spacing"></div>
39+
<div id="content">
40+
<slot id="contentSlot" @slotchange="${this.__onContentSlotChange}"></slot>
41+
</div>
42+
`;
43+
}
44+
}
45+
46+
defineCustomElement(FormItem);
47+
48+
export { FormItem };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2024 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
export * from './vaadin-form-layout.js';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 2024 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { html, LitElement } from 'lit';
7+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8+
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11+
import { FormLayoutMixin } from './vaadin-form-layout-mixin.js';
12+
import { formLayoutStyles } from './vaadin-form-layout-styles.js';
13+
14+
/**
15+
* LitElement based version of `<vaadin-form-layout>` web component.
16+
*
17+
* ## Disclaimer
18+
*
19+
* This component is an experiment and not yet a part of Vaadin platform.
20+
* There is no ETA regarding specific Vaadin version where it'll land.
21+
* Feel free to try this code in your apps as per Apache 2.0 license.
22+
*/
23+
class FormLayout extends FormLayoutMixin(ThemableMixin(ElementMixin(PolylitMixin(LitElement)))) {
24+
static get is() {
25+
return 'vaadin-form-layout';
26+
}
27+
28+
static get styles() {
29+
return formLayoutStyles;
30+
}
31+
32+
/** @protected */
33+
render() {
34+
return html`
35+
<div id="layout">
36+
<slot id="slot"></slot>
37+
</div>
38+
`;
39+
}
40+
}
41+
42+
defineCustomElement(FormLayout);
43+
44+
export { FormLayout };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '../vaadin-lit-form-item.js';
2+
import './form-item.common.js';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '../vaadin-form-item.js';
2+
import './form-item.common.js';

packages/form-layout/test/form-item.test.js renamed to packages/form-layout/test/form-item.common.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import '@vaadin/custom-field';
55
import '@vaadin/text-field';
6-
import '../vaadin-form-item.js';
76

87
describe('form-item', () => {
98
let item, label, input;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import '@vaadin/text-field/vaadin-lit-text-field.js';
2+
import '../vaadin-lit-form-layout.js';
3+
import '../vaadin-lit-form-item.js';
4+
import './form-layout.common.js';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import '@vaadin/text-field/vaadin-text-field.js';
2+
import '../vaadin-form-layout.js';
3+
import '../vaadin-form-item.js';
4+
import './form-layout.common.js';

0 commit comments

Comments
 (0)