Skip to content

Commit a972672

Browse files
authored
Components: Remove Lodash usage from CustomGradientPicker (#41901)
1 parent eb6dd8e commit a972672

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

packages/components/src/custom-gradient-picker/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* External dependencies
3-
*/
4-
import { get, omit } from 'lodash';
5-
61
/**
72
* WordPress dependencies
83
*/
@@ -34,11 +29,8 @@ import {
3429
} from './styles/custom-gradient-picker-styles';
3530

3631
const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {
37-
const angle = get(
38-
gradientAST,
39-
[ 'orientation', 'value' ],
40-
DEFAULT_LINEAR_GRADIENT_ANGLE
41-
);
32+
const angle =
33+
gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
4234
const onAngleChange = ( newAngle ) => {
4335
onChange(
4436
serializeGradient( {
@@ -74,9 +66,11 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
7466
};
7567

7668
const onSetRadialGradient = () => {
69+
// eslint-disable-next-line no-unused-vars
70+
const { orientation, ...restGradientAST } = gradientAST;
7771
onChange(
7872
serializeGradient( {
79-
...omit( gradientAST, [ 'orientation' ] ),
73+
...restGradientAST,
8074
type: 'radial-gradient',
8175
} )
8276
);

packages/components/src/custom-gradient-picker/index.native.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* External dependencies
3-
*/
4-
import { get, omit } from 'lodash';
51
/**
62
* WordPress dependencies
73
*/
@@ -37,7 +33,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
3733
}
3834

3935
function getGradientColor( type ) {
40-
const orientation = get( gradientAST, [ 'orientation' ] );
36+
const { orientation, ...restGradientAST } = gradientAST;
4137

4238
if ( orientation ) {
4339
setGradientOrientation( orientation );
@@ -55,7 +51,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
5551
type,
5652
}
5753
: {
58-
...omit( gradientAST, [ 'orientation' ] ),
54+
...restGradientAST,
5955
type,
6056
}
6157
);
@@ -83,11 +79,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
8379
}
8480

8581
function getGradientAngle() {
86-
return get(
87-
gradientAST,
88-
[ 'orientation', 'value' ],
89-
DEFAULT_LINEAR_GRADIENT_ANGLE
90-
);
82+
return gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
9183
}
9284
return (
9385
<>

packages/components/src/custom-gradient-picker/serializer.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* External dependencies
3-
*/
4-
import { compact, get } from 'lodash';
5-
61
export function serializeGradientColor( { type, value } ) {
72
if ( type === 'literal' ) {
83
return value;
@@ -40,13 +35,12 @@ export function serializeGradient( { type, orientation, colorStops } ) {
4035
const serializedColorStops = colorStops
4136
.sort( ( colorStop1, colorStop2 ) => {
4237
return (
43-
get( colorStop1, [ 'length', 'value' ], 0 ) -
44-
get( colorStop2, [ 'length', 'value' ], 0 )
38+
( colorStop1?.length?.value ?? 0 ) -
39+
( colorStop2?.length?.value ?? 0 )
4540
);
4641
} )
4742
.map( serializeGradientColorStop );
48-
return `${ type }(${ compact( [
49-
serializedOrientation,
50-
...serializedColorStops,
51-
] ).join( ',' ) })`;
43+
return `${ type }(${ [ serializedOrientation, ...serializedColorStops ]
44+
.filter( Boolean )
45+
.join( ',' ) })`;
5246
}

0 commit comments

Comments
 (0)