import React, { useState, useRef } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { Calendar } from './calendar'; import Cell from '../cell'; import Utils from '../utils/date'; import useTranslate from '../hooks/useTranslate'; import { DemoCard, DemoPage } from '../configprovider/styles/demo.page'; interface Day { day: string | number; type: string; } interface T { 'ce5c5446': string; 'c38a08ef': string; 'b840c88f': string; 'a74a1fd4': string; '8dab2f66': string; 'cfbdc781': string; 'c3a3a1d2': string; 'e51e4582': string; '7db1a8b2': string; 'a52bef0c': string; 'd04fcbda': string; '0aaad620': string; '60a53514': string; '781b07fd': string; '1076d771': string; '6ab47cd2': string; } const CalendarDemo = () => { const [translated] = useTranslate({ 'zh-CN': { 'ce5c5446': '基础用法', 'c38a08ef': '选择单个日期', 'b840c88f': '请选择', 'a74a1fd4': '选择日期区间', '8dab2f66': '至', 'cfbdc781': '快捷选择', 'c3a3a1d2': '选择日期', 'e51e4582': '平铺展示', '7db1a8b2': '选择多个日期', 'a52bef0c': '已选择', 'd04fcbda': '自定义日历', '0aaad620': '自定义按钮', '60a53514': '自定义时间文案', '781b07fd': '去某个月', '1076d771': '最近七天', '6ab47cd2': '当月', }, 'zh-TW': { 'ce5c5446': '基礎翻譯', 'c38a08ef': '選擇日期', 'b840c88f': '請選擇', 'a74a1fd4': '選擇日期區間', '8dab2f66': '至', 'cfbdc781': '快捷選擇', 'c3a3a1d2': '選擇日期', 'e51e4582': '平鋪展示', '7db1a8b2': '選擇多個日期', 'a52bef0c': '已選擇', 'd04fcbda': '自定義日曆', '0aaad620': '自定義按鈕', '60a53514': '自定義時間文案', '781b07fd': '去某個月', '1076d771': '最近七天', '6ab47cd2': '當月', }, 'en-US': { 'ce5c5446': 'Basic usage', 'c38a08ef': 'select a single date', 'b840c88f': 'please choose', 'a74a1fd4': 'Select date range', '8dab2f66': 'to', 'cfbdc781': 'quick selection', 'c3a3a1d2': 'select date', 'e51e4582': 'Tiled display', '7db1a8b2': 'select multiple dates', 'a52bef0c': 'chosen', 'd04fcbda': 'custom calendar', '0aaad620': 'custom button', '60a53514': 'Custom time copy', '781b07fd': 'Go Date', '1076d771': 'Last Seven Days', '6ab47cd2': 'This Month', }, }); const [date, setDate] = useState('2022-08-10'); const [date1, setDate1] = useState(['2020-01-23', '2020-01-26']); const [date2, setDate2] = useState('2020-07-08'); const [date3, setDate3] = useState(''); const [date4, setDate4] = useState([]); const [date5, setDate5] = useState(['2020-01-23', '2020-01-26']); const [date6, setDate6] = useState(['2020-01-23', '2020-01-26']); const [date7, setDate7] = useState(['2021-12-23', '2021-12-26']); const [dateWeek, setDateWeek] = useState(''); const [isVisible, setIsVisible] = useState(false); const [isVisible1, setIsVisible1] = useState(false); const [isVisible3, setIsVisible3] = useState(false); const [isVisible4, setIsVisible4] = useState(false); const [isVisible5, setIsVisible5] = useState(false); const [isVisible6, setIsVisible6] = useState(false); const [isVisible7, setIsVisible7] = useState(false); const calendarRef = useRef(null); const openSwitch = () => { setIsVisible(true); }; const openSwitch1 = () => { setIsVisible1(true); }; const openSwitch3 = () => { setIsVisible3(true); }; const openSwitch4 = () => { setIsVisible4(true); }; const openSwitch5 = () => { setIsVisible5(true); }; const openSwitch6 = () => { setIsVisible6(true); }; const openSwitch7 = () => { setIsVisible7(true); }; const closeSwitch = () => { setIsVisible(false); }; const closeSwitch1 = () => { setIsVisible1(false); }; const closeSwitch3 = () => { setIsVisible3(false); }; const closeSwitch4 = () => { setIsVisible4(false); }; const closeSwitch5 = () => { setIsVisible5(false); }; const closeSwitch6 = () => { setIsVisible6(false); }; const closeSwitch7 = () => { setIsVisible7(false); }; const setChooseValue = (param: string) => { setDate(param[3]); setDateWeek(param[4]); }; const setChooseValue1 = (param: string) => { setDate1([...[param[0][3], param[1][3]]]); }; const setChooseValue2 = (param: string) => { setDate2(param[3]); console.log(param[3]); }; const setChooseValue3 = (param: string) => { setDate3(param[3]); }; const setChooseValue4 = (chooseData: any) => { const dateArr = chooseData.map((item: any) => { return item[3]; }); setDate4([...dateArr]); }; const setChooseValue5 = (param: string) => { setDate5([...[param[0][3], param[1][3]]]); }; const setChooseValue6 = (param: string) => { setDate6([...[param[0][3], param[1][3]]]); }; const setChooseValue7 = (param: string) => { setDate7([...[param[0][3], param[1][3]]]); }; const select = (param: string) => { console.log(param); }; const goDate = () => { if (calendarRef.current) { calendarRef.current.scrollToDate('2022-04-01'); } }; const clickBtn = () => { const date = [Utils.date2Str(new Date()), Utils.getDay(6)]; setDate7(date); }; const clickBtn1 = () => { const date = new Date(); const year = date.getFullYear(); let month: any = date.getMonth() + 1; month = month < 10 ? `0${month}` : `${month}`; const yearMonth = `${year}-${month}`; const currMonthDays = Utils.getMonthDays(`${year}`, `${month}`); setDate7([`${yearMonth}-01`, `${yearMonth}-${currMonthDays}`]); }; const onDay = (date: Day) => { return {date.day <= 9 ? `0${date.day}` : date.day}; }; const onBottomInfo = (date: Day) => { let currDate = ''; if (date && date.day <= 10 && date.day > 20) { currDate = ''; } else { currDate = 'mid'; } return {currDate}; }; const onBtn = () => { return ( {translated['781b07fd']} {translated['1076d771']} {translated['6ab47cd2']} ); }; return ( ); }; const styles = StyleSheet.create({ container: { width: '100%', height: 613, overflow: 'hidden', }, wrapper: { paddingHorizontal: 40, flexDirection: 'row' }, d_div: { marginHorizontal: 5, }, d_btn: { backgroundColor: '#fa3f19', color: '#fff', fontSize: 12, paddingVertical: 2, paddingHorizontal: 8, borderRadius: 4, height: 20, }, info: { width: '100%', fontsize: 12, lineHeight: 14, textAlign: 'center' }, }); export default CalendarDemo;