PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / gutenberg / src / controls / hexToRgba.js

hexToRgba.js in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at modules/gutenberg/src/controls/hexToRgba.js

55 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Get HEX color and return RGBA. Default return RGB color.
3 *
4 * @param {string} color - The color string.
5 * @return {boolean} opacity The inline CSS class.
6 */
7
8 function hexToRgba( color, opacity ) {
9 if ( ! color ) {
10 return '';
11 }
12
13 if ( 'undefined' === typeof opacity || '' === opacity ) {
14 opacity = 100;
15 }
16
17 color = color.replace( '#', '' );
18
19 opacity = typeof opacity !== 'undefined' ? opacity / 100 : 1;
20
21 // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
22 const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
23 color = color.replace( shorthandRegex, function ( m, r, g, b ) {
24 return r + r + g + g + b + b;
25 } );
26
27 const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( color );
28
29 const parsed_color = result
30 ? {
31 r: parseInt( result[ 1 ], 16 ),
32 g: parseInt( result[ 2 ], 16 ),
33 b: parseInt( result[ 3 ], 16 ),
34 }
35 : null;
36
37 if ( parsed_color ) {
38 return (
39 'rgba(' +
40 parsed_color.r +
41 ',' +
42 parsed_color.g +
43 ',' +
44 parsed_color.b +
45 ',' +
46 opacity +
47 ')'
48 );
49 }
50
51 return '';
52 }
53
54 export default hexToRgba;
55