-
Notifications
You must be signed in to change notification settings - Fork 83
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: dashboard widget move mode #7817
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @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 type { Constructor } from '@open-wc/dedupe-mixin'; | ||
|
||
/** | ||
* Shared functionality between widgets and sections | ||
*/ | ||
export declare function DashboardItemMixin<T extends Constructor<HTMLElement>>( | ||
base: T, | ||
): Constructor<DashboardItemMixinClass> & T; | ||
|
||
export declare class DashboardItemMixinClass {} |
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,159 @@ | ||
/** | ||
* @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 } from 'lit'; | ||
import { FocusTrapController } from '@vaadin/a11y-base/src/focus-trap-controller.js'; | ||
import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js'; | ||
import { KeyboardController } from './keyboard-controller.js'; | ||
import { fireMove, fireRemove } from './vaadin-dashboard-helpers.js'; | ||
import { dashboardWidgetAndSectionStyles } from './vaadin-dashboard-styles.js'; | ||
|
||
/** | ||
* Shared functionality between widgets and sections | ||
* | ||
* @polymerMixin | ||
* @mixes ResizeMixin | ||
*/ | ||
export const DashboardItemMixin = (superClass) => | ||
class DashboardItemMixinClass extends ResizeMixin(superClass) { | ||
static get styles() { | ||
return dashboardWidgetAndSectionStyles; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
/** @private */ | ||
__selected: { | ||
type: Boolean, | ||
reflectToAttribute: true, | ||
attribute: 'selected', | ||
observer: '__selectedChanged', | ||
}, | ||
|
||
/** @private */ | ||
__focused: { | ||
type: Boolean, | ||
reflectToAttribute: true, | ||
attribute: 'focused', | ||
}, | ||
|
||
/** @private */ | ||
__moveMode: { | ||
type: Boolean, | ||
reflectToAttribute: true, | ||
attribute: 'move-mode', | ||
}, | ||
}; | ||
} | ||
|
||
/** @private */ | ||
__renderDragHandle() { | ||
return html`<button | ||
id="drag-handle" | ||
draggable="true" | ||
class="drag-handle" | ||
tabindex="${this.__selected ? 0 : -1}" | ||
@click="${() => this.__enterMoveMode()}" | ||
></button>`; | ||
} | ||
|
||
/** @private */ | ||
__renderRemoveButton() { | ||
return html`<button | ||
id="remove-button" | ||
tabindex="${this.__selected ? 0 : -1}" | ||
@click="${() => fireRemove(this)}" | ||
></button>`; | ||
} | ||
|
||
/** @private */ | ||
__renderFocusButton() { | ||
return html`<button | ||
aria-label="Select Title for editing" | ||
id="focus-button" | ||
draggable="true" | ||
class="drag-handle" | ||
@click="${() => { | ||
this.__selected = true; | ||
}}" | ||
></button>`; | ||
} | ||
|
||
/** @private */ | ||
__renderModeControls() { | ||
return html`<div | ||
id="move-controls" | ||
class="mode-controls" | ||
.hidden="${!this.__moveMode}" | ||
@pointerdown="${(e) => e.preventDefault()}" | ||
> | ||
<button title="Move backward" @click="${() => fireMove(this, -1)}" id="move-backward"></button> | ||
<button title="Apply" @click="${() => this.__exitMode(true)}" id="move-apply"></button> | ||
<button title="Move forward" @click="${() => fireMove(this, 1)}" id="move-forward"></button> | ||
</div>`; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.__keyboardController = new KeyboardController(this); | ||
this.__focusTrapController = new FocusTrapController(this); | ||
} | ||
|
||
/** @protected */ | ||
ready() { | ||
super.ready(); | ||
this.addController(this.__keyboardController); | ||
this.addController(this.__focusTrapController); | ||
} | ||
|
||
/** @private */ | ||
__selectedChanged(selected) { | ||
if (selected) { | ||
this.__focusTrapController.trapFocus(this.$.focustrap); | ||
} else { | ||
this.__focusTrapController.releaseFocus(); | ||
} | ||
} | ||
|
||
focus() { | ||
if (this.hasAttribute('editable')) { | ||
this.$['focus-button'].focus(); | ||
} else { | ||
super.focus(); | ||
} | ||
} | ||
|
||
/** @private */ | ||
__exitMode(focus) { | ||
if (this.__moveMode) { | ||
this.__moveMode = false; | ||
if (focus) { | ||
this.$['drag-handle'].focus(); | ||
this.__focusTrapController.trapFocus(this.$.focustrap); | ||
} | ||
} | ||
} | ||
|
||
/** @private */ | ||
__focusApply() { | ||
if (this.__moveMode) { | ||
this.$['move-apply'].focus(); | ||
} | ||
} | ||
|
||
/** @private */ | ||
__enterMoveMode() { | ||
this.__selected = true; | ||
yuriy-fix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.__moveMode = true; | ||
requestAnimationFrame(() => { | ||
this.__focusTrapController.trapFocus(this.$['move-controls']); | ||
}); | ||
} | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since widget/section started to have too much of the same exact logic, decided to extract common logic / parts of the html template to a shared mixin