-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from WebDevStudios/enhancement/94-extend-carou…
…sel-block WDS Blocks 2.1: Improve Carousel Block
- Loading branch information
Showing
10 changed files
with
251 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
|
||
*:not(video) { | ||
position: relative; | ||
z-index: 1; | ||
} | ||
} |
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,54 @@ | ||
# `OverlayPanel` # | ||
|
||
Render a `PanelBody` component containing inputs to control background overlay. | ||
|
||
## Properties ## | ||
|
||
### `overlayColor: String` ### | ||
*Required.* The hex code representing the overlay color, if selected. | ||
|
||
### `setOverlayColor( value: String ): Function` ### | ||
*Required.* Called when `overlayColor` is changed, where `value` is the new hex color code. | ||
|
||
### `overlayOpacity: Number` ### | ||
*Required.* The number between 0 and 100 representing the overlay opacity. | ||
|
||
### `setOverlayOpacity( value: Number ): Function` ### | ||
*Required.* Called when `overlayOpacity` is changed, where `value` is the new opacity. | ||
|
||
## Usage ## | ||
|
||
*Note: `overlayColor`/`setOverlayColor` assumes usage of `withColors` higher-order component.* | ||
|
||
```jsx | ||
import { InspectorControls, withColors } from '@wordpress/block-editor'; | ||
import { compose } from '@wordpress/compose'; | ||
|
||
function Edit( props ) { | ||
const { | ||
attributes: { | ||
overlayOpacity, | ||
}, | ||
overlayColor, | ||
setOverlayColor, | ||
setAttributes, | ||
} = props; | ||
|
||
return ( | ||
<InspectorControls> | ||
<OverlayPanel | ||
overlayColor={ overlayColor } | ||
setOverlayColor={ setOverlayColor } | ||
overlayOpacity={ overlayOpacity } | ||
setOverlayOpacity={ ( value ) => | ||
setAttributes( { overlayOpacity: value } ) | ||
} | ||
/> | ||
</InspectorControls> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withColors( { overlayColor: 'background-color' } ), | ||
] )( Edit ); | ||
``` |
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,41 @@ | ||
import { PanelBody, RangeControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import ColorPaletteControl from '../color-palette-control'; | ||
|
||
/** | ||
* The OverlayPanel component displays a panel of controls for background overlay. | ||
* | ||
* @author WebDevStudios | ||
* @since 2.1.0 | ||
* | ||
* @param {Object} [props] Properties passed to the component. | ||
* @return {Element} Element to render. | ||
*/ | ||
export default function OverlayPanel( props ) { | ||
const { | ||
overlayColor, | ||
setOverlayColor, | ||
overlayOpacity, | ||
setOverlayOpacity, | ||
} = props; | ||
|
||
return ( | ||
<PanelBody | ||
title={ __( 'Overlay settings', 'wdsblocks' ) } | ||
className="block-editor-panel-color-gradient-settings" | ||
> | ||
<ColorPaletteControl | ||
color={ overlayColor } | ||
setColor={ setOverlayColor } | ||
label={ __( 'Color', 'wdsblocks' ) } | ||
/> | ||
<RangeControl | ||
label={ __( 'Opacity', 'wdsblocks' ) } | ||
value={ overlayOpacity } | ||
onChange={ ( value ) => setOverlayOpacity( value ) } | ||
min={ 0 } | ||
max={ 100 } | ||
/> | ||
</PanelBody> | ||
); | ||
} |
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,25 @@ | ||
# `withOverlayColor` # | ||
|
||
`withOverlayColor` is a higher-order component used to apply styling specific to background overlays. | ||
|
||
`withOverlay` calls another HOC, `withBackgroundColor`, to apply some background styling. Both HOCs add custom classes and styles to the wrapped component; `withOverlayColor` additionally adds a child component for the overlay itself, provided the overlay and opacity properties are passed. | ||
|
||
## Usage ## | ||
|
||
```jsx | ||
export default function Edit( props ) { | ||
const { | ||
attributes: { overlayColor, customOverlayColor, overlayOpacity }, | ||
} = props; | ||
|
||
const BlockComponent = withOverlayColor( 'div' ); | ||
|
||
return ( | ||
<BlockComponent | ||
overlayColor={ overlayColor } | ||
customOverlayColor={ customOverlayColor } | ||
overlayOpacity={ overlayOpacity } | ||
/> | ||
); | ||
} | ||
``` |
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,69 @@ | ||
import withBackgroundColor from '../withBackgroundColor'; | ||
|
||
/** | ||
* A HOC for displaying a component with a background overlay color. | ||
* | ||
* @author WebDevStudios | ||
* @since 2.1.0 | ||
* | ||
* @param {WPElement} WrappedComponent The wrapped component to display. | ||
* @return {Function} A function that accepts a single param, `props`, to display the wrapped component. | ||
*/ | ||
export default function withOverlayColor( WrappedComponent ) { | ||
/** | ||
* @author WebDevStudios | ||
* @since 2.0.0 | ||
* | ||
* @param {Object} [props] Properties passed to the component. | ||
* @return {Element} Element to render. | ||
*/ | ||
return function ( props ) { | ||
const { | ||
overlayColor, | ||
customOverlayColor, | ||
overlayOpacity, | ||
className, | ||
style, | ||
children, | ||
...passthruProps | ||
} = props; | ||
|
||
const classes = [ className ], | ||
styles = { ...style }; | ||
|
||
const hasOverlay = overlayColor || customOverlayColor; | ||
|
||
// Add overlay class. | ||
classes.push( hasOverlay ? 'has-background-overlay' : null ); | ||
|
||
// Use withBackgroundColor component to handle shared styling/classes. | ||
const OverlayComponent = withBackgroundColor( WrappedComponent ); | ||
|
||
return ( | ||
<OverlayComponent | ||
className={ classes.filter( Boolean ).join( ' ' ) } | ||
style={ styles } | ||
{ ...passthruProps } | ||
backgroundColor={ overlayColor } | ||
customBackgroundColor={ customOverlayColor } | ||
> | ||
{ hasOverlay && !! overlayOpacity && ( | ||
<div | ||
className="background-overlay" | ||
style={ { | ||
opacity: overlayOpacity / 100, | ||
backgroundColor: 'inherit', | ||
height: '100%', | ||
left: 0, | ||
position: 'absolute', | ||
top: 0, | ||
width: '100%', | ||
zIndex: 1, | ||
} } | ||
></div> | ||
) } | ||
{ children } | ||
</OverlayComponent> | ||
); | ||
}; | ||
} |