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

fix (color picker): shadow color and opacity #3074

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 10 additions & 1 deletion src/block-components/block-div/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deprecationBackgrounColorOpacity } from '../helpers'
import { deprecationBackgrounColorOpacity, deprecateShadowColor } from '../helpers'

import { addFilter } from '@wordpress/hooks'
import { semverCompare } from '~stackable/util'
Expand Down Expand Up @@ -29,3 +29,12 @@ export const deprecateBlockBackgroundColorOpacity = {
return deprecationBackgrounColorOpacity.migrate( 'block%s' )( attributes )
},
}

export const deprecateBlockShadowColor = {
isEligible: attributes => {
return deprecateShadowColor.isEligible( 'block%s' )( attributes )
},
migrate: attributes => {
return deprecateShadowColor.migrate( 'block%s' )( attributes )
},
}
2 changes: 1 addition & 1 deletion src/block-components/block-div/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CustomAttributes } from '../custom-attributes'
import { version as VERSION } from 'stackable'

export { useUniqueId }
export { deprecateBlockBackgroundColorOpacity } from './deprecated'
export { deprecateBlockBackgroundColorOpacity, deprecateBlockShadowColor } from './deprecated'

export const BlockDiv = props => {
const {
Expand Down
11 changes: 10 additions & 1 deletion src/block-components/container-div/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deprecationBackgrounColorOpacity } from '../helpers'
import { deprecationBackgrounColorOpacity, deprecateShadowColor } from '../helpers'

export const deprecateContainerBackgroundColorOpacity = {
isEligible: attributes => {
Expand All @@ -8,3 +8,12 @@ export const deprecateContainerBackgroundColorOpacity = {
return deprecationBackgrounColorOpacity.migrate( 'container%s' )( attributes )
},
}

export const deprecateContainerShadowColor = {
isEligible: attributes => {
return deprecateShadowColor.isEligible( 'container%s' )( attributes )
},
migrate: attributes => {
return deprecateShadowColor.migrate( 'container%s' )( attributes )
},
}
2 changes: 1 addition & 1 deletion src/block-components/container-div/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getUniqueBlockClass, useQueryLoopInstanceId } from '~stackable/util'
import { useBlockAttributesContext } from '~stackable/hooks'
import { applyFilters } from '@wordpress/hooks'

export { deprecateContainerBackgroundColorOpacity } from './deprecated'
export { deprecateContainerBackgroundColorOpacity, deprecateContainerShadowColor } from './deprecated'

export const ContainerDiv = props => {
const attributes = useBlockAttributesContext( attributes => {
Expand Down
4 changes: 4 additions & 0 deletions src/block-components/helpers/borders/attributes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { deprecatedAddAttributes } from './deprecated'

export const borderAttributes = {
borderType: {
type: 'string',
Expand Down Expand Up @@ -32,6 +34,8 @@ export const borderAttributes = {
}

export const addBorderAttributes = ( attrObject, attrNameTemplate = '%s' ) => {
deprecatedAddAttributes( attrObject, attrNameTemplate )

attrObject.add( {
attributes: borderAttributes,
attrNameTemplate,
Expand Down
63 changes: 63 additions & 0 deletions src/block-components/helpers/borders/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
extractRgba, rgbaToHexAlpha, getAttrNameFunction,
} from '~stackable/util'

import { addFilter } from '@wordpress/hooks'
import { dispatch } from '@wordpress/data'

Expand Down Expand Up @@ -32,3 +36,62 @@ addFilter( 'stackable.block-component.helpers.borders', 'borders', ( output, get
} )
}
} )

export const deprecatedAddAttributes = ( attrObject, attrNameTemplate = '%s' ) => {
attrObject.add( {
attributes: {
shadow: {
type: 'string',
default: '',
},
},
versionAdded: '3.0.0',
versionDeprecated: '3.12.11',
attrNameTemplate,
} )
}

export const deprecateShadowColor = {
isEligible: attrNameTemplate => attributes => {
const getAttrName = getAttrNameFunction( attrNameTemplate )
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]

if ( getAttribute( 'shadow' ) || getAttribute( 'shadowHover' ) || getAttribute( 'shadowParentHover' ) ) {
return true
}

return false
},
migrate: attrNameTemplate => attributes => {
const getAttrName = getAttrNameFunction( attrNameTemplate )
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]

const newAttributes = {
...attributes,
}

const shadow = getAttribute( 'shadow' )
const shadowHover = getAttribute( 'shadowHover' ) || shadow
const shadowParentHover = getAttribute( 'shadowParentHover' ) || shadowHover

if ( getAttribute( 'shadow' ) && getAttribute( 'shadow' ).indexOf( 'rgba' ) !== -1 ) {
const { options, color } = extractRgba( shadow )
const hex = rgbaToHexAlpha( color )
newAttributes[ getAttrName( 'shadow' ) ] = `${ options } ${ hex }`
}

if ( getAttribute( 'shadowHover' ) && getAttribute( 'shadowHover' ).indexOf( 'rgba' ) !== -1 ) {
const { options, color } = extractRgba( shadowHover )
const hex = rgbaToHexAlpha( color )
newAttributes[ getAttrName( 'shadowHover' ) ] = `${ options } ${ hex }`
}

if ( getAttribute( 'shadowParentHover' ) && getAttribute( 'shadowParentHover' ).indexOf( 'rgba' ) !== -1 ) {
const { options, color } = extractRgba( shadowParentHover )
const hex = rgbaToHexAlpha( color )
newAttributes[ getAttrName( 'shadowParentHover' ) ] = `${ options } ${ hex }`
}

return newAttributes
},
}
49 changes: 48 additions & 1 deletion src/block-components/typography/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getAttrNameFunction } from '~stackable/util'
import {
extractRgba, rgbaToHexAlpha, getAttrNameFunction,
} from '~stackable/util'

export const deprecatedAddAttributes = ( attrObject, options ) => {
const {
Expand Down Expand Up @@ -49,3 +51,48 @@ export const deprecateTypographyGradientColor = {
return newAttributes
},
}

export const deprecateTypographyShadowColor = {
isEligible: attrNameTemplate => attributes => {
const getAttrName = getAttrNameFunction( attrNameTemplate )
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]

if ( getAttribute( 'textShadow' ) || getAttribute( 'textShadowHover' ) || getAttribute( 'textShadowParentHover' ) ) {
return true
}

return false
},
migrate: attrNameTemplate => attributes => {
const getAttrName = getAttrNameFunction( attrNameTemplate )
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]

const newAttributes = {
...attributes,
}

const shadow = getAttribute( 'textShadow' )
const shadowHover = getAttribute( 'textShadowHover' ) || shadow
const shadowParentHover = getAttribute( 'textShadowParentHover' ) || shadowHover

if ( getAttribute( 'textShadow' ) && getAttribute( 'textShadow' ).indexOf( 'rgba' ) !== -1 ) {
const { options, color } = extractRgba( shadowHover )
const hex = rgbaToHexAlpha( color )
newAttributes[ getAttrName( 'textShadow' ) ] = `${ options } ${ hex }`
}

if ( getAttribute( 'textShadowHover' ) && getAttribute( 'textShadowHover' ).indexOf( 'rgba' ) !== -1 ) {
const { options, color } = extractRgba( shadowHover )
const hex = rgbaToHexAlpha( color )
newAttributes[ getAttrName( 'textShadowHover' ) ] = `${ options } ${ hex }`
}

if ( getAttribute( 'textShadowParentHover' ) && getAttribute( 'textShadowParentHover' ).indexOf( 'rgba' ) !== -1 ) {
const { options, color } = extractRgba( shadowParentHover )
const hex = rgbaToHexAlpha( color )
newAttributes[ getAttrName( 'textShadowParentHover' ) ] = `${ options } ${ hex }`
}

return newAttributes
},
}
2 changes: 1 addition & 1 deletion src/block-components/typography/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
memo,
} from '@wordpress/element'

export { deprecateTypographyGradientColor } from './deprecated'
export { deprecateTypographyGradientColor, deprecateTypographyShadowColor } from './deprecated'

export const Typography = memo( forwardRef( ( props, ref ) => {
const {
Expand Down
24 changes: 23 additions & 1 deletion src/block/accordion/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@ import { Save } from './save'
import { attributes } from './schema'

import { withVersion } from '~stackable/higher-order'
import { deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity } from '~stackable/block-components'
import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
deprecateBlockShadowColor, deprecateContainerShadowColor,
} from '~stackable/block-components'

const deprecated = [
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
save: withVersion( '3.12.11' )( Save ),
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )

return hasBlockShadow || hasContainerShadow
},
migrate: attributes => {
let newAttributes = { ...attributes }

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return newAttributes
},
},
// Support the new combined opacity and color.
{
attributes: attributes( '3.11.9' ),
Expand Down
24 changes: 23 additions & 1 deletion src/block/blockquote/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@ import { Save } from './save'
import { attributes } from './schema'

import { withVersion } from '~stackable/higher-order'
import { deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity } from '~stackable/block-components'
import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
deprecateBlockShadowColor, deprecateContainerShadowColor,
} from '~stackable/block-components'

const deprecated = [
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
save: withVersion( '3.12.11' )( Save ),
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )

return hasBlockShadow || hasContainerShadow
},
migrate: attributes => {
let newAttributes = { ...attributes }

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return newAttributes
},
},
{
// Support the new combined opacity and color.
attributes: attributes( '3.11.9' ),
Expand Down
24 changes: 23 additions & 1 deletion src/block/button-group/deprecated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@
import { Save } from '../save'
import { attributes } from '../schema'
import { withVersion } from '~stackable/higher-order'
import { deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity } from '~stackable/block-components'
import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
deprecateBlockShadowColor, deprecateContainerShadowColor,
} from '~stackable/block-components'

const deprecated = [
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
save: withVersion( '3.12.11' )( Save ),
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )

return hasBlockShadow || hasContainerShadow
},
migrate: attributes => {
let newAttributes = { ...attributes }

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return newAttributes
},
},
// Support the new combined opacity and color.
{
attributes: attributes( '3.11.9' ),
Expand Down
25 changes: 24 additions & 1 deletion src/block/button/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@ import { attributes } from './schema'

import { withVersion } from '~stackable/higher-order'
import {
deprecateBlockBackgroundColorOpacity, deprecateButtonGradientColor, deprecateContainerBackgroundColorOpacity,
deprecateBlockBackgroundColorOpacity, deprecateButtonGradientColor,
deprecateContainerBackgroundColorOpacity, deprecateShadowColor,
deprecateContainerShadowColor, deprecateBlockShadowColor,
} from '~stackable/block-components'

const deprecated = [
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
save: withVersion( '3.12.11' )( Save ),
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )
const hasButtonShadow = deprecateShadowColor.isEligible( 'button%s' )( attributes )

return hasBlockShadow || hasContainerShadow || hasButtonShadow
},
migrate: attributes => {
let newAttributes = { ...attributes }

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'button%s' )( attributes )

return newAttributes
},
},
{
// Support the new combined opacity and color.
attributes: attributes( '3.11.9' ),
Expand Down
28 changes: 27 additions & 1 deletion src/block/call-to-action/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { attributes } from './schema'
* External dependencies
*/
import { withVersion } from '~stackable/higher-order'
import { deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity } from '~stackable/block-components'
import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateShadowColor,
} from '~stackable/block-components'
import compareVersions from 'compare-versions'

/**
Expand All @@ -32,6 +35,29 @@ addFilter( 'stackable.call-to-action.save.innerClassNames', 'stackable/3.8.0', (
} )

const deprecated = [
{
// Support the new shadow color.
attributes: attributes( '3.12.11' ),
save: withVersion( '3.12.11' )( Save ),
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )
const hasTopSeparatorShadow = deprecateShadowColor.isEligible( 'topSeparator%s' )( attributes )
const hasBottomSeparatorShadow = deprecateShadowColor.isEligible( 'bottomSeparator%s' )( attributes )

return hasBlockShadow || hasContainerShadow || hasTopSeparatorShadow || hasBottomSeparatorShadow
},
migrate: attributes => {
let newAttributes = { ...attributes }

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )

return newAttributes
},
},
// Support the new combined opacity and color.
{
attributes: attributes( '3.11.9' ),
Expand Down
Loading
Loading