From 9d41dbb9a80be72a63276ec607bb72d74af23dd6 Mon Sep 17 00:00:00 2001 From: boern99 Date: Mon, 9 Dec 2024 18:06:37 +0000 Subject: [PATCH] date-range-picker prev and next design --- src/components/ha-date-range-picker.ts | 212 ++++++++++--------------- src/components/ha-textarea.ts | 6 + 2 files changed, 90 insertions(+), 128 deletions(-) diff --git a/src/components/ha-date-range-picker.ts b/src/components/ha-date-range-picker.ts index 12601e2a4b50..9a397f41ad80 100644 --- a/src/components/ha-date-range-picker.ts +++ b/src/components/ha-date-range-picker.ts @@ -6,7 +6,6 @@ import { mdiCalendar } from "@mdi/js"; import { addDays, addMonths, - addYears, endOfDay, endOfMonth, endOfWeek, @@ -19,6 +18,11 @@ import { addMilliseconds, subMilliseconds, roundToNearestHours, + isFirstDayOfMonth, + isLastDayOfMonth, + subMonths, + differenceInMonths, + isThisYear, } from "date-fns"; import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit"; import { LitElement, css, html, nothing } from "lit"; @@ -26,14 +30,16 @@ import { customElement, property, state } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { calcDate } from "../common/datetime/calc_date"; import { firstWeekdayIndex } from "../common/datetime/first_weekday"; -import { formatDate } from "../common/datetime/format_date"; -import { formatDateTime } from "../common/datetime/format_date_time"; +import { + formatShortDateTimeWithYear, + formatShortDateTime, +} from "../common/datetime/format_date_time"; + import { useAmPm } from "../common/datetime/use_am_pm"; import type { HomeAssistant } from "../types"; import "./date-range-picker"; import "./ha-icon-button"; -import "./ha-svg-icon"; -import "./ha-textfield"; +import "./ha-textarea"; import "./ha-icon-button-next"; import "./ha-icon-button-prev"; @@ -141,9 +147,6 @@ export class HaDateRangePicker extends LitElement { [this.hass.localize( "ui.components.date-range-picker.ranges.this_week" )]: [weekStart, weekEnd], - [this.hass.localize( - "ui.components.date-range-picker.ranges.last_week" - )]: [addDays(weekStart, -7), addDays(weekEnd, -7)], ...(this.extendedPresets ? { [this.hass.localize( @@ -168,28 +171,6 @@ export class HaDateRangePicker extends LitElement { } ), ], - [this.hass.localize( - "ui.components.date-range-picker.ranges.last_month" - )]: [ - calcDate( - addMonths(today, -1), - startOfMonth, - this.hass.locale, - this.hass.config, - { - weekStartsOn, - } - ), - calcDate( - addMonths(today, -1), - endOfMonth, - this.hass.locale, - this.hass.config, - { - weekStartsOn, - } - ), - ], [this.hass.localize( "ui.components.date-range-picker.ranges.this_year" )]: [ @@ -206,28 +187,6 @@ export class HaDateRangePicker extends LitElement { weekStartsOn, }), ], - [this.hass.localize( - "ui.components.date-range-picker.ranges.last_year" - )]: [ - calcDate( - addYears(today, -1), - startOfYear, - this.hass.locale, - this.hass.config, - { - weekStartsOn, - } - ), - calcDate( - addYears(today, -1), - endOfYear, - this.hass.locale, - this.hass.config, - { - weekStartsOn, - } - ), - ], } : {}), }; @@ -261,51 +220,44 @@ export class HaDateRangePicker extends LitElement { >
${!this.minimal - ? html` - - - - + > + +