color-slug-to-color-code.js
26 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { getColorObjectByAttributeValues } from '@wordpress/block-editor'; |
| 5 | |
| 6 | /** |
| 7 | * Internal dependencies |
| 8 | */ |
| 9 | import { vkColorPalette } from '@vkblocks/admin/utils/settings'; |
| 10 | |
| 11 | export const colorSlugToColorCode = (color) => { |
| 12 | let colorCode; |
| 13 | if (color) { |
| 14 | const ColorValue = getColorObjectByAttributeValues( |
| 15 | vkColorPalette, |
| 16 | color |
| 17 | ); |
| 18 | if (ColorValue.color !== undefined) { |
| 19 | colorCode = ColorValue.color; |
| 20 | } else { |
| 21 | colorCode = color; |
| 22 | } |
| 23 | } |
| 24 | return colorCode; |
| 25 | }; |
| 26 |