-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add toggle pane button for theme editor file navigation
Introduces a new `TogglePaneButton` component, aimed at displaying a virtual file system in order to edit the multiple `scss` files found in the pillarbox default theme. When a file in the tree view is selected, its content is loaded into the theme editor for modification and previewing. ***Example*** ```html <toggle-pane-button label="Display a message"> <span>Hello World!</span> </toggle-pane-button> ``
- Loading branch information
Showing
14 changed files
with
303 additions
and
37 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
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,95 @@ | ||
import { html, LitElement, unsafeCSS } from 'lit'; | ||
import togglePaneButtonStyle from './toggle-pane-button.scss?inline'; | ||
|
||
/** | ||
* A LitElement component that creates a toggle button to show or hides a popup pane. | ||
* It changes its state when clicked, and can display custom content within a popup. | ||
* | ||
* @element toggle-pane-button | ||
* | ||
* @property {String} title - The title of the button, shown as a tooltip. | ||
* @property {String} label - The visible label of the button. | ||
* @property {Boolean} opened - Indicates whether the popup is currently visible. Reflects to attribute. | ||
* | ||
* @attribute {Boolean} opened - Reflects the `opened` property to an attribute. Determines the visibility of the popup. | ||
* | ||
* @slot - Default slot for the content of the popup. | ||
* | ||
* @part button - The button element that can be styled independently. | ||
* @part popup - The popup element that appears or hides based on the `opened` state. | ||
* | ||
* @cssproperty [--button-background=#40729d] - The background color of the button. | ||
* @cssproperty [--button-hover-background=#305273] - The background color of the button on hover. | ||
* @cssproperty [--button-color=#fff] - The text color of the button. | ||
* @cssproperty [--popup-background=#333] - The background color of the popup element. | ||
* @cssproperty [--popup-border=1px solid #666] - The border style for the popup element. | ||
* @cssproperty [--popup-border-radius=0.5em] - The border radius of the popup element. | ||
* @cssproperty [--popup-z-index=1] - The z-index of the popup element, controlling its stack order. | ||
* | ||
* @example | ||
* <toggle-pane-button label="Display a message"> | ||
* <span>Hello World!</span> | ||
* </toggle-pane-button> | ||
*/ | ||
class TogglePaneButton extends LitElement { | ||
/** | ||
* A private method to close the popup. | ||
* @type {Function} | ||
* @private | ||
*/ | ||
#closePopup = () => { this.opened = false; }; | ||
|
||
static styles = unsafeCSS(togglePaneButtonStyle); | ||
|
||
static properties = { | ||
opened: { type: Boolean, reflect: true }, | ||
title: { type: String }, | ||
label: { type: String } | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this.opened = false; | ||
} | ||
|
||
render() { | ||
return html` | ||
<button part="button" | ||
@click="${() => { this.opened = !this.opened; }}" | ||
title="${this.title}"> | ||
${this.label} | ||
</button> | ||
<div part="popup"> | ||
<slot></slot> | ||
</div> | ||
`; | ||
} | ||
|
||
updated(_changedProperties) { | ||
super.updated(_changedProperties); | ||
|
||
if (_changedProperties.has('opened')) { | ||
this.#togglePopup(); | ||
} | ||
} | ||
|
||
#togglePopup() { | ||
if (this.opened) { | ||
document.addEventListener('click', this.#closePopup, { once: true }); | ||
} else { | ||
document.removeEventListener('click', this.#closePopup); | ||
} | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this.addEventListener('click', e => e.stopPropagation()); | ||
} | ||
|
||
disconnectedCallback() { | ||
super.disconnectedCallback(); | ||
document.removeEventListener('click', this.#closePopup); | ||
} | ||
} | ||
|
||
customElements.define('toggle-pane-button', TogglePaneButton); |
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,57 @@ | ||
:host { | ||
--button-background: #40729d; | ||
--button-hover-background: #305273; | ||
--button-color: #fff; | ||
--button-border-radius: 0.5em; | ||
--popup-background: #333; | ||
--popup-border: 1px solid #666; | ||
--popup-border-radius: 0.5em; | ||
--popup-z-index: 1; | ||
} | ||
|
||
[part="button"] { | ||
position: relative; /* Needed for the chevron */ | ||
padding: 1em; | ||
color: var(--button-foreground); | ||
background: var(--button-background); | ||
border: none; | ||
border-radius: var(--button-border-radius); | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; /* Smooth transition for hover effect */ | ||
} | ||
|
||
[part="button"]::after { | ||
display: inline-block; | ||
width: 0.3em; | ||
height: 0.3em; | ||
border-right: 2px solid currentcolor; | ||
border-bottom: 2px solid currentcolor; | ||
transform: translate(50%, -50%) rotate(45deg); | ||
transition: transform 0.3s ease; | ||
content: ""; | ||
margin-inline: 0.5em; | ||
} | ||
|
||
[part="button"]:hover { | ||
background-color: var(--button-hover-background); | ||
} | ||
|
||
[part="popup"] { | ||
position: absolute; | ||
z-index: var(--popup-z-index); | ||
display: none; | ||
margin-top: 5px; | ||
padding: 0.7em; | ||
background: var(--popup-background); | ||
border: var(--popup-border); | ||
border-radius: var(--popup-border-radius); | ||
box-shadow: 0 2px 5px rgb(0 0 0 / 20%); | ||
} | ||
|
||
:host([opened]) [part="popup"] { | ||
display: block; | ||
} | ||
|
||
:host([opened]) [part="button"]::after { | ||
transform: translate(50%, -50%) rotate(225deg); | ||
} |
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.