Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lodash: Remove usage from CustomGradientPicker component #41901

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions packages/components/src/custom-gradient-picker/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { get, omit } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -34,11 +29,8 @@ import {
} from './styles/custom-gradient-picker-styles';

const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {
const angle = get(
gradientAST,
[ 'orientation', 'value' ],
DEFAULT_LINEAR_GRADIENT_ANGLE
);
const angle =
gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
const onAngleChange = ( newAngle ) => {
onChange(
serializeGradient( {
Expand Down Expand Up @@ -74,9 +66,11 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
};

const onSetRadialGradient = () => {
// eslint-disable-next-line no-unused-vars
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this ESLint ignoring comment once #41897 is shipped.

const { orientation, ...restGradientAST } = gradientAST;
onChange(
serializeGradient( {
...omit( gradientAST, [ 'orientation' ] ),
...restGradientAST,
type: 'radial-gradient',
} )
);
Expand Down
14 changes: 3 additions & 11 deletions packages/components/src/custom-gradient-picker/index.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* External dependencies
*/
import { get, omit } from 'lodash';
/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -37,7 +33,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
}

function getGradientColor( type ) {
const orientation = get( gradientAST, [ 'orientation' ] );
const { orientation, ...restGradientAST } = gradientAST;

if ( orientation ) {
setGradientOrientation( orientation );
Expand All @@ -55,7 +51,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
type,
}
: {
...omit( gradientAST, [ 'orientation' ] ),
...restGradientAST,
type,
}
);
Expand Down Expand Up @@ -83,11 +79,7 @@ function CustomGradientPicker( { setColor, currentValue, isGradientColor } ) {
}

function getGradientAngle() {
return get(
gradientAST,
[ 'orientation', 'value' ],
DEFAULT_LINEAR_GRADIENT_ANGLE
);
return gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
}
return (
<>
Expand Down
16 changes: 5 additions & 11 deletions packages/components/src/custom-gradient-picker/serializer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { compact, get } from 'lodash';

export function serializeGradientColor( { type, value } ) {
if ( type === 'literal' ) {
return value;
Expand Down Expand Up @@ -40,13 +35,12 @@ export function serializeGradient( { type, orientation, colorStops } ) {
const serializedColorStops = colorStops
.sort( ( colorStop1, colorStop2 ) => {
return (
get( colorStop1, [ 'length', 'value' ], 0 ) -
get( colorStop2, [ 'length', 'value' ], 0 )
( colorStop1?.length?.value ?? 0 ) -
( colorStop2?.length?.value ?? 0 )
);
} )
.map( serializeGradientColorStop );
return `${ type }(${ compact( [
serializedOrientation,
...serializedColorStops,
] ).join( ',' ) })`;
return `${ type }(${ [ serializedOrientation, ...serializedColorStops ]
.filter( Boolean )
.join( ',' ) })`;
}