How to use color-rgba - 4 common examples

To help you get started, we’ve selected a few color-rgba examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gambitph / Stackable / src / util / index.js View on Github external
if ( ! colorVar ) {
			hex = window.getComputedStyle( document.documentElement )
				.getPropertyValue( hex.replace( 'var(', '' ).replace( ')', '' ) ) || '#fff'
		} else {
			// Do also for CSS variables with fallback values.
			hex = window.getComputedStyle( document.documentElement )
				.getPropertyValue( colorVar[ 0 ] ) || '#fff'
		}
	}

	hex = hex.replace( /#/, '' )

	if ( hex.length <= 4 ) {
		hex = hex.replace( /#?(.)(.)(.)/, '$1$1$2$2$3$3' )
	}
	const newColor = rgba( `#${ hex }ff` )
	newColor[ 3 ] = opacity !== null ? opacity : 1
	return `rgba(${ newColor.join( ', ' ) })`
}
github gambitph / Stackable / src / plugins / global-settings / colors / index.js View on Github external
addFilter( 'stackable.util.hex-to-rgba', 'stackable/global-colors', ( output, hexColor, opacity ) => {
	// Only do this for Stackable global colors.
	if ( ! hexColor.includes( '--stk-global-color' ) ) {
		return output
	}

	const colorVarID = hexColor.match( /--stk-global-color-(\S*?(?=,))/ )
	if ( colorVarID ) {
		const colorRegex = /( )(.*)/g

		// Get the fallback value of the global color.
		const colorMatch = hexColor.match( colorRegex )[ 0 ].trim().slice( 0, -1 )

		// If the fallback value is a hex, convert to rgba.
		if ( colorMatch && colorMatch[ 0 ] === '#' ) {
			const rgbaColor = rgba( colorMatch )
			if ( rgbaColor ) {
				rgbaColor.splice( 3, 1 )
				return `rgba(var(--stk-global-color-${ colorVarID[ 1 ] }-rgba, ${ rgbaColor.join( ', ' ) }), ${ opacity !== null ? opacity : 1 })`
			}
		}
	}

	return output
} )
github gambitph / Stackable / src / util / styles / index.js View on Github external
color = window.getComputedStyle( document.documentElement )
						.getPropertyValue( colorVar[ 0 ] ) || '#fff'
				}
			} else {
				return _isDarkColor( color )
			}
		}

		// Add compatibility to rgb/rgba colors.
		if ( color.match( /^rgb/ ) ) {
			const rgbToHex = ( r, g, b ) => '#' + [ r, g, b ].map( x => {
				const hex = x.toString( 16 )
				return hex.length === 1 ? '0' + hex : hex
			} ).join( '' )

			const rgbaColor = rgba( color )
			rgbaColor.splice( 3, 1 )

			color = rgbToHex( ...rgbaColor )
		}

		color = color.replace( /#/g, '' )
		if ( color.length === 3 ) {
			color = color.replace( /(.)(.)(.)/, '$1$1$2$2$3$3' )
		}

		return _isDarkColor( `#${ color }` )
	} catch ( err ) {
		return false
	}
}
github gambitph / Stackable / src / plugins / global-settings / colors / util.js View on Github external
export const getRgb = hex => {
	const rgbColor = rgba( hex.match( /^#/ ) ? hex : `#${ hex }` )
	rgbColor.splice( 3, 1 )
	return rgbColor.join( ', ' )
}

color-rgba

Convert color string (or parseable argument) to RGBA array

MIT
Latest version published 7 months ago

Package Health Score

67 / 100
Full package analysis

Popular color-rgba functions