fix(calendar): day/week view toggle — controlled view prop + currentView in CustomToolbar
This commit is contained in:
@@ -63,7 +63,7 @@ function EventComponent({ event }: { event: CalendarEvent }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Custom toolbar
|
// Custom toolbar
|
||||||
function CustomToolbar({ date, onNavigate, onView, view, label }: any) {
|
function CustomToolbar({ date, onNavigate, onView, currentView, label }: any) {
|
||||||
const goToBack = () => onNavigate(Navigate.PREVIOUS);
|
const goToBack = () => onNavigate(Navigate.PREVIOUS);
|
||||||
const goToNext = () => onNavigate(Navigate.NEXT);
|
const goToNext = () => onNavigate(Navigate.NEXT);
|
||||||
const goToToday = () => onNavigate(Navigate.TODAY);
|
const goToToday = () => onNavigate(Navigate.TODAY);
|
||||||
@@ -88,7 +88,7 @@ function CustomToolbar({ date, onNavigate, onView, view, label }: any) {
|
|||||||
{viewNames.map((name) => (
|
{viewNames.map((name) => (
|
||||||
<Button
|
<Button
|
||||||
key={name}
|
key={name}
|
||||||
variant={view === name ? "default" : "outline"}
|
variant={currentView === name ? "default" : "outline"}
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => onView(name)}
|
onClick={() => onView(name)}
|
||||||
className="capitalize"
|
className="capitalize"
|
||||||
@@ -266,8 +266,8 @@ function CalendarPage() {
|
|||||||
events={calendarEvents}
|
events={calendarEvents}
|
||||||
startAccessor="start"
|
startAccessor="start"
|
||||||
endAccessor="end"
|
endAccessor="end"
|
||||||
date={date}
|
|
||||||
view={view}
|
view={view}
|
||||||
|
defaultView={Views.MONTH}
|
||||||
onNavigate={handleNavigate}
|
onNavigate={handleNavigate}
|
||||||
onView={handleViewChange}
|
onView={handleViewChange}
|
||||||
onSelectEvent={handleSelectEvent}
|
onSelectEvent={handleSelectEvent}
|
||||||
@@ -280,9 +280,8 @@ function CalendarPage() {
|
|||||||
showMultiDayTimes
|
showMultiDayTimes
|
||||||
components={{
|
components={{
|
||||||
event: EventComponent,
|
event: EventComponent,
|
||||||
toolbar: CustomToolbar,
|
toolbar: (props: any) => <CustomToolbar {...props} currentView={view} />,
|
||||||
}}
|
}}
|
||||||
defaultView={Views.MONTH}
|
|
||||||
views={["month", "week", "work_week", "day", "agenda"]}
|
views={["month", "week", "work_week", "day", "agenda"]}
|
||||||
step={30}
|
step={30}
|
||||||
timeslots={2}
|
timeslots={2}
|
||||||
|
|||||||
Reference in New Issue
Block a user