Tag List block: Add support for global style (https://github.com/woocommerce/woocommerce-blocks/pull/5528)
* 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:
parent
481f4c8e8e
commit
d096b21504
|
@ -15,6 +15,10 @@ import { withProductDataContext } from '@woocommerce/shared-hocs';
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
import {
|
||||||
|
useColorProps,
|
||||||
|
useTypographyProps,
|
||||||
|
} from '../../../../hooks/style-attributes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product Tag List Block Component.
|
* Product Tag List Block Component.
|
||||||
|
@ -23,9 +27,12 @@ import './style.scss';
|
||||||
* @param {string} [props.className] CSS Class name for the component.
|
* @param {string} [props.className] CSS Class name for the component.
|
||||||
* @return {*} The component.
|
* @return {*} The component.
|
||||||
*/
|
*/
|
||||||
const Block = ( { className } ) => {
|
const Block = ( props ) => {
|
||||||
|
const { className } = props;
|
||||||
const { parentClassName } = useInnerBlockLayoutContext();
|
const { parentClassName } = useInnerBlockLayoutContext();
|
||||||
const { product } = useProductDataContext();
|
const { product } = useProductDataContext();
|
||||||
|
const colorProps = useColorProps( props );
|
||||||
|
const typographyProps = useTypographyProps( props );
|
||||||
|
|
||||||
if ( isEmpty( product.tags ) ) {
|
if ( isEmpty( product.tags ) ) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -35,11 +42,13 @@ const Block = ( { className } ) => {
|
||||||
<div
|
<div
|
||||||
className={ classnames(
|
className={ classnames(
|
||||||
className,
|
className,
|
||||||
|
colorProps.className,
|
||||||
'wc-block-components-product-tag-list',
|
'wc-block-components-product-tag-list',
|
||||||
{
|
{
|
||||||
[ `${ parentClassName }__product-tag-list` ]: parentClassName,
|
[ `${ parentClassName }__product-tag-list` ]: parentClassName,
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
|
style={ { ...colorProps.style, ...typographyProps.style } }
|
||||||
>
|
>
|
||||||
{ __( 'Tags:', 'woo-gutenberg-products-block' ) }{ ' ' }
|
{ __( 'Tags:', 'woo-gutenberg-products-block' ) }{ ' ' }
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Disabled } from '@wordpress/components';
|
import { Disabled } from '@wordpress/components';
|
||||||
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
|
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
|
||||||
|
import { useBlockProps } from '@wordpress/block-editor';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -13,13 +14,14 @@ import withProductSelector from '../shared/with-product-selector';
|
||||||
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
|
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
|
||||||
|
|
||||||
const Edit = ( { attributes } ) => {
|
const Edit = ( { attributes } ) => {
|
||||||
|
const blockProps = useBlockProps();
|
||||||
return (
|
return (
|
||||||
<>
|
<div { ...blockProps }>
|
||||||
<EditProductLink />
|
<EditProductLink />
|
||||||
<Disabled>
|
<Disabled>
|
||||||
<Block { ...attributes } />
|
<Block { ...attributes } />
|
||||||
</Disabled>
|
</Disabled>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,18 @@ import {
|
||||||
BLOCK_ICON as icon,
|
BLOCK_ICON as icon,
|
||||||
BLOCK_DESCRIPTION as description,
|
BLOCK_DESCRIPTION as description,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
import { Save } from './save';
|
||||||
|
import { supports } from './supports';
|
||||||
|
|
||||||
const blockConfig = {
|
const blockConfig = {
|
||||||
|
apiVersion: 2,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
icon: { src: icon },
|
icon: { src: icon },
|
||||||
attributes,
|
attributes,
|
||||||
|
supports,
|
||||||
edit,
|
edit,
|
||||||
|
save: Save,
|
||||||
};
|
};
|
||||||
|
|
||||||
registerExperimentalBlockType( 'woocommerce/product-tag-list', {
|
registerExperimentalBlockType( 'woocommerce/product-tag-list', {
|
||||||
|
|
|
@ -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 ),
|
||||||
|
} ) }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
|
@ -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,
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue