-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56b856b
commit ea38118
Showing
6 changed files
with
74 additions
and
1 deletion.
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,9 @@ | ||
const expandDetails = !!JSON.parse(localStorage.getItem('details-expanded')); | ||
|
||
addEventListener('load', _ => { | ||
if (expandDetails) { | ||
for (const details of document.getElementsByTagName('details')) { | ||
details.setAttribute('open', 'true'); | ||
} | ||
} | ||
}); |
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,50 @@ | ||
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js'; | ||
|
||
const detailsExpanded = !!JSON.parse(localStorage.getItem('details-expanded')); | ||
|
||
export class DetailsToggle extends LitElement { | ||
static properties = { | ||
_detailsExpanded: { state: true, type: Boolean }, | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this._detailsExpanded = detailsExpanded; | ||
document.addEventListener('detailstoggled', e => { | ||
this._detailsExpanded = !!e?.detail?.expanding; | ||
this.render(); | ||
}); | ||
} | ||
|
||
static styles = css` | ||
:host { | ||
cursor: pointer; | ||
transform: translateY(3px); | ||
} | ||
`; | ||
|
||
toggleDetails() { | ||
this._detailsExpanded = !this._detailsExpanded; | ||
localStorage.setItem('details-expanded', JSON.stringify(this._detailsExpanded)); | ||
if (this._detailsExpanded) { | ||
for (const details of document.getElementsByTagName('details')) { | ||
details.setAttribute('open', 'true'); | ||
} | ||
} else { | ||
for (const details of document.getElementsByTagName('details')) { | ||
details.removeAttribute('open'); | ||
} | ||
} | ||
document.dispatchEvent(new CustomEvent('detailstoggled', { detail: { expanding: this._detailsExpanded } })); | ||
} | ||
|
||
render() { | ||
const icon = this._detailsExpanded ? 'carbon:collapse-categories' : 'carbon:expand-categories'; | ||
const title = this._detailsExpanded ? 'Collapse details' : 'Expand details'; | ||
return html` | ||
<iconify-icon width="24" height="24" icon="${icon}" title="${title}" style="color:var(--header-link-color)" @click=${this.toggleDetails}></iconify-icon> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('fsdocs-details-toggle', DetailsToggle); |
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