sort/components/html/picker.tsx
2024-09-07 08:22:11 +07:00

36 lines
1.2 KiB
TypeScript

import React from 'react';
import { TextInput, Alert, NativeSyntheticEvent, TextInputChangeEventData } from 'react-native';
import { Cfg } from './action';
import { Picker } from '@react-native-picker/picker';
import { cfg } from '../lib/cfg';
export function SelectRenderer({
...props
}: {
[key: string]: any;
}) {
const onPress = () => Alert.alert('pressed!');
const { tnode } = props;
const { domNode } = tnode;
const { attribs } = domNode;
const handleChange = (event: any) => {
const config = Cfg.action as { [key: string]: (event: Function) => void };
const custAction: ((event: Function) => void) | null =
(attribs?.action && typeof config[attribs?.action] === 'function')
? config[attribs?.action]
: null;
if (custAction) {
custAction(event); // Pass only the event
}
}
return (
<Picker
selectedValue={cfg.input[attribs.name] ? cfg.input[attribs.name]:null}
onValueChange={cfg.action[attribs.name] ? cfg.action[attribs.name] : null}>
<Picker.Item label="Java" value="java" />
<Picker.Item label="JavaScript" value="js" />
</Picker>
);
}