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

Gradients: Enable adding custom gradient when gradients are disabled #36900

Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bug Fix

- Fixed `GradientPicker` not displaying `CustomGradientPicker` when no gradients are provided ([#36900](https://github.com/WordPress/gutenberg/pull/36900)).
- Fixed error thrown in `ColorPicker` when used in controlled state in color gradients ([#36941](https://github.com/WordPress/gutenberg/pull/36941)).
- Updated readme to include default value introduced in fix for unexpected movements in the `ColorPicker` ([#35670](https://github.com/WordPress/gutenberg/pull/35670)).
- Replaced hardcoded blue in `ColorPicker` with UI theme color ([#36153](https://github.com/WordPress/gutenberg/pull/36153)).
Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/gradient-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ export default function GradientPicker( {
const clearGradient = useCallback( () => onChange( undefined ), [
onChange,
] );
const Component = __experimentalHasMultipleOrigins
? MultipleOrigin
: SingleOrigin;
const Component =
__experimentalHasMultipleOrigins && gradients?.length
? MultipleOrigin
: SingleOrigin;

return (
<Component
className={ className }
Expand Down
23 changes: 23 additions & 0 deletions packages/components/src/gradient-picker/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,26 @@ export const _default = () => {
/>
);
};

export const WithNoExistingGradients = () => {
const disableCustomGradients = boolean( 'Disable Custom Gradients', false );
const __experimentalHasMultipleOrigins = boolean(
'Experimental Has Multiple Origins',
true
);
const clearable = boolean( 'Clearable', true );
const className = text( 'Class Name', '' );
const gradients = object( 'Gradients', [] );

return (
<GradientPickerWithState
__experimentalHasMultipleOrigins={
__experimentalHasMultipleOrigins
}
disableCustomGradients={ disableCustomGradients }
gradients={ gradients }
clearable={ clearable }
className={ className }
/>
);
};