-
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.
Merge pull request #920 from brianrourkeboll/deets-button
Add expand/collapse-all button for API doc details
- Loading branch information
Showing
6 changed files
with
69 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,46 @@ | ||
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); | ||
} | ||
|
||
static styles = css` | ||
:host { | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
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