Update `PackageRates` component to show single rates as a radio button (#46284)

* Show a single shipping option as radio button

* Add changelog

* Update unused dependency
This commit is contained in:
Thomas Roberts 2024-04-16 13:39:55 +01:00 committed by GitHub
parent 7d41472206
commit ab60527d6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 28 deletions

View File

@ -2,10 +2,7 @@
* External dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import {
RadioControl,
RadioControlOptionLayout,
} from '@woocommerce/blocks-components';
import { RadioControl } from '@woocommerce/blocks-components';
import type { CartShippingPackageShippingRate } from '@woocommerce/types';
import { usePrevious } from '@woocommerce/base-hooks';
@ -71,31 +68,17 @@ const PackageRates = ( {
return noResultsMessage;
}
if ( rates.length > 1 ) {
return (
<RadioControl
className={ className }
onChange={ ( value: string ) => {
setSelectedOption( value );
onSelectRate( value );
} }
highlightChecked={ highlightChecked }
disabled={ disabled }
selected={ selectedOption }
options={ rates.map( renderOption ) }
/>
);
}
const { label, secondaryLabel, description, secondaryDescription } =
renderOption( rates[ 0 ] );
return (
<RadioControlOptionLayout
label={ label }
secondaryLabel={ secondaryLabel }
description={ description }
secondaryDescription={ secondaryDescription }
<RadioControl
className={ className }
onChange={ ( value: string ) => {
setSelectedOption( value );
onSelectRate( value );
} }
highlightChecked={ highlightChecked }
disabled={ disabled }
selected={ selectedOption }
options={ rates.map( renderOption ) }
/>
);
};

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Ensure consistent styling for single shipping methods in the Checkout block