MCPcopy
hub / github.com/obytes/react-native-template-obytes / Select

Function Select

src/components/ui/select.tsx:142–219  ·  view source on GitHub ↗
(props: SelectProps)

Source from the content-addressed store, hash-verified

140};
141
142export function Select(props: SelectProps) {
143 const {
144 label,
145 value,
146 error,
147 options = [],
148 placeholder = 'select...',
149 disabled = false,
150 onSelect,
151 testID,
152 } = props;
153 const modal = useModal();
154
155 const onSelectOption = React.useCallback(
156 (option: OptionType) => {
157 onSelect?.(option.value);
158 modal.dismiss();
159 },
160 [modal, onSelect],
161 );
162
163 const styles = React.useMemo(
164 () =>
165 selectTv({
166 error: Boolean(error),
167 disabled,
168 }),
169 [error, disabled],
170 );
171
172 const textValue = React.useMemo(
173 () =>
174 value !== undefined
175 ? (options?.filter(t => t.value === value)?.[0]?.label ?? placeholder)
176 : placeholder,
177 [value, options, placeholder],
178 );
179
180 return (
181 <>
182 <View className={styles.container()}>
183 {label && (
184 <Text
185 testID={testID ? `${testID}-label` : undefined}
186 className={styles.label()}
187 >
188 {label}
189 </Text>
190 )}
191 <Pressable
192 className={styles.input()}
193 disabled={disabled}
194 onPress={modal.present}
195 testID={testID ? `${testID}-trigger` : undefined}
196 >
197 <View className="flex-1">
198 <Text className={styles.inputValue()}>{textValue}</Text>
199 </View>

Callers

nothing calls this directly

Calls 1

useModalFunction · 0.90

Tested by

no test coverage detected