-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add background style to editor & frontend
- Loading branch information
Showing
10 changed files
with
153 additions
and
21 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,3 @@ | ||
.wp-block-paragraph{ | ||
background: transparent !important; | ||
} |
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,29 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
import tinycolor from 'tinycolor2'; | ||
|
||
/** | ||
* Generate overlay | ||
* | ||
* @param {string} colors comma seperated list of colors | ||
* @param {number} opacity overlay opacity | ||
* | ||
* @returns {string} color overlay | ||
*/ | ||
const getOverlay = ( colors, opacity ) => { | ||
const objColors = colors.split( ',' ); | ||
const overlayAlpha = opacity / 10; | ||
|
||
const cssColor = objColors.map( ( colorCode )=> { | ||
const color = tinycolor( colorCode ); | ||
color.toRgbString(); // "rgb(255, 0, 0)" | ||
color.setAlpha( overlayAlpha ); | ||
color.toRgbString(); // "rgba(255, 0, 0, 0.5)" | ||
return color; | ||
} ).join( ',' ); | ||
|
||
return cssColor; | ||
}; | ||
|
||
export default getOverlay; |
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,80 @@ | ||
/** | ||
* Internal Dependencies | ||
*/ | ||
import getOverlay from './get-overlay'; | ||
|
||
/** | ||
* Generate Style Object for background | ||
*/ | ||
|
||
function getStyle( attributes ) { | ||
// Block Settings | ||
const { | ||
backgroundType, | ||
solidColor, | ||
gradient, | ||
mediaURL, | ||
overlay, | ||
overlayType, | ||
opacity, | ||
} = attributes; | ||
|
||
// Style | ||
let style = {}; | ||
|
||
switch ( backgroundType ) { | ||
case 'color': | ||
style = { background: solidColor }; | ||
break; | ||
|
||
case 'gradient': | ||
style = { background: `linear-gradient(to bottom, ${ gradient })` }; | ||
break; | ||
|
||
case 'image': | ||
// TOOD: Reafctor | ||
if ( overlay && ( 'color' === overlayType || 'gradient' === overlayType ) ) { | ||
switch ( overlayType ) { | ||
case 'color': | ||
if ( solidColor ) { | ||
const overlaySolid = `${ solidColor }, ${ solidColor }`; | ||
style = { | ||
background: `linear-gradient(to bottom, ${ getOverlay( overlaySolid, opacity ) } ), url( ${ mediaURL } )`, | ||
backgroundSize: 'cover', | ||
}; | ||
} else { | ||
style = { | ||
background: `url( ${ mediaURL } )`, | ||
backgroundSize: 'cover', | ||
}; | ||
} | ||
break; | ||
|
||
case 'gradient': | ||
if ( gradient ) { | ||
style = { | ||
background: `linear-gradient(to bottom, ${ getOverlay( gradient, opacity ) }), url( ${ mediaURL } )`, | ||
backgroundSize: 'cover', | ||
}; | ||
} else { | ||
style = { | ||
background: `url( ${ mediaURL } )`, | ||
backgroundSize: 'cover', | ||
}; | ||
} | ||
|
||
break; | ||
} | ||
} else { | ||
style = { | ||
background: `url( ${ mediaURL } )`, | ||
backgroundSize: 'cover', | ||
}; | ||
} | ||
|
||
break; | ||
} | ||
return style; | ||
} | ||
|
||
export default getStyle; |