/** * External dependencies */ import classNames from 'classnames'; import { _n, sprintf } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/html-entities'; import type { ReactElement } from 'react'; import { Panel } from '@woocommerce/blocks-checkout'; import Label from '@woocommerce/base-components/label'; import { useCallback } from '@wordpress/element'; import { useShippingData, useStoreEvents, } from '@woocommerce/base-context/hooks'; import { sanitizeHTML } from '@woocommerce/utils'; import { debounce } from 'lodash'; /** * Internal dependencies */ import PackageRates from './package-rates'; import type { PackageProps } from './types'; import './style.scss'; export const ShippingRatesControlPackage = ( { packageId, className = '', noResultsMessage, renderOption, packageData, collapsible, showItems, }: PackageProps ): ReactElement => { const { selectShippingRate } = useShippingData(); const { dispatchCheckoutEvent } = useStoreEvents(); const multiplePackages = document.querySelectorAll( '.wc-block-components-shipping-rates-control__package' ).length > 1; // If showItems is not set, we check if we have multiple packages. // We sometimes don't want to show items even if we have multiple packages. const shouldShowItems = showItems ?? multiplePackages; // If collapsible is not set, we check if we have multiple packages. // We sometimes don't want to collapse even if we have multiple packages. const shouldBeCollapsible = collapsible ?? multiplePackages; const header = ( <> { ( shouldBeCollapsible || shouldShowItems ) && (
) } { shouldShowItems && (