* Converted config files

* Converted constants file

* Converted attributes file

* Coverted edit file

* Convert block file

* Remove space from config
This commit is contained in:
Tom Cafferkey 2021-10-12 09:21:00 +01:00 committed by GitHub
parent 8475bc7bad
commit 0f4161aff9
7 changed files with 27 additions and 17 deletions

View File

@ -1,4 +1,4 @@
export const blockAttributes = {
export const blockAttributes: Record< string, Record< string, unknown > > = {
productId: {
type: 'number',
default: 0,

View File

@ -2,7 +2,6 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import {
useInnerBlockLayoutContext,
@ -10,11 +9,15 @@ import {
} from '@woocommerce/shared-context';
import { isEmpty } from 'lodash';
import { withProductDataContext } from '@woocommerce/shared-hocs';
import { HTMLAttributes } from 'react';
/**
* Internal dependencies
*/
import './style.scss';
import { Attributes } from './types';
type Props = Attributes & HTMLAttributes< HTMLDivElement >;
/**
* Product Category Block Component.
@ -23,7 +26,7 @@ import './style.scss';
* @param {string} [props.className] CSS Class name for the component.
* @return {*} The component.
*/
const Block = ( { className } ) => {
const Block = ( { className }: Props ): JSX.Element | null => {
const { parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext();
@ -57,8 +60,4 @@ const Block = ( { className } ) => {
);
};
Block.propTypes = {
className: PropTypes.string,
};
export default withProductDataContext( Block );

View File

@ -4,12 +4,12 @@
import { __ } from '@wordpress/i18n';
import { folder, Icon } from '@woocommerce/icons';
export const BLOCK_TITLE = __(
export const BLOCK_TITLE: string = __(
'Product Category List',
'woo-gutenberg-products-block'
);
export const BLOCK_ICON = <Icon srcElement={ folder } />;
export const BLOCK_DESCRIPTION = __(
export const BLOCK_ICON: JSX.Element = <Icon srcElement={ folder } />;
export const BLOCK_DESCRIPTION: string = __(
'Display a list of categories belonging to a product.',
'woo-gutenberg-products-block'
);

View File

@ -11,8 +11,13 @@ import EditProductLink from '@woocommerce/editor-components/edit-product-link';
import Block from './block';
import withProductSelector from '../shared/with-product-selector';
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
import { Attributes } from './types';
const Edit = ( { attributes } ) => {
interface Props {
attributes: Attributes;
}
const Edit = ( { attributes }: Props ): JSX.Element => {
return (
<>
<EditProductLink />

View File

@ -2,11 +2,12 @@
* External dependencies
*/
import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { BlockConfiguration } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import sharedConfig from '../shared/config';
import sharedConfig from './../shared/config';
import attributes from './attributes';
import edit from './edit';
import {
@ -15,7 +16,8 @@ import {
BLOCK_DESCRIPTION as description,
} from './constants';
const blockConfig = {
const blockConfig: BlockConfiguration = {
...sharedConfig,
title,
description,
icon: {
@ -26,7 +28,7 @@ const blockConfig = {
edit,
};
registerExperimentalBlockType( 'woocommerce/product-category-list', {
...sharedConfig,
...blockConfig,
} );
registerExperimentalBlockType(
'woocommerce/product-category-list',
blockConfig
);

View File

@ -0,0 +1,3 @@
export interface Attributes {
productId: number;
}

View File

@ -52,6 +52,7 @@
"@woocommerce/knobs": [ "storybook/knobs" ],
"@woocommerce/settings": [ "assets/js/settings/shared" ],
"@woocommerce/shared-context": [ "assets/js/shared/context" ],
"@woocommerce/shared-hocs": [ "assets/js/shared/hocs" ],
"@woocommerce/type-defs/*": [ "assets/js/types/type-defs/*" ],
"@woocommerce/types": [ "assets/js/types" ]
}