-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit changes a few things. It: - Removes all duplicate presets and leaves only top left to bottom right gradients. As presets, these are arguably more dynamic when using them, compared to vertical or horizontal. - It adds a range of gradients built using the stock Gutenberg color palette colors. - It adds a couple of additional gradients using new colors. - Removes the transparent gradients for now, as they aren't useful yet on the button. We can add back later on. Will elaborate in a comment. (+2 squashed commits) Squashed commits: [a37cac983] Add transparency indication. [f7aa9f8a7] Add: Preset gradient functionality button block
- Loading branch information
1 parent
9494c17
commit 01d065d
Showing
14 changed files
with
266 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/block-editor/src/components/gradient-picker/control.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BaseControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import GradientPicker from './'; | ||
|
||
export default function( { className, ...props } ) { | ||
return ( | ||
<BaseControl | ||
className={ classnames( | ||
'block-editor-gradient-picker-control', | ||
className | ||
) } | ||
> | ||
<BaseControl.VisualLabel> | ||
{ __( 'Gradient Presets' ) } | ||
</BaseControl.VisualLabel> | ||
<GradientPicker | ||
className="block-editor-gradient-picker-control__gradient-picker-presets" | ||
{ ...props } | ||
/> | ||
</BaseControl> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/block-editor/src/components/gradient-picker/control.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.block-editor-gradient-picker-control__gradient-picker-presets { | ||
display: inline-block; | ||
margin-top: 0.6rem; | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/block-editor/src/components/gradient-picker/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { GradientPicker } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
function GradientPickerWithGradients( props ) { | ||
const gradients = useSelect( ( select ) => ( | ||
select( 'core/block-editor' ).getSettings().gradients | ||
) ); | ||
return ( | ||
<GradientPicker | ||
{ ...props } | ||
gradients={ gradients } | ||
/> | ||
); | ||
} | ||
|
||
export default function( props ) { | ||
const ComponentToUse = props.gradients ? | ||
GradientPicker : | ||
GradientPickerWithGradients; | ||
return ( <ComponentToUse { ...props } /> ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ | |
}, | ||
"borderRadius": { | ||
"type": "number" | ||
}, | ||
"customGradient": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { useCallback, useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CircularOptionPicker from '../circular-option-picker'; | ||
|
||
export default function GradientPicker( { | ||
className, | ||
gradients, | ||
onChange, | ||
value, | ||
} ) { | ||
const clearGradient = useCallback( | ||
() => onChange( undefined ), | ||
[ onChange ] | ||
); | ||
const gradientOptions = useMemo( | ||
() => { | ||
return map( gradients, ( { gradient, name } ) => ( | ||
<CircularOptionPicker.Option | ||
key={ gradient } | ||
value={ gradient } | ||
isSelected={ value === gradient } | ||
tooltipText={ name || | ||
// translators: %s: gradient code e.g: "linear-gradient(90deg, rgba(98,16,153,1) 0%, rgba(172,110,22,1) 100%);". | ||
sprintf( __( 'Gradient code: %s' ), gradient ) | ||
} | ||
style={ { color: 'rgba( 0,0,0,0 )', background: gradient } } | ||
onClick={ | ||
value === gradient ? | ||
clearGradient : | ||
() => ( onChange( gradient ) ) | ||
} | ||
aria-label={ name ? | ||
// translators: %s: The name of the gradient e.g: "Angular red to blue". | ||
sprintf( __( 'Gradient: %s' ), name ) : | ||
// translators: %s: gradient code e.g: "linear-gradient(90deg, rgba(98,16,153,1) 0%, rgba(172,110,22,1) 100%);". | ||
sprintf( __( 'Gradient code: %s' ), gradient ) | ||
} | ||
/> | ||
) ); | ||
}, | ||
[ gradients, value, onChange, clearGradient ] | ||
); | ||
return ( | ||
<CircularOptionPicker | ||
className={ className } | ||
options={ gradientOptions } | ||
actions={ ( | ||
<CircularOptionPicker.ButtonAction onClick={ clearGradient }> | ||
{ __( 'Clear' ) } | ||
</CircularOptionPicker.ButtonAction> | ||
) } | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters