@fluid-topics/ftds-period-picker 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ The design system period picker component
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ftds-period-picker
7
+ yarn add @fluid-topics/ftds-period-picker
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import {html} from "lit"
14
+ import "@fluid-topics/ftds-period-picker"
15
+
16
+ function render() {
17
+ return html` <ftds-period-picker foo="bar"></ftds-period-picker> `
18
+ }
19
+ ```
@@ -0,0 +1,21 @@
1
+ import { FtPeriod, FtPeriodPickerConfigOption } from "./ftds-period-picker.properties";
2
+ export declare const nHoursAgo: (n: number) => Date;
3
+ export declare const nDaysAgo: (n: number) => Date;
4
+ export declare const lastNMondays: (n: number) => Date;
5
+ export declare const lastNMonthBeginnings: (n: number) => Date;
6
+ export declare const lastNYearBeginnings: (n: number) => Date;
7
+ export declare const datesLastInstant: (date: Date) => Date;
8
+ export declare const todaysLastInstant: () => Date;
9
+ export declare class FtPeriodsBuiltin {
10
+ static anyTime: (customLabel?: string) => FtPeriodPickerConfigOption;
11
+ static lastNhours: (n: number, customLabel?: string) => FtPeriodPickerConfigOption;
12
+ static lastNdays: (n: number, customLabel?: string) => FtPeriodPickerConfigOption;
13
+ static today: (customLabel?: string) => FtPeriodPickerConfigOption;
14
+ static thisCalendarWeek: (customLabel?: string) => FtPeriodPickerConfigOption;
15
+ static lastNCalendarWeeks: (n: number, customLabel?: string) => FtPeriodPickerConfigOption;
16
+ static thisCalendarMonth: (customLabel?: string) => FtPeriodPickerConfigOption;
17
+ static lastNCalendarMonths: (n: number, customLabel?: string) => FtPeriodPickerConfigOption;
18
+ static thisCalendarYear: (customLabel?: string) => FtPeriodPickerConfigOption;
19
+ static lastNCalendarYears: (n: number, customLabel?: string) => FtPeriodPickerConfigOption;
20
+ static custom: (key: string, label: string, selector: () => FtPeriod) => FtPeriodPickerConfigOption;
21
+ }
@@ -0,0 +1,87 @@
1
+ import { ftPeriodI18nContext } from "./FtdsPeriodPickerMessages";
2
+ export const nHoursAgo = (n) => (new Date(Date.now() - n * 60 * 60 * 1000));
3
+ export const nDaysAgo = (n) => {
4
+ const d = new Date();
5
+ d.setDate(d.getDate() - n);
6
+ d.setHours(0, 0, 0, 0);
7
+ return d;
8
+ };
9
+ export const lastNMondays = (n) => {
10
+ const d = new Date();
11
+ d.setDate(d.getDate() - d.getDay() - 7 * n);
12
+ d.setHours(0, 0, 0, 0);
13
+ return d;
14
+ };
15
+ export const lastNMonthBeginnings = (n) => {
16
+ const d = new Date();
17
+ d.setMonth(d.getMonth() - n, 1);
18
+ d.setHours(0, 0, 0, 0);
19
+ return d;
20
+ };
21
+ export const lastNYearBeginnings = (n) => {
22
+ const d = new Date();
23
+ d.setFullYear(d.getFullYear() - n, 0, 1);
24
+ d.setHours(0, 0, 0, 0);
25
+ return d;
26
+ };
27
+ export const datesLastInstant = (date) => {
28
+ const d = new Date(date);
29
+ d.setHours(23, 59, 59, 999);
30
+ return d;
31
+ };
32
+ export const todaysLastInstant = () => datesLastInstant(new Date());
33
+ export class FtPeriodsBuiltin {
34
+ }
35
+ FtPeriodsBuiltin.anyTime = (customLabel) => ({
36
+ key: "anyTime",
37
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.anyTime()),
38
+ selector: () => ({}),
39
+ });
40
+ FtPeriodsBuiltin.lastNhours = (n, customLabel) => ({
41
+ key: `last${n}hours`,
42
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.lastNHours(n)),
43
+ selector: () => ({ from: nHoursAgo(n), to: todaysLastInstant() }),
44
+ });
45
+ FtPeriodsBuiltin.lastNdays = (n, customLabel) => ({
46
+ key: `last${n}days`,
47
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.lastNDays(n)),
48
+ selector: () => ({ from: nDaysAgo(n), to: todaysLastInstant() }),
49
+ });
50
+ FtPeriodsBuiltin.today = (customLabel) => ({
51
+ key: "today",
52
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.today()),
53
+ selector: () => ({ from: nDaysAgo(0), to: todaysLastInstant() }),
54
+ });
55
+ FtPeriodsBuiltin.thisCalendarWeek = (customLabel) => ({
56
+ key: "thisCalendarWeek",
57
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.thisCalendarWeek()),
58
+ selector: () => ({ from: lastNMondays(0), to: todaysLastInstant() }),
59
+ });
60
+ FtPeriodsBuiltin.lastNCalendarWeeks = (n, customLabel) => ({
61
+ key: `last${n}CalendarWeeks`,
62
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.lastNCalendarWeeks(n)),
63
+ selector: () => ({ from: lastNMondays(n), to: lastNMondays(0) }),
64
+ });
65
+ FtPeriodsBuiltin.thisCalendarMonth = (customLabel) => ({
66
+ key: "thisCalendarMonth",
67
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.thisCalendarMonth()),
68
+ selector: () => ({ from: lastNMonthBeginnings(0), to: todaysLastInstant() }),
69
+ });
70
+ FtPeriodsBuiltin.lastNCalendarMonths = (n, customLabel) => ({
71
+ key: `last${n}CalendarMonth`,
72
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.lastNCalendarMonths(n)),
73
+ selector: () => ({ from: lastNMonthBeginnings(n), to: lastNMonthBeginnings(0) }),
74
+ });
75
+ FtPeriodsBuiltin.thisCalendarYear = (customLabel) => ({
76
+ key: "thisCalendarYear",
77
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.thisCalendarYear()),
78
+ selector: () => ({ from: lastNYearBeginnings(0), to: todaysLastInstant() }),
79
+ });
80
+ FtPeriodsBuiltin.lastNCalendarYears = (n, customLabel) => ({
81
+ key: `last${n}CalendarYears`,
82
+ label: customLabel !== null && customLabel !== void 0 ? customLabel : (() => ftPeriodI18nContext.messages.lastNCalendarYears(n)),
83
+ selector: () => ({ from: lastNYearBeginnings(n), to: lastNYearBeginnings(0) }),
84
+ });
85
+ FtPeriodsBuiltin.custom = (key, label, selector) => ({
86
+ key, label, selector,
87
+ });
@@ -0,0 +1,29 @@
1
+ import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
2
+ export interface FtdsPeriodPickerMessages extends I18nMessages {
3
+ anyTime(): string;
4
+ lastNHours(n: number): string;
5
+ lastNDays(n: number): string;
6
+ fromDate(date: string): string;
7
+ toDate(date: string): string;
8
+ fromToDates(from: string, to: string): string;
9
+ custom(): string;
10
+ from(): string;
11
+ to(): string;
12
+ today(): string;
13
+ thisCalendarWeek(): string;
14
+ lastNCalendarWeeks(n: number): string;
15
+ thisCalendarMonth(): string;
16
+ lastNCalendarMonths(n: number): string;
17
+ thisCalendarYear(): string;
18
+ lastNCalendarYears(n: number): string;
19
+ apply(): string;
20
+ expand(): string;
21
+ cancel(): string;
22
+ mustNotBeEarlierThan(date: string): string;
23
+ mustNotBeLaterThan(date: string): string;
24
+ fromDateMustBeBeforeToDate(): string;
25
+ pickAPeriod(): string;
26
+ calendarIconLabel(): string;
27
+ }
28
+ export declare const ftPeriodI18nContext: I18nMessageContext<FtdsPeriodPickerMessages>;
29
+ export declare const periodPickerDefaultMessages: DefaultI18nMessages<FtdsPeriodPickerMessages>;
@@ -0,0 +1,33 @@
1
+ import { I18nMessageContext, } from "@fluid-topics/ft-i18n";
2
+ export const ftPeriodI18nContext = I18nMessageContext.build("ftPeriodPicker");
3
+ export const periodPickerDefaultMessages = {
4
+ "anyTime": "Any time",
5
+ "lastNHours[\\=1]": "Last hour",
6
+ "lastNHours": "Last {0} hours",
7
+ "lastNDays[\\=1]": "Last day",
8
+ "lastNDays": "Last {0} days",
9
+ "fromDate": "From {0}",
10
+ "toDate": "Until {0}",
11
+ "fromToDates": "From {0} to {1}",
12
+ "custom": "Custom",
13
+ "from": "From",
14
+ "to": "To",
15
+ "today": "Today",
16
+ "thisCalendarWeek": "This week",
17
+ "lastNCalendarWeeks[\\=1]": "Last week",
18
+ "lastNCalendarWeeks": "Last {0} weeks",
19
+ "thisCalendarMonth": "This month",
20
+ "lastNCalendarMonths[\\=1]": "Last month",
21
+ "lastNCalendarMonths": "Last {0} months",
22
+ "thisCalendarYear": "This year",
23
+ "lastNCalendarYears[\\=1]": "Last year",
24
+ "lastNCalendarYears": "Last {0} years",
25
+ "apply": "Apply",
26
+ "expand": "Expand",
27
+ "cancel": "Cancel",
28
+ "mustNotBeEarlierThan": "Date must not be earlier than {0}",
29
+ "mustNotBeLaterThan": "Date must not be later than {0}",
30
+ "fromDateMustBeBeforeToDate": "From date must be before the to date.",
31
+ "pickAPeriod": "Pick a period",
32
+ "calendarIconLabel": "Calendar",
33
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { customElements } from "@fluid-topics/ft-wc-utils";
2
+ import definitions from "./definitions";
3
+ customElements(definitions);
@@ -0,0 +1,7 @@
1
+ import { FtdsPeriodPicker } from "./ftds-period-picker";
2
+ import { FtdsPeriodPickerInSelect } from "./ftds-period-picker-in-select";
3
+ declare const _default: {
4
+ "ftds-period-picker": typeof FtdsPeriodPicker;
5
+ "ftds-period-picker-in-select": typeof FtdsPeriodPickerInSelect;
6
+ };
7
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { FtdsPeriodPicker } from "./ftds-period-picker";
2
+ import { FtdsPeriodPickerInSelect } from "./ftds-period-picker-in-select";
3
+ export default {
4
+ "ftds-period-picker": FtdsPeriodPicker,
5
+ "ftds-period-picker-in-select": FtdsPeriodPickerInSelect,
6
+ };
@@ -0,0 +1,60 @@
1
+ import { FtdsPeriodPickerInSelectProperties } from "./ftds-period-picker-in-select.properties";
2
+ import { PropertyValues } from "lit";
3
+ import { FtdsPeriodPicker } from "./ftds-period-picker";
4
+ import { FtInputLabel } from "@fluid-topics/ft-input-label";
5
+ import { FtdsBase } from "@fluid-topics/ft-wc-utils";
6
+ import { FtdsPeriodPickerDateInputsVisibility, FtdsPeriodPickerInSelectDisplayMode, FtPeriod, FtPeriodPickerConfigOption, FtPeriodPickerOption, FtPeriodSelection } from "./ftds-period-picker.properties";
7
+ import { FtdsFloatingMenu } from "@fluid-topics/ftds-floating-menu";
8
+ import { FtdsIcon } from "@fluid-topics/ftds-icon";
9
+ import { FtdsButton } from "@fluid-topics/ftds-button";
10
+ import { FtdsBaseInput } from "@fluid-topics/ftds-base-input";
11
+ declare const FtdsPeriodPickerInSelect_base: typeof FtdsBase & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-wc-utils").FtInputInterface<FtPeriod>> & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
12
+ export declare class FtdsPeriodPickerInSelect extends FtdsPeriodPickerInSelect_base implements FtdsPeriodPickerInSelectProperties {
13
+ static elementDefinitions: {
14
+ "ftds-floating-menu": typeof FtdsFloatingMenu;
15
+ "ft-input-label": typeof FtInputLabel;
16
+ "ftds-icon": typeof FtdsIcon;
17
+ "ftds-button": typeof FtdsButton;
18
+ "ftds-period-picker": typeof FtdsPeriodPicker;
19
+ "ftds-base-input": typeof FtdsBaseInput;
20
+ };
21
+ static styles: import("lit").CSSResult[];
22
+ dateInputsVisibility: FtdsPeriodPickerDateInputsVisibility;
23
+ displayMode: FtdsPeriodPickerInSelectDisplayMode;
24
+ label: string;
25
+ customPeriodLabel: string;
26
+ defaultPeriod?: FtPeriodSelection;
27
+ /** @deprecated Use defaultPeriod */
28
+ defaultValueKey?: string;
29
+ periods: FtPeriodPickerConfigOption[];
30
+ minDate?: Date;
31
+ maxDate?: Date;
32
+ locale: string;
33
+ ftFloatingMenu?: FtdsFloatingMenu;
34
+ ftdsBaseInput?: FtdsBaseInput;
35
+ periodPickerMenu?: HTMLDivElement;
36
+ periodPickerTriggerButton?: HTMLDivElement;
37
+ ftdsPeriodPicker: FtdsPeriodPicker;
38
+ currentSelection?: FtPeriodPickerOption;
39
+ applyIsDisabled: boolean;
40
+ isMenuOpen: boolean;
41
+ private resizeObserver?;
42
+ get displayValue(): string;
43
+ constructor();
44
+ closeOnEscape(event: KeyboardEvent): void;
45
+ connectedCallback(): void;
46
+ disconnectedCallback(): void;
47
+ willUpdate(): void;
48
+ firstUpdated(props: PropertyValues): void;
49
+ renderMenuTrigger(): import("lit-html").TemplateResult<1>;
50
+ renderMenuContent(): import("lit-html").TemplateResult<1>;
51
+ render(): import("lit-html").TemplateResult<1>;
52
+ private onFloatingMenuOpenStatus;
53
+ private onApply;
54
+ private onCancel;
55
+ private onPeriodValueChange;
56
+ private onPeriodPickerStatusChange;
57
+ private formatCustomDateRange;
58
+ triggerValidation(): void;
59
+ }
60
+ export {};
@@ -0,0 +1,305 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, } from "lit";
8
+ import { FtdsPeriodPicker, FtPeriodChangeEvent, } from "./ftds-period-picker";
9
+ import { FtInputLabel } from "@fluid-topics/ft-input-label";
10
+ import { inSelectStyles } from "./ftds-period-picker-in-select.styles";
11
+ import { property, state, } from "lit/decorators.js";
12
+ import { ftPeriodI18nContext, periodPickerDefaultMessages, } from "./FtdsPeriodPickerMessages";
13
+ import { DateFormatter, dateProperty, deepCopy, DesignSystemFamily, FtdsBase, Status as FtInput_Status, toFtInput, } from "@fluid-topics/ft-wc-utils";
14
+ import { FtdsPeriodPickerDateInputsVisibility, FtdsPeriodPickerInSelectDisplayMode, } from "./ftds-period-picker.properties";
15
+ import { i18n, withI18n, } from "@fluid-topics/ft-i18n";
16
+ import { FtPeriodsBuiltin } from "./FtPeriodsBuiltin";
17
+ import { query } from "lit/decorators/query.js";
18
+ import { FtdsFloatingMenu, } from "@fluid-topics/ftds-floating-menu";
19
+ import { FtdsIcon, FtdsIcons, FtdsIconVariants, } from "@fluid-topics/ftds-icon";
20
+ import { FtdsButton } from "@fluid-topics/ftds-button";
21
+ import { FtdsBaseInput } from "@fluid-topics/ftds-base-input";
22
+ export class FtdsPeriodPickerInSelect extends withI18n(toFtInput(FtdsBase)) {
23
+ get displayValue() {
24
+ var _a, _b, _c;
25
+ if (this.displayMode == FtdsPeriodPickerInSelectDisplayMode.labels) {
26
+ return ((_a = this.currentSelection) === null || _a === void 0 ? void 0 : _a.key) === "custom" ? this.formatCustomDateRange(this.currentSelection.selector()) : (_c = (_b = this.currentSelection) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : "";
27
+ }
28
+ else {
29
+ return this.currentSelection ? this.formatCustomDateRange(this.currentSelection.selector()) : "";
30
+ }
31
+ }
32
+ constructor() {
33
+ super();
34
+ this.dateInputsVisibility = FtdsPeriodPickerDateInputsVisibility.dateInputsAlwaysVisible;
35
+ this.displayMode = FtdsPeriodPickerInSelectDisplayMode.labels;
36
+ this.label = "";
37
+ this.customPeriodLabel = "";
38
+ this.periods = [FtPeriodsBuiltin.anyTime()];
39
+ this.locale = "en-US";
40
+ this.applyIsDisabled = false;
41
+ this.isMenuOpen = false;
42
+ this.addI18nContext(ftPeriodI18nContext, periodPickerDefaultMessages);
43
+ }
44
+ closeOnEscape(event) {
45
+ var _a, _b;
46
+ if (event.key === "Escape") {
47
+ (_a = this.ftFloatingMenu) === null || _a === void 0 ? void 0 : _a.closeMenu();
48
+ (_b = this.periodPickerTriggerButton) === null || _b === void 0 ? void 0 : _b.focus();
49
+ }
50
+ }
51
+ connectedCallback() {
52
+ super.connectedCallback();
53
+ this.addEventListener("keydown", this.closeOnEscape);
54
+ }
55
+ disconnectedCallback() {
56
+ var _a;
57
+ super.disconnectedCallback();
58
+ this.removeEventListener("keydown", this.closeOnEscape);
59
+ (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
60
+ }
61
+ willUpdate() {
62
+ var _a, _b, _c, _d;
63
+ const defaultKey = (_b = (_a = this.defaultPeriod) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : this.defaultValueKey;
64
+ if (!this.currentSelection && defaultKey) {
65
+ if (defaultKey === "custom") {
66
+ this.value = { from: (_c = this.defaultPeriod) === null || _c === void 0 ? void 0 : _c.from, to: (_d = this.defaultPeriod) === null || _d === void 0 ? void 0 : _d.to };
67
+ this.currentSelection = {
68
+ key: "custom",
69
+ label: this.customPeriodLabel,
70
+ selector: () => { var _a; return (_a = this.value) !== null && _a !== void 0 ? _a : {}; },
71
+ };
72
+ }
73
+ else {
74
+ const initialValue = this.periods.find((period) => period.key === defaultKey);
75
+ if (initialValue) {
76
+ this.value = initialValue.selector();
77
+ this.currentSelection = {
78
+ key: initialValue.key,
79
+ label: typeof initialValue.label === "string" ? initialValue.label : initialValue.label(),
80
+ selector: initialValue.selector,
81
+ };
82
+ }
83
+ }
84
+ }
85
+ }
86
+ firstUpdated(props) {
87
+ super.firstUpdated(props);
88
+ if (this.ftdsBaseInput) {
89
+ this.resizeObserver = new ResizeObserver(() => {
90
+ if (this.periodPickerMenu && this.ftdsBaseInput) {
91
+ this.periodPickerMenu.style.width = this.ftdsBaseInput.clientWidth.toString() + "px";
92
+ }
93
+ });
94
+ this.resizeObserver.observe(this.ftdsBaseInput);
95
+ }
96
+ }
97
+ renderMenuTrigger() {
98
+ return html `
99
+ <ftds-base-input
100
+ slot="toggle"
101
+ class="period-picker--trigger"
102
+
103
+ .value=${this.displayValue}
104
+ .status=${this.status}
105
+ .size=${this.size}
106
+ ?disabled=${this.disabled}
107
+
108
+ .errorMessages=${this.errorMessages}
109
+ .warningMessages=${this.warningMessages}
110
+ .helperText=${this.helperText}
111
+
112
+ .label=${this.label}
113
+ ?hideLabel=${this.hideLabel}
114
+ ?raiseLabel=${this.focused || this.displayValue}
115
+
116
+ .prependIcon=${FtdsIcons.CALENDAR_RANGE}
117
+ .prependIconLabel=${ftPeriodI18nContext.messages.calendarIconLabel}
118
+
119
+ .appendIcon=${FtdsIcons.ANGLE_DOWN}
120
+ .appendIconLabel=${ftPeriodI18nContext.messages.expand}
121
+ >
122
+ <input name="${this.name}"
123
+ type="button"
124
+ class="period-picker--trigger-button"
125
+ .value=${this.displayValue}
126
+ readonly
127
+ ?disabled=${this.disabled}
128
+ aria-haspopup="dialog"
129
+ aria-expanded="${this.isMenuOpen}"
130
+ aria-controls="date-range-picker"
131
+ aria-label="${ftPeriodI18nContext.messages.pickAPeriod()}"
132
+ aria-describedby="${this.messagesForScreenReaderElementId}"
133
+ />
134
+
135
+ ${this.renderMessagesForScreenReader()}
136
+ </ftds-base-input>
137
+ `;
138
+ }
139
+ renderMenuContent() {
140
+ return html `
141
+ <div class="period-picker--menu"
142
+ role="dialog"
143
+ aria-modal="false"
144
+ id="date-range-picker">
145
+ <ftds-period-picker .customPeriodLabel=${this.customPeriodLabel}
146
+ .periods=${this.periods}
147
+ .minDate=${this.minDate}
148
+ .maxDate=${this.maxDate}
149
+ .dateInputsVisibility=${this.dateInputsVisibility}
150
+ .defaultPeriod=${this.defaultPeriod}
151
+ .locale=${this.locale}
152
+ @change=${this.onPeriodValueChange}
153
+ @input-validated=${this.onPeriodPickerStatusChange}></ftds-period-picker>
154
+ <div class="period-picker--buttons-container">
155
+ <ftds-button class="cancel-button"
156
+ tertiary
157
+ size="medium"
158
+ family="${DesignSystemFamily.neutral}"
159
+ icon="${FtdsIcons.XMARK}"
160
+ iconVariant="${FtdsIconVariants.regular}"
161
+ label="${ftPeriodI18nContext.messages.cancel()}"
162
+ @click=${this.onCancel}>
163
+ ${ftPeriodI18nContext.messages.cancel()}
164
+ </ftds-button>
165
+ <ftds-button class="apply-button"
166
+ primary
167
+ size="medium" family="${DesignSystemFamily.brand}"
168
+ icon="${FtdsIcons.CHECK}"
169
+ iconVariant="${FtdsIconVariants.regular}"
170
+ label="${ftPeriodI18nContext.messages.apply()}"
171
+ @click=${this.onApply}
172
+ ?disabled=${this.applyIsDisabled}>
173
+ ${ftPeriodI18nContext.messages.apply()}
174
+ </ftds-button>
175
+ </div>
176
+ </div>
177
+ `;
178
+ }
179
+ render() {
180
+ return html `
181
+ <ftds-floating-menu class="period-picker--component"
182
+ @open-status=${this.onFloatingMenuOpenStatus}>
183
+ ${this.renderMenuTrigger()}
184
+ ${this.renderMenuContent()}
185
+ </ftds-floating-menu>
186
+ `;
187
+ }
188
+ onFloatingMenuOpenStatus(e) {
189
+ e.stopPropagation();
190
+ if (e.detail.open) {
191
+ setTimeout(() => this.ftdsPeriodPicker.ftdsRadioGroup.focus(), 0);
192
+ }
193
+ }
194
+ onApply(e) {
195
+ var _a, _b, _c, _d, _e;
196
+ e.stopPropagation();
197
+ if (this.ftdsPeriodPicker) {
198
+ this.currentSelection = this.ftdsPeriodPicker.currentSelection;
199
+ this.value = deepCopy(this.ftdsPeriodPicker.value);
200
+ this.dispatchEvent(new FtPeriodChangeEvent({
201
+ key: (_a = this.currentSelection) === null || _a === void 0 ? void 0 : _a.key,
202
+ from: (_b = this.value) === null || _b === void 0 ? void 0 : _b.from,
203
+ to: (_c = this.value) === null || _c === void 0 ? void 0 : _c.to,
204
+ }));
205
+ this.triggerValidation();
206
+ }
207
+ (_d = this.ftFloatingMenu) === null || _d === void 0 ? void 0 : _d.closeMenu();
208
+ (_e = this.periodPickerTriggerButton) === null || _e === void 0 ? void 0 : _e.focus();
209
+ }
210
+ onCancel(e) {
211
+ var _a, _b;
212
+ e.stopPropagation();
213
+ (_a = this.ftFloatingMenu) === null || _a === void 0 ? void 0 : _a.closeMenu();
214
+ (_b = this.periodPickerTriggerButton) === null || _b === void 0 ? void 0 : _b.focus();
215
+ }
216
+ onPeriodValueChange(e) {
217
+ e.stopPropagation();
218
+ }
219
+ onPeriodPickerStatusChange(e) {
220
+ e.stopPropagation();
221
+ this.applyIsDisabled = e.detail.level === FtInput_Status.error;
222
+ }
223
+ formatCustomDateRange(datePeriod) {
224
+ const dateFromStr = datePeriod.from ? DateFormatter.format(datePeriod.from, this.locale, false, false, false) : "";
225
+ const dateToStr = datePeriod.to ? DateFormatter.format(datePeriod.to, this.locale, false, false, false) : "";
226
+ if (!datePeriod.from && !datePeriod.to) {
227
+ return ftPeriodI18nContext.messages.anyTime();
228
+ }
229
+ else if (datePeriod.from && !datePeriod.to) {
230
+ return ftPeriodI18nContext.messages.fromDate(dateFromStr);
231
+ }
232
+ else if (!datePeriod.from && datePeriod.to) {
233
+ return ftPeriodI18nContext.messages.toDate(dateToStr);
234
+ }
235
+ else {
236
+ return `${dateFromStr} - ${dateToStr}`;
237
+ }
238
+ }
239
+ triggerValidation() {
240
+ super.triggerValidation();
241
+ }
242
+ }
243
+ FtdsPeriodPickerInSelect.elementDefinitions = {
244
+ "ftds-floating-menu": FtdsFloatingMenu,
245
+ "ft-input-label": FtInputLabel,
246
+ "ftds-icon": FtdsIcon,
247
+ "ftds-button": FtdsButton,
248
+ "ftds-period-picker": FtdsPeriodPicker,
249
+ "ftds-base-input": FtdsBaseInput,
250
+ };
251
+ FtdsPeriodPickerInSelect.styles = [inSelectStyles];
252
+ __decorate([
253
+ property()
254
+ ], FtdsPeriodPickerInSelect.prototype, "dateInputsVisibility", void 0);
255
+ __decorate([
256
+ property()
257
+ ], FtdsPeriodPickerInSelect.prototype, "displayMode", void 0);
258
+ __decorate([
259
+ i18n(ftPeriodI18nContext.properties.pickAPeriod())
260
+ ], FtdsPeriodPickerInSelect.prototype, "label", void 0);
261
+ __decorate([
262
+ i18n(ftPeriodI18nContext.properties.custom())
263
+ ], FtdsPeriodPickerInSelect.prototype, "customPeriodLabel", void 0);
264
+ __decorate([
265
+ property({ attribute: false })
266
+ ], FtdsPeriodPickerInSelect.prototype, "defaultPeriod", void 0);
267
+ __decorate([
268
+ property()
269
+ ], FtdsPeriodPickerInSelect.prototype, "defaultValueKey", void 0);
270
+ __decorate([
271
+ property({ attribute: false })
272
+ ], FtdsPeriodPickerInSelect.prototype, "periods", void 0);
273
+ __decorate([
274
+ dateProperty()
275
+ ], FtdsPeriodPickerInSelect.prototype, "minDate", void 0);
276
+ __decorate([
277
+ dateProperty()
278
+ ], FtdsPeriodPickerInSelect.prototype, "maxDate", void 0);
279
+ __decorate([
280
+ property()
281
+ ], FtdsPeriodPickerInSelect.prototype, "locale", void 0);
282
+ __decorate([
283
+ query("ftds-floating-menu")
284
+ ], FtdsPeriodPickerInSelect.prototype, "ftFloatingMenu", void 0);
285
+ __decorate([
286
+ query("ftds-base-input")
287
+ ], FtdsPeriodPickerInSelect.prototype, "ftdsBaseInput", void 0);
288
+ __decorate([
289
+ query(".period-picker--menu")
290
+ ], FtdsPeriodPickerInSelect.prototype, "periodPickerMenu", void 0);
291
+ __decorate([
292
+ query(".period-picker--trigger-button")
293
+ ], FtdsPeriodPickerInSelect.prototype, "periodPickerTriggerButton", void 0);
294
+ __decorate([
295
+ query("ftds-period-picker")
296
+ ], FtdsPeriodPickerInSelect.prototype, "ftdsPeriodPicker", void 0);
297
+ __decorate([
298
+ state()
299
+ ], FtdsPeriodPickerInSelect.prototype, "currentSelection", void 0);
300
+ __decorate([
301
+ state()
302
+ ], FtdsPeriodPickerInSelect.prototype, "applyIsDisabled", void 0);
303
+ __decorate([
304
+ state()
305
+ ], FtdsPeriodPickerInSelect.prototype, "isMenuOpen", void 0);
@@ -0,0 +1,5 @@
1
+ import { FtdsPeriodPickerInSelectDisplayMode, FtdsPeriodPickerProperties } from "./ftds-period-picker.properties";
2
+ export interface FtdsPeriodPickerInSelectProperties extends FtdsPeriodPickerProperties {
3
+ displayMode: FtdsPeriodPickerInSelectDisplayMode;
4
+ defaultValueKey?: string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { dateRangePicker } from "@fluid-topics/design-system-variables";
2
+ export { dateRangePicker as FtdsPeriodPickerCssVariables };
3
+ export declare const inSelectStyles: import("lit").CSSResult;
@@ -0,0 +1,51 @@
1
+ import { css } from "lit";
2
+ import { setVariable } from "@fluid-topics/ft-wc-utils";
3
+ import { FtdsFloatingMenuCssVariables } from "@fluid-topics/ftds-floating-menu";
4
+ import { dateRangePicker } from "@fluid-topics/design-system-variables";
5
+ export { dateRangePicker as FtdsPeriodPickerCssVariables };
6
+ export const inSelectStyles = css `
7
+
8
+ .period-picker--component {
9
+ position: relative;
10
+ display: flex;
11
+ flex-direction: column;
12
+ ${setVariable(FtdsFloatingMenuCssVariables.maxWidth, "none")};
13
+ ${setVariable(FtdsFloatingMenuCssVariables.maxHeight, "none")};
14
+ ${setVariable(FtdsFloatingMenuCssVariables.zIndex, "11")};
15
+
16
+ .period-picker--trigger-button {
17
+ text-align: left;
18
+ }
19
+
20
+ .ftds-floating-menu--wrapper {
21
+ position: fixed;
22
+ }
23
+
24
+ .period-picker--menu {
25
+ padding-top: ${dateRangePicker.menuHorizontalPadding};
26
+ padding-bottom: ${dateRangePicker.menuHorizontalPadding};
27
+
28
+ padding-left: ${dateRangePicker.menuVerticalPadding};
29
+ padding-right: ${dateRangePicker.menuVerticalPadding};
30
+
31
+ box-sizing: border-box;
32
+
33
+ .period-picker--buttons-container {
34
+ display: flex;
35
+ margin-top: ${dateRangePicker.menuVerticalGap};
36
+
37
+ .cancel-button {
38
+ margin-left: auto;
39
+ }
40
+
41
+ .apply-button {
42
+ margin-left: ${dateRangePicker.menuButtonsVerticalGap};
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ input {
49
+ background-color: transparent;
50
+ }
51
+ `;