|
| 1 | +import componentTypes from '@data-driven-forms/react-form-renderer/dist/cjs/component-types'; |
| 2 | + |
| 3 | +const options = [ |
| 4 | + { |
| 5 | + label: 'Morton', |
| 6 | + value: 'Jenifer' |
| 7 | + }, |
| 8 | + { |
| 9 | + label: 'Vega', |
| 10 | + value: 'Cervantes' |
| 11 | + }, |
| 12 | + { |
| 13 | + label: 'Gilbert', |
| 14 | + value: 'Wallace' |
| 15 | + }, |
| 16 | + { |
| 17 | + label: 'Jami', |
| 18 | + value: 'Cecilia' |
| 19 | + }, |
| 20 | + { |
| 21 | + label: 'Ebony', |
| 22 | + value: 'Kay' |
| 23 | + } |
| 24 | +]; |
| 25 | + |
| 26 | +const loadOptions = (inputValue = '') => { |
| 27 | + return new Promise((res) => |
| 28 | + setTimeout(() => { |
| 29 | + if (inputValue.length === 0) { |
| 30 | + return res(options.slice(0, 3)); |
| 31 | + } |
| 32 | + |
| 33 | + return res(options.filter(({ label }) => label.toLocaleLowerCase().includes(inputValue.toLocaleLowerCase()))); |
| 34 | + }, 1500) |
| 35 | + ); |
| 36 | +}; |
| 37 | + |
| 38 | +const selectSchema = { |
| 39 | + fields: [ |
| 40 | + { |
| 41 | + component: componentTypes.SELECT, |
| 42 | + name: 'simple-portal-select', |
| 43 | + label: 'Simple portal select', |
| 44 | + options, |
| 45 | + menuIsPortal: true |
| 46 | + }, |
| 47 | + { |
| 48 | + component: componentTypes.SELECT, |
| 49 | + name: 'simple-async-select', |
| 50 | + label: 'Simple async select', |
| 51 | + loadOptions |
| 52 | + }, |
| 53 | + { |
| 54 | + component: componentTypes.SELECT, |
| 55 | + name: 'simple-searchable-async-select', |
| 56 | + label: 'Simple searchable async select', |
| 57 | + loadOptions, |
| 58 | + isSearchable: true |
| 59 | + }, |
| 60 | + { |
| 61 | + component: componentTypes.SELECT, |
| 62 | + name: 'multi-async-select', |
| 63 | + label: 'multi async select', |
| 64 | + loadOptions, |
| 65 | + isMulti: true |
| 66 | + }, |
| 67 | + { |
| 68 | + component: componentTypes.SELECT, |
| 69 | + name: 'searchable-multi-async-select', |
| 70 | + label: 'Multi searchable async select', |
| 71 | + loadOptions, |
| 72 | + isSearchable: true |
| 73 | + }, |
| 74 | + { |
| 75 | + component: componentTypes.SELECT, |
| 76 | + name: 'multi-simple-select', |
| 77 | + label: 'Simple multi select', |
| 78 | + options, |
| 79 | + isMulti: true |
| 80 | + }, |
| 81 | + { |
| 82 | + component: componentTypes.SELECT, |
| 83 | + name: 'multi-searchable-select', |
| 84 | + label: 'Searchable multi select', |
| 85 | + options, |
| 86 | + isMulti: true, |
| 87 | + isSearchable: true |
| 88 | + }, |
| 89 | + { |
| 90 | + component: componentTypes.SELECT, |
| 91 | + name: 'multi-clearable-searchable-select', |
| 92 | + label: 'Searchable clearable multi select', |
| 93 | + options, |
| 94 | + isMulti: true, |
| 95 | + isSearchable: true, |
| 96 | + isClearable: true |
| 97 | + }, |
| 98 | + { |
| 99 | + component: componentTypes.SELECT, |
| 100 | + name: 'simple-select', |
| 101 | + label: 'Simple-select', |
| 102 | + options |
| 103 | + }, |
| 104 | + { |
| 105 | + component: componentTypes.SELECT, |
| 106 | + name: 'disabled-select', |
| 107 | + label: 'Disabled-select', |
| 108 | + options, |
| 109 | + isDisabled: true |
| 110 | + }, |
| 111 | + { |
| 112 | + component: componentTypes.SELECT, |
| 113 | + name: 'clearable-select', |
| 114 | + label: 'Clearable-select', |
| 115 | + options, |
| 116 | + isClearable: true |
| 117 | + }, |
| 118 | + { |
| 119 | + component: componentTypes.SELECT, |
| 120 | + name: 'searchable-select', |
| 121 | + label: 'Clearable-select', |
| 122 | + options, |
| 123 | + isSearchable: true |
| 124 | + }, |
| 125 | + { |
| 126 | + component: componentTypes.SELECT, |
| 127 | + name: 'dosbaled-option-select', |
| 128 | + label: 'Disabled-option-select', |
| 129 | + options: [...options, { label: 'Disabled option', value: 'disabled', isDisabled: true }] |
| 130 | + } |
| 131 | + ] |
| 132 | +}; |
| 133 | + |
| 134 | +export default { |
| 135 | + ...selectSchema |
| 136 | +}; |
0 commit comments