import React, { useState } from 'react';
import Calendar from '../index';
import { Button, RadioGroup, Radio, LocaleProvider, Select } from '@douyinfe/semi-ui';
import zh_CN from '@douyinfe/semi-ui/locale/source/zh_CN';
import en_GB from '@douyinfe/semi-ui/locale/source/en_GB';
import en_US from '@douyinfe/semi-ui/locale/source/en_US';
import ko_KR from '@douyinfe/semi-ui/locale/source/ko_KR';
import ja_JP from '@douyinfe/semi-ui/locale/source/ja_JP';
import ar from '@douyinfe/semi-ui/locale/source/ar';
import vi_VN from '@douyinfe/semi-ui/locale/source/vi_VN';
import ru_RU from '@douyinfe/semi-ui/locale/source/ru_RU';
import id_ID from '@douyinfe/semi-ui/locale/source/id_ID';
import ms_MY from '@douyinfe/semi-ui/locale/source/ms_MY';
import th_TH from '@douyinfe/semi-ui/locale/source/th_TH';
import tr_TR from '@douyinfe/semi-ui/locale/source/tr_TR';
import pt_BR from '@douyinfe/semi-ui/locale/source/pt_BR';
const { Option } = Select;
export default {
title: 'Calendar',
}
const time = new Date();
let id = 0;
const language = {
zh_CN: zh_CN,
en_GB: en_GB,
ko_KR: ko_KR,
ja_JP: ja_JP,
ar: ar,
vi_VN: vi_VN,
ru_RU: ru_RU,
id_ID: id_ID,
ms_MY: ms_MY,
th_TH: th_TH,
tr_TR: tr_TR,
pt_BR: pt_BR,
};
const events = [
{
allDay: true,
children:
today-allDay
,
},
{
start: time,
children: today-now
,
},
{
allDay: true,
children: today-allDay2
,
},
{
allDay: true,
children: today-allDay3
,
},
{
allDay: true,
children: today-allDay4
,
},
];
const weeklyEvents = [
{
allDay: true,
start: new Date(2019, 6, 15, 8, 0, 0),
children: 7-15-AllDayA
,
},
{
start: new Date(2019, 6, 16, 8, 32, 0),
children: (
7-16 8:32 here is a very long content just to see if the content will collapse or not not
sure if this is long enough aaaaaaaaaaa
),
},
{
start: new Date(2019, 6, 16, 14, 30, 0),
end: new Date(2019, 6, 16, 20, 0, 0),
children: 7-16 14:30-20:00
,
},
{
start: new Date(2019, 6, 18, 14, 45, 0),
end: new Date(2019, 6, 19, 6, 18, 0),
children: (
7-18 14:45 ~ 7-19 6:18
),
},
];
// const events = [];
const date = new Date(2019, 6, 18, 8, 0, 0);
const dailyEventStyle = {
borderRadius: '3px',
boxSizing: 'border-box',
border: 'var(--semi-color-primary) 1px solid',
padding: '10px',
backgroundColor: 'var(--semi-color-primary-light-default)',
height: '100%',
overflow: 'hidden',
};
const allDayStyle = {
borderRadius: '3px',
boxSizing: 'border-box',
border: 'var(--semi-color-bg-1) 1px solid',
marginRight: '12px',
padding: '2px 4px',
backgroundColor: 'var(--semi-color-primary-light-active)',
height: '100%',
overflow: 'hidden',
};
const weeklyEvents2 = [
{
allDay: true,
start: new Date(2019, 6, 22, 8, 0, 0),
children: 7-22-allDay
,
},
{
start: new Date(2019, 6, 23, 8, 32, 0),
children: 7-23 8:32
,
},
{
start: new Date(2019, 6, 23, 14, 30, 0),
end: new Date(2019, 6, 23, 20, 0, 0),
children: 7-23 14:30-20:00
,
},
{
start: new Date(2019, 6, 25, 14, 45, 0),
end: new Date(2019, 6, 26, 6, 18, 0),
children: (
7-25 14:45 ~ 7-26 6:18
),
},
{
start: new Date(2019, 6, 25, 8, 0, 0),
end: new Date(2019, 6, 27, 6, 0, 0),
children: (
7-25 8:00 ~ 7-27 6:00
),
},
{
start: new Date(2019, 6, 22, 9, 0, 0),
end: new Date(2019, 6, 23, 23, 0, 0),
children: (
7-22 9:00 ~ 7-23 23:00
),
},
{
start: new Date(2019, 6, 21, 6, 0, 0),
end: new Date(2019, 6, 25, 6, 0, 0),
children: (
7-21 6:00 ~ 7-25 6:00
),
},
{
start: new Date(2019, 6, 19, 20, 0, 0),
end: new Date(2019, 6, 23, 14, 0, 0),
children: (
7-19 20:00 ~ 7-23 14:00
),
},
{
start: new Date(2019, 6, 26, 10, 0, 0),
end: new Date(2019, 6, 27, 16, 0, 0),
children: 7-26 10:00 ~ 7-27 16:00
,
},
{
start: new Date(2019, 6, 18, 10, 0, 0),
end: new Date(2019, 6, 30, 8, 0, 0),
children: (
7-18 10:00 ~ 7-30 8:00
),
},
];
export const DayCalendar = () => {
return (
);
};
DayCalendar.parameters = {
chromatic: { disableSnapshot: true },
}
export const WeekCalendar = () => {
return (
);
};
export const ThisWeekCalendar = () => {
return (
);
};
export const MonthCalendar = () => {
return ;
};
MonthCalendar.parameters = {
chromatic: { disableSnapshot: true },
}
const AddEventToCalendar = () => {
const [event, setEvent] = useState([]);
const [mode, setMode] = useState('day');
const addEvent = () => {
let newEvent = {
allDay: true,
start: new Date(),
key: `${id}`,
children: today-{id}
,
};
id++;
setEvent([...event, newEvent]);
};
const removeEvent = () => {
let newEvents = [...event];
newEvents.pop();
setEvent([...newEvents]);
};
return (
<>
setMode(e.target.value)} value={mode}>
日视图
周视图
月视图
>
);
};
export const UpdateEvent = () => {
const [event, setEvent] = useState([]);
const [mode, setMode] = useState('day');
const [updateId, setId] = useState(id);
const addEvent = () => {
let key = `${id}`;
let newEvent = {
allDay: true,
start: new Date(),
key,
children: (
{
console.log(key);
setId(key);
}}
>
today-{key}
),
};
id++;
setEvent([...event, newEvent]);
};
const updateEvent = () => {
let ind = event.findIndex(item => {
return item.key === updateId;
});
let newArr = [...event];
newArr[ind].key = `${Math.random()}`;
newArr[ind].children = today-{Math.random(0, 1)}
;
setEvent(newArr);
};
return (
<>
setMode(e.target.value)} value={mode}>
日视图
周视图
月视图
>
);
};
UpdateEvent.parameters = {
chromatic: { disableSnapshot: true },
}
export const DateGridRenderWeek = () => {
return (
{
if (dateString === new Date(2019, 6, 16).toString()) {
return (
123test
);
}
return null;
}}
>
);
};
export const DateGridRenderMonth = () => {
return (
{
console.log(dateString);
if (dateString === new Date(2019, 6, 16).toString()) {
return (
123test
);
}
return null;
}}
>
);
};
export const RangeCalenderMonth = () => {
return (
);
};
export const WithLocaleProvider = () => {
const [locale, setLocale] = useState(zh_CN);
const onLanguageChange = code => {
setLocale(language[code]);
};
return (
);
};
WithLocaleProvider.parameters = {
chromatic: { disableSnapshot: true }
}
class EventRenderDemo extends React.Component {
constructor() {
super();
this.state = {
mode: 'week',
clickDate: '?'
};
}
onSelect(e) {
this.setState({
mode: e.target.value,
});
}
render() {
const { mode } = this.state;
const isMonthView = mode === 'month';
const dailyEventStyle = {
borderRadius: '3px',
boxSizing: 'border-box',
border: 'var(--semi-color-primary) 1px solid',
padding: '10px',
backgroundColor: 'var(--semi-color-primary-light-default)',
height: '100%',
overflow: 'hidden',
};
const allDayStyle = {
borderRadius: '3px',
boxSizing: 'border-box',
border: 'var(--semi-color-bg-1) 1px solid',
padding: '2px 4px',
backgroundColor: 'var(--semi-color-primary-light-active)',
height: '100%',
overflow: 'hidden',
};
const dailyStyle = isMonthView ? allDayStyle : dailyEventStyle;
const events = [
{
key: '0',
start: new Date(2019, 5, 25, 14, 45, 0),
end: new Date(2019, 6, 26, 6, 18, 0),
children: 6月25日 14:45 ~ 7月26日 6:18
,
},
{
key: '1',
start: new Date(2019, 6, 18, 10, 0, 0),
end: new Date(2019, 6, 30, 8, 0, 0),
children: 7月18日 10:00 ~ 7月30日 8:00
,
},
{
key: '2',
start: new Date(2019, 6, 19, 20, 0, 0),
end: new Date(2019, 6, 23, 14, 0, 0),
children: 7月19日 20:00 ~ 7月23日 14:00
,
},
{
key: '3',
start: new Date(2019, 6, 21, 6, 0, 0),
end: new Date(2019, 6, 25, 6, 0, 0),
children: 7月21日 6:00 ~ 7月25日 6:00
,
},
{
key: '4',
allDay: true,
start: new Date(2019, 6, 22, 8, 0, 0),
children: 7月22日 全天
,
},
{
key: '5',
start: new Date(2019, 6, 22, 9, 0, 0),
end: new Date(2019, 6, 23, 23, 0, 0),
children: 7月22日 9:00 ~ 7月23日 23:00
,
},
{
key: '6',
start: new Date(2019, 6, 23, 8, 32, 0),
children: 7月23日 8:32
,
},
{
key: '7',
start: new Date(2019, 6, 23, 14, 30, 0),
end: new Date(2019, 6, 23, 20, 0, 0),
children: 7月23日 14:30-20:00
,
},
{
key: '8',
start: new Date(2019, 6, 25, 8, 0, 0),
end: new Date(2019, 6, 27, 6, 0, 0),
children: 7月25日 8:00 ~ 7月27日 6:00
,
},
{
key: '9',
start: new Date(2019, 6, 26, 10, 0, 0),
end: new Date(2019, 6, 27, 16, 0, 0),
children: 7月26日 10:00 ~ 7月27日 16:00
,
},
];
const displayValue = new Date(2019, 6, 23, 8, 32, 0);
return (
<>
this.onSelect(e)} value={mode}>
日视图
周视图
月视图
多日视图
{ this.setState({clickDate: date.getDate()}); console.log(date.getDate())}}
range={mode === 'range' ? [new Date(2019, 6, 23), new Date(2019, 6, 26)] : []}
>
当前点击的日期是{this.state.clickDate}号
>
);
}
}
export const EventRender = () => ;
export const WeekStartsOnDemo = () => {
const [v, setV] = useState(6);
const allDayStyle = {
borderRadius: '3px',
boxSizing: 'border-box',
border: 'var(--semi-color-bg-1) 1px solid',
padding: '2px 4px',
backgroundColor: 'var(--semi-color-primary-light-active)',
height: '100%',
overflow: 'hidden',
};
const events = [
{
key: '0',
start: new Date(2022, 8, 5, 14, 45, 0),
end: new Date(2022, 8, 6, 6, 18, 0),
children: 9月5日 14:45 ~ 9月6日 6:18
,
}
]
return (
setV(e.target.value)}>
周一
周二
周三
周四
周五
周六
周日
{
if (dateString === new Date(2019, 6, 16).toString()) {
return (
123test
);
}
return null;
}}
>
)
}