@@ -4,6 +4,7 @@ import { action } from "@ember/object";
44import didInsert from " @ember/render-modifiers/modifiers/did-insert" ;
55import didUpdate from " @ember/render-modifiers/modifiers/did-update" ;
66import { service } from " @ember/service" ;
7+ import DButton from " discourse/components/d-button" ;
78import { headerOffset } from " discourse/lib/offset-calculator" ;
89import { debounce } from " discourse-common/utils/decorators" ;
910import TocHeading from " ../components/toc-heading" ;
@@ -21,6 +22,7 @@ export default class TocContents extends Component {
2122 @tracked activeHeadingId = null ;
2223 @tracked headingPositions = [];
2324 @tracked activeAncestorIds = [];
25+ @tracked expandAll = false ;
2426
2527 willDestroy () {
2628 super .willDestroy (... arguments );
@@ -36,6 +38,10 @@ export default class TocContents extends Component {
3638 return this .mappedTocStructure (this .args .tocStructure );
3739 }
3840
41+ get expandLabel () {
42+ return this .expandAll ? " Reset expand" : " Expand all" ;
43+ }
44+
3945 @action
4046 setup () {
4147 this .listenForScroll ();
@@ -64,6 +70,11 @@ export default class TocContents extends Component {
6470 );
6571 }
6672
73+ @action
74+ toggleExpandAll () {
75+ this .expandAll = ! this .expandAll ;
76+ }
77+
6778 @debounce (RESIZE_DEBOUNCE )
6879 calculateHeadingPositions () {
6980 this .updateHeadingPositions ();
@@ -160,6 +171,12 @@ export default class TocContents extends Component {
160171 {{didInsert this . setup}}
161172 {{didUpdate this . updateHeadingPositions @ postID}}
162173 >
174+ <div class =" d-toc-top-buttons" >
175+ <DButton
176+ @ action ={{this .toggleExpandAll }}
177+ @ translatedLabel ={{this .expandLabel }}
178+ />
179+ </div >
163180
164181 {{#each @ tocStructure as | heading | }}
165182 <ul class =" d-toc-heading" >
@@ -168,6 +185,7 @@ export default class TocContents extends Component {
168185 @ activeHeadingId ={{this .activeHeadingId }}
169186 @ activeAncestorIds ={{this .activeAncestorIds }}
170187 @ renderTimeline ={{@ renderTimeline }}
188+ @ expandAll ={{this .expandAll }}
171189 />
172190 </ul >
173191 {{/each }}
0 commit comments