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

Commit 19c7165

Browse files
Alex Floriscaopr
andauthored
Move RadioControland RadioControlAccordion components to components package (#11312)
Co-authored-by: Thomas Roberts <[email protected]>
1 parent 25cc415 commit 19c7165

File tree

16 files changed

+50
-37
lines changed

16 files changed

+50
-37
lines changed

assets/js/base/components/cart-checkout/local-pickup-select/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/**
22
* External dependencies
33
*/
4-
import { RadioControlOption } from '@woocommerce/base-components/radio-control/types';
4+
import {
5+
RadioControl,
6+
RadioControlOptionType,
7+
} from '@woocommerce/blocks-components';
58
import { CartShippingPackageShippingRate } from '@woocommerce/types';
6-
/**
7-
* Internal dependencies
8-
*/
9-
import RadioControl from '../../radio-control';
109

1110
interface LocalPickupSelectProps {
1211
title?: string | undefined;
@@ -17,7 +16,7 @@ interface LocalPickupSelectProps {
1716
renderPickupLocation: (
1817
location: CartShippingPackageShippingRate,
1918
pickupLocationsCount: number
20-
) => RadioControlOption;
19+
) => RadioControlOptionType;
2120
packageCount: number;
2221
}
2322
/**

assets/js/base/components/cart-checkout/shipping-rates-control-package/package-rates.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* External dependencies
33
*/
44
import { useState, useEffect } from '@wordpress/element';
5-
import RadioControl, {
5+
import {
6+
RadioControl,
67
RadioControlOptionLayout,
7-
} from '@woocommerce/base-components/radio-control';
8+
} from '@woocommerce/blocks-components';
89
import type { CartShippingPackageShippingRate } from '@woocommerce/types';
910
import { usePrevious } from '@woocommerce/base-hooks';
1011

assets/js/base/components/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export * from './filter-reset-button';
1010
export * from './filter-submit-button';
1111
export * from './form';
1212
export * from './form-token-field';
13-
export * from './formatted-monetary-amount';
1413
export * from './label';
1514
export * from './load-more-button';
1615
export * from './loading-mask';
@@ -23,8 +22,6 @@ export * from './product-name';
2322
export * from './product-price';
2423
export * from './product-rating';
2524
export * from './quantity-selector';
26-
export * from './radio-control';
27-
export * from './radio-control-accordion';
2825
export * from './read-more';
2926
export * from './reviews';
3027
export * from './sidebar-layout';

assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { cloneElement, useCallback } from '@wordpress/element';
99
import { useEditorContext } from '@woocommerce/base-context';
1010
import classNames from 'classnames';
11-
import RadioControlAccordion from '@woocommerce/base-components/radio-control-accordion';
11+
import { RadioControlAccordion } from '@woocommerce/blocks-components';
1212
import { useDispatch, useSelect } from '@wordpress/data';
1313
import { getPaymentMethods } from '@woocommerce/blocks-registry';
1414

assets/js/blocks/cart-checkout-shared/payment-methods/saved-payment-method-options.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import { useMemo, cloneElement } from '@wordpress/element';
55
import { __, sprintf } from '@wordpress/i18n';
66
import { noticeContexts } from '@woocommerce/base-context';
7-
import RadioControl from '@woocommerce/base-components/radio-control';
7+
import {
8+
RadioControl,
9+
RadioControlOptionType,
10+
} from '@woocommerce/blocks-components';
811
import {
912
usePaymentMethodInterface,
1013
useStoreEvents,
@@ -13,7 +16,6 @@ import { PAYMENT_STORE_KEY } from '@woocommerce/block-data';
1316
import { useDispatch, useSelect } from '@wordpress/data';
1417
import { getPaymentMethods } from '@woocommerce/blocks-registry';
1518
import { isNull } from '@woocommerce/types';
16-
import { RadioControlOption } from '@woocommerce/base-components/radio-control/types';
1719

1820
/**
1921
* Internal dependencies
@@ -87,7 +89,7 @@ const SavedPaymentMethodOptions = () => {
8789
const { removeNotice } = useDispatch( 'core/notices' );
8890
const { dispatchCheckoutEvent } = useStoreEvents();
8991

90-
const options = useMemo< RadioControlOption[] >( () => {
92+
const options = useMemo< RadioControlOptionType[] >( () => {
9193
const types = Object.keys( savedPaymentMethods );
9294

9395
// Get individual payment methods from saved payment methods and put them into a unique array.
@@ -145,7 +147,7 @@ const SavedPaymentMethodOptions = () => {
145147
} );
146148
return mappedOptions.filter(
147149
( option ) => typeof option !== 'undefined'
148-
) as RadioControlOption[];
150+
) as RadioControlOptionType[];
149151
}, [
150152
savedPaymentMethods,
151153
paymentMethods,

assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,24 @@ jest.mock( '../saved-payment-method-options', () => ( { onChange } ) => {
2727
);
2828
} );
2929

30-
jest.mock(
31-
'@woocommerce/base-components/radio-control-accordion',
32-
() =>
33-
( { onChange } ) =>
34-
(
35-
<>
36-
<span>Payment method options</span>
37-
<button onClick={ () => onChange( 'credit-card' ) }>
38-
Select new payment
39-
</button>
40-
</>
41-
)
42-
);
30+
jest.mock( '@woocommerce/blocks-components', () => {
31+
const originalModule = jest.requireActual(
32+
'@woocommerce/blocks-components'
33+
);
34+
35+
return {
36+
__esModule: true,
37+
...originalModule,
38+
RadioControlAccordion: ( { onChange } ) => (
39+
<>
40+
<span>Payment method options</span>
41+
<button onClick={ () => onChange( 'credit-card' ) }>
42+
Select new payment
43+
</button>
44+
</>
45+
),
46+
};
47+
} );
4348

4449
const originalSelect = jest.requireActual( '@wordpress/data' ).select;
4550
const selectMock = jest

assets/js/blocks/checkout/inner-blocks/checkout-pickup-options-block/block.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import {
1010
} from '@wordpress/element';
1111
import { useShippingData, useStoreCart } from '@woocommerce/base-context/hooks';
1212
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
13-
import { FormattedMonetaryAmount } from '@woocommerce/blocks-components';
13+
import {
14+
FormattedMonetaryAmount,
15+
RadioControlOptionType,
16+
} from '@woocommerce/blocks-components';
1417
import { decodeEntities } from '@wordpress/html-entities';
1518
import { getSetting } from '@woocommerce/settings';
1619
import { Icon, mapMarker } from '@wordpress/icons';
17-
import type { RadioControlOption } from '@woocommerce/base-components/radio-control/types';
1820
import { CartShippingPackageShippingRate } from '@woocommerce/types';
1921
import {
2022
isPackageRateCollectable,
@@ -67,7 +69,7 @@ const getPickupDetails = (
6769
const renderPickupLocation = (
6870
option: CartShippingPackageShippingRate,
6971
packageCount: number
70-
): RadioControlOption => {
72+
): RadioControlOptionType => {
7173
const priceWithTaxes = getSetting( 'displayCartPricesIncludingTax', false )
7274
? parseInt( option.price, 10 ) + parseInt( option.taxes, 10 )
7375
: option.price;

bin/webpack-entries.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const getBlockEntries = ( relativePath ) => {
166166
const entries = {
167167
styling: {
168168
// Packages styles
169-
'packages-style': glob.sync( './packages/**/index.js' ),
169+
'packages-style': glob.sync( './packages/**/index.{t,j}s' ),
170170

171171
// Shared blocks code
172172
'wc-blocks': './assets/js/index.js',
@@ -195,7 +195,7 @@ const entries = {
195195
wcBlocksSharedHocs: './assets/js/shared/hocs/index.js',
196196
priceFormat: './packages/prices/index.js',
197197
blocksCheckout: './packages/checkout/index.js',
198-
blocksComponents: './packages/components/index.js',
198+
blocksComponents: './packages/components/index.ts',
199199
},
200200
main: {
201201
// Shared blocks code

packages/checkout/components/order-local-pickup-packages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
CartShippingPackageShippingRate,
88
} from '@woocommerce/type-defs/cart';
99
import { Component } from '@wordpress/element';
10-
import { RadioControlOption } from '@woocommerce/base-components/radio-control/types';
1110

1211
/**
1312
* Internal dependencies
1413
*/
1514
import { createSlotFill } from '../../slot';
15+
import type { RadioControlOption } from '../../../../packages/components/radio-control/types';
1616

1717
const slotName = '__experimentalOrderLocalPickupPackages';
1818
const {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
export { default as CheckboxList } from './checkbox-list';
2+
export { Chip, RemovableChip } from './chip';
23
export { default as Label } from './label';
34
export { default as FormattedMonetaryAmount } from './formatted-monetary-amount';
4-
export { Chip, RemovableChip } from './chip';
5+
export {
6+
default as RadioControl,
7+
RadioControlOption,
8+
RadioControlOptionLayout,
9+
} from './radio-control';
10+
export type { RadioControlOption as RadioControlOptionType } from './radio-control/types';
11+
export { default as RadioControlAccordion } from './radio-control-accordion';
512
export { default as Spinner } from './spinner';

0 commit comments

Comments
 (0)