admin管理员组文章数量:1391951
I'm working on a block that has it's own colour picker. This is working fine and I can see my background colour changing however I'm only able to get the hex value for the colour.
I'm changing the colour as it stands by doing:-
style={{ backgroundColor: `${tint.hex}` }}
Tint is an object returned from the colour picker and I can see that it has a sub object called color that contains rgba values.
How do I get these values and make the backgroundColour use rgba()?
I'm working on a block that has it's own colour picker. This is working fine and I can see my background colour changing however I'm only able to get the hex value for the colour.
I'm changing the colour as it stands by doing:-
style={{ backgroundColor: `${tint.hex}` }}
Tint is an object returned from the colour picker and I can see that it has a sub object called color that contains rgba values.
How do I get these values and make the backgroundColour use rgba()?
Share Improve this question asked Feb 14, 2020 at 0:14 AstridAstrid 1231 silver badge12 bronze badges1 Answer
Reset to default 2If you mean wpponents.ColorPicker
which is based on react-color, then the tint
object also contains a rgb
property with an object of the RGBA value like {r: 51, g: 51, b: 51, a: 1}
.
So in your code, you can use:
style={{ backgroundColor: `rgba(${tint.rgb.r}, ${tint.rgb.g}, ${tint.rgb.b}, ${tint.rgb.a})` }}
And an easy trick to know all the available properties in the color object is by running console.log( tint )
.. :)
本文标签: pluginsGetting RGBA colour from gutenberg colourpicker
版权声明:本文标题:plugins - Getting RGBA colour from gutenberg colourpicker 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744749317a2623078.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论