-
Notifications
You must be signed in to change notification settings - Fork 9
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
9 changed files
with
211 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => 'ef9b4ff8d9255b2758a3'); | ||
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '26721c6dc7cf48bb87ba'); |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
import { | ||
__experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown, | ||
__experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients, | ||
InspectorControls, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
getColorSlugFromValue, | ||
getColorValueFromSlug, | ||
} from '../utility/color.tsx'; | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'blockify/search-input-colors', | ||
( settings, name ) => { | ||
if ( name !== 'core/search' ) { | ||
return settings; | ||
} | ||
|
||
settings.attributes = { | ||
...settings.attributes, | ||
inputBackgroundColor: { | ||
type: 'string', | ||
}, | ||
}; | ||
|
||
return settings; | ||
} | ||
); | ||
|
||
addFilter( | ||
'editor.BlockEdit', | ||
'blockify/search-input-colors', | ||
createHigherOrderComponent( | ||
( BlockEdit ) => { | ||
return ( props: any ) => { | ||
const defaultReturn = <BlockEdit { ...props } />; | ||
|
||
const colorGradientSettings = useMultipleOriginColorsAndGradients(); | ||
|
||
if ( props.name !== 'core/search' ) { | ||
return defaultReturn; | ||
} | ||
|
||
const { | ||
attributes, | ||
setAttributes, | ||
clientId, | ||
} = props; | ||
|
||
const { | ||
inputBackgroundColor, | ||
} = attributes; | ||
|
||
const settings = [ { | ||
label: __( 'Input Background', 'blockify' ), | ||
colorValue: ( typeof inputBackgroundColor === 'string' && inputBackgroundColor?.includes( '-' ) ) ? getColorValueFromSlug( inputBackgroundColor ) : inputBackgroundColor, | ||
onColorChange: ( value: string ) => { | ||
const slug = getColorSlugFromValue( value ); | ||
|
||
setAttributes( { | ||
inputBackgroundColor: slug ? slug : value, | ||
} ); | ||
}, | ||
} ]; | ||
|
||
return ( | ||
<> | ||
<BlockEdit { ...props } /> | ||
<InspectorControls | ||
group={ 'color' } | ||
> | ||
<ColorGradientSettingsDropdown | ||
settings={ settings } | ||
panelId={ clientId } | ||
hasColorsOrGradients={ true } | ||
disableCustomColors={ false } | ||
__experimentalIsRenderedInSidebar | ||
{ ...colorGradientSettings } | ||
/> | ||
</InspectorControls> | ||
</> | ||
); | ||
}; | ||
}, | ||
'withSearchInputColors' | ||
) | ||
); | ||
|
||
addFilter( | ||
'editor.BlockListBlock', | ||
'blockify/search-input-colors', | ||
createHigherOrderComponent( | ||
( BlockListBlock ) => { | ||
return ( props: any ) => { | ||
const defaultReturn = <BlockListBlock { ...props } />; | ||
|
||
if ( props.name !== 'core/search' ) { | ||
return defaultReturn; | ||
} | ||
|
||
const { | ||
attributes, | ||
wrapperProps = {}, | ||
} = props; | ||
|
||
const { | ||
inputBackgroundColor, | ||
borderColor, | ||
} = attributes; | ||
|
||
if ( inputBackgroundColor ) { | ||
const colorValue = inputBackgroundColor?.includes( '-' ) ? `var(--wp--preset--color--${ inputBackgroundColor })` : inputBackgroundColor; | ||
|
||
wrapperProps.style = { | ||
...wrapperProps.style, | ||
'--wp--custom--input--background': colorValue, | ||
}; | ||
} | ||
|
||
if ( borderColor ) { | ||
const colorValue = borderColor?.includes( '-' ) ? `var(--wp--preset--color--${ borderColor })` : borderColor; | ||
|
||
wrapperProps.style = { | ||
...wrapperProps.style, | ||
'--wp--custom--input--border': `var(--wp--custom--border--width,1px) var(--wp--custom--border--style,solid) ${ colorValue }`, | ||
}; | ||
} | ||
|
||
return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />; | ||
}; | ||
}, | ||
'withSearchInputColors' | ||
) | ||
); | ||
|
||
addFilter( | ||
'blocks.getSaveContent.extraProps', | ||
'blockify/search-input-colors', | ||
( extraProps, blockType, attributes ) => { | ||
if ( blockType.name !== 'core/search' ) { | ||
return extraProps; | ||
} | ||
|
||
const { | ||
inputBackgroundColor, | ||
} = attributes; | ||
|
||
if ( inputBackgroundColor ) { | ||
const colorValue = inputBackgroundColor?.includes( '-' ) ? `var(--wp--preset--color--${ inputBackgroundColor })` : inputBackgroundColor; | ||
|
||
extraProps.style = { | ||
...extraProps.style, | ||
'--wp--custom--input--background': colorValue, | ||
}; | ||
} | ||
|
||
return extraProps; | ||
} | ||
); |
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,19 @@ | ||
import { select } from '@wordpress/data'; | ||
import { ColorPalette } from '@wordpress/components'; | ||
import Color = ColorPalette.Color; | ||
|
||
export const getColorSlugFromValue = ( value: string ): string => { | ||
const colors: Color[] = select( 'core/block-editor' )?.getSettings().colors ?? []; | ||
|
||
const color = colors.find( ( color ) => color.color === value ); | ||
|
||
return color?.slug ?? ''; | ||
}; | ||
|
||
export const getColorValueFromSlug = ( slug: string ): string => { | ||
const colors: Color[] = select( 'core/block-editor' )?.getSettings().colors ?? []; | ||
|
||
const color = colors.find( ( color ) => color.slug === slug ); | ||
|
||
return color?.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