UNPKG

@wordpress/components

Version:
60 lines (50 loc) 1.31 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.rgba = rgba; exports.color = color; var _lodash = require("lodash"); var _tinycolor = _interopRequireDefault(require("tinycolor2")); var _colorsValues = require("./colors-values"); /** * External dependencies */ /** * Internal dependencies */ /** * Generating a CSS complient rgba() color value. * * @param {string} hexValue The hex value to convert to rgba(). * @param {number} alpha The alpha value for opacity. * @return {string} The converted rgba() color value. * * @example * rgba( '#000000', 0.5 ) * // rgba(0, 0, 0, 0.5) */ function rgba(hexValue = '', alpha = 1) { const { r, g, b } = (0, _tinycolor.default)(hexValue).toRgb(); return `rgba(${r}, ${g}, ${b}, ${alpha})`; } /** * Retrieves a color from the color palette. * * @param {import('lodash').PropertyPath} value The value to retrieve. * @return {string} The color (or fallback, if not found). * * @example * color( 'blue.wordpress.700' ) * // #00669b */ function color(value) { const fallbackColor = '#000'; return (0, _lodash.get)(_colorsValues.COLORS, value, fallbackColor); } //# sourceMappingURL=colors.js.map