我很难使用带有 react-big-calendar 和 typescript 的自定义工具栏。我正在尝试访问“下一个,上一个”“月,日,周”视图的原始方法。我已经广泛阅读... https://github.com/intljusticemission/react-big-calendar/issues/623 https://github.com/intljusticemission/react-big-calendar/issues/818 http://intljusticemission .github.io/react-big-calendar/examples/index.html#prop-components
自定义 UI 渲染良好,没有错误,现在我需要访问原始方法,以便操作日历。
主要问题是我的按钮正在触发,但实际上并没有导航任何东西。
我认为的一些问题是...
- 我实际上并没有像我想的那样使用navigateMethod
--BigCalendar 中的默认日期和日期实际上并没有改变,因为我每次点击时都会用同一天覆盖它?
-- 我需要从他们的文档中实现这个例子吗?
Custom views can be any React component, that implements the following interface:
interface View {
static title(date: Date, { formats: DateFormat[], culture: string?, ...props }): string
static navigate(date: Date, action: 'PREV' | 'NEXT' | 'DATE'): Date
}
有人有我可以看的例子吗???
这是我的完整源代码。
import React from 'react'
import { MainContent } from '../../../common/templates/partials'
import BigCalendar from 'react-big-calendar'
import ToolBar from 'react-big-calendar'
import Icon from 'app/common/components/Icon'
import moment from 'moment'
const styles = require('./CalendarUI.scss')
BigCalendar.momentLocalizer(moment) // or globalizeLocalizer
const events = [
{
start: new Date(),
end: new Date(),
title: 'Some title',
},
]
class CustomToolbar extends ToolBar {
render() {
// tslint:disable-next-line:no-console
console.log(this.props, this)
/* tslint:disable-next-line */
const {label, onNavigate} = this.props as any
return (
<div className="rbc-toolbar">
<div>
{/* tslint:disable-next-line */}
<button onClick={() => this.props.onNavigate ? onNavigate(null as any, 'PREV') : undefined}>
<Icon icon="B" />
</button>
<label className="label-date">{label}</label>
{/* tslint:disable-next-line */}
<button onClick={() => this.props.onNavigate ? onNavigate(null, 'NEXT') : undefined}>
<Icon icon="A" />
</button>
</div>
<div>
<span className="rbc-btn-group">
<button>Month</button>
<button>Day</button>
<button>Week</button>
</span>
<button className="btn btn-back">
<Icon icon="R" />
</button>
<button className="btn btn-back">
<Icon icon="meet_now" />
</button>
</div>
</div>
)
}
}
const logger = (data: string) =>
// tslint:disable-next-line:no-console
console.log(data)
const CalendarUI = () => (
<MainContent>
<div className={styles.calendarContainer}>
<BigCalendar
defaultDate={moment().toDate()}
defaultView="month"
events={events}
components={{ toolbar: CustomToolbar }}
startAccessor="startDate"
endAccessor="endDate"
onView={logger}
date={moment().toDate()}
/>
</div>
</MainContent>
)
export default CalendarUI