2021-10-29 02:35:17 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-06-12 20:23:52 +00:00
|
|
|
import { cartOutline, bag, bagAlt } from '@woocommerce/icons';
|
2022-02-01 16:54:38 +00:00
|
|
|
import { Icon } from '@wordpress/icons';
|
2021-10-29 02:35:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2023-06-12 20:23:52 +00:00
|
|
|
import { IconType } from '.././types';
|
2021-10-29 02:35:17 +00:00
|
|
|
|
2021-11-17 15:39:07 +00:00
|
|
|
interface Props {
|
|
|
|
count: number;
|
|
|
|
colorClassNames?: string;
|
2023-06-12 20:23:52 +00:00
|
|
|
icon?: IconType;
|
2021-11-17 15:39:07 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 20:23:52 +00:00
|
|
|
const QuantityBadge = ( { count, icon }: Props ): JSX.Element => {
|
|
|
|
function getIcon( iconName?: 'cart' | 'bag' | 'bag-alt' ) {
|
|
|
|
switch ( iconName ) {
|
|
|
|
case 'cart':
|
|
|
|
return cartOutline;
|
|
|
|
case 'bag':
|
|
|
|
return bag;
|
|
|
|
case 'bag-alt':
|
|
|
|
return bagAlt;
|
|
|
|
default:
|
|
|
|
return cartOutline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 15:39:07 +00:00
|
|
|
return (
|
|
|
|
<span className="wc-block-mini-cart__quantity-badge">
|
|
|
|
<Icon
|
|
|
|
className="wc-block-mini-cart__icon"
|
2023-06-12 20:23:52 +00:00
|
|
|
size={ 32 }
|
|
|
|
icon={ getIcon( icon ) }
|
2021-11-17 15:39:07 +00:00
|
|
|
/>
|
2023-05-11 15:23:36 +00:00
|
|
|
<span className="wc-block-mini-cart__badge">
|
|
|
|
{ count > 0 ? count : '' }
|
|
|
|
</span>
|
2021-11-17 15:39:07 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
2021-10-29 02:35:17 +00:00
|
|
|
|
|
|
|
export default QuantityBadge;
|