我的目标是为prev/next功能构建完全自定义的按钮,不只是使用图标字符串,比如字体中的图标字符串,而是使用自定义内部的“元素”,它基本上是一个独立的组件。我知道customButtons对象是在文档中指定的,但这并不能达到添加完全自定义按钮的目的,因为该按钮仍然是一个带有自身背景和内容的"FullCalendar“样式按钮,加上customButtons方法需要传递字符串,而我的自定义按钮将是一个元素。我试图实现的目标如下(我正在使用版本5以防止它有所帮助):
const myCustomPrevBtn = {
return <CustomButton onClick={()=>{}}>Prev</CustomButton >
}
const myCustomNextBtn = {
return <CustomButton onClick={()=>{}}>Next</CustomButton >
}
<FullCalendar
headerToolbar={{
left:'myCustomPrevBtn',
right:'myCustomNextBtn'
}}
plugins={[dayGridPlugin, timeGridPlugin]}
initialView="timeGridWeek"
/>我正在考虑不通过执行headerToolbar来使用FullCalendar的默认headerToolbar={{false}} (因为我们正在讨论prev/next按钮的自定义组件),但不确定如果我采用该路径,如何让用户在前一周或下一周/天/月之间移动。对此有什么想法吗?
发布于 2022-08-24 22:30:42
对于将来看到这种情况的人,我最终会使用ref访问日历API。例如,我将一个ref传递给我的FullCalendar组件,然后在我需要使用的自定义按钮的事件处理程序中,使用该ref的当前值访问日历API的prev/next函数-
<FullCalendar
ref={testRef}
headerToolbar={false}
plugins={[dayGridPlugin, timeGridPlugin]}
initialView="timeGridWeek"
initialEvents={[//some events list]}
/>
// then inside my custom handler
const handlePreviousClick = () => {
const calendarAPI = calendarRef?.current?.getApi();
calendarAPI?.prev();
};希望能帮上忙。
https://stackoverflow.com/questions/73451218
复制相似问题