@@ -71,6 +71,7 @@ const toHex = (
7171const toColor = (
7272 colors : Omit < IGardenTheme [ 'colors' ] , 'base' | 'variables' > ,
7373 palette : IGardenTheme [ 'palette' ] ,
74+ opacity : IGardenTheme [ 'opacity' ] ,
7475 scheme : 'dark' | 'light' ,
7576 hue : string ,
7677 shade ?: number | string ,
@@ -109,7 +110,13 @@ const toColor = (
109110 }
110111
111112 if ( retVal && transparency ) {
112- retVal = rgba ( retVal , transparency ) ;
113+ const alpha = transparency > 1 ? opacity [ transparency ] : transparency ;
114+
115+ if ( alpha === undefined ) {
116+ throw new Error ( 'Error: invalid `transparency` parameter' ) ;
117+ }
118+
119+ retVal = rgba ( retVal , alpha ) ;
113120 }
114121
115122 return retVal ;
@@ -147,7 +154,7 @@ const toProperty = (object: object, path: string) => {
147154 * - `'chromeHue'` = `theme.colors.chromeHue`
148155 * @param {number } [options.shade] A hue shade
149156 * @param {number } [options.offset] A positive or negative value to adjust the shade
150- * @param {number } [options.transparency] An alpha-channel value between 0 and 1
157+ * @param {number } [options.transparency] A `theme.opacity` key or an alpha-channel value between 0 and 1
151158 */
152159export const getColor = memoize (
153160 ( { dark, hue, light, offset, shade, theme, transparency, variable } : ColorParameters ) => {
@@ -184,7 +191,12 @@ export const getColor = memoize(
184191 }
185192
186193 if ( _hue ) {
187- retVal = toColor ( colors , palette , scheme , _hue , _shade , _offset , _transparency ) ;
194+ const opacity =
195+ theme . opacity && Object . keys ( theme . opacity ) . length > 0
196+ ? theme . opacity
197+ : DEFAULT_THEME . opacity ;
198+
199+ retVal = toColor ( colors , palette , opacity , scheme , _hue , _shade , _offset , _transparency ) ;
188200 }
189201
190202 if ( retVal === undefined ) {
0 commit comments