1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Allow users to overwrite TOC default icons (#6913)

* Allow users to overwrite TOC default icons

* Fix docs as requested
This commit is contained in:
Mario Pietsch 2022-11-14 23:04:30 +01:00 committed by GitHub
parent 5e116d2a57
commit ea3503e30c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 10 deletions

View File

@ -1,6 +1,10 @@
title: $:/core/macros/toc title: $:/core/macros/toc
tags: $:/tags/Macro tags: $:/tags/Macro
\define toc-open-icon() $:/core/images/down-arrow
\define toc-closed-icon() $:/core/images/right-arrow
\define toc-caption() \define toc-caption()
\whitespace trim \whitespace trim
<span class="tc-toc-caption tc-tiny-gap-left"> <span class="tc-toc-caption tc-tiny-gap-left">
@ -45,12 +49,12 @@ tags: $:/tags/Macro
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}> <$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<$reveal type="nomatch" stateTitle=<<toc-state>> text="open"> <$reveal type="nomatch" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/right-arrow}} <$transclude tiddler=<<toc-closed-icon>> />
</$button> </$button>
</$reveal> </$reveal>
<$reveal type="match" stateTitle=<<toc-state>> text="open"> <$reveal type="match" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/down-arrow}} <$transclude tiddler=<<toc-open-icon>> />
</$button> </$button>
</$reveal> </$reveal>
<<toc-caption>> <<toc-caption>>
@ -71,13 +75,13 @@ tags: $:/tags/Macro
<li class=<<toc-item-class>>> <li class=<<toc-item-class>>>
<$reveal type="nomatch" stateTitle=<<toc-state>> text="open"> <$reveal type="nomatch" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/right-arrow}} <$transclude tiddler=<<toc-closed-icon>> />
<<toc-caption>> <<toc-caption>>
</$button> </$button>
</$reveal> </$reveal>
<$reveal type="match" stateTitle=<<toc-state>> text="open"> <$reveal type="match" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/down-arrow}} <$transclude tiddler=<<toc-open-icon>> />
<<toc-caption>> <<toc-caption>>
</$button> </$button>
</$reveal> </$reveal>
@ -117,12 +121,12 @@ tags: $:/tags/Macro
<$list filter="[all[current]tagging[]$sort$limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button>"> <$list filter="[all[current]tagging[]$sort$limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button>">
<$reveal type="nomatch" stateTitle=<<toc-state>> text="open"> <$reveal type="nomatch" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/right-arrow}} <$transclude tiddler=<<toc-closed-icon>> />
</$button> </$button>
</$reveal> </$reveal>
<$reveal type="match" stateTitle=<<toc-state>> text="open"> <$reveal type="match" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/down-arrow}} <$transclude tiddler=<<toc-open-icon>> />
</$button> </$button>
</$reveal> </$reveal>
</$list> </$list>
@ -144,13 +148,13 @@ tags: $:/tags/Macro
<$list filter="[all[current]tagging[]$sort$limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button> <$view field='caption'><$view field='title'/></$view>"> <$list filter="[all[current]tagging[]$sort$limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button> <$view field='caption'><$view field='title'/></$view>">
<$reveal type="nomatch" stateTitle=<<toc-state>> text="open"> <$reveal type="nomatch" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/right-arrow}} <$transclude tiddler=<<toc-closed-icon>> />
<<toc-caption>> <<toc-caption>>
</$button> </$button>
</$reveal> </$reveal>
<$reveal type="match" stateTitle=<<toc-state>> text="open"> <$reveal type="match" stateTitle=<<toc-state>> text="open">
<$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep"> <$button setTitle=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
{{$:/core/images/down-arrow}} <$transclude tiddler=<<toc-open-icon>> />
<<toc-caption>> <<toc-caption>>
</$button> </$button>
</$reveal> </$reveal>

View File

@ -0,0 +1,16 @@
caption: Selective (custom icons)
created: 20220819080004663
modified: 20220819081049054
order: 5
tags: table-of-contents-example
title: Example Table of Contents: Selectively Expandable (custom icons)
type: text/vnd.tiddlywiki
<<.from-version "5.2.4">> It is possible to define the `toc-open-icon` and `toc-closed-icon` variable, to change the icons used by the toc macros. This setting works for all toc-macro variants
<$macrocall $name=".example" n="1"
eg="""<$let toc-open-icon="$:/core/images/fold-button" toc-closed-icon="$:/core/images/folder">
<div class="tc-table-of-contents">
<<toc-selective-expandable "Contents">>
</div>
</$let>"""/>

View File

@ -1,5 +1,5 @@
created: 20140919155729620 created: 20140919155729620
modified: 20201017134038305 modified: 20220819093733569
tags: Macros [[Core Macros]] tags: Macros [[Core Macros]]
title: Table-of-Contents Macros title: Table-of-Contents Macros
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -62,4 +62,38 @@ These two parameters are combined into a single [[filter expression|Filter Expre
;template ;template
: Optionally, the title of a tiddler to use as a [[template|TemplateTiddlers]] for transcluding the selected tiddler into the right-hand panel : Optionally, the title of a tiddler to use as a [[template|TemplateTiddlers]] for transcluding the selected tiddler into the right-hand panel
[[Examples|Table-of-Contents Macros (Examples)]] !! Custom Icons
<<.from-version "5.2.4">>
To change the icons used by the Table-of-Contents macros, redefine the macros `toc-open-icon` and `toc-closed-icon`. This setting works for all toc-macro variants.
!!! Default Settings
* <<.var toc-open-icon>>: `\define toc-open-icon() $:/core/images/down-arrow`
* <<.var toc-closed-icon>>: `\define toc-closed-icon() $:/core/images/right-arrow`
!!! Custom Definitions
The default settings can be overwritten in your code using the define-pragma or the let-widget. The <<.wlink LetWidget>> widget can be used, if you have multiple table of contents macros in one tiddler, that need different icons.
''Define new icons using a pragma''
```
\define toc-open-icon() $:/core/images/fold-button
\define toc-closed-icon() $:/core/images/folder
...
```
''Define new icons using the let-widget''
```
<$let toc-open-icon="$:/core/images/fold-button" toc-closed-icon="$:/core/images/folder">
...
</$let>
```
!! Examples
Learn more at [[Examples|Table-of-Contents Macros (Examples)]]