2024-04-23 04:07:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import {
|
|
|
|
InspectorControls,
|
|
|
|
useBlockProps,
|
|
|
|
InnerBlocks,
|
|
|
|
} from '@wordpress/block-editor';
|
|
|
|
import { PanelBody, ColorPicker } from '@wordpress/components';
|
2024-07-24 07:12:38 +00:00
|
|
|
import { type BlockEditProps } from '@wordpress/blocks';
|
|
|
|
|
|
|
|
export type Attributes = {
|
|
|
|
color: string;
|
|
|
|
storeOnly: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type EditProps = BlockEditProps< Attributes >;
|
2024-04-23 04:07:56 +00:00
|
|
|
|
2024-04-26 04:43:08 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2024-07-24 07:12:38 +00:00
|
|
|
export default function Edit( { attributes, setAttributes }: EditProps ) {
|
2024-04-26 04:43:08 +00:00
|
|
|
const { color, storeOnly } = attributes;
|
|
|
|
const blockProps = { ...useBlockProps() };
|
|
|
|
|
|
|
|
if ( storeOnly ) {
|
|
|
|
return (
|
2024-07-24 07:12:38 +00:00
|
|
|
<div { ...blockProps }>
|
|
|
|
<InnerBlocks />
|
|
|
|
</div>
|
2024-04-26 04:43:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-23 04:07:56 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<InspectorControls>
|
|
|
|
<PanelBody title={ __( 'Settings', 'woocommerce' ) }>
|
|
|
|
<ColorPicker
|
|
|
|
color={ color }
|
2024-07-24 07:12:38 +00:00
|
|
|
// @ts-expect-error type is not defined in the library
|
2024-04-23 04:07:56 +00:00
|
|
|
onChange={ ( newColor: string ) =>
|
|
|
|
setAttributes( { color: newColor } )
|
|
|
|
}
|
|
|
|
enableAlpha
|
|
|
|
defaultValue="#bea0f2"
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
2024-04-26 04:43:08 +00:00
|
|
|
<div { ...blockProps }>
|
2024-04-23 04:07:56 +00:00
|
|
|
<InnerBlocks />
|
2024-07-24 07:12:38 +00:00
|
|
|
<style>{ `:root{--woocommerce-coming-soon-color: ${ color } }` }</style>
|
2024-04-23 04:07:56 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|