PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Admin / fields / AsyncSelectOption / index.tsx

index.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Admin/fields/AsyncSelectOption/index.tsx

78 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { AsyncPaginate } from 'react-select-async-paginate';
3 import { AdminSectionField } from '@givewp/components/AdminDetailsPage/AdminSection';
4 import { SelectOption } from '@givewp/admin/types';
5
6 import styles from './styles.module.scss';
7
8
9 /**
10 * @since 4.11.0
11 */
12 export default function AsyncSelectOption({
13 name,
14 label,
15 description = '',
16 selectedOption,
17 loadOptions,
18 mapOptionsForMenu,
19 handleChange,
20 isLoadingError,
21 errorMessage,
22 searchPlaceholder,
23 loadingMessage,
24 loadingError,
25 ariaLabel,
26 noOptionsMessage,
27 children
28 }: AsyncSelectOptionProps) {
29 return (
30 <AdminSectionField error={errorMessage}>
31 <label htmlFor={name}>{label}</label>
32 {description && <p>{description}</p>}
33 {isLoadingError ? (
34 <div role="alert" style={{ color: 'var(--givewp-red-500)', fontSize: '0.875rem' }}>
35 {loadingError}
36 </div>
37 ) : (
38 <AsyncPaginate
39 inputId={name}
40 className={styles.searchableSelect}
41 classNamePrefix="searchableSelect"
42 value={selectedOption}
43 loadOptions={loadOptions}
44 mapOptionsForMenu={mapOptionsForMenu}
45 onChange={handleChange}
46 debounceTimeout={600}
47 placeholder={searchPlaceholder}
48 loadingMessage={() => loadingMessage}
49 noOptionsMessage={() => noOptionsMessage}
50 aria-label={ariaLabel}
51 />
52 )}
53 {children}
54 </AdminSectionField>
55 );
56 }
57
58 interface AsyncSelectOptionProps {
59 name: string;
60 label: string;
61 description?: string;
62 handleChange: (selectedOption: SelectOption) => void;
63 selectedOption: SelectOption | null;
64 loadOptions: (searchInput: string) => Promise<{
65 options: SelectOption[];
66 hasMore: boolean;
67 }>;
68 mapOptionsForMenu: (options: SelectOption[]) => SelectOption[];
69 isLoadingError: Error | null;
70 errorMessage: string;
71 searchPlaceholder: string;
72 loadingMessage: string;
73 loadingError: string,
74 noOptionsMessage: string;
75 ariaLabel: string;
76 children?: JSX.Element | JSX.Element[];
77 }
78