@3mo/date-time-fields 0.13.0-preview.0 → 0.14.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.
@@ -8,12 +8,18 @@ import type { Calendar } from './selection/index.js';
8
8
  * @attr pickerHidden - Hide the date picker
9
9
  * @attr shortcutReferenceDate - The date to use as a reference for shortcuts
10
10
  * @attr precision - The precision of the date picker. Defaults to 'minute'
11
+ * @attr min - The minimum selectable date (inclusive). Dates before this are disabled.
12
+ * @attr max - The maximum selectable date (inclusive). Dates after this are disabled.
13
+ * @attr dateDisabled - A function that determines whether a date should be disabled. Receives a DateTime object and should return a boolean.
11
14
  */
12
15
  export declare abstract class FieldDateTimeBase<T> extends InputFieldComponent<T> {
13
16
  open: boolean;
14
17
  pickerHidden: boolean;
15
18
  shortcutReferenceDate: import("@3mo/date-time/DateTime.js").DateTime;
16
19
  precision: FieldDateTimePrecision;
20
+ min?: DateTime;
21
+ max?: DateTime;
22
+ dateDisabled?: (date: DateTime) => boolean;
17
23
  navigationDate: import("@3mo/date-time/DateTime.js").DateTime;
18
24
  protected readonly calendar?: Calendar;
19
25
  protected connected(): void;
@@ -39,6 +45,7 @@ export declare abstract class FieldDateTimeBase<T> extends InputFieldComponent<T
39
45
  protected get popoverSelectionTemplate(): HTMLTemplateResult;
40
46
  protected abstract get presetsTemplate(): HTMLTemplateResult;
41
47
  protected getPresetTemplate(label: string, value: () => T): HTMLTemplateResult;
48
+ private isPresetDisabled;
42
49
  protected get dateTemplate(): HTMLTemplateResult;
43
50
  protected get calendarTemplate(): HTMLTemplateResult;
44
51
  protected abstract get calendarValue(): DateTimeRange | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"FieldDateTimeBase.d.ts","sourceRoot":"","sources":["../FieldDateTimeBase.ts"],"names":[],"mappings":"AACA,OAAO,EAA0E,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC3H,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,C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AK,gBAAgB,GAQ3B;IAED,OAAO,KAAK,kBAAkB,GAQ7B;IAED,OAAO,KAAK,kBAAkB,GAQ7B;IAED,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,sBAAsB;CAMpF"}
@@ -1,19 +1,33 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { cache, css, html, live, property, style, bind, state, query, ifDefined } from '@a11d/lit';
3
+ import { hasChanged } from '@a11d/equals';
3
4
  import { InputFieldComponent } from '@3mo/field';
4
5
  import { FieldDateTimePrecision } from './FieldDateTimePrecision.js';
6
+ const dateTimeConverter = (value) => {
7
+ if (value instanceof DateTime) {
8
+ return value;
9
+ }
10
+ if (value instanceof Date || typeof value === 'string' || typeof value === 'number') {
11
+ const date = new DateTime(value);
12
+ return isNaN(date.getTime()) ? undefined : date;
13
+ }
14
+ return undefined;
15
+ };
5
16
  /**
6
17
  * @attr open - Whether the date picker is open
7
18
  * @attr pickerHidden - Hide the date picker
8
19
  * @attr shortcutReferenceDate - The date to use as a reference for shortcuts
9
20
  * @attr precision - The precision of the date picker. Defaults to 'minute'
21
+ * @attr min - The minimum selectable date (inclusive). Dates before this are disabled.
22
+ * @attr max - The maximum selectable date (inclusive). Dates after this are disabled.
23
+ * @attr dateDisabled - A function that determines whether a date should be disabled. Receives a DateTime object and should return a boolean.
10
24
  */
11
25
  export class FieldDateTimeBase extends InputFieldComponent {
12
26
  constructor() {
13
27
  super(...arguments);
14
28
  this.open = false;
15
29
  this.pickerHidden = false;
16
- this.shortcutReferenceDate = new DateTime;
30
+ this.shortcutReferenceDate = new DateTime();
17
31
  this.precision = FieldDateTimePrecision.Minute;
18
32
  this.navigationDate = new DateTime();
19
33
  this.handleLanguageChange = () => {
@@ -180,13 +194,25 @@ export class FieldDateTimeBase extends InputFieldComponent {
180
194
  `;
181
195
  }
182
196
  getPresetTemplate(label, value) {
197
+ const v = value();
198
+ if (this.isPresetDisabled(v)) {
199
+ return html.nothing;
200
+ }
183
201
  const handlePresetClick = () => {
184
- const v = value();
185
202
  this.handleChange(v);
186
203
  this.calendar?.setNavigatingValue(v instanceof DateTimeRange ? v.start : v instanceof DateTime ? v : undefined, 'smooth');
187
204
  };
188
205
  return html `<mo-list-item @click=${handlePresetClick}>${label}</mo-list-item>`;
189
206
  }
207
+ isPresetDisabled(value) {
208
+ const dates = value instanceof DateTimeRange
209
+ ? [value.start, value.end].filter((d) => !!d)
210
+ : value instanceof DateTime ? [value] : [];
211
+ const precision = this.precision > FieldDateTimePrecision.Day ? FieldDateTimePrecision.Day : this.precision;
212
+ return dates.some(date => (!!this.min && precision.isSmallerThan(date, this.min) && !precision.equals(date, this.min))
213
+ || (!!this.max && precision.isSmallerThan(this.max, date) && !precision.equals(this.max, date))
214
+ || (this.dateDisabled?.(date) ?? false));
215
+ }
190
216
  get dateTemplate() {
191
217
  return this.calendarTemplate;
192
218
  }
@@ -195,6 +221,9 @@ export class FieldDateTimeBase extends InputFieldComponent {
195
221
  <mo-calendar
196
222
  .precision=${this.precision > FieldDateTimePrecision.Day ? FieldDateTimePrecision.Day : this.precision}
197
223
  .value=${this.calendarValue}
224
+ .min=${this.min}
225
+ .max=${this.max}
226
+ .dateDisabled=${this.dateDisabled}
198
227
  @dateClick=${(e) => this.handleSelectedDateChange(e.detail, this.precision)}
199
228
  ></mo-calendar>
200
229
  `;
@@ -254,11 +283,20 @@ __decorate([
254
283
  property({ type: Boolean })
255
284
  ], FieldDateTimeBase.prototype, "pickerHidden", void 0);
256
285
  __decorate([
257
- property({ type: Object })
286
+ property({ type: Object, converter: dateTimeConverter })
258
287
  ], FieldDateTimeBase.prototype, "shortcutReferenceDate", void 0);
259
288
  __decorate([
260
289
  property({ type: String, converter: value => FieldDateTimePrecision.parse(value || undefined) })
261
290
  ], FieldDateTimeBase.prototype, "precision", void 0);
291
+ __decorate([
292
+ property({ type: Object, converter: dateTimeConverter })
293
+ ], FieldDateTimeBase.prototype, "min", void 0);
294
+ __decorate([
295
+ property({ type: Object, converter: dateTimeConverter })
296
+ ], FieldDateTimeBase.prototype, "max", void 0);
297
+ __decorate([
298
+ property({ type: Object, hasChanged })
299
+ ], FieldDateTimeBase.prototype, "dateDisabled", void 0);
262
300
  __decorate([
263
301
  state()
264
302
  ], FieldDateTimeBase.prototype, "navigationDate", void 0);