-
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.
Add: Preset gradient functionality button block (#17169)
- Loading branch information
1 parent
0bef434
commit 0f8bdf5
Showing
13 changed files
with
258 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
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 { __experimentalGradientPicker } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
function GradientPickerWithGradients( props ) { | ||
const gradients = useSelect( ( select ) => ( | ||
select( 'core/block-editor' ).getSettings().gradients | ||
) ); | ||
return ( | ||
<__experimentalGradientPicker | ||
{ ...props } | ||
gradients={ gradients } | ||
/> | ||
); | ||
} | ||
|
||
export default function( props ) { | ||
const ComponentToUse = props.gradients ? | ||
__experimentalGradientPicker : | ||
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