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

Commit

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

* add specific type

* Enable global style for category list block #4965

Enable global style for category list block

* fix import after merge

* add save function

* add feature flag
  • Loading branch information
gigitux authored Feb 14, 2022
1 parent 49d7698 commit ac3e8f7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 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 '../../../../hooks/style-attributes';

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
20 changes: 19 additions & 1 deletion assets/js/atomic/blocks/product-elements/category-list/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* External dependencies
*/
import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import {
isFeaturePluginBuild,
registerExperimentalBlockType,
} from '@woocommerce/block-settings';
import { BlockConfiguration } from '@wordpress/blocks';

/**
Expand All @@ -15,13 +18,28 @@ import {
BLOCK_ICON as icon,
BLOCK_DESCRIPTION as description,
} from './constants';
import { Save } from './save';

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

Expand Down
21 changes: 21 additions & 0 deletions assets/js/atomic/blocks/product-elements/category-list/save.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import { useBlockProps } from '@wordpress/block-editor';

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 comments on commit ac3e8f7

Please sign in to comment.