/** * External dependencies */ import PropTypes from 'prop-types'; import classNames from 'classnames'; import { _n, sprintf } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/html-entities'; import Label from '@woocommerce/base-components/label'; import Title from '@woocommerce/base-components/title'; import { useSelectShippingRate } from '@woocommerce/base-hooks'; /** * Internal dependencies */ import Panel from '../../panel'; import PackageRates from './package-rates'; import './style.scss'; const Package = ( { packageId, className, noResultsMessage, renderOption, packageData, collapsible = false, collapse = false, showItems = false, } ) => { const { selectShippingRate, selectedShippingRate } = useSelectShippingRate( packageId, packageData.shipping_rates ); const header = ( <> { ( showItems || collapsible ) && ( { packageData.name } ) } { showItems && ( ) } ); const body = ( ); if ( collapsible ) { return ( { body } ); } return (
{ header } { body }
); }; Package.propTypes = { renderOption: PropTypes.func, packageData: PropTypes.shape( { shipping_rates: PropTypes.arrayOf( PropTypes.object ).isRequired, items: PropTypes.arrayOf( PropTypes.shape( { name: PropTypes.string.isRequired, key: PropTypes.string.isRequired, quantity: PropTypes.number.isRequired, } ).isRequired ).isRequired, } ).isRequired, className: PropTypes.string, collapsible: PropTypes.bool, noResultsMessage: PropTypes.node, showItems: PropTypes.bool, }; export default Package;