* Product title: add support global style woocommerce/woocommerce-blocks#4965

* add specific type

* add custom save function

* move hooks in a specific folder

* Tag List block: add support for global style woocommerce/woocommerce-blocks#4965

Tag List Block: add support for global style

* add feature flag
This commit is contained in:
Luigi Teschio 2022-02-14 11:34:28 +01:00 committed by GitHub
parent 481f4c8e8e
commit d096b21504
5 changed files with 57 additions and 3 deletions

View File

@ -15,6 +15,10 @@ import { withProductDataContext } from '@woocommerce/shared-hocs';
* Internal dependencies
*/
import './style.scss';
import {
useColorProps,
useTypographyProps,
} from '../../../../hooks/style-attributes';
/**
* Product Tag List Block Component.
@ -23,9 +27,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 ( isEmpty( product.tags ) ) {
return null;
@ -35,11 +42,13 @@ const Block = ( { className } ) => {
<div
className={ classnames(
className,
colorProps.className,
'wc-block-components-product-tag-list',
{
[ `${ parentClassName }__product-tag-list` ]: parentClassName,
}
) }
style={ { ...colorProps.style, ...typographyProps.style } }
>
{ __( 'Tags:', 'woo-gutenberg-products-block' ) }{ ' ' }
<ul>

View File

@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Disabled } from '@wordpress/components';
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
import { useBlockProps } from '@wordpress/block-editor';
/**
* Internal dependencies
@ -13,13 +14,14 @@ import withProductSelector from '../shared/with-product-selector';
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
const Edit = ( { attributes } ) => {
const blockProps = useBlockProps();
return (
<>
<div { ...blockProps }>
<EditProductLink />
<Disabled>
<Block { ...attributes } />
</Disabled>
</>
</div>
);
};

View File

@ -14,13 +14,18 @@ import {
BLOCK_ICON as icon,
BLOCK_DESCRIPTION as description,
} from './constants';
import { Save } from './save';
import { supports } from './supports';
const blockConfig = {
apiVersion: 2,
title,
description,
icon: { src: icon },
attributes,
supports,
edit,
save: Save,
};
registerExperimentalBlockType( 'woocommerce/product-tag-list', {

View File

@ -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 (
<div
{ ...useBlockProps.save( {
className: classnames( 'is-loading', attributes.className ),
} ) }
/>
);
};

View File

@ -0,0 +1,17 @@
/**
* External dependencies
*/
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
export const supports = {
...( isFeaturePluginBuild() && {
color: {
text: true,
background: false,
link: true,
},
} ),
typography: {
fontSize: true,
},
};