{
- updateAttributes( {
- 'overlay-background-color':
- newColor || '#222222',
- } );
- },
+ onChange: ( newColor ) =>
+ handleColorChange(
+ 'overlay-background-color',
+ newColor
+ ),
},
{
label: __( 'Text', 'blablablocks-formats' ),
value:
activeAttributes[ 'overlay-text-color' ] ||
'#FFFFFF',
- onChange: ( newColor ) => {
- updateAttributes( {
- 'overlay-text-color': newColor || '#FFFFFF',
- } );
- },
+ onChange: ( newColor ) =>
+ handleColorChange(
+ 'overlay-text-color',
+ newColor
+ ),
},
] }
/>
@@ -259,14 +268,7 @@ function OverlayTabContent( {
accessibleWhenDisabled={ true }
className="reset-button"
disabled={ ! overLaySettingsEnabled }
- onClick={ () => {
- removeAttributes( [
- 'overlay-placement',
- 'overlay-background-color',
- 'overlay-text-color',
- 'offset',
- ] );
- } }
+ onClick={ handleReset }
variant="tertiary"
__next40pxDefaultSize={ true }
>
@@ -278,82 +280,36 @@ function OverlayTabContent( {
}
/**
- * IconTabContent Renders the content for the icon tab.
- *
- * @param {Object} props - The properties passed to the component.
- * @param {Object} props.activeAttributes - The active attributes of the infotip.
- * @param {Function} props.updateAttributes - The function to call when the icon tab is updated.
- * @param {Function} props.removeAttributes - The function to call when the icon tab is removed.
- * @return {JSX.Element} - The rendered icon tab content.
+ * IconTabContent
*/
function IconTabContent( {
activeAttributes,
updateAttributes,
removeAttributes,
} ) {
- // Get the selected block
const selectedBlock = useSelect(
( select ) => select( 'core/block-editor' ).getSelectedBlock(),
[]
);
- // Get editor colors array
const { colors = [] } = useSelect(
( select ) => select( 'core/block-editor' ).getSettings() || {},
[]
);
- // Compute the paragraph text color from block attributes:
const blockStyle = selectedBlock?.attributes?.style || {};
const explicitTextColor = blockStyle?.color?.text;
const textColorSlug = selectedBlock?.attributes?.textColor;
-
- // Resolve a fallback from the themes colors if slug is used
const slugColor =
textColorSlug &&
colors.find( ( c ) => c.slug === textColorSlug )?.color;
-
- // Pick whichever color we have (explicit > slug > undefined)
const defaultIconColor = explicitTextColor || slugColor;
- const icons = [
- {
- label: __( 'Info', 'blablablocks-formats' ),
- graphic: info,
- id: 'info',
- },
- {
- label: __( 'Help', 'blablablocks-formats' ),
- graphic: help,
- id: 'help',
- },
- {
- label: __( 'Caution', 'blablablocks-formats' ),
- graphic: caution,
- id: 'caution',
- },
- {
- label: __( 'Error', 'blablablocks-formats' ),
- graphic: error,
- id: 'error',
- },
- {
- label: __( 'Not allowed', 'blablablocks-formats' ),
- graphic: notAllowed,
- id: 'notAllowed',
- },
- {
- label: __( 'Star', 'blablablocks-formats' ),
- graphic: starEmpty,
- id: 'starEmpty',
- },
- ];
-
const iconEnabled = activeAttributes[ 'icon-enabled' ] === 'true';
const currentIconColor =
activeAttributes[ 'icon-color' ] || defaultIconColor;
- const onToggleIcon = () => {
+ const handleToggleIcon = () => {
if ( iconEnabled ) {
removeAttributes( [
'icon-enabled',
@@ -362,17 +318,34 @@ function IconTabContent( {
'icon-type',
] );
} else {
- updateAttributes( {
- 'icon-enabled': 'true',
- } );
+ updateAttributes( { 'icon-enabled': 'true' } );
}
};
+ const handleIconType = ( iconId ) => {
+ updateAttributes( { 'icon-type': iconId } );
+ };
+
+ const handlePositionChange = ( newValue ) => {
+ updateAttributes( { 'icon-position': newValue } );
+ };
+
+ const handleColorChange = ( newColor ) => {
+ updateAttributes( { 'icon-color': newColor || defaultIconColor } );
+ };
+
+ const handleReset = () => {
+ removeAttributes( [
+ 'icon-enabled',
+ 'icon-position',
+ 'icon-color',
+ 'icon-type',
+ ] );
+ };
+
// Show the info icon enabled as a default when no icon type is set, and icons are just enabled.
if ( iconEnabled && ! activeAttributes[ 'icon-type' ] ) {
- updateAttributes( {
- 'icon-type': 'info',
- } );
+ updateAttributes( { 'icon-type': 'info' } );
}
return (
@@ -384,7 +357,7 @@ function IconTabContent( {
@@ -392,7 +365,7 @@ function IconTabContent( {
{ __( 'Type', 'blablablocks-formats' ) }