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 c180843
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 838 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
3 changes: 2 additions & 1 deletion packages/material-ui-lab/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { fade, withStyles } from '@material-ui/core/styles';
import { withStyles } from '@material-ui/core/styles';
import { fade } from '@material-ui/core/styles/colorManipulator';
import ButtonBase from '@material-ui/core/ButtonBase';
import { setRef, withForwardedRef } from '@material-ui/core/utils';
import { clamp } from '@material-ui/lab/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { emphasize, withStyles } from '@material-ui/core/styles';
import { withStyles } from '@material-ui/core/styles';
import { emphasize } from '@material-ui/core/styles/colorManipulator';
import Fab from '@material-ui/core/Fab';
import Tooltip from '@material-ui/core/Tooltip';
import { withForwardedRef } from '@material-ui/core/utils';
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui-lab/src/ToggleButton/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { fade, withStyles } from '@material-ui/core/styles';
import { withStyles } from '@material-ui/core/styles';
import { fade } from '@material-ui/core/styles/colorManipulator';
import ButtonBase from '@material-ui/core/ButtonBase';

export const styles = theme => ({
Expand Down
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
60 changes: 4 additions & 56 deletions packages/material-ui/src/styles/colorManipulator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
/* 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 +185,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 +196,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 +207,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 c180843

Please sign in to comment.