Skip to content

Commit

Permalink
Add colord package to block editor; Replace tinycolor2 with colord on…
Browse files Browse the repository at this point in the history
… duotone hook.
  • Loading branch information
jorgefilipecosta committed Sep 27, 2021
1 parent e9a09f1 commit 84d0a2d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* External dependencies
*/
import classnames from 'classnames';
import tinycolor from 'tinycolor2';
import { colord, extend } from 'colord';
import namesPlugin from 'colord/plugins/names';

/**
* WordPress dependencies
Expand All @@ -25,6 +26,8 @@ import BlockList from '../components/block-list';

const EMPTY_ARRAY = [];

extend( [ namesPlugin ] );

/**
* Convert a list of colors to an object of R, G, and B values.
*
Expand All @@ -36,11 +39,10 @@ export function getValuesFromColors( colors = [] ) {
const values = { r: [], g: [], b: [] };

colors.forEach( ( color ) => {
// Access values directly to skip extra rounding that tinycolor.toRgb() does.
const tcolor = tinycolor( color );
values.r.push( tcolor._r / 255 );
values.g.push( tcolor._g / 255 );
values.b.push( tcolor._b / 255 );
const rgbColor = colord( color ).toRgb();
values.r.push( rgbColor.r / 255 );
values.g.push( rgbColor.g / 255 );
values.b.push( rgbColor.b / 255 );
} );

return values;
Expand Down

0 comments on commit 84d0a2d

Please sign in to comment.