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

Commit

Permalink
Enable global style for category list block #4965
Browse files Browse the repository at this point in the history
Enable global style for category list block
  • Loading branch information
gigitux committed Jan 4, 2022
1 parent dbc8e38 commit 5c04092
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 11 additions & 1 deletion assets/js/atomic/blocks/product-elements/category-list/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { HTMLAttributes } from 'react';
*/
import './style.scss';
import { Attributes } from './types';
import {
useColorProps,
useTypographyProps,
} from '../../../../utils/style-attributes-utils';

type Props = Attributes & HTMLAttributes< HTMLDivElement >;

Expand All @@ -26,10 +30,14 @@ type Props = Attributes & HTMLAttributes< HTMLDivElement >;
* @param {string} [props.className] CSS Class name for the component.
* @return {*} The component.
*/
const Block = ( { className }: Props ): JSX.Element | null => {
const Block = ( props: Props ): JSX.Element | null => {
const { className } = props;
const { parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext();

const colorProps = useColorProps( props );
const typographyProps = useTypographyProps( props );

if ( isEmpty( product.categories ) ) {
return null;
}
Expand All @@ -39,10 +47,12 @@ const Block = ( { className }: Props ): JSX.Element | null => {
className={ classnames(
className,
'wc-block-components-product-category-list',
colorProps.className,
{
[ `${ parentClassName }__product-category-list` ]: parentClassName,
}
) }
style={ { ...colorProps.style, ...typographyProps.style } }
>
{ __( 'Categories:', 'woo-gutenberg-products-block' ) }{ ' ' }
<ul>
Expand Down
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 @@ -18,13 +19,15 @@ interface Props {
}

const Edit = ( { attributes }: Props ): JSX.Element => {
const blockProps = useBlockProps();

return (
<>
<div { ...blockProps }>
<EditProductLink />
<Disabled>
<Block { ...attributes } />
</Disabled>
</>
</div>
);
};

Expand Down
11 changes: 11 additions & 0 deletions assets/js/atomic/blocks/product-elements/category-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ import {

const blockConfig: BlockConfiguration = {
...sharedConfig,
apiVersion: 2,
title,
description,
icon: { src: icon },
attributes,
edit,
supports: {
color: {
text: true,
link: true,
background: false,
},
typography: {
fontSize: true,
},
},
};

registerExperimentalBlockType(
Expand Down

0 comments on commit 5c04092

Please sign in to comment.