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

Commit 7ba8105

Browse files
authored
Convert Product summary to TypeScript (#4099)
* Add WordCountType type * Convert Summary to TypeScript * Convert ProductSummary to TypeScript
1 parent 58646b3 commit 7ba8105

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

assets/js/base/components/cart-checkout/product-summary/index.js renamed to assets/js/base/components/cart-checkout/product-summary/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import PropTypes from 'prop-types';
55
import Summary from '@woocommerce/base-components/summary';
66
import { blocksConfig } from '@woocommerce/block-settings';
77

8+
interface ProductSummaryProps {
9+
className?: string;
10+
shortDescription?: string;
11+
fullDescription?: string;
12+
}
813
/**
914
* Returns an element containing a summary of the product.
1015
*
@@ -17,7 +22,7 @@ const ProductSummary = ( {
1722
className,
1823
shortDescription = '',
1924
fullDescription = '',
20-
} ) => {
25+
}: ProductSummaryProps ): JSX.Element | null => {
2126
const source = shortDescription ? shortDescription : fullDescription;
2227

2328
if ( ! source ) {
@@ -34,10 +39,4 @@ const ProductSummary = ( {
3439
);
3540
};
3641

37-
ProductSummary.propTypes = {
38-
className: PropTypes.string,
39-
shortDescription: PropTypes.string,
40-
fullDescription: PropTypes.string,
41-
};
42-
4342
export default ProductSummary;

assets/js/base/components/summary/index.js renamed to assets/js/base/components/summary/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
* External dependencies
33
*/
44
import { RawHTML, useMemo } from '@wordpress/element';
5+
import { WordCountType } from '@woocommerce/block-settings';
56

67
/**
78
* Internal dependencies
89
*/
910
import { generateSummary } from './utils';
1011

12+
interface SummaryProps {
13+
className?: string;
14+
source: string;
15+
maxLength?: number;
16+
countType?: WordCountType;
17+
}
1118
/**
1219
* Summary component.
1320
*
@@ -22,7 +29,7 @@ export const Summary = ( {
2229
maxLength = 15,
2330
countType = 'words',
2431
className = '',
25-
} ) => {
32+
}: SummaryProps ): JSX.Element => {
2633
const summaryText = useMemo( () => {
2734
return generateSummary( source, maxLength, countType );
2835
}, [ source, maxLength, countType ] );

assets/js/settings/blocks/constants.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
*/
44
import { getSetting, STORE_PAGES } from '@woocommerce/settings';
55

6+
export type WordCountType =
7+
| 'words'
8+
| 'characters_excluding_spaces'
9+
| 'characters_including_spaces';
10+
611
interface WcBlocksConfig {
712
buildPhase: number;
813
pluginUrl: string;
914
productCount: number;
1015
restApiRoutes: Record< string, string[] >;
11-
wordCountType: string;
16+
wordCountType: WordCountType;
1217
}
1318

1419
export const blocksConfig = getSetting( 'wcBlocksConfig', {

0 commit comments

Comments
 (0)