2024-01-31 10:22:06 -05:00
|
|
|
import Component from "@glimmer/component";
|
2024-03-27 16:08:48 +01:00
|
|
|
import { service } from "@ember/service";
|
2024-01-31 10:22:06 -05:00
|
|
|
import DButton from "discourse/components/d-button";
|
2025-02-06 17:00:07 +00:00
|
|
|
import { i18n } from "discourse-i18n";
|
2024-01-31 10:22:06 -05:00
|
|
|
|
|
|
|
|
export default class TocToggle extends Component {
|
|
|
|
|
@service tocProcessor;
|
|
|
|
|
|
|
|
|
|
get shouldShow() {
|
|
|
|
|
// docs and topics with 1 post don't need a toggle
|
|
|
|
|
if (this.tocProcessor.isDocs || this.args.topic?.posts_count === 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.tocProcessor.hasTOC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get toggleLabel() {
|
|
|
|
|
return this.tocProcessor.isTocVisible
|
|
|
|
|
? "toggle_toc.show_timeline"
|
|
|
|
|
: "toggle_toc.show_toc";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get toggleIcon() {
|
2024-12-09 05:12:39 +08:00
|
|
|
return this.tocProcessor.isTocVisible ? "timeline" : "bars-staggered";
|
2024-01-31 10:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
{{#if this.shouldShow}}
|
|
|
|
|
<DButton
|
|
|
|
|
@action={{this.tocProcessor.toggleTocVisibility}}
|
|
|
|
|
@icon={{this.toggleIcon}}
|
|
|
|
|
@translatedLabel={{i18n (themePrefix this.toggleLabel)}}
|
|
|
|
|
class="btn btn-default timeline-toggle"
|
|
|
|
|
/>
|
|
|
|
|
{{/if}}
|
|
|
|
|
</template>
|
|
|
|
|
}
|