scb-wc-test 0.1.107 → 0.1.108
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/all.js +2 -0
- package/index.d.ts +1 -0
- package/index.js +112 -110
- package/mvc/components/all.js +1 -0
- package/mvc/components/scb-datepicker/scb-datepicker.js +254 -0
- package/mvc/components/scb-dialog/scb-dialog.js +1 -1
- package/mvc/components/scb-textfield/scb-textfield.js +35 -2
- package/package.json +6 -2
- package/scb-datepicker/scb-datepicker.d.ts +28 -0
- package/scb-datepicker/scb-datepicker.js +404 -0
- package/scb-textfield/scb-textfield.d.ts +3 -0
- package/scb-textfield/scb-textfield.js +53 -6
- package/scb-wc-test.bundle.js +730 -444
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as m,n as a,i as x,x as h,t as v}from"../../vendor/vendor.js";import"../../vendor/vendor-material.js";(function(){try{var t=typeof globalThis<"u"?globalThis:window;if(!t.__scb_ce_guard_installed__){t.__scb_ce_guard_installed__=!0;var e=customElements.define.bind(customElements);customElements.define=function(i,l,o){try{customElements.get(i)||e(i,l,o)}catch(c){var d=String(c||"");if(d.indexOf("already been used")===-1&&d.indexOf("NotSupportedError")===-1)throw c}}}}catch{}})();var y=Object.defineProperty,g=Object.getOwnPropertyDescriptor,f=t=>{throw TypeError(t)},r=(t,e,i,l)=>{for(var o=l>1?void 0:l?g(e,i):e,d=t.length-1,c;d>=0;d--)(c=t[d])&&(o=(l?c(e,i,o):c(o))||o);return l&&o&&y(e,i,o),o},_=(t,e,i)=>e.has(t)||f("Cannot "+i),w=(t,e,i)=>e.has(t)?f("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),p=(t,e,i)=>(_(t,e,"access private method"),i),n,b,u;let s=class extends x{constructor(){super(),w(this,n),this._internals=null,this.type="text",this.label="",this.supportingText="",this.errorText="",this.leadingIcon="",this.name="",this.pattern="",this.value="",this.underLabel="",this.error=!1,this.disabled=!1,this.required=!1,this.spacing="",this.spacingTop="",this.spacingBottom="",this._form=null,this._formSubmitHandler=null,this._formResetHandler=null,this._initialValue="",this._inputId="","attachInternals"in this&&(this._internals=this.attachInternals())}render(){const t=this.leadingIcon?h`<md-icon class="scb-textfield-icon">${this.leadingIcon}</md-icon>`:null,e=this.error?h`<md-icon class="scb-textfield-error-icon" aria-hidden="true">error</md-icon>`:null;this.underLabel=this.error?this.errorText||"Ogiltig inmatning.":this.supportingText,this.value=this.value||"";const i=this.underLabel?`${this._inputId}-supporting-text`:void 0,l=this.type==="search"&&this.value?h`
|
|
1
|
+
import{a as m,n as a,i as x,x as h,t as v}from"../../vendor/vendor.js";import"../../vendor/vendor-material.js";import"../scb-datepicker/scb-datepicker.js";import"../scb-icon-button/scb-icon-button.js";import"../../vendor/preload-helper.js";import"../scb-button/scb-button.js";import"../scb-divider/scb-divider.js";(function(){try{var t=typeof globalThis<"u"?globalThis:window;if(!t.__scb_ce_guard_installed__){t.__scb_ce_guard_installed__=!0;var e=customElements.define.bind(customElements);customElements.define=function(i,l,o){try{customElements.get(i)||e(i,l,o)}catch(c){var d=String(c||"");if(d.indexOf("already been used")===-1&&d.indexOf("NotSupportedError")===-1)throw c}}}}catch{}})();var y=Object.defineProperty,g=Object.getOwnPropertyDescriptor,f=t=>{throw TypeError(t)},r=(t,e,i,l)=>{for(var o=l>1?void 0:l?g(e,i):e,d=t.length-1,c;d>=0;d--)(c=t[d])&&(o=(l?c(e,i,o):c(o))||o);return l&&o&&y(e,i,o),o},_=(t,e,i)=>e.has(t)||f("Cannot "+i),w=(t,e,i)=>e.has(t)?f("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),p=(t,e,i)=>(_(t,e,"access private method"),i),n,b,u;let s=class extends x{constructor(){super(),w(this,n),this._internals=null,this.type="text",this.label="",this.supportingText="",this.errorText="",this.leadingIcon="",this.name="",this.pattern="",this.value="",this.underLabel="",this.error=!1,this.disabled=!1,this.required=!1,this.spacing="",this.spacingTop="",this.spacingBottom="",this._form=null,this._formSubmitHandler=null,this._formResetHandler=null,this._initialValue="",this._inputId="",this._showDatepicker=!1,this._toggleDatepicker=()=>{this._showDatepicker=!this._showDatepicker},this._onDateSelected=t=>{this.value=t.detail.value,this._showDatepicker=!1,this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("onValueChanged",{detail:{value:this.value},bubbles:!0,composed:!0}))},"attachInternals"in this&&(this._internals=this.attachInternals())}render(){const t=this.leadingIcon?h`<md-icon class="scb-textfield-icon">${this.leadingIcon}</md-icon>`:null,e=this.error?h`<md-icon class="scb-textfield-error-icon" aria-hidden="true">error</md-icon>`:null;this.underLabel=this.error?this.errorText||"Ogiltig inmatning.":this.supportingText,this.value=this.value||"";const i=this.underLabel?`${this._inputId}-supporting-text`:void 0,l=this.type==="search"&&this.value?h`
|
|
2
2
|
<button
|
|
3
3
|
type="button"
|
|
4
4
|
class="scb-textfield-clear"
|
|
@@ -52,6 +52,36 @@ import{a as m,n as a,i as x,x as h,t as v}from"../../vendor/vendor.js";import"..
|
|
|
52
52
|
${this.value}</textarea
|
|
53
53
|
>
|
|
54
54
|
</div>
|
|
55
|
+
`:this.type==="date"?h`
|
|
56
|
+
<label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
|
|
57
|
+
<span
|
|
58
|
+
class="scb-textfield-supporting-text"
|
|
59
|
+
id="${this.underLabel?`${this._inputId}-supporting-text`:""}"
|
|
60
|
+
>${this.underLabel}</span
|
|
61
|
+
>
|
|
62
|
+
<div class="scb-textfield-wrapper" style="position:relative;">
|
|
63
|
+
${t}
|
|
64
|
+
<input
|
|
65
|
+
class="scb-textfield${this.error?" has-error-icon":""}"
|
|
66
|
+
.value=${this.value}
|
|
67
|
+
type="text"
|
|
68
|
+
name="${this.name}"
|
|
69
|
+
id="${this._inputId}"
|
|
70
|
+
?disabled=${this.disabled}
|
|
71
|
+
?required=${this.required}
|
|
72
|
+
aria-invalid=${this.error?"true":"false"}
|
|
73
|
+
aria-describedby=${i}
|
|
74
|
+
readonly
|
|
75
|
+
/>
|
|
76
|
+
<scb-icon-button icon="calendar_today" @click=${this._toggleDatepicker} aria-label="Välj datum" style="position:absolute;right:8px;top:50%;transform:translateY(-50%);"></scb-icon-button>
|
|
77
|
+
<scb-datepicker
|
|
78
|
+
variant="popup"
|
|
79
|
+
.selectedValue=${this.value}
|
|
80
|
+
.open=${this._showDatepicker}
|
|
81
|
+
@date-selected=${this._onDateSelected}
|
|
82
|
+
></scb-datepicker>
|
|
83
|
+
${e}
|
|
84
|
+
</div>
|
|
55
85
|
`:h`
|
|
56
86
|
<label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
|
|
57
87
|
<span
|
|
@@ -99,6 +129,9 @@ ${this.value}</textarea
|
|
|
99
129
|
:host([type='text']) {
|
|
100
130
|
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
101
131
|
}
|
|
132
|
+
:host([type='date']) {
|
|
133
|
+
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
134
|
+
}
|
|
102
135
|
:host([type='search']) {
|
|
103
136
|
--scb-textfield-max-width: var(--scb-textfield-search-max-width);
|
|
104
137
|
}
|
|
@@ -252,4 +285,4 @@ ${this.value}</textarea
|
|
|
252
285
|
height: 100%;
|
|
253
286
|
display: block;
|
|
254
287
|
}
|
|
255
|
-
`];r([a({type:String,reflect:!0})],s.prototype,"type",2);r([a({type:String})],s.prototype,"label",2);r([a({type:String,attribute:"supporting-text"})],s.prototype,"supportingText",2);r([a({type:String,attribute:"error-text"})],s.prototype,"errorText",2);r([a({type:String,attribute:"leading-icon"})],s.prototype,"leadingIcon",2);r([a({type:String})],s.prototype,"name",2);r([a({type:String})],s.prototype,"pattern",2);r([a({type:String,attribute:"value"})],s.prototype,"value",2);r([a({type:String})],s.prototype,"underLabel",2);r([a({type:Boolean,reflect:!0})],s.prototype,"error",2);r([a({type:Boolean,reflect:!0})],s.prototype,"disabled",2);r([a({type:Boolean,reflect:!0})],s.prototype,"required",2);r([a({type:String,reflect:!0})],s.prototype,"spacing",2);r([a({type:String,attribute:"spacing-top",reflect:!0})],s.prototype,"spacingTop",2);r([a({type:String,attribute:"spacing-bottom",reflect:!0})],s.prototype,"spacingBottom",2);s=r([v("scb-textfield")],s);
|
|
288
|
+
`];r([a({type:String,reflect:!0})],s.prototype,"type",2);r([a({type:String})],s.prototype,"label",2);r([a({type:String,attribute:"supporting-text"})],s.prototype,"supportingText",2);r([a({type:String,attribute:"error-text"})],s.prototype,"errorText",2);r([a({type:String,attribute:"leading-icon"})],s.prototype,"leadingIcon",2);r([a({type:String})],s.prototype,"name",2);r([a({type:String})],s.prototype,"pattern",2);r([a({type:String,attribute:"value"})],s.prototype,"value",2);r([a({type:String})],s.prototype,"underLabel",2);r([a({type:Boolean,reflect:!0})],s.prototype,"error",2);r([a({type:Boolean,reflect:!0})],s.prototype,"disabled",2);r([a({type:Boolean,reflect:!0})],s.prototype,"required",2);r([a({type:String,reflect:!0})],s.prototype,"spacing",2);r([a({type:String,attribute:"spacing-top",reflect:!0})],s.prototype,"spacingTop",2);r([a({type:String,attribute:"spacing-bottom",reflect:!0})],s.prototype,"spacingBottom",2);r([a({type:Boolean})],s.prototype,"_showDatepicker",2);s=r([v("scb-textfield")],s);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scb-wc-test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.108",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -123,6 +123,10 @@
|
|
|
123
123
|
"import": "./scb-chip/scb-chip.js",
|
|
124
124
|
"require": "./scb-chip/scb-chip.js"
|
|
125
125
|
},
|
|
126
|
+
"./scb-datepicker": {
|
|
127
|
+
"import": "./scb-datepicker/scb-datepicker.js",
|
|
128
|
+
"require": "./scb-datepicker/scb-datepicker.js"
|
|
129
|
+
},
|
|
126
130
|
"./scb-dialog": {
|
|
127
131
|
"import": "./scb-dialog/scb-dialog.js",
|
|
128
132
|
"require": "./scb-dialog/scb-dialog.js"
|
|
@@ -337,5 +341,5 @@
|
|
|
337
341
|
},
|
|
338
342
|
"./mvc/*": "./mvc/*"
|
|
339
343
|
},
|
|
340
|
-
"buildHash": "
|
|
344
|
+
"buildHash": "35C00C1CE77F40BCC22105339704C4FB4E5291B028748939B0A8797CF24AB24E"
|
|
341
345
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LitElement, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
export declare class ScbDatepicker extends LitElement {
|
|
3
|
+
private _currentDate;
|
|
4
|
+
private _selectedDate;
|
|
5
|
+
private _showMonthDropdown;
|
|
6
|
+
private _showYearDropdown;
|
|
7
|
+
variant: 'static' | 'popup';
|
|
8
|
+
lang: 'sv' | 'en';
|
|
9
|
+
selectedValue: string;
|
|
10
|
+
open: boolean;
|
|
11
|
+
static styles: import('lit').CSSResult[];
|
|
12
|
+
updated(changed: PropertyValues): void;
|
|
13
|
+
private _getMonthDays;
|
|
14
|
+
private _monthNames;
|
|
15
|
+
render(): TemplateResult;
|
|
16
|
+
private _toggleMonthDropdown;
|
|
17
|
+
private _toggleYearDropdown;
|
|
18
|
+
private _onMonthChangeCustom;
|
|
19
|
+
private _onYearChangeCustom;
|
|
20
|
+
private _prevYear;
|
|
21
|
+
private _nextYear;
|
|
22
|
+
private _isToday;
|
|
23
|
+
private _isSelected;
|
|
24
|
+
private _selectDate;
|
|
25
|
+
private _prevMonth;
|
|
26
|
+
private _nextMonth;
|
|
27
|
+
private _close;
|
|
28
|
+
}
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { css as g, LitElement as m, html as n } from "lit";
|
|
2
|
+
import { state as h, property as p, customElement as w } from "lit/decorators.js";
|
|
3
|
+
import "../scb-icon-button/scb-icon-button.js";
|
|
4
|
+
import "../scb-button/scb-button.js";
|
|
5
|
+
import "@material/web/icon/icon.js";
|
|
6
|
+
import "@material/web/ripple/ripple.js";
|
|
7
|
+
import "@material/web/focus/md-focus-ring.js";
|
|
8
|
+
import "../scb-divider/scb-divider.js";
|
|
9
|
+
var v = Object.defineProperty, _ = Object.getOwnPropertyDescriptor, d = (e, t, c, l) => {
|
|
10
|
+
for (var i = l > 1 ? void 0 : l ? _(t, c) : t, o = e.length - 1, s; o >= 0; o--)
|
|
11
|
+
(s = e[o]) && (i = (l ? s(t, c, i) : s(i)) || i);
|
|
12
|
+
return l && i && v(t, c, i), i;
|
|
13
|
+
};
|
|
14
|
+
let a = class extends m {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments), this._currentDate = /* @__PURE__ */ new Date(), this._selectedDate = null, this._showMonthDropdown = !1, this._showYearDropdown = !1, this.variant = "static", this.lang = "sv", this.selectedValue = "", this.open = !0, this._monthNames = [
|
|
17
|
+
this.lang == "sv" ? "Januari" : "January",
|
|
18
|
+
this.lang == "sv" ? "Februari" : "February",
|
|
19
|
+
this.lang == "sv" ? "Mars" : "March",
|
|
20
|
+
(this.lang == "sv", "April"),
|
|
21
|
+
this.lang == "sv" ? "Maj" : "May",
|
|
22
|
+
this.lang == "sv" ? "Juni" : "June",
|
|
23
|
+
this.lang == "sv" ? "Juli" : "July",
|
|
24
|
+
this.lang == "sv" ? "Augusti" : "August",
|
|
25
|
+
(this.lang == "sv", "September"),
|
|
26
|
+
this.lang == "sv" ? "Oktober" : "October",
|
|
27
|
+
(this.lang == "sv", "November"),
|
|
28
|
+
(this.lang == "sv", "December")
|
|
29
|
+
], this._prevYear = () => {
|
|
30
|
+
const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
|
|
31
|
+
this._currentDate = new Date(e - 1, t, 1);
|
|
32
|
+
}, this._nextYear = () => {
|
|
33
|
+
const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
|
|
34
|
+
this._currentDate = new Date(e + 1, t, 1);
|
|
35
|
+
}, this._prevMonth = () => {
|
|
36
|
+
const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
|
|
37
|
+
this._currentDate = new Date(e, t - 1, 1);
|
|
38
|
+
}, this._nextMonth = () => {
|
|
39
|
+
const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
|
|
40
|
+
this._currentDate = new Date(e, t + 1, 1);
|
|
41
|
+
}, this._close = () => {
|
|
42
|
+
this.open = !1, this.dispatchEvent(new CustomEvent("datepicker-closed", {
|
|
43
|
+
bubbles: !0,
|
|
44
|
+
composed: !0
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
updated(e) {
|
|
49
|
+
if (super.updated(e), e.has("selectedValue") && this.selectedValue) {
|
|
50
|
+
const t = new Date(this.selectedValue);
|
|
51
|
+
isNaN(t.getTime()) || (this._selectedDate = t, this._currentDate = new Date(t.getFullYear(), t.getMonth(), 1));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_getMonthDays(e, t) {
|
|
55
|
+
const c = new Date(e, t, 1), l = new Date(e, t + 1, 0), i = [];
|
|
56
|
+
let o = [], s = (c.getDay() + 6) % 7;
|
|
57
|
+
for (let r = 0; r < s; r++) o.push(null);
|
|
58
|
+
for (let r = 1; r <= l.getDate(); r++) {
|
|
59
|
+
const u = new Date(e, t, r);
|
|
60
|
+
o.push(u), o.length === 7 && (i.push(o), o = []);
|
|
61
|
+
}
|
|
62
|
+
if (o.length) {
|
|
63
|
+
for (; o.length < 7; ) o.push(null);
|
|
64
|
+
i.push(o);
|
|
65
|
+
}
|
|
66
|
+
return i;
|
|
67
|
+
}
|
|
68
|
+
render() {
|
|
69
|
+
if (!this.open) return n``;
|
|
70
|
+
const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth(), c = /* @__PURE__ */ new Date(), l = this._getMonthDays(e, t), i = Array.from({ length: 101 }, (o, s) => c.getFullYear() - 50 + s);
|
|
71
|
+
return n`
|
|
72
|
+
<div class="datepicker-popup ${this.variant === "popup" ? "popup" : "static"}">
|
|
73
|
+
<div class="header">
|
|
74
|
+
<div class="month-selector ${this._showMonthDropdown ? "open" : ""} ${this._showYearDropdown ? "disable" : ""}">
|
|
75
|
+
<scb-icon-button icon="chevron_left" @click=${this._prevMonth} aria-label=${this.lang == "sv" ? "Föregående månad" : "Previous month"}></scb-icon-button>
|
|
76
|
+
<div class="custom-dropdown month-dropdown">
|
|
77
|
+
<div
|
|
78
|
+
@keydown=${(o) => {
|
|
79
|
+
(o.key === "Enter" || o.key === " ") && (o.preventDefault(), this._toggleMonthDropdown());
|
|
80
|
+
}}
|
|
81
|
+
tabindex="0" class="dropdown-selected" @click=${() => this._toggleMonthDropdown()}>
|
|
82
|
+
${this._monthNames[t].slice(0, 3)}
|
|
83
|
+
<md-icon>arrow_drop_down</md-icon>
|
|
84
|
+
<md-focus-ring></md-focus-ring>
|
|
85
|
+
<md-ripple></md-ripple>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
<scb-icon-button icon="chevron_right" @click=${this._nextMonth} aria-label=${this.lang == "sv" ? "Nästa månad" : "Next month"}></scb-icon-button>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="year-selector ${this._showMonthDropdown ? "disable" : ""} ${this._showYearDropdown ? "open" : ""}">
|
|
91
|
+
<scb-icon-button icon="chevron_left" @click=${this._prevYear} aria-label=${this.lang == "sv" ? "Föregående år" : "Previous year"}></scb-icon-button>
|
|
92
|
+
<div class="custom-dropdown year-dropdown">
|
|
93
|
+
<div
|
|
94
|
+
@keydown=${(o) => {
|
|
95
|
+
(o.key === "Enter" || o.key === " ") && (o.preventDefault(), this._toggleYearDropdown());
|
|
96
|
+
}}
|
|
97
|
+
tabindex="0" class="dropdown-selected" @click=${() => this._toggleYearDropdown()}>
|
|
98
|
+
${e}
|
|
99
|
+
<md-icon>arrow_drop_down</md-icon>
|
|
100
|
+
<md-focus-ring></md-focus-ring>
|
|
101
|
+
<md-ripple></md-ripple>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
<scb-icon-button icon="chevron_right" @click=${this._nextYear} aria-label=${this.lang == "sv" ? "Nästa år" : "Next year"}></scb-icon-button>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
${this._showMonthDropdown || this._showYearDropdown ? n`<scb-divider></scb-divider>` : ""}
|
|
108
|
+
<div class="datepicker-content" style="position:relative;">
|
|
109
|
+
${this._showMonthDropdown ? n`
|
|
110
|
+
<div class="dropdown-list">
|
|
111
|
+
${this._monthNames.map((o, s) => n`
|
|
112
|
+
<div
|
|
113
|
+
@keydown=${(r) => {
|
|
114
|
+
(r.key === "Enter" || r.key === " ") && (r.preventDefault(), this._onMonthChangeCustom(s));
|
|
115
|
+
}}
|
|
116
|
+
tabindex="0"
|
|
117
|
+
class="dropdown-item${s === t ? " selected" : ""}"
|
|
118
|
+
@click=${() => this._onMonthChangeCustom(s)}
|
|
119
|
+
id=${s === t ? "selected-month" : ""}
|
|
120
|
+
>
|
|
121
|
+
${s === t ? n`<md-icon>check</md-icon>` : ""}
|
|
122
|
+
${o}
|
|
123
|
+
<md-ripple></md-ripple><md-focus-ring inward></md-focus-ring>
|
|
124
|
+
</div>
|
|
125
|
+
`)}
|
|
126
|
+
</div>
|
|
127
|
+
` : ""}
|
|
128
|
+
${this._showYearDropdown ? n`
|
|
129
|
+
<div class="dropdown-list">
|
|
130
|
+
${i.map((o) => n`
|
|
131
|
+
<div
|
|
132
|
+
@keydown=${(s) => {
|
|
133
|
+
(s.key === "Enter" || s.key === " ") && (s.preventDefault(), this._onYearChangeCustom(o));
|
|
134
|
+
}}
|
|
135
|
+
tabindex="0"
|
|
136
|
+
class="dropdown-item${o === e ? " selected" : ""}"
|
|
137
|
+
@click=${() => this._onYearChangeCustom(o)}
|
|
138
|
+
id=${o === e ? "selected-year" : ""}
|
|
139
|
+
>
|
|
140
|
+
${o === e ? n`<md-icon>check</md-icon>` : ""}
|
|
141
|
+
${o}
|
|
142
|
+
<md-ripple></md-ripple><md-focus-ring inward></md-focus-ring>
|
|
143
|
+
</div>
|
|
144
|
+
`)}
|
|
145
|
+
</div>
|
|
146
|
+
` : ""}
|
|
147
|
+
${!this._showMonthDropdown && !this._showYearDropdown ? n`
|
|
148
|
+
<div class="datepicker-calendar">
|
|
149
|
+
<table>
|
|
150
|
+
<thead>
|
|
151
|
+
<tr>
|
|
152
|
+
<th>${this.lang == "sv" ? "Må" : "Mo"}</th><th>${this.lang == "sv" ? "Ti" : "Tu"}</th><th>${this.lang == "sv" ? "On" : "We"}</th><th>${this.lang == "sv" ? "To" : "Th"}</th><th>${this.lang == "sv", "Fr"}</th><th>${this.lang == "sv" ? "Lö" : "Sa"}</th><th>${this.lang == "sv" ? "Sö" : "Su"}</th>
|
|
153
|
+
</tr>
|
|
154
|
+
</thead>
|
|
155
|
+
<tbody>
|
|
156
|
+
${l.map((o) => n`
|
|
157
|
+
<tr>
|
|
158
|
+
${o.map((s) => s ? n`
|
|
159
|
+
<td>
|
|
160
|
+
<div
|
|
161
|
+
@keydown=${(r) => {
|
|
162
|
+
(r.key === "Enter" || r.key === " ") && (r.preventDefault(), this._selectDate(s));
|
|
163
|
+
}}
|
|
164
|
+
role="button"
|
|
165
|
+
tabindex="0"
|
|
166
|
+
class="day${this._isToday(s, c) ? " today" : ""}${this._isSelected(s) ? " selected" : ""}"
|
|
167
|
+
@click=${() => this._selectDate(s)}
|
|
168
|
+
>${s.getDate()}<md-ripple></md-ripple><md-focus-ring></md-focus-ring></div>
|
|
169
|
+
</td>
|
|
170
|
+
` : n`<td></td>`)}
|
|
171
|
+
</tr>
|
|
172
|
+
`)}
|
|
173
|
+
</tbody>
|
|
174
|
+
</table>
|
|
175
|
+
</div>
|
|
176
|
+
` : ""}
|
|
177
|
+
</div>
|
|
178
|
+
<div class="datepicker-footer">
|
|
179
|
+
${!this._showMonthDropdown && !this._showYearDropdown ? n`
|
|
180
|
+
<scb-button variant="text" label=${this.lang == "sv" ? "Stäng" : "Close"} @click=${this._close}></scb-button>
|
|
181
|
+
` : ""}
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
`;
|
|
185
|
+
}
|
|
186
|
+
_toggleMonthDropdown() {
|
|
187
|
+
this._showMonthDropdown = !this._showMonthDropdown, this._showMonthDropdown && (this._showYearDropdown = !1, setTimeout(() => {
|
|
188
|
+
const e = this.renderRoot.querySelector("#selected-month");
|
|
189
|
+
e && e.scrollIntoView({ block: "center" });
|
|
190
|
+
}, 0));
|
|
191
|
+
}
|
|
192
|
+
_toggleYearDropdown() {
|
|
193
|
+
this._showYearDropdown = !this._showYearDropdown, this._showYearDropdown && (this._showMonthDropdown = !1, setTimeout(() => {
|
|
194
|
+
const e = this.renderRoot.querySelector("#selected-year");
|
|
195
|
+
e && e.scrollIntoView({ block: "center" });
|
|
196
|
+
}, 0));
|
|
197
|
+
}
|
|
198
|
+
_onMonthChangeCustom(e) {
|
|
199
|
+
const t = this._currentDate.getFullYear();
|
|
200
|
+
this._currentDate = new Date(t, e, 1), this._showMonthDropdown = !1;
|
|
201
|
+
}
|
|
202
|
+
_onYearChangeCustom(e) {
|
|
203
|
+
const t = this._currentDate.getMonth();
|
|
204
|
+
this._currentDate = new Date(e, t, 1), this._showYearDropdown = !1;
|
|
205
|
+
}
|
|
206
|
+
_isToday(e, t) {
|
|
207
|
+
return e.getDate() === t.getDate() && e.getMonth() === t.getMonth() && e.getFullYear() === t.getFullYear();
|
|
208
|
+
}
|
|
209
|
+
_isSelected(e) {
|
|
210
|
+
return this._selectedDate && e.getDate() === this._selectedDate.getDate() && e.getMonth() === this._selectedDate.getMonth() && e.getFullYear() === this._selectedDate.getFullYear();
|
|
211
|
+
}
|
|
212
|
+
_selectDate(e) {
|
|
213
|
+
this._selectedDate = e;
|
|
214
|
+
const t = e.toISOString().slice(0, 10);
|
|
215
|
+
this.dispatchEvent(new CustomEvent("date-selected", {
|
|
216
|
+
detail: { value: t },
|
|
217
|
+
bubbles: !0,
|
|
218
|
+
composed: !0
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
a.styles = [
|
|
223
|
+
g`
|
|
224
|
+
:host {
|
|
225
|
+
--scb-datepicker-width: 380px;
|
|
226
|
+
width: var(--scb-datepicker-width);
|
|
227
|
+
font-family: var(--brand-font);
|
|
228
|
+
color: var(--md-sys-color-on-surface);
|
|
229
|
+
}
|
|
230
|
+
.month-selector, .year-selector {
|
|
231
|
+
display: flex;
|
|
232
|
+
align-items: center;
|
|
233
|
+
&.disable{
|
|
234
|
+
pointer-events: none;
|
|
235
|
+
opacity: 0.3;
|
|
236
|
+
scb-icon-button{
|
|
237
|
+
visibility: hidden;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
&.open{
|
|
241
|
+
scb-icon-button{
|
|
242
|
+
visibility: hidden;
|
|
243
|
+
}
|
|
244
|
+
.dropdown-selected{
|
|
245
|
+
background: var(--md-sys-color-secondary-container);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
.dropdown-selected {
|
|
250
|
+
position: relative;
|
|
251
|
+
border-radius: 8px;
|
|
252
|
+
font-size: 16px;
|
|
253
|
+
cursor: pointer;
|
|
254
|
+
text-align: left;
|
|
255
|
+
display: flex;
|
|
256
|
+
gap: 8px;
|
|
257
|
+
align-items: center;
|
|
258
|
+
padding: 4px 8px;
|
|
259
|
+
}
|
|
260
|
+
.dropdown-selected:focus {
|
|
261
|
+
outline: none;
|
|
262
|
+
}
|
|
263
|
+
.dropdown-selected md-focus-ring {
|
|
264
|
+
border-radius: 8px;
|
|
265
|
+
}
|
|
266
|
+
.dropdown-list {
|
|
267
|
+
position: relative;
|
|
268
|
+
background: var(--md-sys-color-surface);
|
|
269
|
+
padding: 4px 0;
|
|
270
|
+
}
|
|
271
|
+
.dropdown-item {
|
|
272
|
+
display: flex;
|
|
273
|
+
position: relative;
|
|
274
|
+
cursor: pointer;
|
|
275
|
+
padding: var(--spacing-3) 56px;
|
|
276
|
+
min-height: 40px;
|
|
277
|
+
align-items: center;
|
|
278
|
+
}
|
|
279
|
+
.dropdown-item:focus-within {
|
|
280
|
+
outline: none;
|
|
281
|
+
}
|
|
282
|
+
.dropdown-item md-focus-ring {
|
|
283
|
+
border-radius: var(--md-sys-shape-corner-small);
|
|
284
|
+
}
|
|
285
|
+
.dropdown-item.selected {
|
|
286
|
+
background: var(--md-sys-color-secondary-container, #e3f2fd);
|
|
287
|
+
font-weight: 500;
|
|
288
|
+
padding-left: 16px;
|
|
289
|
+
gap: 16px;
|
|
290
|
+
}
|
|
291
|
+
.datepicker-popup {
|
|
292
|
+
background: var(--md-sys-color-surface);
|
|
293
|
+
border-radius: var(--md-sys-shape-corner-small);
|
|
294
|
+
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.30), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
|
|
295
|
+
max-width: var(--scb-datepicker-width);
|
|
296
|
+
width: 100%;
|
|
297
|
+
font-family: var(--brand-font);
|
|
298
|
+
}
|
|
299
|
+
.datepicker-content{
|
|
300
|
+
overflow-y: auto;
|
|
301
|
+
max-height: 260px;
|
|
302
|
+
}
|
|
303
|
+
.popup {
|
|
304
|
+
position:absolute;
|
|
305
|
+
top:110%;
|
|
306
|
+
left:0;
|
|
307
|
+
z-index:10;
|
|
308
|
+
}
|
|
309
|
+
.header {
|
|
310
|
+
display: flex;
|
|
311
|
+
align-items: center;
|
|
312
|
+
justify-content: space-between;
|
|
313
|
+
margin-bottom: 12px;
|
|
314
|
+
padding: 16px 24px 0 16px;
|
|
315
|
+
flex-wrap: wrap;
|
|
316
|
+
}
|
|
317
|
+
.datepicker-footer{
|
|
318
|
+
padding: 8px 16px 24px 16px;
|
|
319
|
+
}
|
|
320
|
+
.month-label {
|
|
321
|
+
font-size: 18px;
|
|
322
|
+
font-weight: 500;
|
|
323
|
+
}
|
|
324
|
+
.datepicker-calendar{
|
|
325
|
+
padding: 0 16px;
|
|
326
|
+
}
|
|
327
|
+
table {
|
|
328
|
+
width: 100%;
|
|
329
|
+
border-collapse: collapse;
|
|
330
|
+
margin-bottom: 8px;
|
|
331
|
+
}
|
|
332
|
+
th {
|
|
333
|
+
color: var(--md-sys-color-on-surface-variant, #757575);
|
|
334
|
+
font-size: 16px;
|
|
335
|
+
font-weight: 600;
|
|
336
|
+
padding: 4px;
|
|
337
|
+
}
|
|
338
|
+
td {
|
|
339
|
+
text-align: center;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.day:focus-within{
|
|
343
|
+
outline: none;
|
|
344
|
+
}
|
|
345
|
+
.day {
|
|
346
|
+
position: relative;
|
|
347
|
+
width: 40px;
|
|
348
|
+
height: 40px;
|
|
349
|
+
border-radius: 50%;
|
|
350
|
+
border: none;
|
|
351
|
+
background: none;
|
|
352
|
+
font-size: 16px;
|
|
353
|
+
cursor: pointer;
|
|
354
|
+
font-family: 'Inter';
|
|
355
|
+
align-content: center;
|
|
356
|
+
}
|
|
357
|
+
.day.selected {
|
|
358
|
+
background: var(--md-sys-color-secondary-container);
|
|
359
|
+
}
|
|
360
|
+
.close-datepicker {
|
|
361
|
+
margin-top: 8px;
|
|
362
|
+
background: none;
|
|
363
|
+
border-color: none;
|
|
364
|
+
color: var(--md-sys-color-primary, #0057b8);
|
|
365
|
+
font-size: 16px;
|
|
366
|
+
cursor: pointer;
|
|
367
|
+
padding: 4px 12px;
|
|
368
|
+
border-radius: 8px;
|
|
369
|
+
}
|
|
370
|
+
.close-datepicker:hover {
|
|
371
|
+
background: var(--md-sys-color-primary-container, #e3f2fd);
|
|
372
|
+
}
|
|
373
|
+
`
|
|
374
|
+
];
|
|
375
|
+
d([
|
|
376
|
+
h()
|
|
377
|
+
], a.prototype, "_currentDate", 2);
|
|
378
|
+
d([
|
|
379
|
+
h()
|
|
380
|
+
], a.prototype, "_selectedDate", 2);
|
|
381
|
+
d([
|
|
382
|
+
h()
|
|
383
|
+
], a.prototype, "_showMonthDropdown", 2);
|
|
384
|
+
d([
|
|
385
|
+
h()
|
|
386
|
+
], a.prototype, "_showYearDropdown", 2);
|
|
387
|
+
d([
|
|
388
|
+
p({ type: String })
|
|
389
|
+
], a.prototype, "variant", 2);
|
|
390
|
+
d([
|
|
391
|
+
p({ type: String })
|
|
392
|
+
], a.prototype, "lang", 2);
|
|
393
|
+
d([
|
|
394
|
+
p({ type: String })
|
|
395
|
+
], a.prototype, "selectedValue", 2);
|
|
396
|
+
d([
|
|
397
|
+
p({ type: Boolean })
|
|
398
|
+
], a.prototype, "open", 2);
|
|
399
|
+
a = d([
|
|
400
|
+
w("scb-datepicker")
|
|
401
|
+
], a);
|
|
402
|
+
export {
|
|
403
|
+
a as ScbDatepicker
|
|
404
|
+
};
|
|
@@ -27,8 +27,11 @@ export declare class ScbTextField extends LitElement {
|
|
|
27
27
|
private _formResetHandler;
|
|
28
28
|
private _initialValue;
|
|
29
29
|
private _inputId;
|
|
30
|
+
private _showDatepicker;
|
|
30
31
|
static styles: import('lit').CSSResult[];
|
|
31
32
|
render(): TemplateResult;
|
|
33
|
+
private _toggleDatepicker;
|
|
34
|
+
private _onDateSelected;
|
|
32
35
|
/**
|
|
33
36
|
* Vi re-dispatchar inbyggda "input", "change" och "select"-events med { bubbles: true, composed: true }.
|
|
34
37
|
* Vi kör också ett customevent onValueChanged.
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { css as m, LitElement as x, html as d } from "lit";
|
|
2
2
|
import { property as a, customElement as v } from "lit/decorators.js";
|
|
3
3
|
import "@material/web/icon/icon.js";
|
|
4
|
+
import "../scb-datepicker/scb-datepicker.js";
|
|
4
5
|
var y = Object.defineProperty, g = Object.getOwnPropertyDescriptor, f = (t) => {
|
|
5
6
|
throw TypeError(t);
|
|
6
7
|
}, r = (t, e, i, l) => {
|
|
7
|
-
for (var o = l > 1 ? void 0 : l ? g(e, i) : e,
|
|
8
|
-
(u = t[
|
|
8
|
+
for (var o = l > 1 ? void 0 : l ? g(e, i) : e, h = t.length - 1, u; h >= 0; h--)
|
|
9
|
+
(u = t[h]) && (o = (l ? u(e, i, o) : u(o)) || o);
|
|
9
10
|
return l && o && y(e, i, o), o;
|
|
10
|
-
}, _ = (t, e, i) => e.has(t) || f("Cannot " + i), w = (t, e, i) => e.has(t) ? f("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), c = (t, e, i) => (_(t, e, "access private method"), i), n, b,
|
|
11
|
+
}, _ = (t, e, i) => e.has(t) || f("Cannot " + i), w = (t, e, i) => e.has(t) ? f("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), c = (t, e, i) => (_(t, e, "access private method"), i), n, b, p;
|
|
11
12
|
let s = class extends x {
|
|
12
13
|
constructor() {
|
|
13
|
-
super(), w(this, n), this._internals = null, this.type = "text", this.label = "", this.supportingText = "", this.errorText = "", this.leadingIcon = "", this.name = "", this.pattern = "", this.value = "", this.underLabel = "", this.error = !1, this.disabled = !1, this.required = !1, this.spacing = "", this.spacingTop = "", this.spacingBottom = "", this._form = null, this._formSubmitHandler = null, this._formResetHandler = null, this._initialValue = "", this._inputId = "",
|
|
14
|
+
super(), w(this, n), this._internals = null, this.type = "text", this.label = "", this.supportingText = "", this.errorText = "", this.leadingIcon = "", this.name = "", this.pattern = "", this.value = "", this.underLabel = "", this.error = !1, this.disabled = !1, this.required = !1, this.spacing = "", this.spacingTop = "", this.spacingBottom = "", this._form = null, this._formSubmitHandler = null, this._formResetHandler = null, this._initialValue = "", this._inputId = "", this._showDatepicker = !1, this._toggleDatepicker = () => {
|
|
15
|
+
this._showDatepicker = !this._showDatepicker;
|
|
16
|
+
}, this._onDateSelected = (t) => {
|
|
17
|
+
this.value = t.detail.value, this._showDatepicker = !1, this.dispatchEvent(new Event("input", { bubbles: !0, composed: !0 })), this.dispatchEvent(
|
|
18
|
+
new CustomEvent("onValueChanged", {
|
|
19
|
+
detail: { value: this.value },
|
|
20
|
+
bubbles: !0,
|
|
21
|
+
composed: !0
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
}, "attachInternals" in this && (this._internals = this.attachInternals());
|
|
14
25
|
}
|
|
15
26
|
render() {
|
|
16
27
|
const t = this.leadingIcon ? d`<md-icon class="scb-textfield-icon">${this.leadingIcon}</md-icon>` : null, e = this.error ? d`<md-icon class="scb-textfield-error-icon" aria-hidden="true">error</md-icon>` : null;
|
|
@@ -70,6 +81,36 @@ let s = class extends x {
|
|
|
70
81
|
${this.value}</textarea
|
|
71
82
|
>
|
|
72
83
|
</div>
|
|
84
|
+
` : this.type === "date" ? d`
|
|
85
|
+
<label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
|
|
86
|
+
<span
|
|
87
|
+
class="scb-textfield-supporting-text"
|
|
88
|
+
id="${this.underLabel ? `${this._inputId}-supporting-text` : ""}"
|
|
89
|
+
>${this.underLabel}</span
|
|
90
|
+
>
|
|
91
|
+
<div class="scb-textfield-wrapper" style="position:relative;">
|
|
92
|
+
${t}
|
|
93
|
+
<input
|
|
94
|
+
class="scb-textfield${this.error ? " has-error-icon" : ""}"
|
|
95
|
+
.value=${this.value}
|
|
96
|
+
type="text"
|
|
97
|
+
name="${this.name}"
|
|
98
|
+
id="${this._inputId}"
|
|
99
|
+
?disabled=${this.disabled}
|
|
100
|
+
?required=${this.required}
|
|
101
|
+
aria-invalid=${this.error ? "true" : "false"}
|
|
102
|
+
aria-describedby=${i}
|
|
103
|
+
readonly
|
|
104
|
+
/>
|
|
105
|
+
<scb-icon-button icon="calendar_today" @click=${this._toggleDatepicker} aria-label="Välj datum" style="position:absolute;right:8px;top:50%;transform:translateY(-50%);"></scb-icon-button>
|
|
106
|
+
<scb-datepicker
|
|
107
|
+
variant="popup"
|
|
108
|
+
.selectedValue=${this.value}
|
|
109
|
+
.open=${this._showDatepicker}
|
|
110
|
+
@date-selected=${this._onDateSelected}
|
|
111
|
+
></scb-datepicker>
|
|
112
|
+
${e}
|
|
113
|
+
</div>
|
|
73
114
|
` : d`
|
|
74
115
|
<label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
|
|
75
116
|
<span
|
|
@@ -190,10 +231,10 @@ ${this.value}</textarea
|
|
|
190
231
|
};
|
|
191
232
|
n = /* @__PURE__ */ new WeakSet();
|
|
192
233
|
b = function() {
|
|
193
|
-
const t = c(this, n,
|
|
234
|
+
const t = c(this, n, p).call(this, this.spacing), e = c(this, n, p).call(this, this.spacingTop) ?? t, i = c(this, n, p).call(this, this.spacingBottom) ?? t;
|
|
194
235
|
e ? this.style.setProperty("--scb-textfield-spacing-block-start", e) : this.style.removeProperty("--scb-textfield-spacing-block-start"), i ? this.style.setProperty("--scb-textfield-spacing-block-end", i) : this.style.removeProperty("--scb-textfield-spacing-block-end");
|
|
195
236
|
};
|
|
196
|
-
|
|
237
|
+
p = function(t) {
|
|
197
238
|
if (!t) return;
|
|
198
239
|
const e = String(t).trim();
|
|
199
240
|
if (e)
|
|
@@ -225,6 +266,9 @@ s.styles = [
|
|
|
225
266
|
:host([type='text']) {
|
|
226
267
|
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
227
268
|
}
|
|
269
|
+
:host([type='date']) {
|
|
270
|
+
--scb-textfield-max-width: var(--scb-textfield-text-max-width);
|
|
271
|
+
}
|
|
228
272
|
:host([type='search']) {
|
|
229
273
|
--scb-textfield-max-width: var(--scb-textfield-search-max-width);
|
|
230
274
|
}
|
|
@@ -425,6 +469,9 @@ r([
|
|
|
425
469
|
r([
|
|
426
470
|
a({ type: String, attribute: "spacing-bottom", reflect: !0 })
|
|
427
471
|
], s.prototype, "spacingBottom", 2);
|
|
472
|
+
r([
|
|
473
|
+
a({ type: Boolean })
|
|
474
|
+
], s.prototype, "_showDatepicker", 2);
|
|
428
475
|
s = r([
|
|
429
476
|
v("scb-textfield")
|
|
430
477
|
], s);
|