2020-05-13 15:48:03 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
2021-08-20 11:55:30 +00:00
|
|
|
import type { PaymentMethodIcon as PaymentMethodIconType } from '@woocommerce/type-defs/payment-method-icon';
|
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 {
|
|
|
|
icons: PaymentMethodIconType[];
|
|
|
|
align: string;
|
|
|
|
}
|
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.
|
|
|
|
*
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {Object} props Component props.
|
|
|
|
* @param {Array} props.icons Array of icons object configs or ids as strings.
|
|
|
|
* @param {string} props.align How to align the icon.
|
2020-04-29 10:57:58 +00:00
|
|
|
*/
|
2021-08-20 11:55:30 +00:00
|
|
|
export const PaymentMethodIcons = ( {
|
|
|
|
icons = [],
|
|
|
|
align = 'center',
|
|
|
|
}: PaymentMethodIconsProps ): JSX.Element | null => {
|
2020-04-29 10:57:58 +00:00
|
|
|
const iconConfigs = normalizeIconConfig( icons );
|
|
|
|
|
|
|
|
if ( iconConfigs.length === 0 ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:53:42 +00:00
|
|
|
const containerClass = classnames(
|
|
|
|
'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',
|
|
|
|
}
|
|
|
|
);
|
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;
|