You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
polished is a very powerful library to processing colors, but some enviroments only support the hex notation format.
Therefore, is it possible to add new functions to format the color format or add a new parameter to rgb functions to restrict color string type (but there are too many functions).
Basic Example
constFormat{auto: 'auto',// Defaulthex: 'hex',rgb: 'rgb'// Need more precise wording}toColorString({red: 255,green: 205,blue: 100,alpha: 0.72,format: Format.hex})// '#ffcd64b8'// Or new color functiontoHexColorString({red: 255,green: 205,blue: 100,alpha: 0.72})// '#ffcd64b8'// A simple workaroundexportconsttoHexColorString=(color: Object)=>{if(typeofcolor!=='object')thrownewPolishedError(8)constcolorString=toColorString(color)constmaybeRgbaColor=parseToRgb(colorString);if("alpha"inmaybeRgbaColor){const{ alpha, ...RgbColor}=maybeRgbaColor;returnrgb(RgbColor)+Math.trunc(alpha*255).toString(16)}constRgbColor=maybeRgbaColor;returnrgb(RgbColor)};
Reasoning
Some environments do not support all CSS features.
For example, vscode theme config
Color values can be defined in the RGB color model with an alpha channel for transparency. As format, the following hexadecimal notations are supported: #RGB, #RGBA, #RRGGBB and #RRGGBBAA.
--vscode theme color references
The text was updated successfully, but these errors were encountered:
I wanted to use polished to produce a 7 character (#xxxxxx) hex color so that it can be used by HTML5 <input type="color"> but polished produces shortest possible hex, which doesn't work with the native color picker.
Summary
polished is a very powerful library to processing colors, but some enviroments only support the hex notation format.
Therefore, is it possible to add new functions to format the color format or add a new parameter to
rgb
functions to restrict color string type (but there are too many functions).Basic Example
Reasoning
Some environments do not support all CSS features.
For example, vscode theme config
The text was updated successfully, but these errors were encountered: