diff --git a/assets/js/atomic/blocks/product-elements/stock-indicator/block.js b/assets/js/atomic/blocks/product-elements/stock-indicator/block.js index df6a1e30a61..82b737a5f75 100644 --- a/assets/js/atomic/blocks/product-elements/stock-indicator/block.js +++ b/assets/js/atomic/blocks/product-elements/stock-indicator/block.js @@ -14,6 +14,10 @@ import { withProductDataContext } from '@woocommerce/shared-hocs'; * Internal dependencies */ import './style.scss'; +import { + useColorProps, + useTypographyProps, +} from '../../../../hooks/style-attributes'; /** * Product Stock Indicator Block Component. @@ -22,9 +26,12 @@ import './style.scss'; * @param {string} [props.className] CSS Class name for the component. * @return {*} The component. */ -const Block = ( { className } ) => { +const Block = ( props ) => { + const { className } = props; const { parentClassName } = useInnerBlockLayoutContext(); const { product } = useProductDataContext(); + const colorProps = useColorProps( props ); + const typographyProps = useTypographyProps( props ); if ( ! product.id || ! product.is_purchasable ) { return null; @@ -38,6 +45,7 @@ const Block = ( { className } ) => {
{ 'wc-block-components-product-stock-indicator--available-on-backorder': !! isBackordered, } ) } + style={ { ...colorProps.style, ...typographyProps.style } } > { lowStock ? lowStockText( lowStock ) diff --git a/assets/js/atomic/blocks/product-elements/stock-indicator/edit.js b/assets/js/atomic/blocks/product-elements/stock-indicator/edit.js index b08911e3f0b..a29336ad661 100644 --- a/assets/js/atomic/blocks/product-elements/stock-indicator/edit.js +++ b/assets/js/atomic/blocks/product-elements/stock-indicator/edit.js @@ -3,6 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import EditProductLink from '@woocommerce/editor-components/edit-product-link'; +import { useBlockProps } from '@wordpress/block-editor'; /** * Internal dependencies @@ -12,11 +13,12 @@ import withProductSelector from '../shared/with-product-selector'; import { BLOCK_TITLE, BLOCK_ICON } from './constants'; const Edit = ( { attributes } ) => { + const blockProps = useBlockProps(); return ( - <> +
- +
); }; diff --git a/assets/js/atomic/blocks/product-elements/stock-indicator/index.js b/assets/js/atomic/blocks/product-elements/stock-indicator/index.js index 687b95d8415..439ebb8d131 100644 --- a/assets/js/atomic/blocks/product-elements/stock-indicator/index.js +++ b/assets/js/atomic/blocks/product-elements/stock-indicator/index.js @@ -9,6 +9,9 @@ import { registerExperimentalBlockType } from '@woocommerce/block-settings'; import sharedConfig from '../shared/config'; import attributes from './attributes'; import edit from './edit'; +import { Save } from './save'; +import { supports } from './supports'; + import { BLOCK_TITLE as title, BLOCK_ICON as icon, @@ -16,11 +19,14 @@ import { } from './constants'; const blockConfig = { + apiVersion: 2, title, description, icon: { src: icon }, attributes, + supports, edit, + save: Save, }; registerExperimentalBlockType( 'woocommerce/product-stock-indicator', { diff --git a/assets/js/atomic/blocks/product-elements/stock-indicator/save.tsx b/assets/js/atomic/blocks/product-elements/stock-indicator/save.tsx new file mode 100644 index 00000000000..03a720e27df --- /dev/null +++ b/assets/js/atomic/blocks/product-elements/stock-indicator/save.tsx @@ -0,0 +1,21 @@ +/** + * External dependencies + */ +import { useBlockProps } from '@wordpress/block-editor'; +import classnames from 'classnames'; + +type Props = { + attributes: Record< string, unknown > & { + className?: string; + }; +}; + +export const Save = ( { attributes }: Props ): JSX.Element => { + return ( +
+ ); +}; diff --git a/assets/js/atomic/blocks/product-elements/stock-indicator/style.scss b/assets/js/atomic/blocks/product-elements/stock-indicator/style.scss index b2b9e02417d..b9ad469e445 100644 --- a/assets/js/atomic/blocks/product-elements/stock-indicator/style.scss +++ b/assets/js/atomic/blocks/product-elements/stock-indicator/style.scss @@ -3,15 +3,4 @@ margin-bottom: em($gap-small); display: block; @include font-size(small); - - &--in-stock { - color: $in-stock-color; - } - &--out-of-stock { - color: $no-stock-color; - } - &--low-stock, - &--available-on-backorder { - color: $low-stock-color; - } } diff --git a/assets/js/atomic/blocks/product-elements/stock-indicator/supports.js b/assets/js/atomic/blocks/product-elements/stock-indicator/supports.js new file mode 100644 index 00000000000..8d47e2bf6c1 --- /dev/null +++ b/assets/js/atomic/blocks/product-elements/stock-indicator/supports.js @@ -0,0 +1,17 @@ +/** + * External dependencies + */ +import { isFeaturePluginBuild } from '@woocommerce/block-settings'; + +export const supports = { + ...( isFeaturePluginBuild() && { + color: { + text: true, + background: false, + link: false, + }, + } ), + typography: { + fontSize: true, + }, +};