Skip to content

Commit

Permalink
fix now working with shadows without spread
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 13, 2024
1 parent 3891ae6 commit dc1be92
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/components/shadow-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ const ShadowFilterControl = props => {
}

// Split string into 5 parts, the last part contains the rest of the string.
function splitStringIntoParts( str ) {
function splitStringIntoParts( str, splitTo = 5 ) {
const parts = str.split( ' ' )
const result = []
for ( let i = 0; i < 4; i++ ) {
for ( let i = 0; i < splitTo - 1; i++ ) {
if ( parts.length ) {
result.push( parts.shift() )
} else {
Expand All @@ -158,15 +158,21 @@ const ShadowFilterControl = props => {
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 = color
const [ horizontalOffset, verticalOffset, blur, spread, color ] = splitStringIntoParts( _value, props.isFilter ? 4 : 5 )
filters.horizontalOffset = isNaN( parseInt( horizontalOffset ) ) ? 0 : parseInt( horizontalOffset )
filters.verticalOffset = isNaN( parseInt( verticalOffset ) ) ? 0 : parseInt( verticalOffset )
filters.blur = isNaN( parseInt( blur ) ) ? 0 : parseInt( blur )
filters.shadowSpread = isNaN( parseInt( spread ) ) ? 0 : parseInt( spread )
filters.shadowColor = color || ''

if ( props.isFilter ) {
filters.shadowSpread = ''
filters.shadowColor = spread
}

setFilters( { ...filters } )
}
}, [ value ] )
}, [ value, props.isFilter ] )

return (
<Popover
Expand Down Expand Up @@ -220,6 +226,7 @@ const ShadowFilterControl = props => {

ShadowFilterControl.defaultProps = {
hasInset: true,
isFilter: false,
}

const ShadowControl = memo( props => {
Expand Down Expand Up @@ -302,6 +309,7 @@ const ShadowControl = memo( props => {
hover={ props.hover }
parentProps={ props }
hasInset={ props.hasInset }
isFilter={ props.isFilter }
onEscape={ () => setIsPopoverOpen( false ) }
/>
) }
Expand Down

0 comments on commit dc1be92

Please sign in to comment.