Skip to content

Commit

Permalink
feat: add dashboard dense mode (#7881)
Browse files Browse the repository at this point in the history
* feat: add dense mode

* refactor: remove dense property from dashboard and layout

* fix: make dashboard layout extend layout mixin

* chore: add js suffix to import
  • Loading branch information
ugur-vaadin authored Sep 30, 2024
1 parent eb138b7 commit c801860
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/dashboard/src/vaadin-dashboard-layout-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ export declare function DashboardLayoutMixin<T extends Constructor<HTMLElement>>
base: T,
): Constructor<DashboardLayoutMixinClass> & Constructor<ResizeMixinClass> & T;

export declare class DashboardLayoutMixinClass {}
export declare class DashboardLayoutMixinClass {
/**
* Whether the dashboard layout is dense.
*/
dense: boolean;
}
18 changes: 18 additions & 0 deletions packages/dashboard/src/vaadin-dashboard-layout-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const DashboardLayoutMixin = (superClass) =>
display: none !important;
}
:host([dense]) #grid {
grid-auto-flow: dense;
}
#grid {
box-sizing: border-box;
padding: 20px;
Expand Down Expand Up @@ -91,6 +95,20 @@ export const DashboardLayoutMixin = (superClass) =>
`;
}

static get properties() {
return {
/**
* Whether the dashboard layout is dense.
* @type {boolean}
*/
dense: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
};
}

/** @protected */
ready() {
super.ready();
Expand Down
3 changes: 2 additions & 1 deletion packages/dashboard/src/vaadin-dashboard-layout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
*/
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { DashboardLayoutMixin } from './vaadin-dashboard-layout-mixin.js';

/**
* A responsive, grid-based dashboard layout component
*/
declare class DashboardLayout extends ElementMixin(ThemableMixin(HTMLElement)) {}
declare class DashboardLayout extends DashboardLayoutMixin(ElementMixin(ThemableMixin(HTMLElement))) {}

declare global {
interface HTMLElementTagNameMap {
Expand Down
29 changes: 29 additions & 0 deletions packages/dashboard/test/dashboard-layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,33 @@ describe('dashboard layout', () => {
});
});
});

describe('dense', () => {
beforeEach(async () => {
dashboard.appendChild(fixtureSync('<div id="2">Item 2</div>'));
childElements = [...dashboard.querySelectorAll('div')];
setColspan(childElements[1], 2);
dashboard.dense = true;
await nextFrame();
});

it('should display the items in dense mode', () => {
/* prettier-ignore */
expectLayout(dashboard, [
[0, 2],
[1, 1],
]);
});

it('should retain the order of items', async () => {
dashboard.dense = false;
await nextFrame();
/* prettier-ignore */
expectLayout(dashboard, [
[0],
[1, 1],
[2],
]);
});
});
});
2 changes: 2 additions & 0 deletions packages/dashboard/test/typings/dashboard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ assertType<ElementMixinClass>(genericDashboard);
assertType<DashboardLayoutMixinClass>(genericDashboard);
assertType<Array<DashboardItem | DashboardSectionItem<DashboardItem>> | null | undefined>(genericDashboard.items);
assertType<boolean>(genericDashboard.editable);
assertType<boolean>(genericDashboard.dense);

assertType<{
selectWidget: string;
Expand Down Expand Up @@ -112,6 +113,7 @@ narrowedDashboard.addEventListener('dashboard-item-resize-mode-changed', (event)
/* DashboardLayout */
const layout = document.createElement('vaadin-dashboard-layout');
assertType<DashboardLayout>(layout);
assertType<boolean>(layout.dense);

assertType<ElementMixinClass>(layout);
assertType<DashboardLayoutMixinClass>(layout);
Expand Down

0 comments on commit c801860

Please sign in to comment.