Skip to content

Commit

Permalink
added deprecated fade method
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova committed Oct 7, 2020
1 parent c42554d commit 67ee2f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/material-ui/src/styles/colorManipulator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export function recomposeColor(color: ColorObject): string;
export function getContrastRatio(foreground: string, background: string): number;
export function getLuminance(color: string): number;
export function emphasize(color: string, coefficient?: number): string;
/**
* @deprecated
* Use `import { alpha } from '@material-ui/core/styles'` instead.
*/
export function fade(color: string, value: number): string;
export function alpha(color: string, value: number): string;
export function darken(color: string, coefficient: number): string;
export function lighten(color: string, coefficient: number): string;
30 changes: 30 additions & 0 deletions packages/material-ui/src/styles/colorManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,36 @@ export function alpha(color, value) {
return recomposeColor(color);
}

let warnedOnce = false;

/**
* Set the absolute transparency of a color.
* Any existing alpha values are overwritten.
*
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
* @param {number} value - value to set the alpha channel to in the range 0 -1
* @returns {string} A CSS color string. Hex input values are returned as rgb
*
* @deprecated
* Use `import { alpha } from '@material-ui/core/styles'` instead.
*/
export function fade(color, value) {
if (process.env.NODE_ENV !== 'production') {
if (!warnedOnce) {
warnedOnce = true;
console.error(
[
'Material-UI: The `fade` color utility was renamed to `alpha` to better describe its functionality.',
'',
"You should use `import { alpha } from '@material-ui/core/styles'`",
].join('\n'),
);
}
}

return alpha(color, value);
}

/**
* Darkens a color.
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
Expand Down

0 comments on commit 67ee2f2

Please sign in to comment.