@govtechsg/sgds-web-component 3.23.0-rc.7 → 3.24.0-rc.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/components/Datepicker/datepicker-calendar.js +4 -4
- package/components/Datepicker/datepicker-calendar.js.map +1 -1
- package/components/Datepicker/datepicker-header.js +2 -2
- package/components/Datepicker/datepicker-header.js.map +1 -1
- package/components/Datepicker/datepicker-input.js +13 -48
- package/components/Datepicker/datepicker-input.js.map +1 -1
- package/components/Datepicker/index.umd.min.js +342 -342
- package/components/Datepicker/index.umd.min.js.map +1 -1
- package/components/Datepicker/sgds-datepicker.js +6 -6
- package/components/Datepicker/sgds-datepicker.js.map +1 -1
- package/components/Footer/index.umd.min.js +1 -1
- package/components/Footer/index.umd.min.js.map +1 -1
- package/components/Subnav/index.umd.min.js +1 -1
- package/components/Subnav/index.umd.min.js.map +1 -1
- package/components/index.umd.min.js +218 -218
- package/components/index.umd.min.js.map +1 -1
- package/css/grid.css +2 -2
- package/css/grid.js +1 -1
- package/css/utility.css +1 -0
- package/custom-elements.json +1 -1
- package/index.umd.min.js +295 -295
- package/index.umd.min.js.map +1 -1
- package/package.json +1 -3
- package/react/components/Datepicker/datepicker-calendar.cjs.js +4 -4
- package/react/components/Datepicker/datepicker-calendar.cjs.js.map +1 -1
- package/react/components/Datepicker/datepicker-calendar.js +4 -4
- package/react/components/Datepicker/datepicker-calendar.js.map +1 -1
- package/react/components/Datepicker/datepicker-header.cjs.js +2 -2
- package/react/components/Datepicker/datepicker-header.cjs.js.map +1 -1
- package/react/components/Datepicker/datepicker-header.js +2 -2
- package/react/components/Datepicker/datepicker-header.js.map +1 -1
- package/react/components/Datepicker/datepicker-input.cjs.js +13 -52
- package/react/components/Datepicker/datepicker-input.cjs.js.map +1 -1
- package/react/components/Datepicker/datepicker-input.js +13 -48
- package/react/components/Datepicker/datepicker-input.js.map +1 -1
- package/react/components/Datepicker/sgds-datepicker.cjs.js +6 -6
- package/react/components/Datepicker/sgds-datepicker.cjs.js.map +1 -1
- package/react/components/Datepicker/sgds-datepicker.js +6 -6
- package/react/components/Datepicker/sgds-datepicker.js.map +1 -1
- package/react/css/grid.cjs.js +1 -1
- package/react/css/grid.js +1 -1
- package/react/utils/date-helpers.cjs.js +120 -0
- package/react/utils/date-helpers.cjs.js.map +1 -0
- package/react/utils/date-helpers.js +108 -0
- package/react/utils/date-helpers.js.map +1 -0
- package/react/utils/date-mask.cjs.js +203 -0
- package/react/utils/date-mask.cjs.js.map +1 -0
- package/react/utils/date-mask.js +199 -0
- package/react/utils/date-mask.js.map +1 -0
- package/react/utils/time.cjs.js +7 -7
- package/react/utils/time.cjs.js.map +1 -1
- package/react/utils/time.js +1 -1
- package/react/utils/time.js.map +1 -1
- package/themes/root.css +3 -2
- package/utils/date-helpers.d.ts +22 -0
- package/utils/date-helpers.js +107 -0
- package/utils/date-helpers.js.map +1 -0
- package/utils/date-mask.d.ts +44 -0
- package/utils/date-mask.js +198 -0
- package/utils/date-mask.js.map +1 -0
- package/utils/time.js +1 -1
- package/utils/time.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datepicker-header.js","sources":["../../../../src/components/Datepicker/datepicker-header.ts"],"sourcesContent":["import { isBefore, isEqual } from \"date-fns\";\nimport { html } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport { sanitizedNextMonth, sanitizedPreviousMonth } from \"../../utils/time\";\nimport { watch } from \"../../utils/watch\";\nimport SgdsButton from \"../Button/sgds-button\";\nimport SgdsIconButton from \"../IconButton/sgds-icon-button\";\nimport datepickerHeaderStyle from \"./datepicker-header.css\";\nimport { ViewEnum } from \"./types\";\nimport SgdsIcon from \"../Icon/sgds-icon\";\n\nexport class DatepickerHeader extends SgdsElement {\n static styles = [datepickerHeaderStyle];\n /** @internal */\n static dependencies = {\n \"sgds-icon\": SgdsIcon,\n \"sgds-icon-button\": SgdsIconButton,\n \"sgds-button\": SgdsButton\n };\n\n /** @internal */\n @property({ attribute: false })\n displayDate: Date;\n /** @internal */\n @property({ attribute: false })\n focusedDate: Date;\n /** @internal */\n @property({ attribute: false })\n selectedDate: Date[] = [];\n\n /** @internal */\n @property()\n view: ViewEnum;\n /** @internal */\n @property()\n focusedTabIndex: number;\n\n @watch(\"focusedTabIndex\", { waitUntilFirstUpdate: true })\n _handleFocusedTabIndexChange() {\n let buttonToFocus: SgdsButton | SgdsIconButton;\n switch (this.focusedTabIndex) {\n case 0:\n buttonToFocus = this.shadowRoot.querySelector(\"sgds-icon-button[name='arrow-left']\");\n break;\n case 1:\n buttonToFocus = this.shadowRoot.querySelector(\"sgds-button\");\n break;\n case 2:\n buttonToFocus = this.shadowRoot.querySelector(\"sgds-icon-button[name='arrow-right']\");\n break;\n default:\n return;\n }\n buttonToFocus.focus();\n }\n\n private _changeView() {\n switch (this.view) {\n case \"days\":\n this.view = \"months\";\n break;\n case \"months\":\n this.view = \"years\";\n break;\n case \"years\":\n break;\n }\n this.emit(\"sgds-view\", { detail: this.view }); // emit event to render the correct view\n }\n\n public renderHeader(displayDate = this.displayDate, view = this.view) {\n if (view === \"months\") {\n return displayDate.getFullYear();\n }\n if (view === \"years\") {\n const CURRENT_YEAR = new Date().getFullYear();\n const displayYear = displayDate.getFullYear();\n const remainder = (displayYear - CURRENT_YEAR) % 12;\n const yearsPosition = remainder < 0 ? 12 + remainder : remainder;\n const startLimit = displayYear - yearsPosition;\n const endLimit = displayYear - yearsPosition + 12 - 1;\n return `${startLimit} - ${endLimit}`;\n }\n return `${MONTH_LABELS[displayDate.getMonth()]} ${displayDate.getFullYear()}`;\n }\n\n private _renderHeaderTemplate() {\n return html`${this.renderHeader()}`;\n }\n /** @internal */\n private handleClickPrevious() {\n const { view, displayDate, focusedDate } = this;\n let newDisplayDate = new Date(displayDate);\n\n if (view === \"months\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() - 1);\n } else if (this.view === \"years\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() - 12);\n } else {\n /**\n * FocusedDate gets precedence over displayDate.\n * This happens when the arrow keys are pressed to\n * change focus date and user clicks the arrow buttons to\n * shift months\n */\n if (focusedDate.getDate() !== displayDate.getDate()) {\n newDisplayDate = sanitizedPreviousMonth(focusedDate);\n } else {\n newDisplayDate = sanitizedPreviousMonth(newDisplayDate);\n }\n }\n this.displayDate = newDisplayDate; // Update the displayDate property\n // emit event to render correct view\n this.emit(\"sgds-change-calendar\", { detail: this.displayDate });\n }\n\n /** @internal */\n private _handleClickNext() {\n const { view, displayDate, focusedDate } = this;\n let newDisplayDate = new Date(displayDate);\n\n if (view === \"months\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() + 1);\n } else if (this.view === \"years\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() + 12);\n } else {\n /** FocusedDate gets precedence over displayDate */\n if (focusedDate.getDate() !== displayDate.getDate()) {\n newDisplayDate = sanitizedNextMonth(focusedDate);\n } else {\n newDisplayDate = sanitizedNextMonth(newDisplayDate);\n }\n }\n this.displayDate = newDisplayDate; // Update the displayDate property\n\n //emit event to render correct view\n this.emit(\"sgds-change-calendar\", { detail: this.displayDate });\n }\n private _removeCaret(): boolean {\n const displayYear = this.displayDate.getFullYear();\n const displayMonth = this.displayDate.getMonth();\n const displayMonthYear = new Date(displayYear, displayMonth);\n\n if (this.view === \"months\") {\n return displayYear <= 1900;\n }\n if (this.view === \"years\") {\n return displayYear < 1904;\n }\n return isEqual(displayMonthYear, new Date(0, 0, 1)) || isBefore(displayMonthYear, new Date(0, 0, 1));\n }\n\n private _ariaLabelForNextBtn() {\n const nextBtnDate = {\n days: \"Show next month\",\n months: \"Show next year\",\n years: \"Show next 12 years\"\n };\n return nextBtnDate[this.view];\n }\n private _ariaLabelForPrevBtn() {\n const prevBtnDate = {\n days: \"Show previous month\",\n months: \"Show previous year\",\n years: \"Show previous 12 years\"\n };\n return prevBtnDate[this.view];\n }\n\n private _ariaLabelForHeaderBtn() {\n const message = {\n days: `Current view is days, click to show months in ${this.displayDate.getFullYear()}`,\n months: `Current view is months, click to show years between ${this.renderHeader(this.displayDate, \"years\")}`,\n years: `Current view is years`\n };\n return `${this.renderHeader()}. ${message[this.view]}`;\n }\n render() {\n return html`\n <div class=\"datepicker-header dropdown-header\">\n <sgds-icon-button\n name=\"arrow-left\"\n size=\"sm\"\n variant=\"ghost\"\n @click=\"${this.handleClickPrevious}\"\n class=${classMap({ invisible: this._removeCaret() })}\n .ariaLabel=${this._ariaLabelForPrevBtn()}\n >\n </sgds-icon-button>\n <sgds-button\n fullWidth\n variant=\"ghost\"\n size=\"sm\"\n @click=${this._changeView}\n class=${classMap({ disabled: this.view === \"years\" })}\n .ariaLabel=${this._ariaLabelForHeaderBtn()}\n aria-disabled=${this.view === \"years\" ? \"true\" : \"false\"}\n aria-live=\"polite\"\n >\n ${this._renderHeaderTemplate()}\n </sgds-button>\n <sgds-icon-button\n name=\"arrow-right\"\n size=\"sm\"\n variant=\"ghost\"\n @click=\"${this._handleClickNext}\"\n .ariaLabel=${this._ariaLabelForNextBtn()}\n >\n </sgds-icon-button>\n </div>\n `;\n }\n}\n\nexport default DatepickerHeader;\n\nexport const MONTH_LABELS = [\n \"January\",\n \"February\",\n \"March\",\n \"April\",\n \"May\",\n \"June\",\n \"July\",\n \"August\",\n \"September\",\n \"October\",\n \"November\",\n \"December\"\n];\n"],"names":["datepickerHeaderStyle"],"mappings":";;;;;;;;;;;;;;AAaM,MAAO,gBAAiB,SAAQ,WAAW,CAAA;AAAjD,IAAA,WAAA,GAAA;;;QAiBE,IAAY,CAAA,YAAA,GAAW,EAAE,CAAC;KAwL3B;IA9KC,4BAA4B,GAAA;AAC1B,QAAA,IAAI,aAA0C,CAAC;AAC/C,QAAA,QAAQ,IAAI,CAAC,eAAe;AAC1B,YAAA,KAAK,CAAC;gBACJ,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,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SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAGf,UAAA,CAAA;AADC,IAAA,QAAQ,EAAE;AACa,CAAA,EAAA,gBAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAGxB,UAAA,CAAA;IADC,KAAK,CAAC,iBAAiB,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAiBxD,CAAA,EAAA,gBAAA,CAAA,SAAA,EAAA,8BAAA,EAAA,IAAA,CAAA,CAAA;AAkKU,MAAA,YAAY,GAAG;IAC1B,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;IACV,UAAU;;;;;"}
|
|
1
|
+
{"version":3,"file":"datepicker-header.js","sources":["../../../../src/components/Datepicker/datepicker-header.ts"],"sourcesContent":["import { isBeforeDate, isEqualDate } from \"../../utils/date-helpers\";\nimport { html } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport { sanitizedNextMonth, sanitizedPreviousMonth } from \"../../utils/time\";\nimport { watch } from \"../../utils/watch\";\nimport SgdsButton from \"../Button/sgds-button\";\nimport SgdsIconButton from \"../IconButton/sgds-icon-button\";\nimport datepickerHeaderStyle from \"./datepicker-header.css\";\nimport { ViewEnum } from \"./types\";\nimport SgdsIcon from \"../Icon/sgds-icon\";\n\nexport class DatepickerHeader extends SgdsElement {\n static styles = [datepickerHeaderStyle];\n /** @internal */\n static dependencies = {\n \"sgds-icon\": SgdsIcon,\n \"sgds-icon-button\": SgdsIconButton,\n \"sgds-button\": SgdsButton\n };\n\n /** @internal */\n @property({ attribute: false })\n displayDate: Date;\n /** @internal */\n @property({ attribute: false })\n focusedDate: Date;\n /** @internal */\n @property({ attribute: false })\n selectedDate: Date[] = [];\n\n /** @internal */\n @property()\n view: ViewEnum;\n /** @internal */\n @property()\n focusedTabIndex: number;\n\n @watch(\"focusedTabIndex\", { waitUntilFirstUpdate: true })\n _handleFocusedTabIndexChange() {\n let buttonToFocus: SgdsButton | SgdsIconButton;\n switch (this.focusedTabIndex) {\n case 0:\n buttonToFocus = this.shadowRoot.querySelector(\"sgds-icon-button[name='arrow-left']\");\n break;\n case 1:\n buttonToFocus = this.shadowRoot.querySelector(\"sgds-button\");\n break;\n case 2:\n buttonToFocus = this.shadowRoot.querySelector(\"sgds-icon-button[name='arrow-right']\");\n break;\n default:\n return;\n }\n buttonToFocus.focus();\n }\n\n private _changeView() {\n switch (this.view) {\n case \"days\":\n this.view = \"months\";\n break;\n case \"months\":\n this.view = \"years\";\n break;\n case \"years\":\n break;\n }\n this.emit(\"sgds-view\", { detail: this.view }); // emit event to render the correct view\n }\n\n public renderHeader(displayDate = this.displayDate, view = this.view) {\n if (view === \"months\") {\n return displayDate.getFullYear();\n }\n if (view === \"years\") {\n const CURRENT_YEAR = new Date().getFullYear();\n const displayYear = displayDate.getFullYear();\n const remainder = (displayYear - CURRENT_YEAR) % 12;\n const yearsPosition = remainder < 0 ? 12 + remainder : remainder;\n const startLimit = displayYear - yearsPosition;\n const endLimit = displayYear - yearsPosition + 12 - 1;\n return `${startLimit} - ${endLimit}`;\n }\n return `${MONTH_LABELS[displayDate.getMonth()]} ${displayDate.getFullYear()}`;\n }\n\n private _renderHeaderTemplate() {\n return html`${this.renderHeader()}`;\n }\n /** @internal */\n private handleClickPrevious() {\n const { view, displayDate, focusedDate } = this;\n let newDisplayDate = new Date(displayDate);\n\n if (view === \"months\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() - 1);\n } else if (this.view === \"years\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() - 12);\n } else {\n /**\n * FocusedDate gets precedence over displayDate.\n * This happens when the arrow keys are pressed to\n * change focus date and user clicks the arrow buttons to\n * shift months\n */\n if (focusedDate.getDate() !== displayDate.getDate()) {\n newDisplayDate = sanitizedPreviousMonth(focusedDate);\n } else {\n newDisplayDate = sanitizedPreviousMonth(newDisplayDate);\n }\n }\n this.displayDate = newDisplayDate; // Update the displayDate property\n // emit event to render correct view\n this.emit(\"sgds-change-calendar\", { detail: this.displayDate });\n }\n\n /** @internal */\n private _handleClickNext() {\n const { view, displayDate, focusedDate } = this;\n let newDisplayDate = new Date(displayDate);\n\n if (view === \"months\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() + 1);\n } else if (this.view === \"years\") {\n newDisplayDate.setFullYear(newDisplayDate.getFullYear() + 12);\n } else {\n /** FocusedDate gets precedence over displayDate */\n if (focusedDate.getDate() !== displayDate.getDate()) {\n newDisplayDate = sanitizedNextMonth(focusedDate);\n } else {\n newDisplayDate = sanitizedNextMonth(newDisplayDate);\n }\n }\n this.displayDate = newDisplayDate; // Update the displayDate property\n\n //emit event to render correct view\n this.emit(\"sgds-change-calendar\", { detail: this.displayDate });\n }\n private _removeCaret(): boolean {\n const displayYear = this.displayDate.getFullYear();\n const displayMonth = this.displayDate.getMonth();\n const displayMonthYear = new Date(displayYear, displayMonth);\n\n if (this.view === \"months\") {\n return displayYear <= 1900;\n }\n if (this.view === \"years\") {\n return displayYear < 1904;\n }\n return isEqualDate(displayMonthYear, new Date(0, 0, 1)) || isBeforeDate(displayMonthYear, new Date(0, 0, 1));\n }\n\n private _ariaLabelForNextBtn() {\n const nextBtnDate = {\n days: \"Show next month\",\n months: \"Show next year\",\n years: \"Show next 12 years\"\n };\n return nextBtnDate[this.view];\n }\n private _ariaLabelForPrevBtn() {\n const prevBtnDate = {\n days: \"Show previous month\",\n months: \"Show previous year\",\n years: \"Show previous 12 years\"\n };\n return prevBtnDate[this.view];\n }\n\n private _ariaLabelForHeaderBtn() {\n const message = {\n days: `Current view is days, click to show months in ${this.displayDate.getFullYear()}`,\n months: `Current view is months, click to show years between ${this.renderHeader(this.displayDate, \"years\")}`,\n years: `Current view is years`\n };\n return `${this.renderHeader()}. ${message[this.view]}`;\n }\n render() {\n return html`\n <div class=\"datepicker-header dropdown-header\">\n <sgds-icon-button\n name=\"arrow-left\"\n size=\"sm\"\n variant=\"ghost\"\n @click=\"${this.handleClickPrevious}\"\n class=${classMap({ invisible: this._removeCaret() })}\n .ariaLabel=${this._ariaLabelForPrevBtn()}\n >\n </sgds-icon-button>\n <sgds-button\n fullWidth\n variant=\"ghost\"\n size=\"sm\"\n @click=${this._changeView}\n class=${classMap({ disabled: this.view === \"years\" })}\n .ariaLabel=${this._ariaLabelForHeaderBtn()}\n aria-disabled=${this.view === \"years\" ? \"true\" : \"false\"}\n aria-live=\"polite\"\n >\n ${this._renderHeaderTemplate()}\n </sgds-button>\n <sgds-icon-button\n name=\"arrow-right\"\n size=\"sm\"\n variant=\"ghost\"\n @click=\"${this._handleClickNext}\"\n .ariaLabel=${this._ariaLabelForNextBtn()}\n >\n </sgds-icon-button>\n </div>\n `;\n }\n}\n\nexport default DatepickerHeader;\n\nexport const MONTH_LABELS = [\n \"January\",\n \"February\",\n \"March\",\n \"April\",\n \"May\",\n \"June\",\n \"July\",\n \"August\",\n \"September\",\n \"October\",\n \"November\",\n \"December\"\n];\n"],"names":["datepickerHeaderStyle"],"mappings":";;;;;;;;;;;;;;AAaM,MAAO,gBAAiB,SAAQ,WAAW,CAAA;AAAjD,IAAA,WAAA,GAAA;;;QAiBE,IAAY,CAAA,YAAA,GAAW,EAAE,CAAC;KAwL3B;IA9KC,4BAA4B,GAAA;AAC1B,QAAA,IAAI,aAA0C,CAAC;AAC/C,QAAA,QAAQ,IAAI,CAAC,eAAe;AAC1B,YAAA,KAAK,CAAC;gBACJ,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,qCAAqC,CAAC,CAAC;gBACrF,MAAM;AACR,YAAA,KAAK,CAAC;gBACJ,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;gBAC7D,MAAM;AACR,YAAA,KAAK,CAAC;gB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,CAAA;IADC,KAAK,CAAC,iBAAiB,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAiBxD,CAAA,EAAA,gBAAA,CAAA,SAAA,EAAA,8BAAA,EAAA,IAAA,CAAA,CAAA;AAkKU,MAAA,YAAY,GAAG;IAC1B,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;IACV,UAAU;;;;;"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var tslib = require('tslib');
|
|
7
|
-
var
|
|
8
|
-
var
|
|
7
|
+
var dateHelpers = require('../../utils/date-helpers.cjs.js');
|
|
8
|
+
var dateMask = require('../../utils/date-mask.cjs.js');
|
|
9
9
|
var lit = require('lit');
|
|
10
10
|
var decorators_js = require('lit/decorators.js');
|
|
11
11
|
var classMap_js = require('lit/directives/class-map.js');
|
|
@@ -13,10 +13,6 @@ var time = require('../../utils/time.cjs.js');
|
|
|
13
13
|
var sgdsInput = require('../Input/sgds-input.cjs.js');
|
|
14
14
|
var datepickerInput = require('./datepicker-input.cjs2.js');
|
|
15
15
|
|
|
16
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
-
|
|
18
|
-
var IMask__default = /*#__PURE__*/_interopDefaultLegacy(IMask);
|
|
19
|
-
|
|
20
16
|
class DatepickerInput extends sgdsInput.SgdsInput {
|
|
21
17
|
constructor() {
|
|
22
18
|
super();
|
|
@@ -27,11 +23,11 @@ class DatepickerInput extends sgdsInput.SgdsInput {
|
|
|
27
23
|
this._validateInput = async () => {
|
|
28
24
|
const dates = this.mask.value.split(" - ");
|
|
29
25
|
const noEmptyDates = dates.filter(d => d !== this.dateFormat);
|
|
30
|
-
const dateArray = noEmptyDates.map(date => time.setTimeToNoon(
|
|
31
|
-
const invalidDates = dateArray.filter(date => !
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
const dateArray = noEmptyDates.map(date => time.setTimeToNoon(dateHelpers.parseDate(date, time.DATE_PATTERNS[this.dateFormat].fnsPattern)));
|
|
27
|
+
const invalidDates = dateArray.filter(date => !dateHelpers.isValidDate(date) ||
|
|
28
|
+
dateHelpers.isBeforeDate(date, new Date(0, 0, 1)) ||
|
|
29
|
+
dateHelpers.isBeforeDate(date, time.setTimeToNoon(new Date(this.minDate))) ||
|
|
30
|
+
dateHelpers.isAfterDate(date, time.setTimeToNoon(new Date(this.maxDate))));
|
|
35
31
|
if (invalidDates.length > 0) {
|
|
36
32
|
this.setInvalid(true);
|
|
37
33
|
return this.emit("i-sgds-invalid-input");
|
|
@@ -54,11 +50,11 @@ class DatepickerInput extends sgdsInput.SgdsInput {
|
|
|
54
50
|
_handleBlur() {
|
|
55
51
|
const dates = this.mask.value.split(" - ");
|
|
56
52
|
const noEmptyDates = dates.filter(d => d !== this.dateFormat);
|
|
57
|
-
const dateArray = noEmptyDates.map(date => time.setTimeToNoon(
|
|
58
|
-
const invalidDates = dateArray.filter(date => !
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
const dateArray = noEmptyDates.map(date => time.setTimeToNoon(dateHelpers.parseDate(date, time.DATE_PATTERNS[this.dateFormat].fnsPattern)));
|
|
54
|
+
const invalidDates = dateArray.filter(date => !dateHelpers.isValidDate(date) ||
|
|
55
|
+
dateHelpers.isBeforeDate(date, new Date(0, 0, 1)) ||
|
|
56
|
+
dateHelpers.isBeforeDate(date, time.setTimeToNoon(new Date(this.minDate))) ||
|
|
57
|
+
dateHelpers.isAfterDate(date, time.setTimeToNoon(new Date(this.maxDate))));
|
|
62
58
|
// Only clear if the mask is complete AND there are invalid dates
|
|
63
59
|
// This clears complete but invalid dates like "20/20/2026"
|
|
64
60
|
// Incomplete dates remain in the input as-is (validation only runs on complete dates)
|
|
@@ -82,42 +78,7 @@ class DatepickerInput extends sgdsInput.SgdsInput {
|
|
|
82
78
|
async _applyInputMask(dateFormat) {
|
|
83
79
|
const shadowInput = await this.shadowInput;
|
|
84
80
|
const imPattern = this.mode === "single" ? time.DATE_PATTERNS[dateFormat].imPattern : time.DATE_PATTERNS[dateFormat].imRangePattern;
|
|
85
|
-
|
|
86
|
-
d: { mask: IMask__default["default"].MaskedRange, placeholderChar: "D", from: 0, to: 9, maxLength: 1 },
|
|
87
|
-
m: { mask: IMask__default["default"].MaskedRange, placeholderChar: "M", from: 0, to: 9, maxLength: 1 },
|
|
88
|
-
y: { mask: IMask__default["default"].MaskedRange, placeholderChar: "Y", from: 0, to: 9, maxLength: 1 },
|
|
89
|
-
D: { mask: IMask__default["default"].MaskedRange, placeholderChar: "D", from: 0, to: 9, maxLength: 1 },
|
|
90
|
-
M: { mask: IMask__default["default"].MaskedRange, placeholderChar: "M", from: 0, to: 9, maxLength: 1 },
|
|
91
|
-
Y: { mask: IMask__default["default"].MaskedRange, placeholderChar: "Y", from: 0, to: 9, maxLength: 1 }
|
|
92
|
-
};
|
|
93
|
-
const maskOptions = {
|
|
94
|
-
mask: imPattern,
|
|
95
|
-
pattern: imPattern,
|
|
96
|
-
eager: true,
|
|
97
|
-
overwrite: true,
|
|
98
|
-
// define str -> date convertion
|
|
99
|
-
parse: function (str) {
|
|
100
|
-
const dates = str.split(" - ");
|
|
101
|
-
return dates.map(date => dateFns.parse(date, time.DATE_PATTERNS[dateFormat].fnsPattern, new Date()));
|
|
102
|
-
},
|
|
103
|
-
format: function (dateArr) {
|
|
104
|
-
const dateStrings = dateArr.map(date => {
|
|
105
|
-
let dayStr, monthStr = "";
|
|
106
|
-
const day = date.getDate();
|
|
107
|
-
const month = date.getMonth() + 1;
|
|
108
|
-
const year = date.getFullYear();
|
|
109
|
-
if (day < 10)
|
|
110
|
-
dayStr = "0" + day;
|
|
111
|
-
if (month < 10)
|
|
112
|
-
monthStr = "0" + month;
|
|
113
|
-
return [dayStr, monthStr, year].join("/");
|
|
114
|
-
});
|
|
115
|
-
return dateStrings.join(" - ");
|
|
116
|
-
},
|
|
117
|
-
lazy: false,
|
|
118
|
-
blocks
|
|
119
|
-
};
|
|
120
|
-
this.mask = IMask__default["default"](shadowInput, maskOptions);
|
|
81
|
+
this.mask = new dateMask.DateMask(shadowInput, { pattern: imPattern });
|
|
121
82
|
this.mask.on("accept", () => {
|
|
122
83
|
this.value = this.mask.masked.value;
|
|
123
84
|
this.emit("i-sgds-mask-input-change", { detail: this.value });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datepicker-input.cjs.js","sources":["../../../../src/components/Datepicker/datepicker-input.ts"],"sourcesContent":["import { isAfter, isBefore, isValid, parse } from \"date-fns\";\nimport IMask, { InputMask } from \"imask\";\nimport { html, PropertyValueMap } from \"lit\";\nimport { property, queryAsync } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { DATE_PATTERNS, setTimeToNoon } from \"../../utils/time\";\nimport { SgdsInput } from \"../Input/sgds-input\";\nimport datepickerInputStyles from \"./datepicker-input.css\";\nexport type DateFormat = \"MM/DD/YYYY\" | \"DD/MM/YYYY\" | \"YYYY/MM/DD\";\n\nexport class DatepickerInput extends SgdsInput {\n static styles = [...SgdsInput.styles, datepickerInputStyles];\n /** Date format reflected on input */\n private dateFormat = \"DD/MM/YYYY\";\n\n /** ISO date string to set the lowest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) minDate: string;\n\n /** ISO date string to set the highest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) maxDate: string;\n\n /** Changes DatePicker to single date selection or range date selection */\n @property({ type: String, reflect: true }) mode: \"single\" | \"range\" = \"single\";\n\n @queryAsync(\"input\")\n shadowInput: Promise<HTMLInputElement>;\n\n private mask: InputMask;\n constructor() {\n super();\n this.type = \"text\";\n }\n\n protected override _handleBlur() {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parse(date, DATE_PATTERNS[this.dateFormat].fnsPattern, new Date()))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValid(date) ||\n isBefore(date, new Date(0, 0, 1)) ||\n isBefore(date, setTimeToNoon(new Date(this.minDate))) ||\n isAfter(date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n // Only clear if the mask is complete AND there are invalid dates\n // This clears complete but invalid dates like \"20/20/2026\"\n // Incomplete dates remain in the input as-is (validation only runs on complete dates)\n if (this.mask.masked.isComplete && invalidDates.length > 0 && dateArray.length > 0) {\n this.value = \"\";\n this.mask.value = \"\";\n this.setInvalid(false);\n }\n\n this.emit(\"sgds-blur\");\n }\n\n protected override async _handleChange(e: Event) {\n this.value = this.input.value;\n this.emit(\"sgds-change\");\n super._mixinHandleChange(e);\n await this._validateInput();\n }\n\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n this._applyInputMask(this.dateFormat);\n }\n private async _applyInputMask(dateFormat: string) {\n const shadowInput = await this.shadowInput;\n const imPattern =\n this.mode === \"single\" ? DATE_PATTERNS[dateFormat].imPattern : DATE_PATTERNS[dateFormat].imRangePattern;\n const blocks = {\n d: { mask: IMask.MaskedRange, placeholderChar: \"D\", from: 0, to: 9, maxLength: 1 },\n m: { mask: IMask.MaskedRange, placeholderChar: \"M\", from: 0, to: 9, maxLength: 1 },\n y: { mask: IMask.MaskedRange, placeholderChar: \"Y\", from: 0, to: 9, maxLength: 1 },\n D: { mask: IMask.MaskedRange, placeholderChar: \"D\", from: 0, to: 9, maxLength: 1 },\n M: { mask: IMask.MaskedRange, placeholderChar: \"M\", from: 0, to: 9, maxLength: 1 },\n Y: { mask: IMask.MaskedRange, placeholderChar: \"Y\", from: 0, to: 9, maxLength: 1 }\n };\n const maskOptions = {\n mask: imPattern,\n pattern: imPattern,\n eager: true,\n overwrite: true,\n // define str -> date convertion\n parse: function (str: string) {\n const dates = str.split(\" - \");\n return dates.map(date => parse(date, DATE_PATTERNS[dateFormat].fnsPattern, new Date()));\n },\n format: function (dateArr: Date[]) {\n const dateStrings = dateArr.map(date => {\n let dayStr: string,\n monthStr = \"\";\n const day = date.getDate();\n const month = date.getMonth() + 1;\n const year = date.getFullYear();\n\n if (day < 10) dayStr = \"0\" + day;\n if (month < 10) monthStr = \"0\" + month;\n\n return [dayStr, monthStr, year].join(\"/\");\n });\n return dateStrings.join(\" - \");\n },\n lazy: false,\n blocks\n };\n\n this.mask = IMask(shadowInput, maskOptions);\n this.mask.on(\"accept\", () => {\n this.value = this.mask.masked.value;\n this.emit(\"i-sgds-mask-input-change\", { detail: this.value });\n });\n /**\n * Validation after date is complete\n */\n this.mask.on(\"complete\", this._validateInput);\n }\n public updateMaskValue() {\n this.mask?.updateValue();\n }\n private _validateInput = async () => {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parse(date, DATE_PATTERNS[this.dateFormat].fnsPattern, new Date()))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValid(date) ||\n isBefore(date, new Date(0, 0, 1)) ||\n isBefore(date, setTimeToNoon(new Date(this.minDate))) ||\n isAfter(date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n if (invalidDates.length > 0) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (this.mode === \"range\" && dateArray.length === 1) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (invalidDates.length === 0 && dateArray.length > 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-selectdates-input\", { detail: dateArray });\n }\n if (dateArray.length === 0 && invalidDates.length === 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-empty-input\");\n }\n };\n\n public destroyInputMask() {\n this.mask?.destroy();\n }\n public async applyInputMask() {\n return await this._applyInputMask(this.dateFormat);\n }\n public async focus() {\n const input = await this.shadowInput;\n return input.focus();\n }\n render() {\n return html`\n <div\n class=\"form-control-container ${classMap({\n disabled: this.disabled\n })}\"\n >\n ${this._renderLabel()}\n <div class=\"datepicker-input-container\">\n ${this._renderInput()}\n <slot name=\"calendar-btn\"></slot>\n </div>\n ${this._renderFeedback()}\n </div>\n `;\n }\n}\n\nexport default DatepickerInput;\n"],"names":["SgdsInput","setTimeToNoon","parse","DATE_PATTERNS","isValid","isBefore","isAfter","IMask","html","classMap","datepickerInputStyles","__decorate","property","queryAsync"],"mappings":";;;;;;;;;;;;;;;;;;;AAUM,MAAO,eAAgB,SAAQA,mBAAS,CAAA;AAkB5C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE,CAAC;;QAhBF,IAAU,CAAA,UAAA,GAAG,YAAY,CAAC;;QASS,IAAI,CAAA,IAAA,GAAuB,QAAQ,CAAC;QAsGvE,IAAc,CAAA,cAAA,GAAG,YAAW;AAClC,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3C,YAAA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9D,YAAA,MAAM,SAAS,GAAsB,YAAY,CAAC,GAAG,CAAC,IAAI,IACxDC,kBAAa,CAACC,aAAK,CAAC,IAAI,EAAEC,kBAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,CAClF,CAAC;AACF,YAAA,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CACnC,IAAI,IACF,CAACC,eAAO,CAAC,IAAI,CAAC;AACd,gBAAAC,gBAAQ,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACjC,gBAAAA,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idDate, parseDate } from \"../../utils/date-helpers\";\nimport { DateMask } from \"../../utils/date-mask\";\nimport { html, PropertyValueMap } from \"lit\";\nimport { property, queryAsync } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { DATE_PATTERNS, setTimeToNoon } from \"../../utils/time\";\nimport { SgdsInput } from \"../Input/sgds-input\";\nimport datepickerInputStyles from \"./datepicker-input.css\";\nexport type DateFormat = \"MM/DD/YYYY\" | \"DD/MM/YYYY\" | \"YYYY/MM/DD\";\n\nexport class DatepickerInput extends SgdsInput {\n static styles = [...SgdsInput.styles, datepickerInputStyles];\n /** Date format reflected on input */\n private dateFormat = \"DD/MM/YYYY\";\n\n /** ISO date string to set the lowest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) minDate: string;\n\n /** ISO date string to set the highest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) maxDate: string;\n\n /** Changes DatePicker to single date selection or range date selection */\n @property({ type: String, reflect: true }) mode: \"single\" | \"range\" = \"single\";\n\n @queryAsync(\"input\")\n shadowInput: Promise<HTMLInputElement>;\n\n private mask: DateMask;\n constructor() {\n super();\n this.type = \"text\";\n }\n\n protected override _handleBlur() {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parseDate(date, DATE_PATTERNS[this.dateFormat].fnsPattern))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValidDate(date as Date) ||\n isBeforeDate(date as Date, new Date(0, 0, 1)) ||\n isBeforeDate(date as Date, setTimeToNoon(new Date(this.minDate))) ||\n isAfterDate(date as Date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n // Only clear if the mask is complete AND there are invalid dates\n // This clears complete but invalid dates like \"20/20/2026\"\n // Incomplete dates remain in the input as-is (validation only runs on complete dates)\n if (this.mask.masked.isComplete && invalidDates.length > 0 && dateArray.length > 0) {\n this.value = \"\";\n this.mask.value = \"\";\n this.setInvalid(false);\n }\n\n this.emit(\"sgds-blur\");\n }\n\n protected override async _handleChange(e: Event) {\n this.value = this.input.value;\n this.emit(\"sgds-change\");\n super._mixinHandleChange(e);\n await this._validateInput();\n }\n\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n this._applyInputMask(this.dateFormat);\n }\n private async _applyInputMask(dateFormat: string) {\n const shadowInput = await this.shadowInput;\n const imPattern =\n this.mode === \"single\" ? DATE_PATTERNS[dateFormat].imPattern : DATE_PATTERNS[dateFormat].imRangePattern;\n\n this.mask = new DateMask(shadowInput, { pattern: imPattern });\n this.mask.on(\"accept\", () => {\n this.value = this.mask.masked.value;\n this.emit(\"i-sgds-mask-input-change\", { detail: this.value });\n });\n /**\n * Validation after date is complete\n */\n this.mask.on(\"complete\", this._validateInput);\n }\n public updateMaskValue() {\n this.mask?.updateValue();\n }\n private _validateInput = async () => {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parseDate(date, DATE_PATTERNS[this.dateFormat].fnsPattern))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValidDate(date as Date) ||\n isBeforeDate(date as Date, new Date(0, 0, 1)) ||\n isBeforeDate(date as Date, setTimeToNoon(new Date(this.minDate))) ||\n isAfterDate(date as Date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n if (invalidDates.length > 0) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (this.mode === \"range\" && dateArray.length === 1) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (invalidDates.length === 0 && dateArray.length > 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-selectdates-input\", { detail: dateArray });\n }\n if (dateArray.length === 0 && invalidDates.length === 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-empty-input\");\n }\n };\n\n public destroyInputMask() {\n this.mask?.destroy();\n }\n public async applyInputMask() {\n return await this._applyInputMask(this.dateFormat);\n }\n public async focus() {\n const input = await this.shadowInput;\n return input.focus();\n }\n render() {\n return html`\n <div\n class=\"form-control-container ${classMap({\n disabled: this.disabled\n })}\"\n >\n ${this._renderLabel()}\n <div class=\"datepicker-input-container\">\n ${this._renderInput()}\n <slot name=\"calendar-btn\"></slot>\n </div>\n ${this._renderFeedback()}\n </div>\n `;\n }\n}\n\nexport default DatepickerInput;\n"],"names":["SgdsInput","setTimeToNoon","parseDate","DATE_PATTERNS","isValidDate","isBeforeDate","isAfterDate","DateMask","html","classMap","datepickerInputStyles","__decorate","property","queryAsync"],"mappings":";;;;;;;;;;;;;;;AAUM,MAAO,eAAgB,SAAQA,mBAAS,CAAA;AAkB5C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE,CAAC;;QAhBF,IAAU,CAAA,UAAA,GAAG,YAAY,CAAC;;QASS,IAAI,CAAA,IAAA,GAAuB,QAAQ,CAAC;QAkEvE,IAAc,CAAA,cAAA,GAAG,YAAW;AAClC,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3C,YAAA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9D,MAAM,SAAS,GAAsB,YAAY,CAAC,GAAG,CAAC,IAAI,IACxDC,kBAAa,CAACC,qBAAS,CAAC,IAAI,EAAEC,kBAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,CAAC,CAC1E,CAAC;AACF,YAAA,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CACnC,IAAI,IACF,CAACC,uBAAW,CAAC,IAAY,CAAC;AAC1B,gBAAAC,wBAAY,CAAC,IAAY,EAAE,IAAI,IAAI,CAAC,CAAC,EAA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AAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAAqC,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAG/ED,gBAAA,CAAA;IADCE,wBAAU,CAAC,OAAO,CAAC;AACmB,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,aAAA,EAAA,KAAA,CAAA,CAAA;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { __decorate } from 'tslib';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { parseDate, isValidDate, isBeforeDate, isAfterDate } from '../../utils/date-helpers.js';
|
|
4
|
+
import { DateMask } from '../../utils/date-mask.js';
|
|
5
5
|
import { html } from 'lit';
|
|
6
6
|
import { property, queryAsync } from 'lit/decorators.js';
|
|
7
7
|
import { classMap } from 'lit/directives/class-map.js';
|
|
@@ -19,11 +19,11 @@ class DatepickerInput extends SgdsInput {
|
|
|
19
19
|
this._validateInput = async () => {
|
|
20
20
|
const dates = this.mask.value.split(" - ");
|
|
21
21
|
const noEmptyDates = dates.filter(d => d !== this.dateFormat);
|
|
22
|
-
const dateArray = noEmptyDates.map(date => setTimeToNoon(
|
|
23
|
-
const invalidDates = dateArray.filter(date => !
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const dateArray = noEmptyDates.map(date => setTimeToNoon(parseDate(date, DATE_PATTERNS[this.dateFormat].fnsPattern)));
|
|
23
|
+
const invalidDates = dateArray.filter(date => !isValidDate(date) ||
|
|
24
|
+
isBeforeDate(date, new Date(0, 0, 1)) ||
|
|
25
|
+
isBeforeDate(date, setTimeToNoon(new Date(this.minDate))) ||
|
|
26
|
+
isAfterDate(date, setTimeToNoon(new Date(this.maxDate))));
|
|
27
27
|
if (invalidDates.length > 0) {
|
|
28
28
|
this.setInvalid(true);
|
|
29
29
|
return this.emit("i-sgds-invalid-input");
|
|
@@ -46,11 +46,11 @@ class DatepickerInput extends SgdsInput {
|
|
|
46
46
|
_handleBlur() {
|
|
47
47
|
const dates = this.mask.value.split(" - ");
|
|
48
48
|
const noEmptyDates = dates.filter(d => d !== this.dateFormat);
|
|
49
|
-
const dateArray = noEmptyDates.map(date => setTimeToNoon(
|
|
50
|
-
const invalidDates = dateArray.filter(date => !
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const dateArray = noEmptyDates.map(date => setTimeToNoon(parseDate(date, DATE_PATTERNS[this.dateFormat].fnsPattern)));
|
|
50
|
+
const invalidDates = dateArray.filter(date => !isValidDate(date) ||
|
|
51
|
+
isBeforeDate(date, new Date(0, 0, 1)) ||
|
|
52
|
+
isBeforeDate(date, setTimeToNoon(new Date(this.minDate))) ||
|
|
53
|
+
isAfterDate(date, setTimeToNoon(new Date(this.maxDate))));
|
|
54
54
|
// Only clear if the mask is complete AND there are invalid dates
|
|
55
55
|
// This clears complete but invalid dates like "20/20/2026"
|
|
56
56
|
// Incomplete dates remain in the input as-is (validation only runs on complete dates)
|
|
@@ -74,42 +74,7 @@ class DatepickerInput extends SgdsInput {
|
|
|
74
74
|
async _applyInputMask(dateFormat) {
|
|
75
75
|
const shadowInput = await this.shadowInput;
|
|
76
76
|
const imPattern = this.mode === "single" ? DATE_PATTERNS[dateFormat].imPattern : DATE_PATTERNS[dateFormat].imRangePattern;
|
|
77
|
-
|
|
78
|
-
d: { mask: IMask.MaskedRange, placeholderChar: "D", from: 0, to: 9, maxLength: 1 },
|
|
79
|
-
m: { mask: IMask.MaskedRange, placeholderChar: "M", from: 0, to: 9, maxLength: 1 },
|
|
80
|
-
y: { mask: IMask.MaskedRange, placeholderChar: "Y", from: 0, to: 9, maxLength: 1 },
|
|
81
|
-
D: { mask: IMask.MaskedRange, placeholderChar: "D", from: 0, to: 9, maxLength: 1 },
|
|
82
|
-
M: { mask: IMask.MaskedRange, placeholderChar: "M", from: 0, to: 9, maxLength: 1 },
|
|
83
|
-
Y: { mask: IMask.MaskedRange, placeholderChar: "Y", from: 0, to: 9, maxLength: 1 }
|
|
84
|
-
};
|
|
85
|
-
const maskOptions = {
|
|
86
|
-
mask: imPattern,
|
|
87
|
-
pattern: imPattern,
|
|
88
|
-
eager: true,
|
|
89
|
-
overwrite: true,
|
|
90
|
-
// define str -> date convertion
|
|
91
|
-
parse: function (str) {
|
|
92
|
-
const dates = str.split(" - ");
|
|
93
|
-
return dates.map(date => parse(date, DATE_PATTERNS[dateFormat].fnsPattern, new Date()));
|
|
94
|
-
},
|
|
95
|
-
format: function (dateArr) {
|
|
96
|
-
const dateStrings = dateArr.map(date => {
|
|
97
|
-
let dayStr, monthStr = "";
|
|
98
|
-
const day = date.getDate();
|
|
99
|
-
const month = date.getMonth() + 1;
|
|
100
|
-
const year = date.getFullYear();
|
|
101
|
-
if (day < 10)
|
|
102
|
-
dayStr = "0" + day;
|
|
103
|
-
if (month < 10)
|
|
104
|
-
monthStr = "0" + month;
|
|
105
|
-
return [dayStr, monthStr, year].join("/");
|
|
106
|
-
});
|
|
107
|
-
return dateStrings.join(" - ");
|
|
108
|
-
},
|
|
109
|
-
lazy: false,
|
|
110
|
-
blocks
|
|
111
|
-
};
|
|
112
|
-
this.mask = IMask(shadowInput, maskOptions);
|
|
77
|
+
this.mask = new DateMask(shadowInput, { pattern: imPattern });
|
|
113
78
|
this.mask.on("accept", () => {
|
|
114
79
|
this.value = this.mask.masked.value;
|
|
115
80
|
this.emit("i-sgds-mask-input-change", { detail: this.value });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datepicker-input.js","sources":["../../../../src/components/Datepicker/datepicker-input.ts"],"sourcesContent":["import { isAfter, isBefore, isValid, parse } from \"date-fns\";\nimport IMask, { InputMask } from \"imask\";\nimport { html, PropertyValueMap } from \"lit\";\nimport { property, queryAsync } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { DATE_PATTERNS, setTimeToNoon } from \"../../utils/time\";\nimport { SgdsInput } from \"../Input/sgds-input\";\nimport datepickerInputStyles from \"./datepicker-input.css\";\nexport type DateFormat = \"MM/DD/YYYY\" | \"DD/MM/YYYY\" | \"YYYY/MM/DD\";\n\nexport class DatepickerInput extends SgdsInput {\n static styles = [...SgdsInput.styles, datepickerInputStyles];\n /** Date format reflected on input */\n private dateFormat = \"DD/MM/YYYY\";\n\n /** ISO date string to set the lowest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) minDate: string;\n\n /** ISO date string to set the highest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) maxDate: string;\n\n /** Changes DatePicker to single date selection or range date selection */\n @property({ type: String, reflect: true }) mode: \"single\" | \"range\" = \"single\";\n\n @queryAsync(\"input\")\n shadowInput: Promise<HTMLInputElement>;\n\n private mask: InputMask;\n constructor() {\n super();\n this.type = \"text\";\n }\n\n protected override _handleBlur() {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parse(date, DATE_PATTERNS[this.dateFormat].fnsPattern, new Date()))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValid(date) ||\n isBefore(date, new Date(0, 0, 1)) ||\n isBefore(date, setTimeToNoon(new Date(this.minDate))) ||\n isAfter(date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n // Only clear if the mask is complete AND there are invalid dates\n // This clears complete but invalid dates like \"20/20/2026\"\n // Incomplete dates remain in the input as-is (validation only runs on complete dates)\n if (this.mask.masked.isComplete && invalidDates.length > 0 && dateArray.length > 0) {\n this.value = \"\";\n this.mask.value = \"\";\n this.setInvalid(false);\n }\n\n this.emit(\"sgds-blur\");\n }\n\n protected override async _handleChange(e: Event) {\n this.value = this.input.value;\n this.emit(\"sgds-change\");\n super._mixinHandleChange(e);\n await this._validateInput();\n }\n\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n this._applyInputMask(this.dateFormat);\n }\n private async _applyInputMask(dateFormat: string) {\n const shadowInput = await this.shadowInput;\n const imPattern =\n this.mode === \"single\" ? DATE_PATTERNS[dateFormat].imPattern : DATE_PATTERNS[dateFormat].imRangePattern;\n const blocks = {\n d: { mask: IMask.MaskedRange, placeholderChar: \"D\", from: 0, to: 9, maxLength: 1 },\n m: { mask: IMask.MaskedRange, placeholderChar: \"M\", from: 0, to: 9, maxLength: 1 },\n y: { mask: IMask.MaskedRange, placeholderChar: \"Y\", from: 0, to: 9, maxLength: 1 },\n D: { mask: IMask.MaskedRange, placeholderChar: \"D\", from: 0, to: 9, maxLength: 1 },\n M: { mask: IMask.MaskedRange, placeholderChar: \"M\", from: 0, to: 9, maxLength: 1 },\n Y: { mask: IMask.MaskedRange, placeholderChar: \"Y\", from: 0, to: 9, maxLength: 1 }\n };\n const maskOptions = {\n mask: imPattern,\n pattern: imPattern,\n eager: true,\n overwrite: true,\n // define str -> date convertion\n parse: function (str: string) {\n const dates = str.split(\" - \");\n return dates.map(date => parse(date, DATE_PATTERNS[dateFormat].fnsPattern, new Date()));\n },\n format: function (dateArr: Date[]) {\n const dateStrings = dateArr.map(date => {\n let dayStr: string,\n monthStr = \"\";\n const day = date.getDate();\n const month = date.getMonth() + 1;\n const year = date.getFullYear();\n\n if (day < 10) dayStr = \"0\" + day;\n if (month < 10) monthStr = \"0\" + month;\n\n return [dayStr, monthStr, year].join(\"/\");\n });\n return dateStrings.join(\" - \");\n },\n lazy: false,\n blocks\n };\n\n this.mask = IMask(shadowInput, maskOptions);\n this.mask.on(\"accept\", () => {\n this.value = this.mask.masked.value;\n this.emit(\"i-sgds-mask-input-change\", { detail: this.value });\n });\n /**\n * Validation after date is complete\n */\n this.mask.on(\"complete\", this._validateInput);\n }\n public updateMaskValue() {\n this.mask?.updateValue();\n }\n private _validateInput = async () => {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parse(date, DATE_PATTERNS[this.dateFormat].fnsPattern, new Date()))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValid(date) ||\n isBefore(date, new Date(0, 0, 1)) ||\n isBefore(date, setTimeToNoon(new Date(this.minDate))) ||\n isAfter(date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n if (invalidDates.length > 0) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (this.mode === \"range\" && dateArray.length === 1) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (invalidDates.length === 0 && dateArray.length > 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-selectdates-input\", { detail: dateArray });\n }\n if (dateArray.length === 0 && invalidDates.length === 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-empty-input\");\n }\n };\n\n public destroyInputMask() {\n this.mask?.destroy();\n }\n public async applyInputMask() {\n return await this._applyInputMask(this.dateFormat);\n }\n public async focus() {\n const input = await this.shadowInput;\n return input.focus();\n }\n render() {\n return html`\n <div\n class=\"form-control-container ${classMap({\n disabled: this.disabled\n })}\"\n >\n ${this._renderLabel()}\n <div class=\"datepicker-input-container\">\n ${this._renderInput()}\n <slot name=\"calendar-btn\"></slot>\n </div>\n ${this._renderFeedback()}\n </div>\n `;\n }\n}\n\nexport default DatepickerInput;\n"],"names":["datepickerInputStyles"],"mappings":";;;;;;;;;;;AAUM,MAAO,eAAgB,SAAQ,SAAS,CAAA;AAkB5C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE,CAAC;;QAhBF,IAAU,CAAA,UAAA,GAAG,YAAY,CAAC;;QASS,IAAI,CAAA,IAAA,GAAuB,QAAQ,CAAC;QAsGvE,IAAc,CAAA,cAAA,GAAG,YAAW;AAClC,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3C,YAAA,MAAM,YAAY,GAAG,K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A,CAAA;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAAqC,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAG/E,UAAA,CAAA;IADC,UAAU,CAAC,OAAO,CAAC;AACmB,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,aAAA,EAAA,KAAA,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"datepicker-input.js","sources":["../../../../src/components/Datepicker/datepicker-input.ts"],"sourcesContent":["import { isAfterDate, isBeforeDate, isValidDate, parseDate } from \"../../utils/date-helpers\";\nimport { DateMask } from \"../../utils/date-mask\";\nimport { html, PropertyValueMap } from \"lit\";\nimport { property, queryAsync } from \"lit/decorators.js\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { DATE_PATTERNS, setTimeToNoon } from \"../../utils/time\";\nimport { SgdsInput } from \"../Input/sgds-input\";\nimport datepickerInputStyles from \"./datepicker-input.css\";\nexport type DateFormat = \"MM/DD/YYYY\" | \"DD/MM/YYYY\" | \"YYYY/MM/DD\";\n\nexport class DatepickerInput extends SgdsInput {\n static styles = [...SgdsInput.styles, datepickerInputStyles];\n /** Date format reflected on input */\n private dateFormat = \"DD/MM/YYYY\";\n\n /** ISO date string to set the lowest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) minDate: string;\n\n /** ISO date string to set the highest allowable date value. e.g. \"2016-05-19T12:00:00.000Z\" */\n @property({ type: String }) maxDate: string;\n\n /** Changes DatePicker to single date selection or range date selection */\n @property({ type: String, reflect: true }) mode: \"single\" | \"range\" = \"single\";\n\n @queryAsync(\"input\")\n shadowInput: Promise<HTMLInputElement>;\n\n private mask: DateMask;\n constructor() {\n super();\n this.type = \"text\";\n }\n\n protected override _handleBlur() {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parseDate(date, DATE_PATTERNS[this.dateFormat].fnsPattern))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValidDate(date as Date) ||\n isBeforeDate(date as Date, new Date(0, 0, 1)) ||\n isBeforeDate(date as Date, setTimeToNoon(new Date(this.minDate))) ||\n isAfterDate(date as Date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n // Only clear if the mask is complete AND there are invalid dates\n // This clears complete but invalid dates like \"20/20/2026\"\n // Incomplete dates remain in the input as-is (validation only runs on complete dates)\n if (this.mask.masked.isComplete && invalidDates.length > 0 && dateArray.length > 0) {\n this.value = \"\";\n this.mask.value = \"\";\n this.setInvalid(false);\n }\n\n this.emit(\"sgds-blur\");\n }\n\n protected override async _handleChange(e: Event) {\n this.value = this.input.value;\n this.emit(\"sgds-change\");\n super._mixinHandleChange(e);\n await this._validateInput();\n }\n\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n this._applyInputMask(this.dateFormat);\n }\n private async _applyInputMask(dateFormat: string) {\n const shadowInput = await this.shadowInput;\n const imPattern =\n this.mode === \"single\" ? DATE_PATTERNS[dateFormat].imPattern : DATE_PATTERNS[dateFormat].imRangePattern;\n\n this.mask = new DateMask(shadowInput, { pattern: imPattern });\n this.mask.on(\"accept\", () => {\n this.value = this.mask.masked.value;\n this.emit(\"i-sgds-mask-input-change\", { detail: this.value });\n });\n /**\n * Validation after date is complete\n */\n this.mask.on(\"complete\", this._validateInput);\n }\n public updateMaskValue() {\n this.mask?.updateValue();\n }\n private _validateInput = async () => {\n const dates = this.mask.value.split(\" - \");\n const noEmptyDates = dates.filter(d => d !== this.dateFormat);\n const dateArray: Date[] | string[] = noEmptyDates.map(date =>\n setTimeToNoon(parseDate(date, DATE_PATTERNS[this.dateFormat].fnsPattern))\n );\n const invalidDates = dateArray.filter(\n date =>\n !isValidDate(date as Date) ||\n isBeforeDate(date as Date, new Date(0, 0, 1)) ||\n isBeforeDate(date as Date, setTimeToNoon(new Date(this.minDate))) ||\n isAfterDate(date as Date, setTimeToNoon(new Date(this.maxDate)))\n );\n\n if (invalidDates.length > 0) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (this.mode === \"range\" && dateArray.length === 1) {\n this.setInvalid(true);\n return this.emit(\"i-sgds-invalid-input\");\n }\n if (invalidDates.length === 0 && dateArray.length > 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-selectdates-input\", { detail: dateArray });\n }\n if (dateArray.length === 0 && invalidDates.length === 0) {\n this.setInvalid(false);\n return this.emit(\"i-sgds-empty-input\");\n }\n };\n\n public destroyInputMask() {\n this.mask?.destroy();\n }\n public async applyInputMask() {\n return await this._applyInputMask(this.dateFormat);\n }\n public async focus() {\n const input = await this.shadowInput;\n return input.focus();\n }\n render() {\n return html`\n <div\n class=\"form-control-container ${classMap({\n disabled: this.disabled\n })}\"\n >\n ${this._renderLabel()}\n <div class=\"datepicker-input-container\">\n ${this._renderInput()}\n <slot name=\"calendar-btn\"></slot>\n </div>\n ${this._renderFeedback()}\n </div>\n `;\n }\n}\n\nexport default DatepickerInput;\n"],"names":["datepickerInputStyles"],"mappings":";;;;;;;;;;;AAUM,MAAO,eAAgB,SAAQ,SAAS,CAAA;AAkB5C,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE,CAAC;;QAhBF,IAAU,CAAA,UAAA,GAAG,YAAY,CAAC;;QASS,IAAI,CAAA,IAAA,GAAuB,QAAQ,CAAC;QAkEvE,IAAc,CAAA,cAAA,GAAG,YAAW;AAClC,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3C,YAAA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9D,MAAM,SAAS,GAAsB,YAAY,CAAC,GA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,CAAA,CAAA;AAGhB,UAAA,CAAA;AAA3B,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAAiB,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAGD,UAAA,CAAA;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAAqC,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAG/E,UAAA,CAAA;IADC,UAAU,CAAC,OAAO,CAAC;AACmB,CAAA,EAAA,eAAA,CAAA,SAAA,EAAA,aAAA,EAAA,KAAA,CAAA,CAAA;;;;"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var tslib = require('tslib');
|
|
7
|
-
var
|
|
7
|
+
var dateHelpers = require('../../utils/date-helpers.cjs.js');
|
|
8
8
|
var lit = require('lit');
|
|
9
9
|
var decorators_js = require('lit/decorators.js');
|
|
10
10
|
var live_js = require('lit/directives/live.js');
|
|
@@ -84,20 +84,20 @@ class SgdsDatepicker extends validatorMixin.SgdsFormValidatorMixin(dropdownEleme
|
|
|
84
84
|
this._makeInputValueString = (startDate, endDate, dateFormat) => {
|
|
85
85
|
if (!startDate && !endDate)
|
|
86
86
|
return this.value;
|
|
87
|
-
const
|
|
87
|
+
const fmtDate = (date) => dateHelpers.formatDate(date, time.DATE_PATTERNS[dateFormat].fnsPattern);
|
|
88
88
|
switch (this.mode) {
|
|
89
89
|
case "single": {
|
|
90
90
|
if (startDate) {
|
|
91
|
-
this.value =
|
|
91
|
+
this.value = fmtDate(startDate);
|
|
92
92
|
}
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
95
|
case "range": {
|
|
96
96
|
if (startDate && endDate) {
|
|
97
|
-
this.value = `${
|
|
97
|
+
this.value = `${fmtDate(startDate)} - ${fmtDate(endDate)}`;
|
|
98
98
|
}
|
|
99
99
|
if (startDate && !endDate) {
|
|
100
|
-
this.value = `${
|
|
100
|
+
this.value = `${fmtDate(startDate)} - ${this.dateFormat}`;
|
|
101
101
|
}
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
@@ -183,7 +183,7 @@ class SgdsDatepicker extends validatorMixin.SgdsFormValidatorMixin(dropdownEleme
|
|
|
183
183
|
return console.error("Invalid date format in initialValue:", invalidDates);
|
|
184
184
|
}
|
|
185
185
|
else {
|
|
186
|
-
const initialSelectedDates = this.initialValue.map(v => time.setTimeToNoon(
|
|
186
|
+
const initialSelectedDates = this.initialValue.map(v => time.setTimeToNoon(dateHelpers.parseDate(v, time.DATE_PATTERNS[this.dateFormat].fnsPattern)));
|
|
187
187
|
this._handleSelectDates(initialSelectedDates);
|
|
188
188
|
}
|
|
189
189
|
}
|