@genesislcap/foundation-ui 14.437.4 → 14.437.5-canary.date-picker-updates

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.
@@ -22,6 +22,14 @@ export declare class DatePicker extends FoundationElement {
22
22
  format: string;
23
23
  formatChanged(oldValue: string, newValue: string): void;
24
24
  lang: string;
25
+ langChanged(): void;
26
+ /**
27
+ * @attr use-locale-format - when true, `format` is set from dayjs locale `L`.
28
+ * Uses the browser locale (`navigator.language`) unless `lang` is set on the element.
29
+ * @default false
30
+ */
31
+ useLocaleFormat: boolean;
32
+ useLocaleFormatChanged(): void;
25
33
  visible: boolean;
26
34
  /**
27
35
  * @attr inline-calendar - display the calendar beneath the value display.
@@ -68,6 +76,19 @@ export declare class DatePicker extends FoundationElement {
68
76
  * ```
69
77
  */
70
78
  label: string;
79
+ /**
80
+ * @attr allow-empty - when true, no initial date is selected; the input shows a placeholder until the user picks a date.
81
+ * @default false
82
+ * @example
83
+ * ```html
84
+ * <rapid-date-picker allow-empty format="DD/MM/YYYY"></rapid-date-picker>
85
+ * ```
86
+ */
87
+ allowEmpty: boolean;
88
+ /**
89
+ * @attr placeholder - hint shown when allow-empty is set and no date is selected. Defaults from `format` (e.g. DD/MM/YYYY → dd/mm/yyyy).
90
+ */
91
+ placeholder: string;
71
92
  /**
72
93
  * @attr value - sets the value of the date picker
73
94
  * @example
@@ -116,8 +137,39 @@ export declare class DatePicker extends FoundationElement {
116
137
  disabledDaysOfWeek: number[];
117
138
  calendar: Calendar;
118
139
  substringNumber: number;
140
+ disconnectedCallback(): void;
119
141
  connectedCallback(): void;
142
+ /**
143
+ * Clears the selected date (only when `allow-empty` is enabled).
144
+ * @public
145
+ */
146
+ clear(): void;
147
+ /**
148
+ * @internal
149
+ */
150
+ get inputValue(): string;
151
+ /**
152
+ * @internal
153
+ */
154
+ get inputPlaceholder(): string;
155
+ /**
156
+ * Locale for display format and calendar labels: explicit `lang`, or browser when using locale format.
157
+ * @internal
158
+ */
159
+ private get effectiveLang();
160
+ private applyLocaleFormat;
161
+ private initializeEmpty;
162
+ private initializeWithValue;
163
+ private initializeWithDefaultDate;
164
+ private applyValue;
165
+ private clearToEmpty;
120
166
  updateHeaderText(): void;
167
+ protected visibleChanged(_prev: boolean, next: boolean): void;
168
+ private clickOutside;
169
+ private keydownOutside;
170
+ private handleKeydownOutside;
171
+ private handleClickOutside;
172
+ private closeCalendar;
121
173
  toggleCalendar(): void;
122
174
  toggleVisibility(): void;
123
175
  isSelectedDate(date: any): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../../src/date-picker/date-picker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAO/D,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,eAAO,MAAM,iCAAiC,EAAE,cAA0B,CAAC;AAE3E,eAAO,MAAM,uBAAuB,IAAK,CAAC;AAE1C;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,iBAAiB;IAC/C;;;;;;;;;OASG;IACG,MAAM,SAAgB;IAC5B,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAK1C,IAAI,SAAW;IACf,OAAO,UAAS;IAEtB;;;;;;;;;OASG;IACsD,cAAc,EAAE,OAAO,CAAC;IACjF,qBAAqB;IAIrB;;;;;;;;;OASG;IACoD,YAAY,EAAE,OAAO,CAAC;IAC7E,2BAA2B;IAI3B;;;;;;;;;OASG;IACG,QAAQ,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAY;IAE/D;;;;;;;;OAQG;IACG,KAAK,EAAE,MAAM,CAAC;IACpB;;;;;;;;OAQG;IACG,KAAK,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAU/C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BAAmB;IAI3B,OAAO,CAAC,yBAAyB;IAkBjC,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,YAAY;IAepB,gBAAgB,IAAI,IAAI;IAKxB,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IAa7D,OAAO,CAAC,YAAY,CAAiD;IAErE,OAAO,CAAC,cAAc,CAAsD;IAE5E,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,aAAa;IAQrB,cAAc,IAAI,IAAI;IAUtB,gBAAgB,IAAI,IAAI;IASxB,cAAc,CAAC,IAAI,KAAA,GAAG,OAAO;IAO7B,sBAAsB,IAAI,OAAO;IASjC,SAAS,IAAI,IAAI;IAMjB,SAAS,IAAI,IAAI;IAMjB,SAAS,CAAC,GAAG,KAAA,GAAG,IAAI;IAgBpB,gBAAgB,IAAI,GAAG,EAAE;CAkB1B;AACD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;qBAM/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"date-picker.template.d.ts","sourceRoot":"","sources":["../../../src/date-picker/date-picker.template.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,oEAmEnD,CAAC;AAEF,eAAO,MAAM,4BAA4B,iEAExC,CAAC"}
1
+ {"version":3,"file":"date-picker.template.d.ts","sourceRoot":"","sources":["../../../src/date-picker/date-picker.template.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,oEA0EnD,CAAC;AAEF,eAAO,MAAM,4BAA4B,iEAExC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import 'dayjs/locale/en-gb';
2
+ /**
3
+ * Maps BCP-47 tags to dayjs locale names (dayjs provides `en`, `en-gb`, not `en-US`).
4
+ * @public
5
+ */
6
+ export declare function resolveDayjsLocale(lang: string): string;
7
+ /**
8
+ * Browser BCP-47 locale (e.g. `en-GB`), or `en` when unavailable (SSR/tests).
9
+ * @public
10
+ */
11
+ export declare function getBrowserLocale(): string;
12
+ /**
13
+ * Display format from dayjs locale `L` (e.g. en / en-US → MM/DD/YYYY, en-gb → DD/MM/YYYY).
14
+ * Falls back to `en` when the locale is not loaded in dayjs.
15
+ * @public
16
+ */
17
+ export declare function getDisplayFormatForLang(lang?: string): string;
18
+ /**
19
+ * Maps a dayjs-style display format to a lowercase placeholder hint (e.g. DD/MM/YYYY → dd/mm/yyyy).
20
+ * @public
21
+ */
22
+ export declare function formatToPlaceholder(format: string): string;
23
+ export declare function hasDateValue(value: string | null | undefined): boolean;
24
+ //# sourceMappingURL=date-picker.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-picker.util.d.ts","sourceRoot":"","sources":["../../../src/date-picker/date-picker.util.ts"],"names":[],"mappings":"AAEA,OAAO,oBAAoB,CAAC;AAI5B;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASvD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAKzC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,MAAa,GAAG,MAAM,CASnE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQ1D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEtE"}
@@ -1,4 +1,5 @@
1
1
  export * from './date-picker.styles';
2
2
  export * from './date-picker.template';
3
3
  export * from './date-picker';
4
+ export * from './date-picker.util';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-picker/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-picker/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC"}
@@ -138,6 +138,17 @@ export declare const ActionsMenu: React.ForwardRefExoticComponent<
138
138
  >;
139
139
  export type ActionsMenuRef = ActionsMenuWC;
140
140
 
141
+ export declare const AiCriteriaSearch: React.ForwardRefExoticComponent<
142
+ React.PropsWithChildren<
143
+ Omit<PublicOf<AiCriteriaSearchWC>, 'children' | 'style'> &
144
+ HTMLWCProps & {
145
+ onCriteriaChanged?: (event: CustomEvent<unknown>) => void;
146
+ onValidationErrors?: (event: CustomEvent<unknown>) => void;
147
+ }
148
+ > & React.RefAttributes<AiCriteriaSearchWC>
149
+ >;
150
+ export type AiCriteriaSearchRef = AiCriteriaSearchWC;
151
+
141
152
  export declare const Accordion: React.ForwardRefExoticComponent<
142
153
  React.PropsWithChildren<
143
154
  Omit<PublicOf<AccordionWC>, 'children' | 'style'> &
@@ -156,17 +167,6 @@ export declare const AiIndicator: React.ForwardRefExoticComponent<
156
167
  >;
157
168
  export type AiIndicatorRef = AiIndicatorWC;
158
169
 
159
- export declare const AiCriteriaSearch: React.ForwardRefExoticComponent<
160
- React.PropsWithChildren<
161
- Omit<PublicOf<AiCriteriaSearchWC>, 'children' | 'style'> &
162
- HTMLWCProps & {
163
- onCriteriaChanged?: (event: CustomEvent<unknown>) => void;
164
- onValidationErrors?: (event: CustomEvent<unknown>) => void;
165
- }
166
- > & React.RefAttributes<AiCriteriaSearchWC>
167
- >;
168
- export type AiCriteriaSearchRef = AiCriteriaSearchWC;
169
-
170
170
  export declare const Anchor: React.ForwardRefExoticComponent<
171
171
  React.PropsWithChildren<
172
172
  Omit<PublicOf<AnchorWC>, 'children' | 'style'> &
@@ -6,9 +6,11 @@ import dayjs from 'dayjs';
6
6
  import customParseFormat from 'dayjs/plugin/customParseFormat';
7
7
  import localeData from 'dayjs/plugin/localeData';
8
8
  import LocalizedFormat from 'dayjs/plugin/localizedFormat';
9
+ import { wasClickOutsideElement } from '../utils';
9
10
  import Calendar from './calendar';
10
11
  import { foundationDatePickerStyles as styles } from './date-picker.styles';
11
12
  import { foundationDatePickerTemplate as template } from './date-picker.template';
13
+ import { formatToPlaceholder, getBrowserLocale, getDisplayFormatForLang, hasDateValue, } from './date-picker.util';
12
14
  import Day from './day';
13
15
  import { getNextEnabledDay } from './day.util';
14
16
  export const foundationDatePickerShadowOptions = undefined;
@@ -56,12 +58,24 @@ export class DatePicker extends FoundationElement {
56
58
  * ```
57
59
  */
58
60
  this.disabledDaysOfWeek = [];
61
+ this.clickOutside = (e) => this.handleClickOutside(e);
62
+ this.keydownOutside = (e) => this.handleKeydownOutside(e);
59
63
  }
60
64
  formatChanged(oldValue, newValue) {
61
- if (newValue && this.calendar) {
65
+ if (newValue && this.calendar && hasDateValue(this.value)) {
62
66
  this.formatDate = dayjs(this.currentDate.Date).format(newValue);
63
67
  }
64
68
  }
69
+ langChanged() {
70
+ if (this.useLocaleFormat) {
71
+ this.applyLocaleFormat();
72
+ }
73
+ }
74
+ useLocaleFormatChanged() {
75
+ if (this.useLocaleFormat) {
76
+ this.applyLocaleFormat();
77
+ }
78
+ }
65
79
  inlineCalendarChanged() {
66
80
  this.toggleVisibility();
67
81
  }
@@ -69,40 +83,184 @@ export class DatePicker extends FoundationElement {
69
83
  this.toggleVisibility();
70
84
  }
71
85
  valueChanged(oldValue, newValue) {
72
- if (newValue && this.calendar) {
73
- const localeFormat = dayjs().localeData().longDateFormat('L');
74
- this.currentDate = new Day(dayjs(newValue, localeFormat).toDate(), this.lang);
75
- this.calendar.goToDate(this.currentDate.monthNumber, this.currentDate.year);
76
- this.formatDate = dayjs(this.currentDate.Date).format(this.format);
77
- this.updateHeaderText();
78
- this.monthList = this.getMonthDaysGrid();
86
+ if (!this.calendar) {
87
+ return;
88
+ }
89
+ if (this.allowEmpty && !hasDateValue(newValue)) {
90
+ this.clearToEmpty(false);
91
+ return;
79
92
  }
93
+ if (hasDateValue(newValue)) {
94
+ this.applyValue(newValue);
95
+ }
96
+ }
97
+ disconnectedCallback() {
98
+ document.removeEventListener('mousedown', this.clickOutside);
99
+ document.removeEventListener('keydown', this.keydownOutside);
100
+ super.disconnectedCallback();
80
101
  }
81
102
  connectedCallback() {
82
- var _a;
83
103
  super.connectedCallback();
84
104
  dayjs.extend(customParseFormat);
85
105
  dayjs.extend(LocalizedFormat);
86
106
  dayjs.extend(localeData);
87
107
  this.substringNumber = 3;
108
+ if (this.useLocaleFormat) {
109
+ this.applyLocaleFormat();
110
+ }
88
111
  const dateString = this.value;
89
- const dayjsDate = dateString ? dayjs(dateString, 'MM-DD-YYYY') : dayjs();
90
- let currentDate = new Day(dayjsDate.toDate(), this.lang);
112
+ if (this.allowEmpty && !hasDateValue(dateString)) {
113
+ this.initializeEmpty();
114
+ return;
115
+ }
116
+ if (hasDateValue(dateString)) {
117
+ this.initializeWithValue(dateString);
118
+ return;
119
+ }
120
+ this.initializeWithDefaultDate();
121
+ }
122
+ /**
123
+ * Clears the selected date (only when `allow-empty` is enabled).
124
+ * @public
125
+ */
126
+ clear() {
127
+ if (!this.allowEmpty) {
128
+ return;
129
+ }
130
+ this.clearToEmpty(true);
131
+ }
132
+ /**
133
+ * @internal
134
+ */
135
+ get inputValue() {
136
+ return hasDateValue(this.value) ? this.formatDate : '';
137
+ }
138
+ /**
139
+ * @internal
140
+ */
141
+ get inputPlaceholder() {
142
+ var _a;
143
+ if (!this.allowEmpty || hasDateValue(this.value)) {
144
+ return '';
145
+ }
146
+ return ((_a = this.placeholder) === null || _a === void 0 ? void 0 : _a.trim()) || formatToPlaceholder(this.format);
147
+ }
148
+ /**
149
+ * Locale for display format and calendar labels: explicit `lang`, or browser when using locale format.
150
+ * @internal
151
+ */
152
+ get effectiveLang() {
153
+ if (this.useLocaleFormat && !this.hasAttribute('lang')) {
154
+ return getBrowserLocale();
155
+ }
156
+ return this.lang;
157
+ }
158
+ applyLocaleFormat() {
159
+ this.format = getDisplayFormatForLang(this.effectiveLang);
160
+ }
161
+ initializeEmpty() {
162
+ const viewDate = dayjs();
163
+ this.currentDate = new Day(viewDate.toDate(), this.effectiveLang);
164
+ this.calendar = new Calendar(this.currentDate.year, this.currentDate.monthNumber, this.effectiveLang);
165
+ this.formatDate = '';
166
+ this.value = '';
167
+ this.currentMonth = this.calendar.month.name;
168
+ this.currentYear = this.calendar.year;
169
+ this.monthList = this.getMonthDaysGrid();
170
+ }
171
+ initializeWithValue(dateString) {
172
+ this.applyValue(dateString);
173
+ }
174
+ initializeWithDefaultDate() {
175
+ var _a;
176
+ let currentDate = new Day(dayjs().toDate(), this.effectiveLang);
91
177
  if ((_a = this.disabledDaysOfWeek) === null || _a === void 0 ? void 0 : _a.length) {
92
- currentDate = getNextEnabledDay(this.disabledDaysOfWeek, currentDate, this.lang);
178
+ currentDate = getNextEnabledDay(this.disabledDaysOfWeek, currentDate, this.effectiveLang);
93
179
  }
94
180
  this.currentDate = currentDate;
95
- this.calendar = new Calendar(this.currentDate.year, this.currentDate.monthNumber, this.lang);
181
+ this.calendar = new Calendar(this.currentDate.year, this.currentDate.monthNumber, this.effectiveLang);
96
182
  this.value = dayjs(this.currentDate.Date).format('MM-DD-YYYY');
97
183
  this.currentMonth = this.calendar.month.name;
98
184
  this.currentYear = this.calendar.year;
99
185
  this.formatDate = dayjs(this.currentDate.Date).format(this.format);
100
186
  this.monthList = this.getMonthDaysGrid();
101
187
  }
188
+ applyValue(dateString) {
189
+ var _a;
190
+ const parsed = dayjs(dateString, this.format, true).isValid()
191
+ ? dayjs(dateString, this.format)
192
+ : dayjs(dateString, 'MM-DD-YYYY');
193
+ let currentDate = new Day(parsed.toDate(), this.effectiveLang);
194
+ if ((_a = this.disabledDaysOfWeek) === null || _a === void 0 ? void 0 : _a.length) {
195
+ currentDate = getNextEnabledDay(this.disabledDaysOfWeek, currentDate, this.effectiveLang);
196
+ }
197
+ this.currentDate = currentDate;
198
+ if (!this.calendar) {
199
+ this.calendar = new Calendar(this.currentDate.year, this.currentDate.monthNumber, this.effectiveLang);
200
+ }
201
+ else {
202
+ this.calendar.goToDate(this.currentDate.monthNumber, this.currentDate.year);
203
+ }
204
+ this.formatDate = dayjs(this.currentDate.Date).format(this.format);
205
+ this.value = dayjs(this.currentDate.Date).format('MM-DD-YYYY');
206
+ this.updateHeaderText();
207
+ this.monthList = this.getMonthDaysGrid();
208
+ }
209
+ clearToEmpty(emitEvent) {
210
+ const viewDate = dayjs();
211
+ this.currentDate = new Day(viewDate.toDate(), this.effectiveLang);
212
+ if (this.calendar) {
213
+ this.calendar.goToDate(this.currentDate.monthNumber, this.currentDate.year);
214
+ this.updateHeaderText();
215
+ this.monthList = this.getMonthDaysGrid();
216
+ }
217
+ this.formatDate = '';
218
+ this.value = '';
219
+ if (emitEvent) {
220
+ this.$emit('value-changed', undefined);
221
+ }
222
+ }
102
223
  updateHeaderText() {
103
224
  this.currentMonth = this.calendar.month.name;
104
225
  this.currentYear = this.calendar.year;
105
226
  }
227
+ visibleChanged(_prev, next) {
228
+ if (this.inlineCalendar) {
229
+ return;
230
+ }
231
+ if (next) {
232
+ document.addEventListener('mousedown', this.clickOutside);
233
+ document.addEventListener('keydown', this.keydownOutside);
234
+ }
235
+ else {
236
+ document.removeEventListener('mousedown', this.clickOutside);
237
+ document.removeEventListener('keydown', this.keydownOutside);
238
+ }
239
+ }
240
+ handleKeydownOutside(event) {
241
+ if (this.inlineCalendar || !this.visible) {
242
+ return;
243
+ }
244
+ if (event.key === 'Escape') {
245
+ event.preventDefault();
246
+ this.closeCalendar();
247
+ }
248
+ }
249
+ handleClickOutside(event) {
250
+ if (this.inlineCalendar || !this.visible) {
251
+ return;
252
+ }
253
+ if (wasClickOutsideElement(event, this)) {
254
+ this.closeCalendar();
255
+ }
256
+ }
257
+ closeCalendar() {
258
+ if (!this.visible) {
259
+ return;
260
+ }
261
+ this.visible = false;
262
+ this.toggleVisibility();
263
+ }
106
264
  toggleCalendar() {
107
265
  this.visible = !this.visible;
108
266
  this.toggleVisibility();
@@ -115,6 +273,9 @@ export class DatePicker extends FoundationElement {
115
273
  this.calendarDropdownClasses = classNames(['visible', this.visible], this.position, ['inline', this.inlineCalendar], ['hide-weekends', this.hideWeekends]);
116
274
  }
117
275
  isSelectedDate(date) {
276
+ if (this.allowEmpty && !hasDateValue(this.value)) {
277
+ return false;
278
+ }
118
279
  return dayjs(date.Date).isSame(this.currentDate.Date, 'day');
119
280
  }
120
281
  isCurrentCalendarMonth() {
@@ -135,8 +296,10 @@ export class DatePicker extends FoundationElement {
135
296
  this.monthList = this.getMonthDaysGrid();
136
297
  }
137
298
  selectDay(day) {
138
- if (dayjs(day.Date).isSame(this.currentDate.Date))
299
+ const sameDayAsCurrent = dayjs(day.Date).isSame(this.currentDate.Date, 'day');
300
+ if (sameDayAsCurrent && hasDateValue(this.value)) {
139
301
  return;
302
+ }
140
303
  this.currentDate = day;
141
304
  if (day.monthNumber !== this.calendar.month.number) {
142
305
  this.prevMonth();
@@ -168,6 +331,9 @@ __decorate([
168
331
  __decorate([
169
332
  attr
170
333
  ], DatePicker.prototype, "lang", void 0);
334
+ __decorate([
335
+ attr({ attribute: 'use-locale-format', mode: 'boolean' })
336
+ ], DatePicker.prototype, "useLocaleFormat", void 0);
171
337
  __decorate([
172
338
  attr
173
339
  ], DatePicker.prototype, "visible", void 0);
@@ -183,6 +349,12 @@ __decorate([
183
349
  __decorate([
184
350
  attr
185
351
  ], DatePicker.prototype, "label", void 0);
352
+ __decorate([
353
+ attr({ attribute: 'allow-empty', mode: 'boolean' })
354
+ ], DatePicker.prototype, "allowEmpty", void 0);
355
+ __decorate([
356
+ attr
357
+ ], DatePicker.prototype, "placeholder", void 0);
186
358
  __decorate([
187
359
  attr
188
360
  ], DatePicker.prototype, "value", void 0);
@@ -6,7 +6,15 @@ const SUNDAY_INDEX = 1;
6
6
  const SATURDAY_INDEX = 7;
7
7
  const WEEKEND_DAY_INDICES = [SUNDAY_INDEX, SATURDAY_INDEX];
8
8
  export const getPrefixedDatePicker = (prefix) => html `
9
- <${prefix}-text-field data-test-id="date-picker" readonly :value="${(x) => x.formatDate}" part="date-toggle" class="date-toggle" @click="${(x) => x.toggleCalendar()}">
9
+ <${prefix}-text-field
10
+ data-test-id="date-picker"
11
+ readonly
12
+ :value="${(x) => x.inputValue}"
13
+ placeholder="${(x) => x.inputPlaceholder}"
14
+ part="date-toggle"
15
+ class="date-toggle"
16
+ @click="${(x) => x.toggleCalendar()}"
17
+ >
10
18
  ${(x) => x.label}
11
19
  <div class="input-icon-container" part="input-icon-container" slot="end"><${prefix}-icon variant="regular" name="calendar-alt" size="sm"></${prefix}-icon></div>
12
20
  </${prefix}-text-field>
@@ -0,0 +1,59 @@
1
+ import dayjs from 'dayjs';
2
+ import localeData from 'dayjs/plugin/localeData';
3
+ import 'dayjs/locale/en-gb';
4
+ dayjs.extend(localeData);
5
+ /**
6
+ * Maps BCP-47 tags to dayjs locale names (dayjs provides `en`, `en-gb`, not `en-US`).
7
+ * @public
8
+ */
9
+ export function resolveDayjsLocale(lang) {
10
+ const normalized = ((lang === null || lang === void 0 ? void 0 : lang.trim()) || 'en').toLowerCase().replace('_', '-');
11
+ if (normalized === 'en-us' || normalized === 'en') {
12
+ return 'en';
13
+ }
14
+ if (normalized === 'en-gb') {
15
+ return 'en-gb';
16
+ }
17
+ return lang.trim();
18
+ }
19
+ /**
20
+ * Browser BCP-47 locale (e.g. `en-GB`), or `en` when unavailable (SSR/tests).
21
+ * @public
22
+ */
23
+ export function getBrowserLocale() {
24
+ if (typeof navigator !== 'undefined' && navigator.language) {
25
+ return navigator.language;
26
+ }
27
+ return 'en';
28
+ }
29
+ /**
30
+ * Display format from dayjs locale `L` (e.g. en / en-US → MM/DD/YYYY, en-gb → DD/MM/YYYY).
31
+ * Falls back to `en` when the locale is not loaded in dayjs.
32
+ * @public
33
+ */
34
+ export function getDisplayFormatForLang(lang = 'en') {
35
+ const locale = resolveDayjsLocale(lang);
36
+ dayjs.locale(locale);
37
+ const format = dayjs.localeData().longDateFormat('L');
38
+ if (format) {
39
+ return format;
40
+ }
41
+ dayjs.locale('en');
42
+ return dayjs.localeData().longDateFormat('L') || 'MM/DD/YYYY';
43
+ }
44
+ /**
45
+ * Maps a dayjs-style display format to a lowercase placeholder hint (e.g. DD/MM/YYYY → dd/mm/yyyy).
46
+ * @public
47
+ */
48
+ export function formatToPlaceholder(format) {
49
+ return format
50
+ .replace(/YYYY/g, 'yyyy')
51
+ .replace(/YY(?!Y)/g, 'yy')
52
+ .replace(/DD/g, 'dd')
53
+ .replace(/D(?!D)/g, 'd')
54
+ .replace(/MM/g, 'mm')
55
+ .replace(/M(?!M)/g, 'm');
56
+ }
57
+ export function hasDateValue(value) {
58
+ return value !== null && value !== undefined && String(value).trim() !== '';
59
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './date-picker.styles';
2
2
  export * from './date-picker.template';
3
3
  export * from './date-picker';
4
+ export * from './date-picker.util';
package/dist/react.cjs CHANGED
@@ -112,16 +112,6 @@ const ActionsMenu = React.forwardRef(function ActionsMenu(props, ref) {
112
112
  return React.createElement(customElements.getName(ActionsMenuWC) ?? '%%prefix%%-actions-menu', { ...rest, ref }, children);
113
113
  });
114
114
 
115
- const Accordion = React.forwardRef(function Accordion(props, ref) {
116
- const { children, ...rest } = props;
117
- return React.createElement(customElements.getName(AccordionWC) ?? '%%prefix%%-accordion', { ...rest, ref }, children);
118
- });
119
-
120
- const AiIndicator = React.forwardRef(function AiIndicator(props, ref) {
121
- const { children, ...rest } = props;
122
- return React.createElement(customElements.getName(AiIndicatorWC) ?? '%%prefix%%-ai-indicator', { ...rest, ref }, children);
123
- });
124
-
125
115
  const AiCriteriaSearch = React.forwardRef(function AiCriteriaSearch(props, ref) {
126
116
  const { onCriteriaChanged, onValidationErrors, children, ...rest } = props;
127
117
  const _innerRef = React.useRef(null);
@@ -144,6 +134,16 @@ const AiCriteriaSearch = React.forwardRef(function AiCriteriaSearch(props, ref)
144
134
  return React.createElement(customElements.getName(AiCriteriaSearchWC) ?? '%%prefix%%-ai-criteria-search', { ...rest, ref: _mergeRefs(_innerRef, ref) }, children);
145
135
  });
146
136
 
137
+ const Accordion = React.forwardRef(function Accordion(props, ref) {
138
+ const { children, ...rest } = props;
139
+ return React.createElement(customElements.getName(AccordionWC) ?? '%%prefix%%-accordion', { ...rest, ref }, children);
140
+ });
141
+
142
+ const AiIndicator = React.forwardRef(function AiIndicator(props, ref) {
143
+ const { children, ...rest } = props;
144
+ return React.createElement(customElements.getName(AiIndicatorWC) ?? '%%prefix%%-ai-indicator', { ...rest, ref }, children);
145
+ });
146
+
147
147
  const Anchor = React.forwardRef(function Anchor(props, ref) {
148
148
  const { children, ...rest } = props;
149
149
  return React.createElement(customElements.getName(AnchorWC) ?? '%%prefix%%-anchor', { ...rest, ref }, children);
@@ -879,9 +879,9 @@ const UrlInput = React.forwardRef(function UrlInput(props, ref) {
879
879
  module.exports = {
880
880
  AccordionItem,
881
881
  ActionsMenu,
882
+ AiCriteriaSearch,
882
883
  Accordion,
883
884
  AiIndicator,
884
- AiCriteriaSearch,
885
885
  Anchor,
886
886
  AnchoredRegion,
887
887
  Avatar,
package/dist/react.mjs CHANGED
@@ -110,16 +110,6 @@ export const ActionsMenu = React.forwardRef(function ActionsMenu(props, ref) {
110
110
  return React.createElement(customElements.getName(ActionsMenuWC) ?? '%%prefix%%-actions-menu', { ...rest, ref }, children);
111
111
  });
112
112
 
113
- export const Accordion = React.forwardRef(function Accordion(props, ref) {
114
- const { children, ...rest } = props;
115
- return React.createElement(customElements.getName(AccordionWC) ?? '%%prefix%%-accordion', { ...rest, ref }, children);
116
- });
117
-
118
- export const AiIndicator = React.forwardRef(function AiIndicator(props, ref) {
119
- const { children, ...rest } = props;
120
- return React.createElement(customElements.getName(AiIndicatorWC) ?? '%%prefix%%-ai-indicator', { ...rest, ref }, children);
121
- });
122
-
123
113
  export const AiCriteriaSearch = React.forwardRef(function AiCriteriaSearch(props, ref) {
124
114
  const { onCriteriaChanged, onValidationErrors, children, ...rest } = props;
125
115
  const _innerRef = React.useRef(null);
@@ -142,6 +132,16 @@ export const AiCriteriaSearch = React.forwardRef(function AiCriteriaSearch(props
142
132
  return React.createElement(customElements.getName(AiCriteriaSearchWC) ?? '%%prefix%%-ai-criteria-search', { ...rest, ref: _mergeRefs(_innerRef, ref) }, children);
143
133
  });
144
134
 
135
+ export const Accordion = React.forwardRef(function Accordion(props, ref) {
136
+ const { children, ...rest } = props;
137
+ return React.createElement(customElements.getName(AccordionWC) ?? '%%prefix%%-accordion', { ...rest, ref }, children);
138
+ });
139
+
140
+ export const AiIndicator = React.forwardRef(function AiIndicator(props, ref) {
141
+ const { children, ...rest } = props;
142
+ return React.createElement(customElements.getName(AiIndicatorWC) ?? '%%prefix%%-ai-indicator', { ...rest, ref }, children);
143
+ });
144
+
145
145
  export const Anchor = React.forwardRef(function Anchor(props, ref) {
146
146
  const { children, ...rest } = props;
147
147
  return React.createElement(customElements.getName(AnchorWC) ?? '%%prefix%%-anchor', { ...rest, ref }, children);