mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Migrate SelectBlock to ControlSelect
This commit is contained in:
parent
00b720088a
commit
d24adbfe2f
5 changed files with 57 additions and 57 deletions
|
@ -0,0 +1,53 @@
|
|||
import Select, { components } from 'react-select';
|
||||
|
||||
import data from '../../../utils/data';
|
||||
import { Title, Action, Description } from '../Elements';
|
||||
|
||||
const DEFAULT_ELEMENT_ORDER = [ 'title', 'action', 'description' ];
|
||||
|
||||
const DropdownIndicator = ( props ) => (
|
||||
<components.DropdownIndicator { ...props }>
|
||||
{ data().getImage( 'icon-arrow-down.svg' ) }
|
||||
</components.DropdownIndicator>
|
||||
);
|
||||
|
||||
const ELEMENT_RENDERERS = {
|
||||
title: ( { title } ) => <Title>{ title }</Title>,
|
||||
action: ( { actionProps } ) => (
|
||||
<Action>
|
||||
<Select
|
||||
className="ppcp-r-multiselect"
|
||||
classNamePrefix="ppcp-r"
|
||||
isMulti={ actionProps?.isMulti }
|
||||
options={ actionProps?.options }
|
||||
components={ { DropdownIndicator } }
|
||||
/>
|
||||
</Action>
|
||||
),
|
||||
description: ( { description } ) => (
|
||||
<Description>{ description }</Description>
|
||||
),
|
||||
};
|
||||
|
||||
const ControlSelect = ( {
|
||||
title,
|
||||
description,
|
||||
order = DEFAULT_ELEMENT_ORDER,
|
||||
...props
|
||||
} ) => (
|
||||
<Action>
|
||||
{ order.map( ( elementKey ) => {
|
||||
const RenderElement = ELEMENT_RENDERERS[ elementKey ];
|
||||
return RenderElement ? (
|
||||
<RenderElement
|
||||
key={ elementKey }
|
||||
title={ title }
|
||||
description={ description }
|
||||
actionProps={ props.actionProps }
|
||||
/>
|
||||
) : null;
|
||||
} ) }
|
||||
</Action>
|
||||
);
|
||||
|
||||
export default ControlSelect;
|
Loading…
Add table
Add a link
Reference in a new issue