@freshworks/crayons
Version:
Crayons Web Components library
71 lines (67 loc) • 1.98 kB
JavaScript
import { attachShadow, proxyCustomElement } from '@stencil/core/internal/client';
import { f as formatDate } from './format-date-util.js';
let FormatDate = class extends HTMLElement {
constructor() {
super();
this.__registerHost();
attachShadow(this);
/** The date/time to format. If not set, the current date and time will be used. */
this.date = new Date();
/** When set, 24 hour time will always be used. */
this.hourFormat = 'auto';
}
render() {
const date = new Date(this.date);
const hour12 = this.hourFormat === 'auto' ? undefined : this.hourFormat === '12';
// Check if the given date is invalid.
if (isNaN(date.getMilliseconds())) {
console.error(`Invalid date ${this.date}`);
return;
}
{
return formatDate({
date: date,
locale: this.locale,
options: {
weekday: this.weekday,
year: this.year,
month: this.month,
day: this.day,
hour: this.hour,
minute: this.minute,
second: this.second,
timeZoneName: this.timeZoneName,
timeZone: this.timeZone,
hour12: hour12,
},
});
}
}
};
FormatDate = /*@__PURE__*/ proxyCustomElement(FormatDate, [1, "fw-format-date", {
"date": [8],
"locale": [1],
"weekday": [1],
"year": [1],
"month": [1],
"day": [1],
"hour": [1],
"minute": [1],
"second": [1],
"hourFormat": [1, "hour-format"],
"timeZoneName": [1, "time-zone-name"],
"timeZone": [1, "time-zone"]
}]);
function defineCustomElement$1() {
const components = ["fw-format-date"];
components.forEach(tagName => { switch (tagName) {
case "fw-format-date":
if (!customElements.get(tagName)) {
customElements.define(tagName, FormatDate);
}
break;
} });
}
const FwFormatDate = FormatDate;
const defineCustomElement = defineCustomElement$1;
export { FwFormatDate, defineCustomElement };