Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions src/panels/calendar/ha-full-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import fullcalendarStyle from "@fullcalendar/common/main.css";
import type { CalendarOptions } from "@fullcalendar/core";
import { Calendar } from "@fullcalendar/core";
import allLocales from "@fullcalendar/core/locales-all";
import dayGridPlugin from "@fullcalendar/daygrid";
// @ts-ignore
import daygridStyle from "@fullcalendar/daygrid/main.css";
Expand Down Expand Up @@ -44,23 +45,38 @@ declare global {
}
}

const getListWeekRange = (currentDate: Date): { start: Date; end: Date } => {
const startDate = new Date(currentDate.valueOf());
const endDate = new Date(currentDate.valueOf());

endDate.setDate(endDate.getDate() + 7);

return { start: startDate, end: endDate };
};

const defaultFullCalendarConfig: CalendarOptions = {
headerToolbar: false,
plugins: [dayGridPlugin, listPlugin, interactionPlugin],
initialView: "dayGridMonth",
dayMaxEventRows: true,
height: "parent",
eventDisplay: "list-item",
locales: allLocales,
views: {
list: {
visibleRange: getListWeekRange,
},
},
};

const viewButtons: ToggleButton[] = [
{ label: "Month View", value: "dayGridMonth", iconPath: mdiViewModule },
{ label: "Week View", value: "dayGridWeek", iconPath: mdiViewWeek },
{ label: "Day View", value: "dayGridDay", iconPath: mdiViewDay },
{ label: "List View", value: "listWeek", iconPath: mdiViewAgenda },
{ label: "List View", value: "list", iconPath: mdiViewAgenda },
];

class HAFullCalendar extends LitElement {
export class HAFullCalendar extends LitElement {
public hass!: HomeAssistant;

@property({ type: Boolean, reflect: true }) public narrow = false;
Expand All @@ -79,6 +95,10 @@ class HAFullCalendar extends LitElement {

@internalProperty() private _activeView?: FullCalendarView;

public updateSize(): void {
this.calendar?.updateSize();
}

protected render(): TemplateResult {
const viewToggleButtons = this._viewToggleButtons(this.views);

Expand Down Expand Up @@ -186,6 +206,12 @@ class HAFullCalendar extends LitElement {
this.calendar!.changeView(this._activeView);
this._fireViewChanged();
}

const oldHass = changedProps.get("hass") as HomeAssistant;

if (oldHass && oldHass.language !== this.hass.language) {
this.calendar.setOption("locale", this.hass.language);
}
}

protected firstUpdated(): void {
Expand Down Expand Up @@ -243,7 +269,7 @@ class HAFullCalendar extends LitElement {
this._fireViewChanged();
}

private _handleView(ev): void {
private _handleView(ev: CustomEvent): void {
this._activeView = ev.detail.value;
this.calendar!.changeView(this._activeView!);
this._fireViewChanged();
Expand Down Expand Up @@ -487,6 +513,23 @@ class HAFullCalendar extends LitElement {
:host([narrow]) .fc-dayGridMonth-view .fc-scrollgrid-sync-table {
overflow: hidden;
}

.fc-scroller::-webkit-scrollbar {
width: 0.4rem;
height: 0.4rem;
}

.fc-scroller::-webkit-scrollbar-thumb {
-webkit-border-radius: 4px;
border-radius: 4px;
background: var(--scrollbar-thumb-color);
}

.fc-scroller {
overflow-y: auto;
scrollbar-color: var(--scrollbar-thumb-color) transparent;
scrollbar-width: thin;
}
`,
];
}
Expand Down
10 changes: 8 additions & 2 deletions src/panels/lovelace/cards/hui-calendar-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LitElement,
property,
PropertyValues,
query,
TemplateResult,
} from "lit-element";
import { HA_COLOR_PALETTE } from "../../../common/const";
Expand All @@ -24,6 +25,7 @@ import type {
HomeAssistant,
} from "../../../types";
import "../../calendar/ha-full-calendar";
import type { HAFullCalendar } from "../../calendar/ha-full-calendar";
import { findEntities } from "../common/find-entites";
import { installResizeObserver } from "../common/install-resize-observer";
import "../components/hui-warning";
Expand Down Expand Up @@ -71,6 +73,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {

@internalProperty() private _veryNarrow = false;

@query("ha-full-calendar", true) private _calendar?: HAFullCalendar;

private _startDate?: Date;

private _endDate?: Date;
Expand Down Expand Up @@ -121,8 +125,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
}

const views: FullCalendarView[] = this._veryNarrow
? ["listWeek"]
: ["listWeek", "dayGridMonth", "dayGridDay"];
? ["list"]
: ["list", "dayGridMonth", "dayGridDay"];

return html`
<ha-card>
Expand Down Expand Up @@ -186,6 +190,8 @@ export class HuiCalendarCard extends LitElement implements LovelaceCard {
}
this._narrow = card.offsetWidth < 870;
this._veryNarrow = card.offsetWidth < 350;

this._calendar?.updateSize();
}

private async _attachObserver(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export type FullCalendarView =
| "dayGridMonth"
| "dayGridWeek"
| "dayGridDay"
| "listWeek";
| "list";

export interface ToggleButton {
label: string;
Expand Down