Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Tag List block: Add support for global style (#5528)
Browse files Browse the repository at this point in the history
* Product title: add support global style #4965

* add specific type

* add custom save function

* move hooks in a specific folder

* Tag List block: add support for global style #4965

Tag List Block: add support for global style

* add feature flag
  • Loading branch information
gigitux authored Feb 14, 2022
1 parent c324204 commit ddd31b7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
11 changes: 10 additions & 1 deletion assets/js/atomic/blocks/product-elements/tag-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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>
Expand Down
6 changes: 4 additions & 2 deletions assets/js/atomic/blocks/product-elements/tag-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>
);
};

Expand Down
5 changes: 5 additions & 0 deletions assets/js/atomic/blocks/product-elements/tag-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
21 changes: 21 additions & 0 deletions assets/js/atomic/blocks/product-elements/tag-list/save.tsx
Original file line number Diff line number Diff line change
@@ -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 ),
} ) }
/>
);
};
17 changes: 17 additions & 0 deletions assets/js/atomic/blocks/product-elements/tag-list/supports.js
Original file line number Diff line number Diff line change
@@ -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,
},
};

0 comments on commit ddd31b7

Please sign in to comment.