Skip to content

Commit

Permalink
evaluate polished
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 30, 2019
1 parent 02f135d commit cc2f67e
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 834 deletions.
2 changes: 1 addition & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--install.frozen-lockfile true

network-timeout 150000
1 change: 1 addition & 0 deletions packages/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"hoist-non-react-statics": "^3.2.1",
"is-plain-object": "^2.0.4",
"normalize-scroll-left": "^0.1.2",
"polished": "^3.2.0",
"popper.js": "^1.14.1",
"prop-types": "^15.7.2",
"react-event-listener": "^0.6.6",
Expand Down
59 changes: 4 additions & 55 deletions packages/material-ui/src/styles/colorManipulator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
/* eslint-disable no-use-before-define */

import warning from 'warning';

/**
* Returns a number whose value is limited to the given range.
*
* @param {number} value The value to be clamped
* @param {number} min The lower boundary of the output range
* @param {number} max The upper boundary of the output range
* @returns {number} A number in the range [min, max]
*/
function clamp(value, min = 0, max = 1) {
warning(
value >= min && value <= max,
`Material-UI: the value provided ${value} is out of range [${min}, ${max}].`,
);

if (value < min) {
return min;
}
if (value > max) {
return max;
}
return value;
}
import { lighten as lighten2, darken as darken2, rgba } from 'polished';

/**
* Converts a color from CSS hex format to CSS rgb format.
Expand Down Expand Up @@ -208,15 +186,7 @@ export function emphasize(color, coefficient = 0.15) {
* @returns {string} A CSS color string. Hex input values are returned as rgb
*/
export function fade(color, value) {
color = decomposeColor(color);
value = clamp(value);

if (color.type === 'rgb' || color.type === 'hsl') {
color.type += 'a';
}
color.values[3] = value;

return recomposeColor(color);
return rgba(color, value);
}

/**
Expand All @@ -227,17 +197,7 @@ export function fade(color, value) {
* @returns {string} A CSS color string. Hex input values are returned as rgb
*/
export function darken(color, coefficient) {
color = decomposeColor(color);
coefficient = clamp(coefficient);

if (color.type.indexOf('hsl') !== -1) {
color.values[2] *= 1 - coefficient;
} else if (color.type.indexOf('rgb') !== -1) {
for (let i = 0; i < 3; i += 1) {
color.values[i] *= 1 - coefficient;
}
}
return recomposeColor(color);
return darken2(coefficient, color);
}

/**
Expand All @@ -248,16 +208,5 @@ export function darken(color, coefficient) {
* @returns {string} A CSS color string. Hex input values are returned as rgb
*/
export function lighten(color, coefficient) {
color = decomposeColor(color);
coefficient = clamp(coefficient);

if (color.type.indexOf('hsl') !== -1) {
color.values[2] += (100 - color.values[2]) * coefficient;
} else if (color.type.indexOf('rgb') !== -1) {
for (let i = 0; i < 3; i += 1) {
color.values[i] += (255 - color.values[i]) * coefficient;
}
}

return recomposeColor(color);
return lighten2(coefficient, color);
}
Loading

0 comments on commit cc2f67e

Please sign in to comment.