Skip to content

Commit ea38118

Browse files
Add expand/collapse details button
1 parent 56b856b commit ea38118

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-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-description-heading {
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 => {
14+
this._detailsExpanded = !!e?.detail?.expanding;
15+
this.render();
16+
});
17+
}
18+
19+
static styles = css`
20+
:host {
21+
cursor: pointer;
22+
transform: translateY(3px);
23+
}
24+
`;
25+
26+
toggleDetails() {
27+
this._detailsExpanded = !this._detailsExpanded;
28+
localStorage.setItem('details-expanded', JSON.stringify(this._detailsExpanded));
29+
if (this._detailsExpanded) {
30+
for (const details of document.getElementsByTagName('details')) {
31+
details.setAttribute('open', 'true');
32+
}
33+
} else {
34+
for (const details of document.getElementsByTagName('details')) {
35+
details.removeAttribute('open');
36+
}
37+
}
38+
document.dispatchEvent(new CustomEvent('detailstoggled', { detail: { expanding: this._detailsExpanded } }));
39+
}
40+
41+
render() {
42+
const icon = this._detailsExpanded ? 'carbon:collapse-categories' : 'carbon:expand-categories';
43+
const title = this._detailsExpanded ? 'Collapse details' : 'Expand details';
44+
return html`
45+
<iconify-icon width="24" height="24" icon="${icon}" title="${title}" style="color:var(--header-link-color)" @click=${this.toggleDetails}></iconify-icon>
46+
`;
47+
}
48+
}
49+
50+
customElements.define('fsdocs-details-toggle', DetailsToggle);

src/FSharp.Formatting.ApiDocs/GenerateHtml.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ 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" ] [
113+
div [ Class "fsdocs-description-heading" ] [ !! "Description"; fsdocsDetailsToggle [] ]
114+
]
113115
]
114116
]
115117
tbody [] [

src/FSharp.Formatting.Common/HtmlModel.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,6 @@ 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+
let fsdocsDetailsToggle (props: HtmlProperties list) =
755+
HtmlElement.CustomElement("fsdocs-details-toggle", props, [])

0 commit comments

Comments
 (0)