-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
327 additions
and
147 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
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
} | ||
}, | ||
"supports": { | ||
"inserter": false, | ||
"className": false, | ||
"anchor": true, | ||
"color": { | ||
|
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,95 @@ | ||
import { hasBlockSupport } from '@wordpress/blocks'; | ||
import { TextControl } from '@wordpress/components'; | ||
|
||
export function hasFlexBasisValue( props ) { | ||
return props.attributes?.unitone?.flexBasis !== undefined; | ||
} | ||
|
||
export function resetFlexBasis( { attributes = {}, setAttributes } ) { | ||
delete attributes?.unitone?.flexBasis; | ||
const newUnitone = { ...attributes?.unitone }; | ||
|
||
setAttributes( { | ||
unitone: !! Object.keys( newUnitone ).length ? newUnitone : undefined, | ||
} ); | ||
} | ||
|
||
export function useIsFlexBasisDisabled( { | ||
name: blockName, | ||
attributes: { __unstableUnitoneSupports }, | ||
} = {} ) { | ||
return ( | ||
! hasBlockSupport( blockName, 'unitone.flexBasis' ) && | ||
! __unstableUnitoneSupports?.flexBasis | ||
); | ||
} | ||
|
||
export function FlexBasisEdit( props ) { | ||
const { | ||
label, | ||
attributes: { unitone }, | ||
setAttributes, | ||
} = props; | ||
|
||
return ( | ||
<TextControl | ||
label={ label } | ||
value={ unitone?.flexBasis || '' } | ||
onChange={ ( newValue ) => { | ||
const newUnitone = { | ||
...unitone, | ||
flexBasis: newValue || undefined, | ||
}; | ||
if ( null == newUnitone.flexBasis ) { | ||
delete newUnitone.flexBasis; | ||
} | ||
|
||
setAttributes( { | ||
unitone: !! Object.keys( newUnitone ).length | ||
? newUnitone | ||
: undefined, | ||
} ); | ||
} } | ||
/> | ||
); | ||
} | ||
|
||
export function saveFlexBasisProp( extraProps, blockType, attributes ) { | ||
if ( | ||
! hasBlockSupport( blockType, 'unitone.flexBasis' ) && | ||
! attributes?.__unstableUnitoneSupports?.flexBasis | ||
) { | ||
delete attributes?.unitone?.flexBasis; | ||
if ( | ||
!! attributes?.unitone && | ||
! Object.keys( attributes?.unitone ).length | ||
) { | ||
delete attributes?.unitone; | ||
} | ||
return extraProps; | ||
} | ||
|
||
if ( undefined === attributes?.unitone?.flexBasis ) { | ||
return extraProps; | ||
} | ||
|
||
extraProps.style = { | ||
...extraProps.style, | ||
'--unitone--flex-basis': attributes?.unitone?.flexBasis, | ||
}; | ||
|
||
return extraProps; | ||
} | ||
|
||
export function editFlexBasisProp( settings ) { | ||
const existingGetEditWrapperProps = settings.getEditWrapperProps; | ||
settings.getEditWrapperProps = ( attributes ) => { | ||
let props = {}; | ||
if ( existingGetEditWrapperProps ) { | ||
props = existingGetEditWrapperProps( attributes ); | ||
} | ||
return saveFlexBasisProp( props, settings, attributes ); | ||
}; | ||
|
||
return settings; | ||
} |
Oops, something went wrong.