import { useLayoutEffect, useState } from "react"; import { View } from "react-native"; import stylesheet from "./stylesheet"; import { NCoreUIKitLocalize, NCoreUIKitTheme, DateTimePicker, PageContainer, CodeViewer, SelectBox, Header, Switch, Text } from "ncore-ui-kit"; import { useNavigation } from "@react-navigation/native"; import type RootStackParamList from "../../../navigation/type"; import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; import type { DateTimePickerPickerType, IDateTimePickerProps } from "ncore-ui-kit"; const DATE_TIME_PICKER_TYPES: Array = [ "default", "danger", "warning", "success", "info", "question" ]; const DATE_TIME_PICKER_SPREAD_BEHAVIOURS: Array = [ "baseline", "stretch", "free" ]; const DATE_TIME_PICKER_PICKER_TYPES: Array = [ "date", "time", "date-time" ]; const DATE_TIME_PICKER_VARIANTS: Array = [ "single", "range", "rrule" ]; const DATE_TIME_PICKER_TYPES_DATA = DATE_TIME_PICKER_TYPES.map((item) => ({ __title: item as string, __key: item as string })); const DATE_TIME_PICKER_SPREAD_BEHAVIOURS_DATA = DATE_TIME_PICKER_SPREAD_BEHAVIOURS.map((item) => ({ __title: item as string, __key: item as string })); const DATE_TIME_PICKER_PICKER_TYPES_DATA = DATE_TIME_PICKER_PICKER_TYPES.map( (item) => ({ __title: item as string, __key: item as string }), ); const DATE_TIME_PICKER_VARIANTS_DATA = DATE_TIME_PICKER_VARIANTS.map( (item) => ({ __title: item as string, __key: item as string }), ); const DateTimePickerPage = () => { const { radiuses, borders, spaces, colors } = NCoreUIKitTheme.useContext(); const { localize } = NCoreUIKitLocalize.useContext(); const navigation = useNavigation>(); const [ spreadIndex, setSpreadIndex ] = useState(1); const [ pickerTypeIndex, setPickerTypeIndex ] = useState(0); const [ variantIndex, setVariantIndex ] = useState(0); const [ typeIndex, setTypeIndex ] = useState(0); const [ isDisabled, setIsDisabled ] = useState(false); useLayoutEffect(() => { navigation.setOptions({ header: () =>
, headerShown: true }); }, []); return {localize("dateTimePicker-desc")} {localize("usage")} "} language="tsx" /> { if (selectedItems.length > 0) { const index = DATE_TIME_PICKER_TYPES.indexOf( selectedItems[0]! .__key as IDateTimePickerProps["type"], ); if (index !== -1) setTypeIndex(index); } }} initialSelectedItems={ DATE_TIME_PICKER_TYPES_DATA[typeIndex] ? [ DATE_TIME_PICKER_TYPES_DATA[typeIndex]! ] : [] } title={localize("dateTimePicker-changeType")} titleExtractor={(item) => item.__title} keyExtractor={(item) => item.__key} data={DATE_TIME_PICKER_TYPES_DATA} spreadBehaviour="free" /> { if (selectedItems.length > 0) { const index = DATE_TIME_PICKER_SPREAD_BEHAVIOURS.indexOf( selectedItems[0]! .__key as IDateTimePickerProps["spreadBehaviour"], ); if (index !== -1) setSpreadIndex(index); } }} initialSelectedItems={ DATE_TIME_PICKER_SPREAD_BEHAVIOURS_DATA[spreadIndex] ? [ DATE_TIME_PICKER_SPREAD_BEHAVIOURS_DATA[ spreadIndex ]! ] : [] } title={localize("dateTimePicker-changeSpread")} data={DATE_TIME_PICKER_SPREAD_BEHAVIOURS_DATA} titleExtractor={(item) => item.__title} keyExtractor={(item) => item.__key} spreadBehaviour="free" /> { if (selectedItems.length > 0) { const index = DATE_TIME_PICKER_PICKER_TYPES.indexOf( selectedItems[0]! .__key as DateTimePickerPickerType, ); if (index !== -1) setPickerTypeIndex(index); } }} initialSelectedItems={ DATE_TIME_PICKER_PICKER_TYPES_DATA[pickerTypeIndex] ? [ DATE_TIME_PICKER_PICKER_TYPES_DATA[ pickerTypeIndex ]! ] : [] } data={DATE_TIME_PICKER_PICKER_TYPES_DATA} titleExtractor={(item) => item.__title} title={localize( "dateTimePicker-changePickerType", )} keyExtractor={(item) => item.__key} spreadBehaviour="free" /> { if (selectedItems.length > 0) { const index = DATE_TIME_PICKER_VARIANTS.indexOf( selectedItems[0]! .__key as IDateTimePickerProps["variant"], ); if (index !== -1) setVariantIndex(index); } }} initialSelectedItems={ DATE_TIME_PICKER_VARIANTS_DATA[variantIndex] ? [ DATE_TIME_PICKER_VARIANTS_DATA[variantIndex]! ] : [] } title={localize("dateTimePicker-changeVariant")} titleExtractor={(item) => item.__title} data={DATE_TIME_PICKER_VARIANTS_DATA} keyExtractor={(item) => item.__key} spreadBehaviour="free" /> { setIsDisabled(!isDisabled); }} spreadBehaviour="free" isActive={isDisabled} /> ; }; export default DateTimePickerPage;