Skip to content

Commit

Permalink
fix (shadow color): support custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 11, 2024
1 parent c72e178 commit 3d1baa7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/components/shadow-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,35 @@ const ShadowFilterControl = props => {

useEffect( () => {
if ( value ) {
let _value = value
let hexValue = ''
_value = _value.replace( /#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/g, value => {
hexValue = value
return ''
} ).trim()

let _value = value.trim()
if ( _value.startsWith( 'inset' ) ) {
filters.inset = true
_value = _value.replace( /^inset\s*/, '' )
} else {
filters.inset = false
}

const [ horizontalOffset, verticalOffset, blur, spread ] = _value.split( ' ' )
// Split string into 5 parts, the last part contains the rest of the string.
function splitStringIntoParts( str ) {
const parts = str.split( ' ' )
const result = []
for ( let i = 0; i < 4; i++ ) {
if ( parts.length ) {
result.push( parts.shift() )
} else {
result.push( '' )
}
}
result.push( parts.join( ' ' ) )
return result
}

const [ horizontalOffset, verticalOffset, blur, spread, color ] = splitStringIntoParts( _value )
filters.horizontalOffset = parseInt( horizontalOffset )
filters.verticalOffset = parseInt( verticalOffset )
filters.blur = parseInt( blur )
filters.shadowSpread = isNaN( parseInt( spread ) ) ? '' : parseInt( spread )
filters.shadowColor = hexValue
filters.shadowColor = color
setFilters( { ...filters } )
}
}, [ value ] )
Expand Down

0 comments on commit 3d1baa7

Please sign in to comment.