2020-05-13 15:48:03 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2022-12-23 11:59:02 +00:00
|
|
|
import type { PaymentMethodIcons as PaymentMethodIconsType } from '@woocommerce/types';
|
2020-05-13 15:48:03 +00:00
|
|
|
|
2020-04-29 10:57:58 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import PaymentMethodIcon from './payment-method-icon';
|
|
|
|
import { getCommonIconProps } from './common-icons';
|
|
|
|
import { normalizeIconConfig } from './utils';
|
|
|
|
import './style.scss';
|
|
|
|
|
2021-08-20 11:55:30 +00:00
|
|
|
interface PaymentMethodIconsProps {
|
2021-09-15 16:36:02 +00:00
|
|
|
icons: PaymentMethodIconsType;
|
|
|
|
align?: 'left' | 'right' | 'center';
|
2021-10-25 15:31:22 +00:00
|
|
|
className?: string;
|
2021-08-20 11:55:30 +00:00
|
|
|
}
|
2020-04-29 10:57:58 +00:00
|
|
|
/**
|
|
|
|
* For a given list of icons, render each as a list item, using common icons
|
|
|
|
* where available.
|
|
|
|
*/
|
2021-08-20 11:55:30 +00:00
|
|
|
export const PaymentMethodIcons = ( {
|
|
|
|
icons = [],
|
|
|
|
align = 'center',
|
2021-10-25 15:31:22 +00:00
|
|
|
className,
|
2021-08-20 11:55:30 +00:00
|
|
|
}: PaymentMethodIconsProps ): JSX.Element | null => {
|
2020-04-29 10:57:58 +00:00
|
|
|
const iconConfigs = normalizeIconConfig( icons );
|
|
|
|
|
|
|
|
if ( iconConfigs.length === 0 ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-05-31 03:49:36 +00:00
|
|
|
const containerClass = clsx(
|
2020-06-17 09:53:42 +00:00
|
|
|
'wc-block-components-payment-method-icons',
|
|
|
|
{
|
|
|
|
'wc-block-components-payment-method-icons--align-left':
|
|
|
|
align === 'left',
|
|
|
|
'wc-block-components-payment-method-icons--align-right':
|
|
|
|
align === 'right',
|
2021-10-25 15:31:22 +00:00
|
|
|
},
|
|
|
|
className
|
2020-06-17 09:53:42 +00:00
|
|
|
);
|
2020-05-13 15:48:03 +00:00
|
|
|
|
2020-04-29 10:57:58 +00:00
|
|
|
return (
|
2020-05-13 15:48:03 +00:00
|
|
|
<div className={ containerClass }>
|
2020-04-29 10:57:58 +00:00
|
|
|
{ iconConfigs.map( ( icon ) => {
|
|
|
|
const iconProps = {
|
|
|
|
...icon,
|
|
|
|
...getCommonIconProps( icon.id ),
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<PaymentMethodIcon
|
|
|
|
key={ 'payment-method-icon-' + icon.id }
|
|
|
|
{ ...iconProps }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentMethodIcons;
|