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-07-21 09:35:32 +00:00
|
|
|
import { IconType, ColorItem } from '.././types';
|
2021-10-29 02:35:17 +00:00
|
|
|
|
2021-11-17 15:39:07 +00:00
|
|
|
interface Props {
|
|
|
|
count: number;
|
2023-06-12 20:23:52 +00:00
|
|
|
icon?: IconType;
|
2023-07-21 09:35:32 +00:00
|
|
|
iconColor: ColorItem | { color: undefined };
|
|
|
|
productCountColor: ColorItem | { color: undefined };
|
2021-11-17 15:39:07 +00:00
|
|
|
}
|
|
|
|
|
2023-06-19 09:42:37 +00:00
|
|
|
const QuantityBadge = ( {
|
|
|
|
count,
|
|
|
|
icon,
|
|
|
|
iconColor,
|
|
|
|
productCountColor,
|
|
|
|
}: Props ): JSX.Element => {
|
2023-06-12 20:23:52 +00:00
|
|
|
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-07-21 09:35:32 +00:00
|
|
|
color={ iconColor.color }
|
2023-06-19 09:42:37 +00:00
|
|
|
size={ 20 }
|
2023-06-12 20:23:52 +00:00
|
|
|
icon={ getIcon( icon ) }
|
2021-11-17 15:39:07 +00:00
|
|
|
/>
|
2023-06-19 09:42:37 +00:00
|
|
|
<span
|
|
|
|
className="wc-block-mini-cart__badge"
|
2023-07-21 09:35:32 +00:00
|
|
|
style={ { background: productCountColor.color } }
|
2023-06-19 09:42:37 +00:00
|
|
|
>
|
2023-05-11 15:23:36 +00:00
|
|
|
{ count > 0 ? count : '' }
|
|
|
|
</span>
|
2021-11-17 15:39:07 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
2021-10-29 02:35:17 +00:00
|
|
|
|
|
|
|
export default QuantityBadge;
|