Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add layout improvements behind feature flag #8552

Merged
merged 13 commits into from
Jan 31, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/
import type { CSSResult } from 'lit';

export const horizontalLayoutStyles: CSSResult;
export const horizontalLayoutStyles: CSSResult[];
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';

export const horizontalLayoutStyles = css`
export const baseStyles = css`
:host {
display: flex;
box-sizing: border-box;
Expand All @@ -28,3 +28,21 @@
gap: 1em;
}
`;

// Layout improvements are part of a feature for Flow users where children that have been configured to use full size
// using `HasSize.setSizeFull()` and others, get additional styles so that they effectively take the remaining space in
// the layout, rather than explicitly use 100% width/height. The respective data attributes are set by Flow's `HasSize`
// class.
const enableLayoutImprovements = window.Vaadin.featureFlags.layoutImprovements;
const layoutImprovementStyles = css`
::slotted([data-width-full]) {
flex: 1;
}

::slotted(vaadin-horizontal-layout[data-width-full]),
::slotted(vaadin-vertical-layout[data-width-full]) {
min-width: 0;
}

Check failure on line 45 in packages/horizontal-layout/src/vaadin-horizontal-layout-styles.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `·`
`;

export const horizontalLayoutStyles = enableLayoutImprovements ? [baseStyles, layoutImprovementStyles] : [baseStyles];
3 changes: 3 additions & 0 deletions packages/horizontal-layout/test/enable-layout-improvements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.Vaadin ??= {};
window.Vaadin.featureFlags ??= {};
window.Vaadin.featureFlags.layoutImprovements = true;
48 changes: 48 additions & 0 deletions packages/horizontal-layout/test/horizontal-layout.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,52 @@ describe('vaadin-horizontal-layout', () => {
expect(wrapper.scrollWidth).to.equal(200);
});
});

describe('layout improvements disabled', () => {
let layout, children;

describe('flex', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-horizontal-layout>
<div></div>
<div data-width-full></div>
</vaadin-horizontal-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should not set flex on any children', () => {
children.forEach((child) => {
expect(getComputedStyle(child).flex).to.equal('0 1 auto');
});
});
});

describe('min-width', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-horizontal-layout>
<div></div>
<div data-width-full></div>
<vaadin-button></vaadin-button>
<vaadin-button data-width-full></vaadin-button>
<vaadin-horizontal-layout></vaadin-horizontal-layout>
<vaadin-horizontal-layout data-width-full></vaadin-horizontal-layout>
<vaadin-vertical-layout></vaadin-vertical-layout>
<vaadin-vertical-layout data-width-full></vaadin-vertical-layout>
</vaadin-horizontal-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should not set min-width on any children', () => {
children.forEach((child) => {
expect(getComputedStyle(child).minWidth).to.equal('auto');
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './enable-layout-improvements.js';
import '../vaadin-lit-horizontal-layout.js';
import './layout-improvements.common.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './enable-layout-improvements.js';
import '../vaadin-horizontal-layout.js';
import './layout-improvements.common.js';
65 changes: 65 additions & 0 deletions packages/horizontal-layout/test/layout-improvements.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';

describe('layout improvements enabled', () => {
let layout, children;

describe('flex', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-horizontal-layout>
<div></div>
<div data-width-full></div>
</vaadin-horizontal-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should set flex on full width children only', () => {
const fullWidthChildren = children.filter((child) => child.hasAttribute('data-width-full'));
const remainingChildren = children.filter((child) => !fullWidthChildren.includes(child));

fullWidthChildren.forEach((child) => {
expect(getComputedStyle(child).flex).to.equal('1 1 0%');
});
remainingChildren.forEach((child) => {
expect(getComputedStyle(child).flex).to.equal('0 1 auto');
});
});
});

describe('min-width', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-horizontal-layout>
<div></div>
<div data-width-full></div>
<vaadin-button></vaadin-button>
<vaadin-button data-width-full></vaadin-button>
<vaadin-horizontal-layout></vaadin-horizontal-layout>
<vaadin-horizontal-layout data-width-full></vaadin-horizontal-layout>
<vaadin-vertical-layout></vaadin-vertical-layout>
<vaadin-vertical-layout data-width-full></vaadin-vertical-layout>
</vaadin-horizontal-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should set min-width on layout components with full width only', () => {
const layoutChildren = children.filter(
(child) => child.localName.endsWith('layout') && child.hasAttribute('data-width-full'),
);
const remainingChildren = children.filter((child) => !layoutChildren.includes(child));

layoutChildren.forEach((child) => {
expect(getComputedStyle(child).minWidth).to.equal('0px');
});

remainingChildren.forEach((child) => {
expect(getComputedStyle(child).minWidth).to.equal('auto');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/
import type { CSSResult } from 'lit';

export const verticalLayoutStyles: CSSResult;
export const verticalLayoutStyles: CSSResult[];
21 changes: 20 additions & 1 deletion packages/vertical-layout/src/vaadin-vertical-layout-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';

export const verticalLayoutStyles = css`
export const baseStyles = css`
:host {
display: flex;
flex-direction: column;
Expand All @@ -18,6 +18,7 @@ export const verticalLayoutStyles = css`
}

/* Theme variations */

web-padawan marked this conversation as resolved.
Show resolved Hide resolved
:host([theme~='margin']) {
margin: 1em;
}
Expand All @@ -30,3 +31,21 @@ export const verticalLayoutStyles = css`
gap: 1em;
}
`;

// Layout improvements are part of a feature for Flow users where children that have been configured to use full size
// using `HasSize.setSizeFull()` and others, get additional styles so that they effectively take the remaining space in
// the layout, rather than explicitly use 100% width/height. The respective data attributes are set by Flow's `HasSize`
// class.
const enableLayoutImprovements = window.Vaadin.featureFlags.layoutImprovements;
const layoutImprovementStyles = css`
::slotted([data-height-full]) {
flex: 1;
}

::slotted(vaadin-horizontal-layout[data-height-full]),
::slotted(vaadin-vertical-layout[data-height-full]) {
min-height: 0;
}
`;

export const verticalLayoutStyles = enableLayoutImprovements ? [baseStyles, layoutImprovementStyles] : [baseStyles];
3 changes: 3 additions & 0 deletions packages/vertical-layout/test/enable-layout-improvements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.Vaadin ??= {};
window.Vaadin.featureFlags ??= {};
window.Vaadin.featureFlags.layoutImprovements = true;
3 changes: 3 additions & 0 deletions packages/vertical-layout/test/layout-improvements-lit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './enable-layout-improvements.js';
import '../vaadin-lit-vertical-layout.js';
import './layout-improvements.common.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './enable-layout-improvements.js';
import '../vaadin-vertical-layout.js';
import './layout-improvements.common.js';
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved
65 changes: 65 additions & 0 deletions packages/vertical-layout/test/layout-improvements.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';

describe('layout improvements enabled', () => {
let layout, children;

describe('flex', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-vertical-layout>
<div></div>
<div data-height-full></div>
</vaadin-vertical-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should set flex on full height children only', () => {
const fullHeightChildren = children.filter((child) => child.hasAttribute('data-height-full'));
const remainingChildren = children.filter((child) => !fullHeightChildren.includes(child));

fullHeightChildren.forEach((child) => {
expect(getComputedStyle(child).flex).to.equal('1 1 0%');
});
remainingChildren.forEach((child) => {
expect(getComputedStyle(child).flex).to.equal('0 1 auto');
});
});
});

describe('min-height', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-vertical-layout>
<div></div>
<div data-height-full></div>
<vaadin-button></vaadin-button>
<vaadin-button data-height-full></vaadin-button>
<vaadin-horizontal-layout></vaadin-horizontal-layout>
<vaadin-horizontal-layout data-height-full></vaadin-horizontal-layout>
<vaadin-vertical-layout></vaadin-vertical-layout>
<vaadin-vertical-layout data-height-full></vaadin-vertical-layout>
</vaadin-vertical-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should set min-height on layout components with full height only', () => {
const layoutChildren = children.filter(
(child) => child.localName.endsWith('layout') && child.hasAttribute('data-height-full'),
);
const remainingChildren = children.filter((child) => !layoutChildren.includes(child));

layoutChildren.forEach((child) => {
expect(getComputedStyle(child).minHeight).to.equal('0px');
});

remainingChildren.forEach((child) => {
expect(getComputedStyle(child).minHeight).to.equal('auto');
});
});
});
});
48 changes: 48 additions & 0 deletions packages/vertical-layout/test/vertical-layout.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,52 @@ describe('vaadin-vertical-layout', () => {
expect(wrapper.scrollHeight).to.equal(200);
});
});

describe('layout improvements disabled', () => {
let layout, children;

describe('flex', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-vertical-layout>
<div></div>
<div data-height-full></div>
</vaadin-vertical-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should not set flex on any children', () => {
children.forEach((child) => {
expect(getComputedStyle(child).flex).to.equal('0 1 auto');
});
});
});

describe('min-height', () => {
beforeEach(async () => {
layout = fixtureSync(`
<vaadin-vertical-layout>
<div></div>
<div data-height-full></div>
<vaadin-button></vaadin-button>
<vaadin-button data-height-full></vaadin-button>
<vaadin-horizontal-layout></vaadin-horizontal-layout>
<vaadin-horizontal-layout data-height-full></vaadin-horizontal-layout>
<vaadin-vertical-layout></vaadin-vertical-layout>
<vaadin-vertical-layout data-height-full></vaadin-vertical-layout>
</vaadin-vertical-layout>
`);
children = Array.from(layout.children);
await nextFrame();
});

it('should not set min-height on any children', () => {
children.forEach((child) => {
expect(getComputedStyle(child).minHeight).to.equal('auto');
});
});
});
});
});
Loading