Add a cascade for dynamically choosing tiddler icons

This commit is contained in:
jeremy@jermolene.com 2021-11-10 14:27:14 +00:00
parent a1ab220df6
commit 5f213567dd
17 changed files with 64 additions and 34 deletions

View File

@ -27,6 +27,9 @@ Basics/Tiddlers/Prompt: Number of tiddlers
Basics/Title/Prompt: Title of this ~TiddlyWiki
Basics/Username/Prompt: Username for signing edits
Basics/Version/Prompt: ~TiddlyWiki version
Cascades/Caption: Cascades
Cascades/Hint: These global rules are used to dynamically choose certain templates. The result of the cascade is the result of the first filter in the sequence that returns a result
Cascades/TagPrompt: Filters tagged <$macrocall $name="tag" tag=<<currentTiddler>>/>
EditorTypes/Caption: Editor Types
EditorTypes/Editor/Caption: Editor
EditorTypes/Hint: These tiddlers determine which editor is used to edit specific tiddler types.
@ -201,13 +204,12 @@ Stylesheets/Caption: Stylesheets
Stylesheets/Expand/Caption: Expand All
Stylesheets/Hint: This is the rendered CSS of the current stylesheet tiddlers tagged with <<tag "$:/tags/Stylesheet">>
Stylesheets/Restore/Caption: Restore
Templates/Caption: Templates
Templates/Hint: These are the global rules used to dynamically choose templates.
Templates/TagPrompt: Filters tagged <$macrocall $name="tag" tag=<<currentTiddler>>/>
Theme/Caption: Theme
Theme/Prompt: Current theme:
TiddlerFields/Caption: Tiddler Fields
TiddlerFields/Hint: This is the full set of TiddlerFields in use in this wiki (including system tiddlers but excluding shadow tiddlers).
TiddlerIcon/Caption: Tiddler Icon
TiddlerIcon/Hint: This rules cascade is used to dynamically choose the icon for a tiddler.
Toolbars/Caption: Toolbars
Toolbars/EditToolbar/Caption: Edit Toolbar
Toolbars/EditToolbar/Hint: Choose which buttons are displayed for tiddlers in edit mode. Drag and drop to change the ordering

View File

@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/Cascades
tags: $:/tags/ControlPanel/Advanced
caption: {{$:/language/ControlPanel/Cascades/Caption}}
{{$:/language/ControlPanel/Cascades/Hint}}
<div class="tc-control-panel">
<$macrocall $name="tabs" tabsList="[all[shadows+tiddlers]tag[$:/tags/ControlPanel/Cascades]!has[draft.of]]" default="$:/core/ui/ControlPanel/StoryTiddler"/>
</div>

View File

@ -1,5 +1,5 @@
title: $:/core/ui/ControlPanel/EditTemplateBody
tags: $:/tags/ControlPanel/Templates
tags: $:/tags/ControlPanel/Cascade
caption: {{$:/language/ControlPanel/EditTemplateBody/Caption}}
\define lingo-base() $:/language/ControlPanel/EditTemplateBody/

View File

@ -1,5 +1,5 @@
title: $:/core/ui/ControlPanel/StoryTiddler
tags: $:/tags/ControlPanel/Templates
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/StoryTiddler/Caption}}
\define lingo-base() $:/language/ControlPanel/StoryTiddler/

View File

@ -0,0 +1,9 @@
title: $:/core/ui/ControlPanel/TiddlerIcon
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/TiddlerIcon/Caption}}
\define lingo-base() $:/language/ControlPanel/TiddlerIcon/
<<lingo Hint>>
{{$:/tags/TiddlerIconFilter||$:/snippets/ListTaggedCascade}}

View File

@ -1,5 +1,5 @@
title: $:/core/ui/ControlPanel/ViewTemplateBody
tags: $:/tags/ControlPanel/Templates
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/ViewTemplateBody/Caption}}
\define lingo-base() $:/language/ControlPanel/ViewTemplateBody/

View File

@ -1,5 +1,5 @@
title: $:/core/ui/ControlPanel/ViewTemplateTitle
tags: $:/tags/ControlPanel/Templates
tags: $:/tags/ControlPanel/Cascades
caption: {{$:/language/ControlPanel/ViewTemplateTitle/Caption}}
\define lingo-base() $:/language/ControlPanel/ViewTemplateTitle/

View File

@ -1,9 +0,0 @@
title: $:/core/ui/ControlPanel/Templates
tags: $:/tags/ControlPanel/Advanced
caption: {{$:/language/ControlPanel/Templates/Caption}}
{{$:/language/ControlPanel/Templates/Hint}}
<div class="tc-control-panel">
<$macrocall $name="tabs" tabsList="[all[shadows+tiddlers]tag[$:/tags/ControlPanel/Templates]!has[draft.of]]" default="$:/core/ui/ControlPanel/StoryTiddler"/>
</div>

View File

@ -1,6 +1,6 @@
title: $:/snippets/ListTaggedCascade
{{||$:/language/ControlPanel/Templates/TagPrompt}}
{{||$:/language/ControlPanel/Cascades/TagPrompt}}
<ol>
<$list filter="[all[shadows+tiddlers]tag<currentTiddler>]">

View File

@ -16,7 +16,7 @@ title: $:/core/ui/TagPickerTagTemplate
<$set name="backgroundColor" value={{!!color}}>
<$wikify name="foregroundColor" text="""<$macrocall $name="contrastcolour" target={{!!color}} fallbackTarget=<<fallbackTarget>> colourA=<<colourA>> colourB=<<colourB>>/>""">
<span class="tc-tag-label tc-btn-invisible" style=<<tag-pill-styles>>>
<$transclude tiddler={{!!icon}}/><$view field="title" format="text"/>
{{||$:/core/ui/TiddlerIcon}}<$view field="title" format="text"/>
</span>
</$wikify>
</$set>

View File

@ -3,7 +3,7 @@ title: $:/core/ui/TagTemplate
\whitespace trim
<span class="tc-tag-list-item" data-tag-title=<<currentTiddler>>>
<$set name="transclusion" value=<<currentTiddler>>>
<$macrocall $name="tag-pill-body" tag=<<currentTiddler>> icon={{!!icon}} colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""popup=<<qualify "$:/state/popup/tag">> dragFilter='[all[current]tagging[]]' tag='span'"""/>
<$macrocall $name="tag-pill-body" tag=<<currentTiddler>> colour={{!!color}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""popup=<<qualify "$:/state/popup/tag">> dragFilter='[all[current]tagging[]]' tag='span'"""/>
<$reveal state=<<qualify "$:/state/popup/tag">> type="popup" position="below" animate="yes" class="tc-drop-down">
<$set name="tv-show-missing-links" value="yes">
<$transclude tiddler="$:/core/ui/ListItemTemplate"/>

15
core/ui/TiddlerIcon.tid Normal file
View File

@ -0,0 +1,15 @@
title: $:/core/ui/TiddlerIcon
\whitespace trim
\define title-styles()
fill:$(foregroundColor)$;
\end
<$let tiddlerIcon={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]get[text]] }}}>
<$list filter="[<tiddlerIcon>!is[blank]]" variable="ignore">
<$let foregroundColor={{!!color}}>
<span class=<<iconSpanClass>> style=<<title-styles>>>
<$transclude tiddler=<<tiddlerIcon>>/>
</span>
</$let>
</$list>
</$let>

View File

@ -2,9 +2,6 @@ title: $:/core/ui/ViewTemplate/title
tags: $:/tags/ViewTemplate
\whitespace trim
\define title-styles()
fill:$(foregroundColor)$;
\end
<div class="tc-tiddler-title">
<div class="tc-titlebar">
<span class="tc-tiddler-controls">
@ -12,15 +9,9 @@ fill:$(foregroundColor)$;
</span>
<$set name="tv-wikilinks" value={{$:/config/Tiddlers/TitleLinks}}>
<$link>
<$set name="foregroundColor" value={{!!color}}>
<$list filter="[all[current]has[icon]]~[[$:/config/DefaultTiddlerIcon]has[text]]">
<span class="tc-tiddler-title-icon" style=<<title-styles>>>
<$transclude tiddler={{!!icon}}>
<$transclude tiddler={{$:/config/DefaultTiddlerIcon}}/>
</$transclude>
</span>
</$list>
</$set>
<$let iconSpanClass="tc-tiddler-title-icon">
{{||$:/core/ui/TiddlerIcon}}
</$let>
<$transclude tiddler={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/ViewTemplateTitleFilter]get[text]] :and[!is[blank]else[$:/core/ui/ViewTemplate/title/default]] }}} />
</$link>
</$set>

View File

@ -0,0 +1,5 @@
title: $:/config/TiddlerIconFilters/
tags: $:/tags/TiddlerIconFilter
icon-field: [has[icon]then{!!icon}]
default: [{$:/config/DefaultTiddlerIcon}has[text]]

View File

@ -10,18 +10,18 @@ color:$(foregroundColor)$;
\define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions)
<$vars foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">> backgroundColor="""$colour$""">
<$element-tag$ $element-attributes$ class="tc-tag-label tc-btn-invisible" style=<<tag-pill-styles>>>
$actions$<$transclude tiddler="""$icon$"""/><$view tiddler=<<__tag__>> field="title" format="text" />
$actions${{||$:/core/ui/TiddlerIcon}}<$view tiddler=<<__tag__>> field="title" format="text" />
</$element-tag$>
</$vars>
\end
\define tag-pill-body(tag,icon,colour,palette,element-tag,element-attributes,actions)
<$macrocall $name="tag-pill-inner" tag=<<__tag__>> icon="""$icon$""" colour="""$colour$""" fallbackTarget={{$palette$##tag-background}} colourA={{$palette$##foreground}} colourB={{$palette$##background}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
<$macrocall $name="tag-pill-inner" tag=<<__tag__>> colour="""$colour$""" fallbackTarget={{$palette$##tag-background}} colourA={{$palette$##foreground}} colourB={{$palette$##background}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
\end
\define tag-pill(tag,element-tag:"span",element-attributes:"",actions:"")
<span class="tc-tag-list-item" data-tag-title=<<__tag__>>>
<$macrocall $name="tag-pill-body" tag=<<__tag__>> icon={{{ [<__tag__>get[icon]] }}} colour={{{ [<__tag__>get[color]] }}} palette={{$:/palette}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
<$macrocall $name="tag-pill-body" tag=<<__tag__>> colour={{{ [<__tag__>get[color]] }}} palette={{$:/palette}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/>
</span>
\end

View File

@ -0,0 +1,3 @@
title: $:/tags/TiddlerIconFilter
list: $:/config/TiddlerIconFilters/icon-field $:/config/TiddlerIconFilters/default

View File

@ -0,0 +1,5 @@
title: $:/_tw5.com/CustomTiddlerIconCascadeDemo
tags: $:/tags/TiddlerIconFilter
[tag[TableOfContents]then[$:/core/images/globe]]
[tag[Working with TiddlyWiki]then[$:/core/images/help]]