Skip to content

Commit f8a42dc

Browse files
authored
Merge pull request #920 from brianrourkeboll/deets-button
Add expand/collapse-all button for API doc details
2 parents 6bd2905 + 9d1364f commit f8a42dc

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed

docs/_template.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<script src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js"></script>
2323
<link href="{{root}}{{fsdocs-favicon-src}}" rel="icon" sizes="32x32" type="image/png"/>
2424
<script type="application/javascript" src="{{root}}content/fsdocs-theme-set-dark.js"></script>
25+
<script type="application/javascript" src="{{root}}content/fsdocs-details-set-expanded.js"></script>
2526
<link href="{{root}}content/fsdocs-default.css" rel="stylesheet" type="text/css"/>
2627
<link href="{{root}}content/fsdocs-theme.css" rel="stylesheet" type="text/css"/>
2728
{{fsdocs-head-extra}}
@@ -93,6 +94,7 @@
9394
</dialog>
9495
<script type="module" src="{{root}}content/fsdocs-tips.js"></script>
9596
<script type="module" src="{{root}}content/fsdocs-theme-toggle.js"></script>
97+
<script type="module" src="{{root}}content/fsdocs-details-toggle.js"></script>
9698
<script type="module" src="{{root}}content/fsdocs-theme.js"></script>
9799
<script type="module" src="{{root}}content/fsdocs-search.js"></script>
98100
{{fsdocs-body-extra}}

docs/content/fsdocs-default.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,13 @@ span[onmouseout] {
10001000
margin-top: 0;
10011001
}
10021002

1003+
.fsdocs-member-list-header {
1004+
display: flex;
1005+
flex-direction: row;
1006+
justify-content: space-between;
1007+
align-items: flex-start;
1008+
}
1009+
10031010
.fsdocs-xmldoc {
10041011
& pre {
10051012
overflow-x: auto;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const expandDetails = !!JSON.parse(localStorage.getItem('details-expanded'));
2+
3+
addEventListener('load', _ => {
4+
if (expandDetails) {
5+
for (const details of document.getElementsByTagName('details')) {
6+
details.setAttribute('open', 'true');
7+
}
8+
}
9+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
2+
3+
const detailsExpanded = !!JSON.parse(localStorage.getItem('details-expanded'));
4+
5+
export class DetailsToggle extends LitElement {
6+
static properties = {
7+
_detailsExpanded: { state: true, type: Boolean },
8+
};
9+
10+
constructor() {
11+
super();
12+
this._detailsExpanded = detailsExpanded;
13+
document.addEventListener('detailstoggled', e => this._detailsExpanded = !!e?.detail?.expanding);
14+
}
15+
16+
static styles = css`
17+
:host {
18+
cursor: pointer;
19+
}
20+
`;
21+
22+
toggleDetails() {
23+
this._detailsExpanded = !this._detailsExpanded;
24+
localStorage.setItem('details-expanded', JSON.stringify(this._detailsExpanded));
25+
if (this._detailsExpanded) {
26+
for (const details of document.getElementsByTagName('details')) {
27+
details.setAttribute('open', 'true');
28+
}
29+
} else {
30+
for (const details of document.getElementsByTagName('details')) {
31+
details.removeAttribute('open');
32+
}
33+
}
34+
document.dispatchEvent(new CustomEvent('detailstoggled', { detail: { expanding: this._detailsExpanded } }));
35+
}
36+
37+
render() {
38+
const icon = this._detailsExpanded ? 'carbon:collapse-categories' : 'carbon:expand-categories';
39+
const title = this._detailsExpanded ? 'Collapse details' : 'Expand details';
40+
return html`
41+
<iconify-icon width="24" height="24" icon="${icon}" title="${title}" style="color:var(--header-link-color)" @click=${this.toggleDetails}></iconify-icon>
42+
`;
43+
}
44+
}
45+
46+
customElements.define('fsdocs-details-toggle', DetailsToggle);

src/FSharp.Formatting.ApiDocs/GenerateHtml.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
109109
thead [] [
110110
tr [] [
111111
td [ Class "fsdocs-member-list-header" ] [ !!tableHeader ]
112-
td [ Class "fsdocs-member-list-header" ] [ !! "Description" ]
112+
td [ Class "fsdocs-member-list-header" ] [ !! "Description"; fsdocsDetailsToggle [] ]
113113
]
114114
]
115115
tbody [] [

src/FSharp.Formatting.Common/HtmlModel.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,7 @@ module internal Html =
750750
/// Web component from https://iconify.design/docs/
751751
let iconifyIcon (props: HtmlProperties list) =
752752
HtmlElement.CustomElement("iconify-icon", props, [])
753+
754+
/// Toggle button for API doc details.
755+
let fsdocsDetailsToggle (props: HtmlProperties list) =
756+
HtmlElement.CustomElement("fsdocs-details-toggle", props, [])

0 commit comments

Comments
 (0)