The HTML standard type=color
input control only displays the selected color if it has been specified using a 6-digit hex #RRGGBB
value. This is not a problem if you ONLY use the type=color
control to select a color. However, if you have some other method of setting the color (e.g. directly in tiddler content or from a ViewTemplate) that does not use type=color
, such as
<$edit-text type="text" field="color"/>
then you can enter colors using any valid CSS format, including:
- 3-, 4-, or 8-digit hex =
#RGB
or #RGBA
or #RRGGBBAA
- decimal RGB values =
rgb(255,255,255)
or rgba(255,255,255,255)
- X11 color names = “red”, “green”, “blue”, “cyan”, etc.
These color values will still be applied when rendering the tiddler, but… since they don’t conform to the 6-digit hex values supported by the type=color
HTML input, they show as black for the color control in the tiddler editor.
I’ve written code that solves this problem by converting the above color value formats to 6-digit hex, but it is not trivial, and probably won’t ever make it into the TWCore. See TiddlyTools/Palettes/Manager. Specifically, this macro:
\define palette-manager-colour-pick(field,index,tip)
\define hex(n) ^#[A-Fa-f0-9]{$n$}$
<!-- GET #RRGGBB FROM MACRO/WIDGET VALUE, MATCHNG X11 NAMES, EXPAND #RGBA, CONVERT RGBA() -->
<$let id={{{ [<__index__>!match[]] ~[<__field__>] }}} c={{{ [<currentTiddler>getindex<id>] ~[<currentTiddler>get<id>] }}}>
<$wikify name=v text=<<c>>>
<$let
c={{{ [<c>prefix[#]] ~[<v>] }}}
c={{{ [<X11Colors>indexes[]match:caseinsensitive<c>] :map[<X11Colors>getindex<currentTiddler>] ~[<c>] }}}
c={{{ [<c>regexp<hex 3,4>split[]!match[#]] :map[<currentTiddler>addsuffix<currentTiddler>] +[join[]!match[]addprefix[#]] ~[<c>] }}}
a={{{ [<c>regexp<hex 8>split[]last[2]join[]] }}}
c={{{ [<c>regexp<hex 8>split[]first[7]join[]] ~[<c>] }}}
d={{{ [<c>lowercase[]prefix[rgb]split[(]nth[2]trim[)]split[,]join[ ]] }}}
d={{{ [enlist:raw<d>first[3]] =[enlist:raw<d>nth[4]!match[]multiply[255]trunc[]] +[join[ ]] }}}
hi={{{ [enlist:raw<d>divide[16]] :map[[0123456789abcdef]split[]zth<currentTiddler>] +[join[ ]] }}}
lo={{{ [enlist:raw<d>remainder[16]] :map[[0123456789abcdef]split[]zth<currentTiddler>] +[join[ ]] }}}
r={{{ [enlist:raw<hi>nth[1]] =[enlist:raw<lo>nth[1]] +[join[]] }}}
g={{{ [enlist:raw<hi>nth[2]] =[enlist:raw<lo>nth[2]] +[join[]] }}}
b={{{ [enlist:raw<hi>nth[3]] =[enlist:raw<lo>nth[3]] +[join[]] }}}
a={{{ [enlist:raw<hi>nth[4]] =[enlist:raw<lo>nth[4]] +[join[]] ~[<a>] }}}
c={{{ [<r>] =[<g>] =[<b>] +[join[]!match[]addprefix[#]] ~[<c>] }}}>
<$eventcatcher stopPropagation=never $focusin="<$action-deletetiddler $tiddler=<<pick>>/>"
$change="<$action-setfield $field=<<__field__>> $index=<<__index__>> $value={{{ [<pick>getindex<id>] [<a>] +[join[]] }}}/><$action-deletetiddler $tiddler=<<pick>>/>">
<span title={{{ [[pick a color for]] [<__tip__>] +[join[ ]] }}}>
<$edit-text tiddler=<<pick>> index=<<id>> tag=input type=color default=<<c>> class={{{ [[tt-palettemanager-colourpick tc-popup-handle]] [<id>] +[join[ ]] }}}/>
\end
Note that <X11Colors>
is a reference to a separate tiddler (TiddlyTools/Settings/Colors/X11), which is a DataDictionary tiddler that contains 151 color name indexes with their corresponding #RRGGBB color values. If this tiddler is not present, the reference to it just “falls through” without changing the computed color value (<c>
).
For general info on X11 color names, see X11 color names - Wikipedia
enjoy,
-e