@aurodesignsystem-dev/auro-datetime 0.0.0-pr82.0 → 0.0.0-pr82.2
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/demo/api.md +10 -10
- package/demo/auro-datetime.min.js +18 -8
- package/dist/auro-datetime-DxCkU1MY.js +6 -0
- package/dist/index.d.ts +2 -6
- package/dist/index.js +1 -1
- package/dist/registered.js +1 -1
- package/package.json +1 -1
- package/dist/auro-datetime-BobtS5w7.js +0 -6
package/demo/api.md
CHANGED
|
@@ -7,16 +7,16 @@ The `auro-datetime` element is for the purposes of providing an easy to use date
|
|
|
7
7
|
|
|
8
8
|
### Properties & Attributes
|
|
9
9
|
|
|
10
|
-
| Properties | Attributes | Modifiers | Type | Default | Description
|
|
11
|
-
| ---------- | ---------- | --------- | ------------------------------------------------------------------------------------------------ | ------- |
|
|
12
|
-
| cap | cap | | boolean | | Capitalize AM or PM designation
|
|
13
|
-
| locale | locale | | string | `en-US` | BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP')
|
|
14
|
-
| month | month | | `short` \| `long` | `short` | Defines format of month
|
|
15
|
-
| setDate | setDate | | string | | Pass in string to set date
|
|
16
|
-
| timeZone | timeZone | | string | | Pass in string to define [timeZone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
17
|
-
| type | type | | `date` \| `time` \| `year` \| `month` \| `weekday` \| `day` \| `numeric` \| `tzDate` \| `tzTime` | | Defines type of data to render
|
|
18
|
-
| utc | utc | | string | | Pass in ISO 8601 UTC formatted time code
|
|
19
|
-
| weekday | weekday | | `short` \| `long` | `short` | Defines format of weekday
|
|
10
|
+
| Properties | Attributes | Modifiers | Type | Default | Description |
|
|
11
|
+
| ---------- | ---------- | --------- | ------------------------------------------------------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------- |
|
|
12
|
+
| cap | cap | | boolean | | Capitalize AM or PM designation |
|
|
13
|
+
| locale | locale | | string | `en-US` | BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP'). |
|
|
14
|
+
| month | month | | `short` \| `long` | `short` | Defines format of month |
|
|
15
|
+
| setDate | setDate | | string | | Pass in string to set date |
|
|
16
|
+
| timeZone | timeZone | | string | | Pass in string to define [timeZone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) |
|
|
17
|
+
| type | type | | `date` \| `time` \| `year` \| `month` \| `weekday` \| `day` \| `numeric` \| `tzDate` \| `tzTime` | | Defines type of data to render |
|
|
18
|
+
| utc | utc | | string | | Pass in ISO 8601 UTC formatted time code |
|
|
19
|
+
| weekday | weekday | | `short` \| `long` | `short` | Defines format of weekday |
|
|
20
20
|
|
|
21
21
|
### Methods
|
|
22
22
|
|
|
@@ -131,6 +131,7 @@ class AuroDatetime extends i {
|
|
|
131
131
|
_initializeDefaults() {
|
|
132
132
|
this.weekday = "short";
|
|
133
133
|
this.month = "short";
|
|
134
|
+
this.locale = "en-US";
|
|
134
135
|
|
|
135
136
|
/**
|
|
136
137
|
* @private
|
|
@@ -169,7 +170,6 @@ class AuroDatetime extends i {
|
|
|
169
170
|
|
|
170
171
|
/**
|
|
171
172
|
* BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
172
|
-
* Defaults to 'en-US' when not set.
|
|
173
173
|
* @type {string}
|
|
174
174
|
* @default 'en-US'
|
|
175
175
|
*/
|
|
@@ -224,6 +224,16 @@ class AuroDatetime extends i {
|
|
|
224
224
|
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroDatetime);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
willUpdate(changedProperties) {
|
|
228
|
+
if (changedProperties.has('locale') && this.locale) {
|
|
229
|
+
try {
|
|
230
|
+
Intl.getCanonicalLocales(this.locale);
|
|
231
|
+
} catch {
|
|
232
|
+
this.locale = "en-US";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
227
237
|
firstUpdated() {
|
|
228
238
|
// Add the tag name as an attribute if it is different than the component name
|
|
229
239
|
this.runtimeUtils.handleComponentTagRename(this, "auro-datetime");
|
|
@@ -244,7 +254,7 @@ class AuroDatetime extends i {
|
|
|
244
254
|
newDate = new Date(this.setDate);
|
|
245
255
|
}
|
|
246
256
|
|
|
247
|
-
return newDate.toLocaleString(this.locale
|
|
257
|
+
return newDate.toLocaleString(this.locale, this.dateTemplate);
|
|
248
258
|
}
|
|
249
259
|
|
|
250
260
|
/**
|
|
@@ -280,7 +290,7 @@ class AuroDatetime extends i {
|
|
|
280
290
|
this.template.weekday = this.template;
|
|
281
291
|
}
|
|
282
292
|
|
|
283
|
-
return newDate.toLocaleString(this.locale
|
|
293
|
+
return newDate.toLocaleString(this.locale, this.template);
|
|
284
294
|
}
|
|
285
295
|
|
|
286
296
|
/**
|
|
@@ -300,7 +310,7 @@ class AuroDatetime extends i {
|
|
|
300
310
|
newDate = new Date(this.setDate);
|
|
301
311
|
}
|
|
302
312
|
|
|
303
|
-
return newDate.toLocaleString(this.locale
|
|
313
|
+
return newDate.toLocaleString(this.locale, this.dateTemplate);
|
|
304
314
|
}
|
|
305
315
|
|
|
306
316
|
/**
|
|
@@ -320,12 +330,12 @@ class AuroDatetime extends i {
|
|
|
320
330
|
|
|
321
331
|
if (this.cap) {
|
|
322
332
|
return newTime
|
|
323
|
-
.toLocaleString(this.locale
|
|
333
|
+
.toLocaleString(this.locale, this.timeTemplate)
|
|
324
334
|
.replace(/^0+/u, "");
|
|
325
335
|
}
|
|
326
336
|
|
|
327
337
|
return newTime
|
|
328
|
-
.toLocaleString(this.locale
|
|
338
|
+
.toLocaleString(this.locale, this.timeTemplate)
|
|
329
339
|
.replace(/^0+/u, "")
|
|
330
340
|
.toLowerCase();
|
|
331
341
|
}
|
|
@@ -342,11 +352,11 @@ class AuroDatetime extends i {
|
|
|
342
352
|
const newDateTime = new Date(scrubTimeZone);
|
|
343
353
|
|
|
344
354
|
if (this.cap) {
|
|
345
|
-
return newDateTime.toLocaleString(this.locale
|
|
355
|
+
return newDateTime.toLocaleString(this.locale, template).replace(/^0+/u, "");
|
|
346
356
|
}
|
|
347
357
|
|
|
348
358
|
return newDateTime
|
|
349
|
-
.toLocaleString(this.locale
|
|
359
|
+
.toLocaleString(this.locale, template)
|
|
350
360
|
.replace(/^0+/u, "")
|
|
351
361
|
.replace("AM", "am")
|
|
352
362
|
.replace("PM", "pm");
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{LitElement as e,html as t}from"lit";class a{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,a=(t,s=t&&t.closest(e))=>t&&t!==document&&t!==window?s||a(t.getRootNode().host):null){return a(t)}handleComponentTagRename(e,t){const a=t.toLowerCase();e.tagName.toLowerCase()!==a&&e.setAttribute(a,!0)}elementMatch(e,t){const a=t.toLowerCase();return e.tagName.toLowerCase()===a||e.hasAttribute(a)}getSlotText(e,t){const a=e.shadowRoot?.querySelector(`slot[name="${t}"]`);return(a?.assignedNodes({flatten:!0})||[]).map(e=>e.textContent?.trim()).join(" ").trim()||null}}class s extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.locale="en-US",this.runtimeUtils=new a}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit",timeZone:this.timeZone},this.template={}}static get properties(){return{cap:{type:Boolean},locale:{type:String},month:{type:String},setDate:{type:String},timeZone:{type:String},type:{type:String},utc:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,s)}willUpdate(e){if(e.has("locale")&&this.locale)try{Intl.getCanonicalLocales(this.locale)}catch{this.locale="en-US"}}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}humanDate(){let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale,this.dateTemplate)}humanDateConversion(){let e=new Date;switch(this.utc?(this.template.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.type){case"day":this.template.day="numeric";break;case"month":this.template.month=this.month;break;case"year":this.template.year="numeric";break;case"weekday":this.template.weekday=this.weekday;break;default:this.template.weekday=this.template}return e.toLocaleString(this.locale,this.template)}numericDate(){this.dateTemplate.month="numeric",Reflect.deleteProperty(this.dateTemplate,"weekday");let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale,this.dateTemplate)}humanTime(){let e=new Date;return this.utc?(this.timeTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.cap?e.toLocaleString(this.locale,this.timeTemplate).replace(/^0+/u,""):e.toLocaleString(this.locale,this.timeTemplate).replace(/^0+/u,"").toLowerCase()}tzTime(e){const t=this.setDate.slice(0,-6),a=new Date(t);return this.cap?a.toLocaleString(this.locale,e).replace(/^0+/u,""):a.toLocaleString(this.locale,e).replace(/^0+/u,"").replace("AM","am").replace("PM","pm")}whichDate(){let e="";switch(this.type){case"date":e=this.humanDate();break;case"tzDate":e=this.tzTime(this.dateTemplate);break;case"tzTime":e=this.tzTime(this.timeTemplate);break;case"time":e=this.humanTime();break;case"year":case"month":case"weekday":case"day":e=this.humanDateConversion();break;case"numeric":e=this.numericDate();break;default:this.humanDate()}return this.setDate&&!this.type||this.utc&&!this.type?this.humanDate():e}render(){return t`
|
|
2
|
+
<slot name="pre"></slot>
|
|
3
|
+
<span class="yield">${this.whichDate()}</span>
|
|
4
|
+
<slot name="post"></slot>
|
|
5
|
+
<slot></slot>
|
|
6
|
+
`}}export{s as A};
|
package/dist/index.d.ts
CHANGED
|
@@ -75,8 +75,7 @@ type BaseEvents = {};
|
|
|
75
75
|
export type AuroDatetimeProps = {
|
|
76
76
|
/** Capitalize AM or PM designation */
|
|
77
77
|
cap?: AuroDatetime["cap"];
|
|
78
|
-
/** BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
79
|
-
Defaults to 'en-US' when not set. */
|
|
78
|
+
/** BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP'). */
|
|
80
79
|
locale?: AuroDatetime["locale"];
|
|
81
80
|
/** Defines format of month */
|
|
82
81
|
month?: AuroDatetime["month"];
|
|
@@ -95,8 +94,7 @@ Defaults to 'en-US' when not set. */
|
|
|
95
94
|
export type AuroDatetimeSolidJsProps = {
|
|
96
95
|
/** Capitalize AM or PM designation */
|
|
97
96
|
"prop:cap"?: AuroDatetime["cap"];
|
|
98
|
-
/** BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
99
|
-
Defaults to 'en-US' when not set. */
|
|
97
|
+
/** BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP'). */
|
|
100
98
|
"prop:locale"?: AuroDatetime["locale"];
|
|
101
99
|
/** Defines format of month */
|
|
102
100
|
"prop:month"?: AuroDatetime["month"];
|
|
@@ -127,7 +125,6 @@ export type CustomElements = {
|
|
|
127
125
|
*
|
|
128
126
|
* - `cap`: Capitalize AM or PM designation
|
|
129
127
|
* - `locale`: BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
130
|
-
* Defaults to 'en-US' when not set.
|
|
131
128
|
* - `month`: Defines format of month
|
|
132
129
|
* - `setDate`: Pass in string to set date
|
|
133
130
|
* - `timeZone`: Pass in string to define [timeZone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
@@ -164,7 +161,6 @@ export type CustomElementsSolidJs = {
|
|
|
164
161
|
*
|
|
165
162
|
* - `cap`: Capitalize AM or PM designation
|
|
166
163
|
* - `locale`: BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
167
|
-
* Defaults to 'en-US' when not set.
|
|
168
164
|
* - `month`: Defines format of month
|
|
169
165
|
* - `setDate`: Pass in string to set date
|
|
170
166
|
* - `timeZone`: Pass in string to define [timeZone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{A as AuroDatetime}from"./auro-datetime-
|
|
1
|
+
export{A as AuroDatetime}from"./auro-datetime-DxCkU1MY.js";import"lit";
|
package/dist/registered.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as r}from"./auro-datetime-
|
|
1
|
+
import{A as r}from"./auro-datetime-DxCkU1MY.js";import"lit";r.register();
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"================================================================================"
|
|
8
8
|
],
|
|
9
9
|
"name": "@aurodesignsystem-dev/auro-datetime",
|
|
10
|
-
"version": "0.0.0-pr82.
|
|
10
|
+
"version": "0.0.0-pr82.2",
|
|
11
11
|
"description": "auro-datetime HTML custom element",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{LitElement as e,html as t}from"lit";class a{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,a=(t,s=t&&t.closest(e))=>t&&t!==document&&t!==window?s||a(t.getRootNode().host):null){return a(t)}handleComponentTagRename(e,t){const a=t.toLowerCase();e.tagName.toLowerCase()!==a&&e.setAttribute(a,!0)}elementMatch(e,t){const a=t.toLowerCase();return e.tagName.toLowerCase()===a||e.hasAttribute(a)}getSlotText(e,t){const a=e.shadowRoot?.querySelector(`slot[name="${t}"]`);return(a?.assignedNodes({flatten:!0})||[]).map(e=>e.textContent?.trim()).join(" ").trim()||null}}class s extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.runtimeUtils=new a}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit",timeZone:this.timeZone},this.template={}}static get properties(){return{cap:{type:Boolean},locale:{type:String},month:{type:String},setDate:{type:String},timeZone:{type:String},type:{type:String},utc:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,s)}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}humanDate(){let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale||"en-us",this.dateTemplate)}humanDateConversion(){let e=new Date;switch(this.utc?(this.template.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.type){case"day":this.template.day="numeric";break;case"month":this.template.month=this.month;break;case"year":this.template.year="numeric";break;case"weekday":this.template.weekday=this.weekday;break;default:this.template.weekday=this.template}return e.toLocaleString(this.locale||"en-us",this.template)}numericDate(){this.dateTemplate.month="numeric",Reflect.deleteProperty(this.dateTemplate,"weekday");let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale||"en-us",this.dateTemplate)}humanTime(){let e=new Date;return this.utc?(this.timeTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.cap?e.toLocaleString(this.locale||"en-us",this.timeTemplate).replace(/^0+/u,""):e.toLocaleString(this.locale||"en-us",this.timeTemplate).replace(/^0+/u,"").toLowerCase()}tzTime(e){const t=this.setDate.slice(0,-6),a=new Date(t);return this.cap?a.toLocaleString(this.locale||"en-us",e).replace(/^0+/u,""):a.toLocaleString(this.locale||"en-us",e).replace(/^0+/u,"").replace("AM","am").replace("PM","pm")}whichDate(){let e="";switch(this.type){case"date":e=this.humanDate();break;case"tzDate":e=this.tzTime(this.dateTemplate);break;case"tzTime":e=this.tzTime(this.timeTemplate);break;case"time":e=this.humanTime();break;case"year":case"month":case"weekday":case"day":e=this.humanDateConversion();break;case"numeric":e=this.numericDate();break;default:this.humanDate()}return this.setDate&&!this.type||this.utc&&!this.type?this.humanDate():e}render(){return t`
|
|
2
|
-
<slot name="pre"></slot>
|
|
3
|
-
<span class="yield">${this.whichDate()}</span>
|
|
4
|
-
<slot name="post"></slot>
|
|
5
|
-
<slot></slot>
|
|
6
|
-
`}}export{s as A};
|