({
allowCreateWhileLoading = false,
createOptionPosition = 'last',
formatCreateLabel = builtins.formatCreateLabel,
isValidNewOption = builtins.isValidNewOption,
// @ts-ignore
getNewOptionData = builtins.getNewOptionData,
onCreateOption,
options: propsOptions = [],
onChange: propsOnChange,
...restSelectProps
}: BaseCreatableProps<Option, IsMulti, Group>)
| 103 | }; |
| 104 | |
| 105 | export default function useCreatable< |
| 106 | Option, |
| 107 | IsMulti extends boolean, |
| 108 | Group extends GroupBase<Option> |
| 109 | >({ |
| 110 | allowCreateWhileLoading = false, |
| 111 | createOptionPosition = 'last', |
| 112 | formatCreateLabel = builtins.formatCreateLabel, |
| 113 | isValidNewOption = builtins.isValidNewOption, |
| 114 | // @ts-ignore |
| 115 | getNewOptionData = builtins.getNewOptionData, |
| 116 | onCreateOption, |
| 117 | options: propsOptions = [], |
| 118 | onChange: propsOnChange, |
| 119 | ...restSelectProps |
| 120 | }: BaseCreatableProps<Option, IsMulti, Group>): PublicBaseSelectProps< |
| 121 | Option, |
| 122 | IsMulti, |
| 123 | Group |
| 124 | > { |
| 125 | const { |
| 126 | getOptionValue = baseGetOptionValue, |
| 127 | getOptionLabel = baseGetOptionLabel, |
| 128 | inputValue, |
| 129 | isLoading, |
| 130 | isMulti, |
| 131 | value, |
| 132 | name, |
| 133 | } = restSelectProps; |
| 134 | |
| 135 | const newOption = useMemo( |
| 136 | () => |
| 137 | isValidNewOption(inputValue, cleanValue(value), propsOptions, { |
| 138 | getOptionValue, |
| 139 | getOptionLabel, |
| 140 | }) |
| 141 | ? getNewOptionData(inputValue, formatCreateLabel(inputValue)) |
| 142 | : undefined, |
| 143 | [ |
| 144 | formatCreateLabel, |
| 145 | getNewOptionData, |
| 146 | getOptionLabel, |
| 147 | getOptionValue, |
| 148 | inputValue, |
| 149 | isValidNewOption, |
| 150 | propsOptions, |
| 151 | value, |
| 152 | ] |
| 153 | ); |
| 154 | |
| 155 | const options = useMemo( |
| 156 | () => |
| 157 | (allowCreateWhileLoading || !isLoading) && newOption |
| 158 | ? createOptionPosition === 'first' |
| 159 | ? [newOption, ...propsOptions] |
| 160 | : [...propsOptions, newOption] |
| 161 | : propsOptions, |
| 162 | [ |
no test coverage detected
searching dependent graphs…