-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic dashboard section structure
- Loading branch information
1 parent
f7051b0
commit 2be720f
Showing
16 changed files
with
422 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2000 - 2024 Vaadin Ltd. | ||
* | ||
* This program is available under Vaadin Commercial License and Service Terms. | ||
* | ||
* | ||
* See https://vaadin.com/commercial-license-and-service-terms for the full | ||
* license. | ||
*/ | ||
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js'; | ||
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; | ||
|
||
/** | ||
* A Section component for use with the Dashboard component | ||
*/ | ||
declare class DashboardSection extends ControllerMixin(ElementMixin(HTMLElement)) { | ||
/** | ||
* The title of the section | ||
*/ | ||
sectionTitle: string | null | undefined; | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'vaadin-dashboard-section': DashboardSection; | ||
} | ||
} | ||
|
||
export { DashboardSection }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2000 - 2024 Vaadin Ltd. | ||
* | ||
* This program is available under Vaadin Commercial License and Service Terms. | ||
* | ||
* | ||
* See https://vaadin.com/commercial-license-and-service-terms for the full | ||
* license. | ||
*/ | ||
import { html, LitElement } from 'lit'; | ||
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js'; | ||
import { defineCustomElement } from '@vaadin/component-base/src/define.js'; | ||
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; | ||
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js'; | ||
import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; | ||
import { TitleController } from './title-controller.js'; | ||
|
||
/** | ||
* A section component for use with the Dashboard component | ||
* | ||
* @customElement | ||
* @extends HTMLElement | ||
* @mixes ElementMixin | ||
* @mixes ControllerMixin | ||
*/ | ||
class DashboardSection extends ControllerMixin(ElementMixin(PolylitMixin(LitElement))) { | ||
static get is() { | ||
return 'vaadin-dashboard-section'; | ||
} | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
display: grid; | ||
grid-template-columns: subgrid; | ||
grid-column: 1 / -1 !important; | ||
gap: var(--vaadin-dashboard-gap, 1rem); | ||
} | ||
:host([hidden]) { | ||
display: none !important; | ||
} | ||
header { | ||
display: flex; | ||
grid-column: 1 / -1; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
`; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
/** | ||
* The title of the section | ||
*/ | ||
sectionTitle: { | ||
type: String, | ||
value: '', | ||
observer: '__onsectionTitleChanged', | ||
}, | ||
}; | ||
} | ||
|
||
/** @protected */ | ||
render() { | ||
return html` | ||
<header> | ||
<slot name="title" @slotchange="${this.__onTitleSlotChange}"></slot> | ||
<slot name="header"></slot> | ||
<div id="header-actions"></div> | ||
</header> | ||
<slot></slot> | ||
`; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.__titleController = new TitleController(this); | ||
this.__titleController.addEventListener('slot-content-changed', (event) => { | ||
const { node } = event.target; | ||
if (node) { | ||
this.setAttribute('aria-labelledby', node.id); | ||
} | ||
}); | ||
} | ||
|
||
/** @protected */ | ||
ready() { | ||
super.ready(); | ||
this.addController(this.__titleController); | ||
|
||
if (!this.hasAttribute('role')) { | ||
this.setAttribute('role', 'section'); | ||
} | ||
} | ||
|
||
/** @private */ | ||
__onsectionTitleChanged(sectionTitle) { | ||
this.__titleController.setTitle(sectionTitle); | ||
} | ||
} | ||
|
||
defineCustomElement(DashboardSection); | ||
|
||
export { DashboardSection }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.