UNPKG

6.98 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11};
12var _DuoyunTimePanelElement_instances, _DuoyunTimePanelElement_time_get, _DuoyunTimePanelElement_parts_get, _DuoyunTimePanelElement_toArr, _DuoyunTimePanelElement_toString, _DuoyunTimePanelElement_onHourClick, _DuoyunTimePanelElement_onMinuteClick, _DuoyunTimePanelElement_onSecondClick;
13import { adoptedStyle, customElement, globalemitter, property, boolattribute, } from '@mantou/gem/lib/decorators';
14import { GemElement, html } from '@mantou/gem/lib/element';
15import { createCSSSheet, css, classMap } from '@mantou/gem/lib/utils';
16import { Time, parseDate } from '../lib/time';
17import { theme } from '../lib/theme';
18import { isNotNullish } from '../lib/types';
19import { locale } from '../lib/locale';
20import { focusStyle } from '../lib/styles';
21const style = createCSSSheet(css `
22 :host(:where(:not([hidden]))) {
23 display: grid;
24 grid-template: 'hour minute second' / 1fr 1fr 1fr;
25 gap: 1px;
26 text-align: center;
27 line-height: 2;
28 }
29 .header {
30 white-space: nowrap;
31 overflow: hidden;
32 text-overflow: ellipsis;
33 padding-inline: 0.2em;
34 }
35 .scrollbar {
36 flex-grow: 1;
37 overflow: auto;
38 scrollbar-width: thin;
39 scrollbar-gutter: both-edges;
40 scroll-snap-type: y proximity;
41 }
42 .cell {
43 scroll-snap-align: start;
44 }
45 .cell:where(:hover) {
46 background: ${theme.lightBackgroundColor};
47 }
48 .checked {
49 background: ${theme.hoverBackgroundColor};
50 }
51`);
52/**
53 * @customElement dy-time-panel
54 */
55let DuoyunTimePanelElement = class DuoyunTimePanelElement extends GemElement {
56 constructor() {
57 super({ delegatesFocus: true });
58 _DuoyunTimePanelElement_instances.add(this);
59 _DuoyunTimePanelElement_toArr.set(this, (l) => Array.from({ length: l }, (_, index) => index));
60 _DuoyunTimePanelElement_toString.set(this, (n) => n.toString().padStart(2, '0'));
61 _DuoyunTimePanelElement_onHourClick.set(this, (n) => {
62 this.change(__classPrivateFieldGet(this, _DuoyunTimePanelElement_instances, "a", _DuoyunTimePanelElement_time_get).setHours(n));
63 });
64 _DuoyunTimePanelElement_onMinuteClick.set(this, (n) => {
65 this.change(__classPrivateFieldGet(this, _DuoyunTimePanelElement_instances, "a", _DuoyunTimePanelElement_time_get).setMinutes(n));
66 });
67 _DuoyunTimePanelElement_onSecondClick.set(this, (n) => {
68 this.change(__classPrivateFieldGet(this, _DuoyunTimePanelElement_instances, "a", _DuoyunTimePanelElement_time_get).setSeconds(n));
69 });
70 this.mounted = () => {
71 var _a;
72 (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`.checked`).forEach((e) => {
73 e.scrollIntoView({ block: 'center' });
74 });
75 };
76 this.render = () => {
77 const { hour, minute, second } = __classPrivateFieldGet(this, _DuoyunTimePanelElement_instances, "a", _DuoyunTimePanelElement_parts_get);
78 return html `
79 ${this.headless
80 ? ''
81 : html `
82 <div class="header">${locale.hour}</div>
83 <div class="header">${locale.minute}</div>
84 <div class="header">${locale.second}</div>
85 `}
86 <div class="scrollbar">
87 ${__classPrivateFieldGet(this, _DuoyunTimePanelElement_toArr, "f").call(this, 24).map((h) => html `
88 <div
89 class=${classMap({ cell: true, checked: isNotNullish(h) && Number(hour) === h })}
90 @click=${() => __classPrivateFieldGet(this, _DuoyunTimePanelElement_onHourClick, "f").call(this, h)}
91 >
92 ${__classPrivateFieldGet(this, _DuoyunTimePanelElement_toString, "f").call(this, h)}
93 </div>
94 `)}
95 </div>
96 <div class="scrollbar">
97 ${__classPrivateFieldGet(this, _DuoyunTimePanelElement_toArr, "f").call(this, 60).map((m) => html `
98 <div
99 class=${classMap({ cell: true, checked: isNotNullish(m) && Number(minute) === m })}
100 @click=${() => __classPrivateFieldGet(this, _DuoyunTimePanelElement_onMinuteClick, "f").call(this, m)}
101 >
102 ${__classPrivateFieldGet(this, _DuoyunTimePanelElement_toString, "f").call(this, m)}
103 </div>
104 `)}
105 </div>
106 <div class="scrollbar">
107 ${__classPrivateFieldGet(this, _DuoyunTimePanelElement_toArr, "f").call(this, 60).map((s) => html `
108 <div
109 class=${classMap({ cell: true, checked: isNotNullish(s) && Number(second) === s })}
110 @click=${() => __classPrivateFieldGet(this, _DuoyunTimePanelElement_onSecondClick, "f").call(this, s)}
111 >
112 ${__classPrivateFieldGet(this, _DuoyunTimePanelElement_toString, "f").call(this, s)}
113 </div>
114 `)}
115 </div>
116 `;
117 };
118 }
119};
120_DuoyunTimePanelElement_toArr = new WeakMap(), _DuoyunTimePanelElement_toString = new WeakMap(), _DuoyunTimePanelElement_onHourClick = new WeakMap(), _DuoyunTimePanelElement_onMinuteClick = new WeakMap(), _DuoyunTimePanelElement_onSecondClick = new WeakMap(), _DuoyunTimePanelElement_instances = new WeakSet(), _DuoyunTimePanelElement_time_get = function _DuoyunTimePanelElement_time_get() {
121 return isNotNullish(this.value) ? new Time(this.value) : new Time();
122}, _DuoyunTimePanelElement_parts_get = function _DuoyunTimePanelElement_parts_get() {
123 return isNotNullish(this.value) ? parseDate(this.value) : {};
124};
125__decorate([
126 boolattribute
127], DuoyunTimePanelElement.prototype, "headless", void 0);
128__decorate([
129 globalemitter
130], DuoyunTimePanelElement.prototype, "change", void 0);
131__decorate([
132 property
133], DuoyunTimePanelElement.prototype, "value", void 0);
134DuoyunTimePanelElement = __decorate([
135 customElement('dy-time-panel'),
136 adoptedStyle(style),
137 adoptedStyle(focusStyle)
138], DuoyunTimePanelElement);
139export { DuoyunTimePanelElement };
140//# sourceMappingURL=time-panel.js.map
\No newline at end of file