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

Components: Simplify CustomGradientPicker's utility props #49588

Merged
merged 1 commit into from
Apr 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
* External dependencies
*/
import type gradientParser from 'gradient-parser';
/**
* Internal dependencies
*/
import type { ColorStopTypeAndValue } from './types';

export function serializeGradientColor( {
type,
value,
}: ColorStopTypeAndValue ) {
}: gradientParser.ColorStop ) {
if ( type === 'literal' ) {
return value;
}
Expand Down Expand Up @@ -38,7 +34,7 @@ export function serializeGradientColorStop( {
return `${ serializeGradientColor( {
type,
value,
} as ColorStopTypeAndValue ) } ${ serializeGradientPosition( length ) }`;
} as gradientParser.ColorStop ) } ${ serializeGradientPosition( length ) }`;
}

export function serializeGradientOrientation(
Expand Down
18 changes: 0 additions & 18 deletions packages/components/src/custom-gradient-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ export type GradientTypePickerProps = {

export type ControlPoint = { color: string; position: number };

// When dealing with unions of objects, using `Pick` will result
// in a new type where each desired prop is a union of the values for that prop
// across all of the original union members. This does not maintain the specific
// combinations of props present in the original union.
// To avoid this, the `DistributivePick` type will
// "distribute" the `Pick` across the union. This allows the `Pick`
// to act on each member individually, maintaining the relationships between the
// resulting props.
// https://stackoverflow.com/questions/57103834/typescript-omit-a-property-from-all-interfaces-in-a-union-but-keep-the-union-s
type DistributivePick< T, K extends keyof T > = T extends any
? Pick< T, K >
: never;

export type ColorStopTypeAndValue = DistributivePick<
gradientParser.ColorStop,
'type' | 'value'
>;

export type CustomGradientBarProps = {
background: React.CSSProperties[ 'background' ];
hasGradient: boolean;
Expand Down