kempo-ui 0.4.1 → 0.4.3
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/dist/components/Calendar.js +170 -0
- package/dist/components/Slider.js +188 -0
- package/dist/components/Time.js +37 -0
- package/docs/components/accordion.html +12 -0
- package/docs/components/aside.html +12 -0
- package/docs/components/calendar.html +712 -0
- package/docs/components/card.html +12 -0
- package/docs/components/code-editor.html +12 -0
- package/docs/components/color-picker.html +12 -0
- package/docs/components/combobox.html +12 -0
- package/docs/components/content-slider.html +12 -0
- package/docs/components/context.html +12 -0
- package/docs/components/dialog.html +12 -0
- package/docs/components/dropdown.html +12 -0
- package/docs/components/filter-list.html +12 -0
- package/docs/components/focus-capture.html +12 -0
- package/docs/components/html-editor.html +12 -0
- package/docs/components/hybrid-component.html +12 -0
- package/docs/components/icon.html +12 -0
- package/docs/components/import.html +12 -0
- package/docs/components/light-component.html +12 -0
- package/docs/components/nav-spacer.html +12 -0
- package/docs/components/nav.html +12 -0
- package/docs/components/photo-viewer.html +12 -0
- package/docs/components/progress.html +12 -0
- package/docs/components/resize.html +12 -0
- package/docs/components/shadow-component.html +12 -0
- package/docs/components/show-more.html +12 -0
- package/docs/components/slider.html +789 -0
- package/docs/components/sortable.html +12 -0
- package/docs/components/spinner.html +12 -0
- package/docs/components/split.html +12 -0
- package/docs/components/table.html +12 -0
- package/docs/components/tableControls.html +12 -0
- package/docs/components/tableCustomFields.html +12 -0
- package/docs/components/tableFetchRecords.html +12 -0
- package/docs/components/tableFieldSortHide.html +12 -0
- package/docs/components/tablePagination.html +12 -0
- package/docs/components/tablePlaceholder.html +12 -0
- package/docs/components/tableRecordEditing.html +12 -0
- package/docs/components/tableRecordFiltering.html +12 -0
- package/docs/components/tableRecordHiding.html +12 -0
- package/docs/components/tableRecordSearching.html +12 -0
- package/docs/components/tableRecordSelection.html +12 -0
- package/docs/components/tableRowControls.html +12 -0
- package/docs/components/tableServerSync.html +12 -0
- package/docs/components/tableSorting.html +12 -0
- package/docs/components/tabs.html +12 -0
- package/docs/components/tags.html +12 -0
- package/docs/components/theme-select.html +12 -0
- package/docs/components/theme-switcher.html +12 -0
- package/docs/components/time.html +662 -0
- package/docs/components/timestamp.html +12 -0
- package/docs/components/toast.html +12 -0
- package/docs/components/toggle.html +12 -0
- package/docs/components/tree.html +12 -0
- package/docs/index.html +30 -0
- package/docs/src/components/Calendar.js +170 -0
- package/docs/src/components/Slider.js +188 -0
- package/docs/src/components/Time.js +37 -0
- package/docs/utils/context.html +12 -0
- package/docs/utils/cookie.html +12 -0
- package/docs/utils/debounce.html +12 -0
- package/docs/utils/drag.html +12 -0
- package/docs/utils/elevation.html +12 -0
- package/docs/utils/formatTimestamp.html +12 -0
- package/docs/utils/object.html +12 -0
- package/docs/utils/propConverters.html +12 -0
- package/docs/utils/string.html +12 -0
- package/docs/utils/theme.html +12 -0
- package/docs/utils/toTitleCase.html +12 -0
- package/docs/utils/type.html +12 -0
- package/docs/utils/wait.html +12 -0
- package/docs-src/components/calendar.page.html +254 -0
- package/docs-src/components/slider.page.html +331 -0
- package/docs-src/components/time.page.html +204 -0
- package/docs-src/index.page.html +18 -0
- package/docs-src/nav.fragment.html +12 -0
- package/llms.txt +3 -0
- package/package.json +1 -1
- package/src/components/Calendar.js +473 -0
- package/src/components/Slider.js +480 -0
- package/src/components/Time.js +137 -0
- package/tests/components/Slider.browser-test.js +823 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import{html as e,css as t}from"../lit-all.min.js";import a from"./ShadowComponent.js";const i=["January","February","March","April","May","June","July","August","September","October","November","December"],s=["Su","Mo","Tu","We","Th","Fr","Sa"];export default class r extends a{static formAssociated=!0;static properties={value:{type:String,reflect:!0},name:{type:String,reflect:!0},mode:{type:String,reflect:!0},min:{type:String,reflect:!0},max:{type:String,reflect:!0},disabled:{type:Boolean,reflect:!0},required:{type:Boolean,reflect:!0},view:{state:!0},hoverDate:{state:!0}};constructor(){super(),this.internals=this.attachInternals(),this.value="",this.name="",this.mode="single",this.min="",this.max="",this.disabled=!1,this.required=!1;const e=new Date;this.view=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`,this.hoverDate=null}#e=!1;updated(e){if(super.updated(e),this.internals.setFormValue(this.value),this.required&&!this.value?this.internals.setValidity({valueMissing:!0},"Please select a date.",this.shadowRoot?.querySelector(".day")):this.internals.setValidity({}),e.has("value")&&void 0!==e.get("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0})),e.has("value")&&this.value&&!this.#e){const e=this.fromIso(this.value.split(",")[0]);if(e){const t=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`;t!==this.view&&(this.view=t)}}this.#e=!1}get isRange(){return"range"===this.mode}get viewYear(){return Number(this.view.split("-")[0])}get viewMonth(){return Number(this.view.split("-")[1])-1}get parsed(){if(!this.value)return this.isRange?{start:null,end:null}:{date:null};if(this.isRange){const[e,t]=this.value.split(",");return{start:e?this.fromIso(e):null,end:t?this.fromIso(t):null}}return{date:this.fromIso(this.value)}}toIso=e=>e?`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`:"";fromIso=e=>{if(!e)return null;const[t,a,i]=e.split("-").map(Number);return isNaN(t)||isNaN(a)||isNaN(i)?null:new Date(t,a-1,i)};isSameDay=(e,t)=>!(!e||!t)&&(e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate());isWithinRange=(e,t,a)=>{if(!t||!a||!e)return!1;const i=e.getTime();return i>t.getTime()&&i<a.getTime()};resolveDate=e=>{if(!e)return null;const t=String(e).toLowerCase();if("today"===t||"tomorrow"===t||"yesterday"===t){const e=new Date;return e.setHours(0,0,0,0),"tomorrow"===t&&e.setDate(e.getDate()+1),"yesterday"===t&&e.setDate(e.getDate()-1),e}return this.fromIso(e)};get minDate(){return this.resolveDate(this.min)||this.fromIso("1900-01-01")}get maxDate(){if(this.max)return this.resolveDate(this.max);const e=new Date;return new Date(e.getFullYear()+10,11,31)}isDisabledDate=e=>{if(!e)return!1;const t=this.minDate;if(t&&e<t)return!0;const a=this.maxDate;return!!(a&&e>a)};get availableYears(){const e=this.minDate?.getFullYear()??1900,t=this.maxDate?.getFullYear()??(new Date).getFullYear()+10,a=[];for(let i=e;i<=t;i++)a.push(i);return a}isMonthDisabled=(e,t)=>{const a=new Date(e,t+1,0),i=new Date(e,t,1),s=this.minDate,r=this.maxDate;return!!(s&&a<s)||!!(r&&i>r)};get weekGrid(){const e=this.viewYear,t=this.viewMonth,a=new Date(e,t,1).getDay(),i=new Date(e,t,1-a),s=[];for(let e=0;e<6;e++){const t=[];for(let a=0;a<7;a++){const s=new Date(i);s.setDate(i.getDate()+7*e+a),t.push(s)}s.push(t)}return s}get monthLabel(){return`${i[this.viewMonth]} ${this.viewYear}`}prevMonth=()=>{const e=new Date(this.viewYear,this.viewMonth-1,1);this.view=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`};nextMonth=()=>{const e=new Date(this.viewYear,this.viewMonth+1,1);this.view=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`};goToMonth=(e,t)=>{this.view=`${e}-${String(t+1).padStart(2,"0")}`};goToToday=()=>{const e=new Date;this.view=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`};handleDayClick=e=>{if(!this.disabled&&!this.isDisabledDate(e))if(this.#e=!0,this.isRange){const{start:t,end:a}=this.parsed;this.value=!t||a?this.toIso(e):e<t?`${this.toIso(e)},${this.toIso(t)}`:`${this.toIso(t)},${this.toIso(e)}`}else this.value=this.toIso(e)};handleDayHover=e=>{this.isRange&&(this.hoverDate=e)};handleMouseLeave=()=>{this.isRange&&(this.hoverDate=null)};handleMonthChange=e=>{this.goToMonth(this.viewYear,Number(e.target.value))};handleYearChange=e=>{this.goToMonth(Number(e.target.value),this.viewMonth)};render(){const t=new Date,a=this.parsed,r=a.date,n=a.start,o=a.end,l=this.isRange&&n&&!o&&this.hoverDate?this.hoverDate:o,d=this.isRange&&n&&l&&n>l?l:n,h=this.isRange&&n&&l&&n>l?n:l;return e`
|
|
2
|
+
<div class="header">
|
|
3
|
+
<select
|
|
4
|
+
class="month-select"
|
|
5
|
+
aria-label="Month"
|
|
6
|
+
?disabled=${this.disabled}
|
|
7
|
+
@change=${this.handleMonthChange}
|
|
8
|
+
>
|
|
9
|
+
${i.map((t,a)=>e`
|
|
10
|
+
<option
|
|
11
|
+
value=${a}
|
|
12
|
+
?selected=${a===this.viewMonth}
|
|
13
|
+
?disabled=${this.isMonthDisabled(this.viewYear,a)}
|
|
14
|
+
>${t}</option>
|
|
15
|
+
`)}
|
|
16
|
+
</select>
|
|
17
|
+
<select
|
|
18
|
+
class="year-select"
|
|
19
|
+
aria-label="Year"
|
|
20
|
+
?disabled=${this.disabled}
|
|
21
|
+
@change=${this.handleYearChange}
|
|
22
|
+
>
|
|
23
|
+
${this.availableYears.map(t=>e`
|
|
24
|
+
<option value=${t} ?selected=${t===this.viewYear}>${t}</option>
|
|
25
|
+
`)}
|
|
26
|
+
</select>
|
|
27
|
+
</div>
|
|
28
|
+
<div class="grid" @mouseleave=${this.handleMouseLeave}>
|
|
29
|
+
<div class="row head">
|
|
30
|
+
${s.map(t=>e`<div class="dow">${t}</div>`)}
|
|
31
|
+
</div>
|
|
32
|
+
${this.weekGrid.map(a=>e`
|
|
33
|
+
<div class="row">
|
|
34
|
+
${a.map(a=>{const i=a.getMonth()!==this.viewMonth,s=this.isSameDay(a,t),n=!this.isRange&&this.isSameDay(a,r),l=this.isRange&&this.isSameDay(a,d),g=this.isRange&&this.isSameDay(a,h),u=this.isRange&&this.isWithinRange(a,d,h),c=this.isDisabledDate(a),v=["day",i?"outside":"",s?"today":"",n?"selected":"",l?"range-start":"",g&&!l?"range-end":"",u?"in-range":"",this.isRange&&!o&&(l||g||u)&&!n?"preview":"",c?"disabled":""].filter(Boolean).join(" ");return e`
|
|
35
|
+
<button
|
|
36
|
+
type="button"
|
|
37
|
+
class="no-btn ${v}"
|
|
38
|
+
?disabled=${c||this.disabled}
|
|
39
|
+
aria-selected=${n||l||g?"true":"false"}
|
|
40
|
+
@click=${()=>this.handleDayClick(a)}
|
|
41
|
+
@mouseenter=${()=>this.handleDayHover(a)}
|
|
42
|
+
>${a.getDate()}</button>
|
|
43
|
+
`})}
|
|
44
|
+
</div>
|
|
45
|
+
`)}
|
|
46
|
+
</div>
|
|
47
|
+
`}static styles=t`
|
|
48
|
+
:host {
|
|
49
|
+
--day_size: 2rem;
|
|
50
|
+
--day_radius: var(--radius);
|
|
51
|
+
--day_bg__selected: var(--c_primary);
|
|
52
|
+
--day_tc__selected: white;
|
|
53
|
+
--day_bg__range: var(--c_bg__alt);
|
|
54
|
+
--day_bg__hover: var(--c_bg__alt);
|
|
55
|
+
|
|
56
|
+
display: inline-block;
|
|
57
|
+
border: 1px solid var(--c_border);
|
|
58
|
+
border-radius: var(--radius);
|
|
59
|
+
padding: 0.5rem;
|
|
60
|
+
background: var(--c_bg);
|
|
61
|
+
user-select: none;
|
|
62
|
+
}
|
|
63
|
+
:host([disabled]) {
|
|
64
|
+
opacity: 0.5;
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
}
|
|
67
|
+
.header {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
gap: 0.25rem;
|
|
71
|
+
padding: 0.25rem;
|
|
72
|
+
margin-bottom: 0.25rem;
|
|
73
|
+
}
|
|
74
|
+
.month-select,
|
|
75
|
+
.year-select {
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
width: auto;
|
|
78
|
+
}
|
|
79
|
+
.month-select {
|
|
80
|
+
flex: 1;
|
|
81
|
+
}
|
|
82
|
+
.grid {
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
}
|
|
86
|
+
.row {
|
|
87
|
+
display: grid;
|
|
88
|
+
grid-template-columns: repeat(7, var(--day_size));
|
|
89
|
+
}
|
|
90
|
+
.row.head {
|
|
91
|
+
margin-bottom: 0.25rem;
|
|
92
|
+
}
|
|
93
|
+
.dow {
|
|
94
|
+
display: flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
justify-content: center;
|
|
97
|
+
font-size: 0.75rem;
|
|
98
|
+
color: var(--tc_muted);
|
|
99
|
+
font-weight: 500;
|
|
100
|
+
height: var(--day_size);
|
|
101
|
+
}
|
|
102
|
+
.day {
|
|
103
|
+
appearance: none;
|
|
104
|
+
background: transparent;
|
|
105
|
+
border: 1px solid transparent;
|
|
106
|
+
border-radius: var(--day_radius);
|
|
107
|
+
width: var(--day_size);
|
|
108
|
+
height: var(--day_size);
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
color: var(--tc);
|
|
111
|
+
font: inherit;
|
|
112
|
+
font-size: 0.875rem;
|
|
113
|
+
padding: 0;
|
|
114
|
+
position: relative;
|
|
115
|
+
display: inline-flex;
|
|
116
|
+
align-items: center;
|
|
117
|
+
justify-content: center;
|
|
118
|
+
transition: background var(--animation_ms), color var(--animation_ms);
|
|
119
|
+
}
|
|
120
|
+
.day:hover:not(:disabled):not(.selected):not(.range-start):not(.range-end) {
|
|
121
|
+
background: var(--day_bg__hover);
|
|
122
|
+
}
|
|
123
|
+
.day:focus-visible {
|
|
124
|
+
outline: none;
|
|
125
|
+
border-color: var(--c_primary);
|
|
126
|
+
box-shadow: var(--focus_shadow);
|
|
127
|
+
z-index: 1;
|
|
128
|
+
}
|
|
129
|
+
.day.outside {
|
|
130
|
+
color: var(--tc_muted);
|
|
131
|
+
opacity: 0.5;
|
|
132
|
+
}
|
|
133
|
+
.day.today {
|
|
134
|
+
font-weight: 700;
|
|
135
|
+
border-color: var(--c_primary);
|
|
136
|
+
}
|
|
137
|
+
.day.selected,
|
|
138
|
+
.day.in-range,
|
|
139
|
+
.day.range-start,
|
|
140
|
+
.day.range-end {
|
|
141
|
+
background: var(--day_bg__selected);
|
|
142
|
+
color: var(--day_tc__selected);
|
|
143
|
+
border-color: transparent;
|
|
144
|
+
}
|
|
145
|
+
.day.in-range {
|
|
146
|
+
border-radius: 0;
|
|
147
|
+
}
|
|
148
|
+
.day.range-start:not(.range-end) {
|
|
149
|
+
border-top-right-radius: 0;
|
|
150
|
+
border-bottom-right-radius: 0;
|
|
151
|
+
}
|
|
152
|
+
.day.range-end:not(.range-start) {
|
|
153
|
+
border-top-left-radius: 0;
|
|
154
|
+
border-bottom-left-radius: 0;
|
|
155
|
+
}
|
|
156
|
+
.day.outside.in-range,
|
|
157
|
+
.day.outside.range-start,
|
|
158
|
+
.day.outside.range-end {
|
|
159
|
+
opacity: 0.6;
|
|
160
|
+
}
|
|
161
|
+
.day.preview.in-range,
|
|
162
|
+
.day.preview.range-start,
|
|
163
|
+
.day.preview.range-end {
|
|
164
|
+
opacity: 0.75;
|
|
165
|
+
}
|
|
166
|
+
.day:disabled {
|
|
167
|
+
opacity: 0.3;
|
|
168
|
+
cursor: not-allowed;
|
|
169
|
+
}
|
|
170
|
+
`}customElements.define("k-calendar",r);
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import{html as t,css as e}from"../lit-all.min.js";import i from"./ShadowComponent.js";export default class s extends i{static formAssociated=!0;static properties={value:{type:String,reflect:!0},name:{type:String,reflect:!0},min:{type:Number,reflect:!0},max:{type:Number,reflect:!0},steps:{type:String,reflect:!0},format:{type:String,reflect:!0},tooltip:{type:Boolean,reflect:!0},vertical:{type:Boolean,reflect:!0},disabled:{type:Boolean,reflect:!0}};#t=null;constructor(){super(),this.internals=this.attachInternals(),this.value="0",this.name="",this.min=0,this.max=100,this.steps=null,this.format=null,this.tooltip=!1,this.vertical=!1,this.disabled=!1,this.tabIndex=0}connectedCallback(){super.connectedCallback(),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("keydown",this.handleKeyDown)}get isRange(){return String(this.value).includes(",")}get formattedValue(){return this.format?this.isRange?`${this.formatValue(this.lower)},${this.formatValue(this.upper)}`:this.formatValue(this.lower):this.value}updated(t){super.updated(t),this.internals.setFormValue(this.formattedValue),t.has("value")&&void 0!==t.get("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.formattedValue},bubbles:!0}))}get stepValues(){return this.steps?this.steps.split(",").map(t=>Number(t.trim())).filter(t=>!isNaN(t)).sort((t,e)=>t-e):null}get lower(){const t=String(this.value).split(",");return Number(t[0])||0}get upper(){const t=String(this.value).split(",");return t.length>1?Number(t[1]):this.max}get percentage(){return(this.lower-this.min)/(this.max-this.min)*100}get upperPercentage(){return(this.upper-this.min)/(this.max-this.min)*100}formatValue=t=>{if(!this.format)return String(t);const e=this.format,i=e.match(/0([^0]?)0+/);if(!i)return e.replace("0",String(Math.round(t)));const s=i[0].indexOf(i[1])>0?i[1]:"",r=s?i[0].split(s)[1].length:0,a=t.toFixed(r);return e.replace(i[0],a)};snapToNearest=t=>{const e=this.stepValues;if(!e||0===e.length)return Math.min(this.max,Math.max(this.min,t));let i=e[0],s=Math.abs(t-i);for(let r=1;r<e.length;r++){const a=Math.abs(t-e[r]);a<s&&(i=e[r],s=a)}return i};ratioFromEvent=t=>{const e=this.shadowRoot.querySelector("#track").getBoundingClientRect();return this.vertical?Math.min(1,Math.max(0,1-(t.clientY-e.top)/e.height)):Math.min(1,Math.max(0,(t.clientX-e.left)/e.width))};valueFromEvent=t=>{const e=this.min+this.ratioFromEvent(t)*(this.max-this.min);return this.snapToNearest(e)};setValue=t=>{if(this.disabled)return;const e=Math.min(this.max,Math.max(this.min,t)),i=this.snapToNearest(e);if(this.isRange){if(i>this.upper)return;i!==this.lower&&(this.value=`${i},${this.upper}`)}else i!==this.lower&&(this.value=String(i))};setUpper=t=>{if(this.disabled||!this.isRange)return;const e=Math.min(this.max,Math.max(this.min,t)),i=this.snapToNearest(e);i<this.lower||i!==this.upper&&(this.value=`${this.lower},${i}`)};closestThumb=t=>{if(!this.isRange)return"lower";return Math.abs(t-this.lower)<=Math.abs(t-this.upper)?"lower":"upper"};stepIncrement=(t,e)=>{const i=this.stepValues;if(i&&i.length>0){const s=i.indexOf(t);if(e>0){if(s>=0&&s<i.length-1)return i[s+1];if(-1===s)return i.find(e=>e>t)??i[i.length-1]}else{if(s>0)return i[s-1];if(-1===s)return[...i].reverse().find(e=>e<t)??i[0]}return t}return t+e};handleTrackClick=t=>{if(this.disabled)return;const e=this.valueFromEvent(t);this.isRange&&"upper"===this.closestThumb(e)?this.setUpper(e):this.setValue(e)};handleThumbDown=(t,e)=>{if(this.disabled)return;e.preventDefault(),e.stopPropagation(),this.#t=t,this.requestUpdate();const i=t=>{const e=t.touches?t.touches[0]:t,i=this.valueFromEvent(e);"upper"===this.#t?this.setUpper(i):this.setValue(i)},s=()=>{this.#t=null,this.requestUpdate(),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s),window.removeEventListener("touchmove",i),window.removeEventListener("touchend",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s),window.addEventListener("touchmove",i),window.addEventListener("touchend",s)};handleKeyDown=t=>{if(this.disabled)return;const e=this.stepValues,i="ArrowRight"===t.key||"ArrowUp"===t.key,s="ArrowLeft"===t.key||"ArrowDown"===t.key;if(i||s){t.preventDefault();const e=i?1:-1;this.isRange&&"upper"===this.#t?this.setUpper(this.stepIncrement(this.upper,e)):this.setValue(this.stepIncrement(this.lower,e))}else"Home"===t.key?(t.preventDefault(),this.setValue(e?e[0]:this.min)):"End"===t.key&&(t.preventDefault(),this.isRange?this.setUpper(e?e[e.length-1]:this.max):this.setValue(e?e[e.length-1]:this.max))};renderHorizontal=()=>{const e=this.percentage,i=this.stepValues;if(this.isRange){const s=this.upperPercentage;return t`
|
|
2
|
+
<div id="track" @click=${this.handleTrackClick}>
|
|
3
|
+
<div id="fill" style="left:${e}%;width:${s-e}%"></div>
|
|
4
|
+
${i?i.map(e=>{const i=(e-this.min)/(this.max-this.min)*100;return t`<div class="step-dot" style="left:${i}%"></div>`}):""}
|
|
5
|
+
<div
|
|
6
|
+
class="thumb${"lower"===this.#t?" active":""}"
|
|
7
|
+
style="left:${e}%"
|
|
8
|
+
@mousedown=${t=>this.handleThumbDown("lower",t)}
|
|
9
|
+
@touchstart=${t=>this.handleThumbDown("lower",t)}
|
|
10
|
+
>${this.tooltip&&"lower"===this.#t?t`<div class="tooltip">${this.formatValue(this.lower)}</div>`:""}</div>
|
|
11
|
+
<div
|
|
12
|
+
class="thumb${"upper"===this.#t?" active":""}"
|
|
13
|
+
style="left:${s}%"
|
|
14
|
+
@mousedown=${t=>this.handleThumbDown("upper",t)}
|
|
15
|
+
@touchstart=${t=>this.handleThumbDown("upper",t)}
|
|
16
|
+
>${this.tooltip&&"upper"===this.#t?t`<div class="tooltip">${this.formatValue(this.upper)}</div>`:""}</div>
|
|
17
|
+
</div>
|
|
18
|
+
`}return t`
|
|
19
|
+
<div id="track" @click=${this.handleTrackClick}>
|
|
20
|
+
<div id="fill" style="width:${e}%"></div>
|
|
21
|
+
${i?i.map(e=>{const i=(e-this.min)/(this.max-this.min)*100;return t`<div class="step-dot" style="left:${i}%"></div>`}):""}
|
|
22
|
+
<div
|
|
23
|
+
class="thumb${"lower"===this.#t?" active":""}"
|
|
24
|
+
style="left:${e}%"
|
|
25
|
+
@mousedown=${t=>this.handleThumbDown("lower",t)}
|
|
26
|
+
@touchstart=${t=>this.handleThumbDown("lower",t)}
|
|
27
|
+
>${this.tooltip&&"lower"===this.#t?t`<div class="tooltip">${this.formatValue(this.lower)}</div>`:""}</div>
|
|
28
|
+
</div>
|
|
29
|
+
`};renderVertical=()=>{const e=this.percentage,i=this.stepValues;if(this.isRange){const s=this.upperPercentage;return t`
|
|
30
|
+
<div id="track" @click=${this.handleTrackClick}>
|
|
31
|
+
<div id="fill" style="bottom:${e}%;height:${s-e}%"></div>
|
|
32
|
+
${i?i.map(e=>{const i=(e-this.min)/(this.max-this.min)*100;return t`<div class="step-dot" style="bottom:${i}%"></div>`}):""}
|
|
33
|
+
<div
|
|
34
|
+
class="thumb${"lower"===this.#t?" active":""}"
|
|
35
|
+
style="bottom:${e}%"
|
|
36
|
+
@mousedown=${t=>this.handleThumbDown("lower",t)}
|
|
37
|
+
@touchstart=${t=>this.handleThumbDown("lower",t)}
|
|
38
|
+
>${this.tooltip&&"lower"===this.#t?t`<div class="tooltip">${this.formatValue(this.lower)}</div>`:""}</div>
|
|
39
|
+
<div
|
|
40
|
+
class="thumb${"upper"===this.#t?" active":""}"
|
|
41
|
+
style="bottom:${s}%"
|
|
42
|
+
@mousedown=${t=>this.handleThumbDown("upper",t)}
|
|
43
|
+
@touchstart=${t=>this.handleThumbDown("upper",t)}
|
|
44
|
+
>${this.tooltip&&"upper"===this.#t?t`<div class="tooltip">${this.formatValue(this.upper)}</div>`:""}</div>
|
|
45
|
+
</div>
|
|
46
|
+
`}return t`
|
|
47
|
+
<div id="track" @click=${this.handleTrackClick}>
|
|
48
|
+
<div id="fill" style="height:${e}%"></div>
|
|
49
|
+
${i?i.map(e=>{const i=(e-this.min)/(this.max-this.min)*100;return t`<div class="step-dot" style="bottom:${i}%"></div>`}):""}
|
|
50
|
+
<div
|
|
51
|
+
class="thumb${"lower"===this.#t?" active":""}"
|
|
52
|
+
style="bottom:${e}%"
|
|
53
|
+
@mousedown=${t=>this.handleThumbDown("lower",t)}
|
|
54
|
+
@touchstart=${t=>this.handleThumbDown("lower",t)}
|
|
55
|
+
>${this.tooltip&&"lower"===this.#t?t`<div class="tooltip">${this.formatValue(this.lower)}</div>`:""}</div>
|
|
56
|
+
</div>
|
|
57
|
+
`};render(){return t`
|
|
58
|
+
${this.vertical?this.renderVertical():this.renderHorizontal()}
|
|
59
|
+
<div id="label"><slot></slot></div>
|
|
60
|
+
`}static styles=e`
|
|
61
|
+
:host {
|
|
62
|
+
--track_height: 6px;
|
|
63
|
+
--track_background: var(--c_border);
|
|
64
|
+
--track_radius: 99999px;
|
|
65
|
+
--fill_background: var(--c_primary);
|
|
66
|
+
--thumb_size: 20px;
|
|
67
|
+
--thumb_background: var(--c_primary);
|
|
68
|
+
--thumb_border: 2px solid white;
|
|
69
|
+
--thumb_shadow: var(--focus_shadow);
|
|
70
|
+
--step_dot_size: 8px;
|
|
71
|
+
--step_dot_background: var(--c_bg__alt);
|
|
72
|
+
--step_dot_border: 1px solid var(--c_border);
|
|
73
|
+
--vertical_height: 10rem;
|
|
74
|
+
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
gap: 0.5rem;
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
user-select: none;
|
|
80
|
+
}
|
|
81
|
+
:host([disabled]) {
|
|
82
|
+
opacity: 0.5;
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
}
|
|
85
|
+
:host([vertical]) {
|
|
86
|
+
flex-direction: column;
|
|
87
|
+
width: auto;
|
|
88
|
+
display: inline-flex;
|
|
89
|
+
}
|
|
90
|
+
#track {
|
|
91
|
+
flex: 1;
|
|
92
|
+
height: var(--track_height);
|
|
93
|
+
background: var(--track_background);
|
|
94
|
+
border-radius: var(--track_radius);
|
|
95
|
+
position: relative;
|
|
96
|
+
}
|
|
97
|
+
:host([vertical]) #track {
|
|
98
|
+
height: auto;
|
|
99
|
+
width: var(--track_height);
|
|
100
|
+
min-height: var(--vertical_height);
|
|
101
|
+
}
|
|
102
|
+
#fill {
|
|
103
|
+
background: var(--fill_background);
|
|
104
|
+
border-radius: var(--track_radius);
|
|
105
|
+
pointer-events: none;
|
|
106
|
+
}
|
|
107
|
+
:host(:not([vertical])) #fill {
|
|
108
|
+
height: 100%;
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 0;
|
|
111
|
+
left: 0;
|
|
112
|
+
}
|
|
113
|
+
:host([vertical]) #fill {
|
|
114
|
+
width: 100%;
|
|
115
|
+
position: absolute;
|
|
116
|
+
bottom: 0;
|
|
117
|
+
left: 0;
|
|
118
|
+
}
|
|
119
|
+
.thumb {
|
|
120
|
+
width: var(--thumb_size);
|
|
121
|
+
height: var(--thumb_size);
|
|
122
|
+
background: var(--thumb_background);
|
|
123
|
+
border: var(--thumb_border);
|
|
124
|
+
border-radius: 50%;
|
|
125
|
+
position: absolute;
|
|
126
|
+
box-shadow: 0 0 0 transparent;
|
|
127
|
+
cursor: grab;
|
|
128
|
+
transition: box-shadow 0.15s;
|
|
129
|
+
z-index: 1;
|
|
130
|
+
}
|
|
131
|
+
:host(:not([vertical])) .thumb {
|
|
132
|
+
top: 50%;
|
|
133
|
+
transform: translate(-50%, -50%);
|
|
134
|
+
}
|
|
135
|
+
:host([vertical]) .thumb {
|
|
136
|
+
left: 50%;
|
|
137
|
+
transform: translate(-50%, 50%);
|
|
138
|
+
}
|
|
139
|
+
.thumb:active,
|
|
140
|
+
.thumb.active {
|
|
141
|
+
cursor: grabbing;
|
|
142
|
+
box-shadow: var(--focus_shadow);
|
|
143
|
+
}
|
|
144
|
+
.tooltip {
|
|
145
|
+
position: absolute;
|
|
146
|
+
background: var(--c_text);
|
|
147
|
+
color: var(--c_bg);
|
|
148
|
+
padding: 0.15rem 0.4rem;
|
|
149
|
+
border-radius: 0.25rem;
|
|
150
|
+
font-size: 0.75rem;
|
|
151
|
+
white-space: nowrap;
|
|
152
|
+
pointer-events: none;
|
|
153
|
+
line-height: 1.2;
|
|
154
|
+
}
|
|
155
|
+
:host(:not([vertical])) .tooltip {
|
|
156
|
+
bottom: calc(100% + 6px);
|
|
157
|
+
left: 50%;
|
|
158
|
+
transform: translateX(-50%);
|
|
159
|
+
}
|
|
160
|
+
:host([vertical]) .tooltip {
|
|
161
|
+
right: calc(100% + 6px);
|
|
162
|
+
top: 50%;
|
|
163
|
+
transform: translateY(-50%);
|
|
164
|
+
}
|
|
165
|
+
.step-dot {
|
|
166
|
+
width: var(--step_dot_size);
|
|
167
|
+
height: var(--step_dot_size);
|
|
168
|
+
background: var(--step_dot_background);
|
|
169
|
+
border: var(--step_dot_border);
|
|
170
|
+
border-radius: 50%;
|
|
171
|
+
position: absolute;
|
|
172
|
+
pointer-events: none;
|
|
173
|
+
}
|
|
174
|
+
:host(:not([vertical])) .step-dot {
|
|
175
|
+
top: 50%;
|
|
176
|
+
transform: translate(-50%, -50%);
|
|
177
|
+
}
|
|
178
|
+
:host([vertical]) .step-dot {
|
|
179
|
+
left: 50%;
|
|
180
|
+
transform: translate(-50%, 50%);
|
|
181
|
+
}
|
|
182
|
+
#label {
|
|
183
|
+
font-size: 0.875rem;
|
|
184
|
+
}
|
|
185
|
+
#label:empty {
|
|
186
|
+
display: none;
|
|
187
|
+
}
|
|
188
|
+
`}customElements.define("k-slider",s);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import{html as e,css as t}from"../lit-all.min.js";import i from"./ShadowComponent.js";export default class r extends i{static formAssociated=!0;static properties={value:{type:String,reflect:!0},name:{type:String,reflect:!0},increment:{type:Number,reflect:!0},military:{type:Boolean,reflect:!0},disabled:{type:Boolean,reflect:!0},required:{type:Boolean,reflect:!0}};constructor(){super(),this.internals=this.attachInternals(),this.value="",this.name="",this.increment=1,this.military=!1,this.disabled=!1,this.required=!1}updated(e){super.updated(e),this.internals.setFormValue(this.value),this.required&&!this.value?this.internals.setValidity({valueMissing:!0},"Please enter a time.",this.shadowRoot?.querySelector("input")):this.internals.setValidity({}),e.has("value")&&void 0!==e.get("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}get stepSeconds(){return 60*Math.max(1,Math.floor(this.increment||1))}roundToIncrement=e=>{if(!e)return"";const[t,i]=e.split(":");let r=Number(t),a=Number(i);if(isNaN(r)||isNaN(a))return e;const s=Math.max(1,Math.floor(this.increment||1));return a=Math.round(a/s)*s,a>=60&&(a-=60,r=(r+1)%24),`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`};handleNativeChange=e=>{this.disabled||(this.value=e.target.value||"")};handleBlur=e=>{if(this.disabled)return;const t=this.roundToIncrement(e.target.value);t!==this.value&&(this.value=t)};render(){return e`
|
|
2
|
+
<input
|
|
3
|
+
type="time"
|
|
4
|
+
.value=${this.value||""}
|
|
5
|
+
step=${this.stepSeconds}
|
|
6
|
+
lang=${this.military?"en-GB":"en-US"}
|
|
7
|
+
?disabled=${this.disabled}
|
|
8
|
+
?required=${this.required}
|
|
9
|
+
@change=${this.handleNativeChange}
|
|
10
|
+
@blur=${this.handleBlur}
|
|
11
|
+
/>
|
|
12
|
+
`}static styles=t`
|
|
13
|
+
:host {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
}
|
|
16
|
+
:host([disabled]) {
|
|
17
|
+
opacity: 0.5;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
input {
|
|
21
|
+
padding: var(--spacer_h) var(--spacer);
|
|
22
|
+
border: 1px solid var(--c_border);
|
|
23
|
+
border-radius: var(--radius);
|
|
24
|
+
background: var(--c_bg);
|
|
25
|
+
color: var(--tc);
|
|
26
|
+
font: inherit;
|
|
27
|
+
outline: none;
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
transition: border-color var(--animation_ms);
|
|
30
|
+
}
|
|
31
|
+
input:focus {
|
|
32
|
+
border-color: var(--c_primary);
|
|
33
|
+
}
|
|
34
|
+
input::-webkit-calendar-picker-indicator {
|
|
35
|
+
display: none;
|
|
36
|
+
}
|
|
37
|
+
`}customElements.define("k-time",r);
|
|
@@ -62,6 +62,9 @@
|
|
|
62
62
|
href="../components/accordion.html">Accordion<br><small>Component</small></a></k-filter-item>
|
|
63
63
|
<k-filter-item filter-keywords="aside sidebar components"><a
|
|
64
64
|
href="../components/aside.html">Aside<br><small>Component</small></a></k-filter-item>
|
|
65
|
+
<k-filter-item filter-keywords="calendar date picker range month day components"><a
|
|
66
|
+
href="../components/calendar.html"
|
|
67
|
+
>Calendar<br><small>Component</small></a></k-filter-item>
|
|
65
68
|
<k-filter-item filter-keywords="card components"><a
|
|
66
69
|
href="../components/card.html">Card<br><small>Component</small></a></k-filter-item>
|
|
67
70
|
<k-filter-item filter-keywords="code editor codeeditor monaco components"><a
|
|
@@ -111,6 +114,9 @@
|
|
|
111
114
|
<k-filter-item filter-keywords="show more showmore components"><a
|
|
112
115
|
href="../components/show-more.html"
|
|
113
116
|
>Show More<br><small>Component</small></a></k-filter-item>
|
|
117
|
+
<k-filter-item filter-keywords="slider range input step components"><a
|
|
118
|
+
href="../components/slider.html"
|
|
119
|
+
>Slider<br><small>Component</small></a></k-filter-item>
|
|
114
120
|
<k-filter-item filter-keywords="sortable drag drop sort components"><a
|
|
115
121
|
href="../components/sortable.html"
|
|
116
122
|
>Sortable<br><small>Component</small></a></k-filter-item>
|
|
@@ -172,6 +178,9 @@
|
|
|
172
178
|
<k-filter-item filter-keywords="theme switcher dark light components"><a
|
|
173
179
|
href="../components/theme-switcher.html"
|
|
174
180
|
>Theme Switcher<br><small>Component</small></a></k-filter-item>
|
|
181
|
+
<k-filter-item filter-keywords="time picker clock hour minute form components"><a
|
|
182
|
+
href="../components/time.html"
|
|
183
|
+
>Time<br><small>Component</small></a></k-filter-item>
|
|
175
184
|
<k-filter-item filter-keywords="timestamp date time components"><a
|
|
176
185
|
href="../components/timestamp.html"
|
|
177
186
|
>Timestamp<br><small>Component</small></a></k-filter-item>
|
|
@@ -266,6 +275,7 @@
|
|
|
266
275
|
<h3>Components</h3>
|
|
267
276
|
<a href="../components/accordion.html">Accordion</a>
|
|
268
277
|
<a href="../components/aside.html">Aside</a>
|
|
278
|
+
<a href="../components/calendar.html">Calendar</a>
|
|
269
279
|
<a href="../components/card.html">Card</a>
|
|
270
280
|
<a href="../components/code-editor.html">Code Editor</a>
|
|
271
281
|
<a href="../components/combobox.html">Combobox</a>
|
|
@@ -285,6 +295,7 @@
|
|
|
285
295
|
<a href="../components/progress.html">Progress</a>
|
|
286
296
|
<a href="../components/resize.html">Resize</a>
|
|
287
297
|
<a href="../components/show-more.html">Show More</a>
|
|
298
|
+
<a href="../components/slider.html">Slider</a>
|
|
288
299
|
<a href="../components/sortable.html">Sortable</a>
|
|
289
300
|
<a href="../components/spinner.html">Spinner</a>
|
|
290
301
|
<a href="../components/split.html">Split</a>
|
|
@@ -293,6 +304,7 @@
|
|
|
293
304
|
<a href="../components/tags.html">Tags</a>
|
|
294
305
|
<a href="../components/theme-select.html">Theme Select</a>
|
|
295
306
|
<a href="../components/theme-switcher.html">Theme Switcher</a>
|
|
307
|
+
<a href="../components/time.html">Time</a>
|
|
296
308
|
<a href="../components/timestamp.html">Timestamp</a>
|
|
297
309
|
<a href="../components/toast.html">Toast</a>
|
|
298
310
|
<a href="../components/toggle.html">Toggle</a>
|
|
@@ -62,6 +62,9 @@
|
|
|
62
62
|
href="../components/accordion.html">Accordion<br><small>Component</small></a></k-filter-item>
|
|
63
63
|
<k-filter-item filter-keywords="aside sidebar components"><a
|
|
64
64
|
href="../components/aside.html">Aside<br><small>Component</small></a></k-filter-item>
|
|
65
|
+
<k-filter-item filter-keywords="calendar date picker range month day components"><a
|
|
66
|
+
href="../components/calendar.html"
|
|
67
|
+
>Calendar<br><small>Component</small></a></k-filter-item>
|
|
65
68
|
<k-filter-item filter-keywords="card components"><a
|
|
66
69
|
href="../components/card.html">Card<br><small>Component</small></a></k-filter-item>
|
|
67
70
|
<k-filter-item filter-keywords="code editor codeeditor monaco components"><a
|
|
@@ -111,6 +114,9 @@
|
|
|
111
114
|
<k-filter-item filter-keywords="show more showmore components"><a
|
|
112
115
|
href="../components/show-more.html"
|
|
113
116
|
>Show More<br><small>Component</small></a></k-filter-item>
|
|
117
|
+
<k-filter-item filter-keywords="slider range input step components"><a
|
|
118
|
+
href="../components/slider.html"
|
|
119
|
+
>Slider<br><small>Component</small></a></k-filter-item>
|
|
114
120
|
<k-filter-item filter-keywords="sortable drag drop sort components"><a
|
|
115
121
|
href="../components/sortable.html"
|
|
116
122
|
>Sortable<br><small>Component</small></a></k-filter-item>
|
|
@@ -172,6 +178,9 @@
|
|
|
172
178
|
<k-filter-item filter-keywords="theme switcher dark light components"><a
|
|
173
179
|
href="../components/theme-switcher.html"
|
|
174
180
|
>Theme Switcher<br><small>Component</small></a></k-filter-item>
|
|
181
|
+
<k-filter-item filter-keywords="time picker clock hour minute form components"><a
|
|
182
|
+
href="../components/time.html"
|
|
183
|
+
>Time<br><small>Component</small></a></k-filter-item>
|
|
175
184
|
<k-filter-item filter-keywords="timestamp date time components"><a
|
|
176
185
|
href="../components/timestamp.html"
|
|
177
186
|
>Timestamp<br><small>Component</small></a></k-filter-item>
|
|
@@ -266,6 +275,7 @@
|
|
|
266
275
|
<h3>Components</h3>
|
|
267
276
|
<a href="../components/accordion.html">Accordion</a>
|
|
268
277
|
<a href="../components/aside.html">Aside</a>
|
|
278
|
+
<a href="../components/calendar.html">Calendar</a>
|
|
269
279
|
<a href="../components/card.html">Card</a>
|
|
270
280
|
<a href="../components/code-editor.html">Code Editor</a>
|
|
271
281
|
<a href="../components/combobox.html">Combobox</a>
|
|
@@ -285,6 +295,7 @@
|
|
|
285
295
|
<a href="../components/progress.html">Progress</a>
|
|
286
296
|
<a href="../components/resize.html">Resize</a>
|
|
287
297
|
<a href="../components/show-more.html">Show More</a>
|
|
298
|
+
<a href="../components/slider.html">Slider</a>
|
|
288
299
|
<a href="../components/sortable.html">Sortable</a>
|
|
289
300
|
<a href="../components/spinner.html">Spinner</a>
|
|
290
301
|
<a href="../components/split.html">Split</a>
|
|
@@ -293,6 +304,7 @@
|
|
|
293
304
|
<a href="../components/tags.html">Tags</a>
|
|
294
305
|
<a href="../components/theme-select.html">Theme Select</a>
|
|
295
306
|
<a href="../components/theme-switcher.html">Theme Switcher</a>
|
|
307
|
+
<a href="../components/time.html">Time</a>
|
|
296
308
|
<a href="../components/timestamp.html">Timestamp</a>
|
|
297
309
|
<a href="../components/toast.html">Toast</a>
|
|
298
310
|
<a href="../components/toggle.html">Toggle</a>
|