litos-ui 0.15.6 → 0.15.8
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/lib/button/index.d.ts +4 -0
- package/lib/button/index.js +88 -61
- package/lib/check/check.js +6 -7
- package/lib/check/checkbox.js +1 -1
- package/lib/check/radio.js +10 -6
- package/lib/{check-BlDsQQo0.js → check-A86JxUfd.js} +1 -1
- package/lib/collapse/index.d.ts +19 -0
- package/lib/collapse/index.js +88 -0
- package/lib/collapse/item.d.ts +15 -0
- package/lib/collapse/item.js +115 -0
- package/lib/color_picker/index.js +1 -1
- package/lib/date_picker/index.js +1 -1
- package/lib/description_panel/index.d.ts +4 -4
- package/lib/description_panel/index.js +59 -11
- package/lib/dialog/dialog_container.js +1 -1
- package/lib/form/form_inner.d.ts +5 -1
- package/lib/form/form_inner.js +33 -27
- package/lib/form/form_item.js +9 -9
- package/lib/icon/d_arrow_left.d.ts +6 -0
- package/lib/icon/d_arrow_left.js +13 -0
- package/lib/icon/d_arrow_right.d.ts +6 -0
- package/lib/icon/d_arrow_right.js +13 -0
- package/lib/icon/more.d.ts +6 -0
- package/lib/icon/more.js +13 -0
- package/lib/icon/select.d.ts +6 -0
- package/lib/icon/select.js +13 -0
- package/lib/icon/zoom_in.d.ts +6 -0
- package/lib/icon/zoom_in.js +13 -0
- package/lib/icon/zoom_out.d.ts +6 -0
- package/lib/icon/zoom_out.js +13 -0
- package/lib/image/image_preview.d.ts +24 -0
- package/lib/image/image_preview.js +104 -0
- package/lib/image/index.d.ts +50 -0
- package/lib/image/index.js +176 -0
- package/lib/index-D4II9KsF.js +4 -0
- package/lib/index.d.ts +36 -4
- package/lib/index.js +157 -120
- package/lib/input/index.d.ts +5 -0
- package/lib/input/index.js +93 -71
- package/lib/litos-ui.css +1 -1
- package/lib/mask/index.d.ts +23 -0
- package/lib/mask/index.js +110 -0
- package/lib/md_input/index.js +11 -11
- package/lib/message/index.js +2 -2
- package/lib/modal/index.d.ts +1 -1
- package/lib/modal/index.js +7 -7
- package/lib/modal/modal_box.js +10 -10
- package/lib/page_header/index.d.ts +20 -0
- package/lib/page_header/index.js +109 -0
- package/lib/pagination/index.d.ts +27 -0
- package/lib/pagination/index.js +248 -0
- package/lib/qrcode/index.js +4 -4
- package/lib/select/index.d.ts +79 -0
- package/lib/select/index.js +406 -0
- package/lib/select_ori/index.js +1 -1
- package/lib/switch/index.js +4 -4
- package/lib/tabbar/index.d.ts +3 -1
- package/lib/tabbar/index.js +14 -8
- package/lib/tabbar/item.js +1 -1
- package/lib/table/index.d.ts +63 -0
- package/lib/table/index.js +260 -0
- package/lib/table/types.d.ts +36 -0
- package/lib/tabs/index.d.ts +7 -0
- package/lib/tabs/index.js +43 -0
- package/lib/tag/index.d.ts +16 -0
- package/lib/tag/index.js +80 -0
- package/lib/theme/index.js +6 -6
- package/lib/utils/index.d.ts +6 -28
- package/lib/utils/index.js +61 -86
- package/lib/utils/popover.d.ts +137 -0
- package/lib/utils/popover.js +354 -0
- package/lib/utils/transition.js +26 -50
- package/package.json +71 -71
- package/styles/popover.css +66 -0
- package/styles/reset.css +1 -1
- package/styles/select.css +37 -0
- package/styles/tabs.css +13 -0
- package/styles/vars.css +2 -1
- package/lib/index-dwS1N2uN.js +0 -4
- package/lib/popconfirm/index.d.ts +0 -7
- package/lib/popconfirm/index.js +0 -30
- package/lib/popover/index.d.ts +0 -34
- package/lib/popover/index.js +0 -150
- /package/lib/{menu/base.js → table/types.js} +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import c from "../base.js";
|
|
2
|
+
import { kebabToCamel as b, parseAttrValue as x } from "../utils/index.js";
|
|
3
|
+
import { $one as h, $$ as o, iterate as g, formatStyle as p, shouldEventNext as y, on as C, off as u } from "ph-utils/dom";
|
|
4
|
+
import { random as _ } from "ph-utils";
|
|
5
|
+
const m = ":host{--l-table-max-height: 100%;--l-table-td-padding: 10px;--l-table-th-padding: var(--l-table-td-padding);--l-table-layout: auto;display:inline-block;width:100%;max-height:var(--l-table-max-height);overflow:auto;font-size:14px}.l-table{width:100%;border-collapse:collapse;border-spacing:0;table-layout:var(--l-table-layout)}.l-table th,.l-table td{padding:var(--l-table-th-padding);border-bottom:1px solid #e6e6e6}.l-table th{text-align:left;background-color:#f2f2f2}.l-table td{background-color:#fff;transition:background-color .3s}.l-table tr:hover td{background-color:#f2f2f2}.l-table__empty-col{color:#999;text-align:center}.l-table-stripe tr:nth-child(2n) td{background-color:#fafafa}.l-table-stripe tr:nth-child(2n):hover td{background-color:#f2f2f2}.l-table-border th,.l-table-border td{border:1px solid #e6e6e6}.l-table-fixed{--l-table-layout: fixed}.l-table-fixed .l-fixed{position:-webkit-sticky;position:sticky;z-index:1;box-sizing:border-box}.l-table-fixed thead.l-fixed,.l-table-fixed tfoot.l-fixed{z-index:2}";
|
|
6
|
+
class S extends c {
|
|
7
|
+
static baseName = "table";
|
|
8
|
+
/** 斑马纹 */
|
|
9
|
+
stripe = !0;
|
|
10
|
+
/** 是否显示四周边框 */
|
|
11
|
+
border = !1;
|
|
12
|
+
/** 是否固定表头 */
|
|
13
|
+
fixedHead = !1;
|
|
14
|
+
/** 是否固定列,在进行列解析时,会自动确认该属性 */
|
|
15
|
+
fixedColumn = !1;
|
|
16
|
+
/** 最大高度 */
|
|
17
|
+
maxHeight;
|
|
18
|
+
/** 表格布局 */
|
|
19
|
+
tableLayout;
|
|
20
|
+
columns = [];
|
|
21
|
+
data = [];
|
|
22
|
+
sortInfo;
|
|
23
|
+
/** 缓存列通用样式, 避免渲染数据时,重复计算 */
|
|
24
|
+
_globalColStyles;
|
|
25
|
+
connectedCallback() {
|
|
26
|
+
this.loadStyleText(m), super.connectedCallback();
|
|
27
|
+
}
|
|
28
|
+
setColumns(e) {
|
|
29
|
+
let i = 0, t = 0;
|
|
30
|
+
this.columns = this._parseColumns(e, i, t), this.rerender("all");
|
|
31
|
+
}
|
|
32
|
+
setData(e) {
|
|
33
|
+
this.data = e, this.columns && this.columns.length > 0 && this.rerender("body");
|
|
34
|
+
}
|
|
35
|
+
setDefaultSort(e) {
|
|
36
|
+
this.sortInfo = e, this.rerender("all");
|
|
37
|
+
}
|
|
38
|
+
changeFixed(e) {
|
|
39
|
+
const i = {
|
|
40
|
+
fixedHead: this.fixedHead,
|
|
41
|
+
fixedColumn: this.fixedColumn,
|
|
42
|
+
...e
|
|
43
|
+
};
|
|
44
|
+
if (this.fixedHead = i.fixedHead, this.fixedColumn = i.fixedColumn, this.rendered) {
|
|
45
|
+
const t = h(".l-table", this.root);
|
|
46
|
+
t && (this.fixedHead || this.fixedColumn ? t.classList.add("l-table-fixed") : t.classList.remove("l-table-fixed"));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
static get observedAttributes() {
|
|
50
|
+
return ["stripe", "border", "fixed-head", "max-height", "table-layout"];
|
|
51
|
+
}
|
|
52
|
+
attributeChangedCallback(e, i, t) {
|
|
53
|
+
e = b(e);
|
|
54
|
+
const s = x(
|
|
55
|
+
t,
|
|
56
|
+
this[e],
|
|
57
|
+
e
|
|
58
|
+
);
|
|
59
|
+
if (s !== this[e])
|
|
60
|
+
switch (this[e] = s, e) {
|
|
61
|
+
case "stripe":
|
|
62
|
+
this._classAttrChannge("stripe", s);
|
|
63
|
+
break;
|
|
64
|
+
case "border":
|
|
65
|
+
this._classAttrChannge("border", s);
|
|
66
|
+
break;
|
|
67
|
+
case "fixedHead":
|
|
68
|
+
this._updateFixedHead(), this.changeFixed();
|
|
69
|
+
break;
|
|
70
|
+
case "maxHeight":
|
|
71
|
+
this._changeMaxHeight();
|
|
72
|
+
break;
|
|
73
|
+
case "tableLayout":
|
|
74
|
+
this._changeCssVar("table-layout", s);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
render() {
|
|
79
|
+
const e = o("table", {
|
|
80
|
+
class: [
|
|
81
|
+
"l-table",
|
|
82
|
+
this.stripe ? "l-table-stripe" : "",
|
|
83
|
+
this.border ? "l-table-border" : "",
|
|
84
|
+
this.fixedHead || this.fixedColumn ? "l-table-fixed" : ""
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
return e.appendChild(this._headRender()), e.appendChild(this._bodyRender()), e;
|
|
88
|
+
}
|
|
89
|
+
rerender(e) {
|
|
90
|
+
if (this.rendered) {
|
|
91
|
+
if (e === "all" || e === "head") {
|
|
92
|
+
const i = h("thead", this.root);
|
|
93
|
+
i && i.replaceWith(this._headRender());
|
|
94
|
+
}
|
|
95
|
+
if (e === "all" || e === "body") {
|
|
96
|
+
const i = h("tbody", this.root);
|
|
97
|
+
i && i.replaceWith(this._bodyRender());
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
_changeCssVar(e, i) {
|
|
102
|
+
if (!this.rendered) return;
|
|
103
|
+
const t = `--l-table-${e}`;
|
|
104
|
+
i ? this.style.setProperty(t, i) : this.style.removeProperty(t);
|
|
105
|
+
}
|
|
106
|
+
_changeMaxHeight() {
|
|
107
|
+
let e = this.maxHeight;
|
|
108
|
+
e && typeof e == "number" && (e = `${e}px`), this._changeCssVar("max-height", e);
|
|
109
|
+
}
|
|
110
|
+
_classAttrChannge(e, i) {
|
|
111
|
+
if (this.rendered) {
|
|
112
|
+
const t = h("table", this.root);
|
|
113
|
+
t && t.classList.toggle(`l-table-${e}`, i);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
_updateFixedHead() {
|
|
117
|
+
if (this.rendered) {
|
|
118
|
+
const e = h("thead", this.root);
|
|
119
|
+
e && (e.classList.toggle("l-fixed", this.fixedHead), e.style.top = this.fixedHead ? "0" : "");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
_headRender() {
|
|
123
|
+
const e = o("thead", {
|
|
124
|
+
class: {
|
|
125
|
+
"l-fixed": this.fixedHead
|
|
126
|
+
},
|
|
127
|
+
style: {
|
|
128
|
+
top: this.fixedHead ? "0" : void 0
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return this.columns && this._rendHeadRow(e, this.columns), e;
|
|
132
|
+
}
|
|
133
|
+
_rendHeadRow(e, i) {
|
|
134
|
+
const t = o("tr");
|
|
135
|
+
for (let s = 0, a = i.length; s < a; s++) {
|
|
136
|
+
const r = i[s];
|
|
137
|
+
t.appendChild(this._headColRender(r, s)), r.children && this._rendHeadRow(e, r.children);
|
|
138
|
+
}
|
|
139
|
+
e.appendChild(t);
|
|
140
|
+
}
|
|
141
|
+
_headColRender(e, i) {
|
|
142
|
+
const t = o("th");
|
|
143
|
+
if (e.titleColspan && e.titleColspan > 1 && (t.colSpan = e.titleColspan), e.titleRowspan && e.titleRowspan > 1 && (t.rowSpan = e.titleRowspan), t.style.cssText = this._getColumnStyle(e, "th"), e.fixed && t.classList.add("l-fixed"), t.appendChild(
|
|
144
|
+
o("span", {
|
|
145
|
+
textContent: e.title
|
|
146
|
+
})
|
|
147
|
+
), e.sorter) {
|
|
148
|
+
const s = o("span", { class: "caret-wrapper" });
|
|
149
|
+
s.appendChild(o("span", { class: "sort-caret ascending" })), s.appendChild(o("span", { class: "sort-caret descending" })), t.appendChild(s);
|
|
150
|
+
}
|
|
151
|
+
return t;
|
|
152
|
+
}
|
|
153
|
+
_bodyRender() {
|
|
154
|
+
const e = o("tbody");
|
|
155
|
+
if (this.data && this.data.length > 0)
|
|
156
|
+
for (let i = 0, t = this.data.length; i < t; i++) {
|
|
157
|
+
const s = this.data[i];
|
|
158
|
+
if (this.columns) {
|
|
159
|
+
const a = o("tr");
|
|
160
|
+
this._bodyRowRender(this.columns, i, s, a), e.appendChild(a);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const i = o("tr"), t = o("td", {
|
|
165
|
+
class: "l-table__empty-col",
|
|
166
|
+
textContent: "暂无数据"
|
|
167
|
+
});
|
|
168
|
+
this.columns && (t.colSpan = this.columns.length), i.appendChild(t), e.appendChild(i);
|
|
169
|
+
}
|
|
170
|
+
return e;
|
|
171
|
+
}
|
|
172
|
+
_bodyRowRender(e, i, t, s) {
|
|
173
|
+
for (let a = 0, r = e.length; a < r; a++) {
|
|
174
|
+
const l = e[a];
|
|
175
|
+
if (l.children && l.children.length > 0)
|
|
176
|
+
this._bodyRowRender(l.children, i, t, s);
|
|
177
|
+
else {
|
|
178
|
+
const d = o("td");
|
|
179
|
+
if (typeof l.rowspan == "number" && (d.rowSpan = l.rowspan), typeof l.rowspan == "function" && (d.rowSpan = l.rowspan(t, i)), typeof l.colspan == "number" && (d.colSpan = l.colspan), typeof l.colspan == "function" && (d.colSpan = l.colspan(t, i)), l.fixed && (d.className = "l-fixed"), d.style.cssText = this._getColumnStyle(l), l.render) {
|
|
180
|
+
const n = l.render(t, i);
|
|
181
|
+
typeof n == "string" ? d.innerHTML = n : Array.isArray(n) ? g(n, (f) => {
|
|
182
|
+
d.appendChild(f);
|
|
183
|
+
}) : d.appendChild(n);
|
|
184
|
+
} else
|
|
185
|
+
d.textContent = l.key ? t[l.key] : "";
|
|
186
|
+
s.appendChild(d);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 解析列配置,表头跨行跨列、固定列
|
|
192
|
+
* @param columns 列配置
|
|
193
|
+
* @param leftOffset 左边固定列偏移
|
|
194
|
+
* @param rightOffset 右边固定列偏移
|
|
195
|
+
* @returns
|
|
196
|
+
*/
|
|
197
|
+
_parseColumns(e, i, t) {
|
|
198
|
+
const s = [];
|
|
199
|
+
for (let a = 0, r = e.length; a < r; a++) {
|
|
200
|
+
const l = e[a];
|
|
201
|
+
if (l.id || (l.id = l.key || l.title), l.id || (l.id = `${a}_${_(6)}`), l.fixed) {
|
|
202
|
+
const d = Number.parseFloat(`${l.width || 0}`);
|
|
203
|
+
l.fixed === "left" ? (l.left = i, i += d) : l.fixed === "right" && (l.right = t, t += d);
|
|
204
|
+
}
|
|
205
|
+
if (l.children) {
|
|
206
|
+
const d = this._parseColumns(
|
|
207
|
+
l.children,
|
|
208
|
+
i,
|
|
209
|
+
t
|
|
210
|
+
);
|
|
211
|
+
l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan = d.reduce((n, f) => n + (f.titleColspan || 1), 0)), s.push({ ...l, children: d });
|
|
212
|
+
} else
|
|
213
|
+
l.titleRowspan = l.titleRowspan || this._getMaxDepth(e), l.titleColspan = l.titleColspan || 1, s.push({ ...l });
|
|
214
|
+
}
|
|
215
|
+
return s;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 获取多级表头的最大深度
|
|
219
|
+
* @param headers 表头配置
|
|
220
|
+
* @returns 最大深度, 最大跨行数
|
|
221
|
+
*/
|
|
222
|
+
_getMaxDepth(e) {
|
|
223
|
+
let i = 1;
|
|
224
|
+
for (const t of e)
|
|
225
|
+
t.children && (i = Math.max(i, this._getMaxDepth(t.children) + 1));
|
|
226
|
+
return i;
|
|
227
|
+
}
|
|
228
|
+
_getColumnStyle(e, i = "td") {
|
|
229
|
+
const t = e.id;
|
|
230
|
+
if (this._globalColStyles && t in this._globalColStyles)
|
|
231
|
+
return this._globalColStyles[t][i];
|
|
232
|
+
const s = {};
|
|
233
|
+
e.width && (typeof e.width == "number" ? s.width = `${e.width}px` : s.width = e.width), e.fixed && (e.fixed === "left" ? (s.left = `${e.left}px`, s["box-shadow"] = "-4px 0 4px -4px #d9d9d9 inset") : e.fixed === "right" && (s.right = `${e.right}px`, s["box-shadow"] = "4px 0 4px -4px #d9d9d9 inset")), this._globalColStyles || (this._globalColStyles = {});
|
|
234
|
+
const a = p(s), r = {
|
|
235
|
+
th: a,
|
|
236
|
+
td: a + p(e.style || "")
|
|
237
|
+
};
|
|
238
|
+
return this._globalColStyles[t] = r, r[i];
|
|
239
|
+
}
|
|
240
|
+
_handleTap = (e) => {
|
|
241
|
+
const [i, t, s] = y(
|
|
242
|
+
e,
|
|
243
|
+
"data-action",
|
|
244
|
+
e.currentTarget
|
|
245
|
+
);
|
|
246
|
+
if (i) {
|
|
247
|
+
const a = s.dataset;
|
|
248
|
+
this.emit("action", { detail: a });
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
afterInit() {
|
|
252
|
+
this._changeMaxHeight(), C(this.root, "click", this._handleTap);
|
|
253
|
+
}
|
|
254
|
+
beforeDestroy() {
|
|
255
|
+
u(this.root, "click", this._handleTap);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
export {
|
|
259
|
+
S as default
|
|
260
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Column {
|
|
2
|
+
/** 列的唯一标识 */
|
|
3
|
+
id?: string;
|
|
4
|
+
/** 列的标题 */
|
|
5
|
+
title?: string;
|
|
6
|
+
/** 列标识, 列排序必传 */
|
|
7
|
+
key?: string;
|
|
8
|
+
/** 列宽度, 固定列时,需要传 */
|
|
9
|
+
width?: number | string;
|
|
10
|
+
/** 是否固定列, left - 固定在左方, right - 固定右方 */
|
|
11
|
+
fixed?: "left" | "right";
|
|
12
|
+
/** 列固定左时, 左边偏移量 */
|
|
13
|
+
left?: number;
|
|
14
|
+
/** 列固定右时, 右边偏移量 */
|
|
15
|
+
right?: number;
|
|
16
|
+
/** 多级表头 */
|
|
17
|
+
children?: Column[];
|
|
18
|
+
/** 表头跨行 */
|
|
19
|
+
titleRowspan?: number;
|
|
20
|
+
/** 表头跨列 */
|
|
21
|
+
titleColspan?: number;
|
|
22
|
+
/** 列是否支持排序 */
|
|
23
|
+
sorter?: boolean | "default" | ((a: any, b: any) => number);
|
|
24
|
+
/** 列的样式 */
|
|
25
|
+
style?: Record<string, string | null | undefined>;
|
|
26
|
+
/** td colspan */
|
|
27
|
+
colspan?: number | ((rowData: any, rowIndex: number) => number);
|
|
28
|
+
/** td rowspan */
|
|
29
|
+
rowspan?: number | ((rowData: any, rowIndex: number) => number);
|
|
30
|
+
/** 单元格内容渲染函数 */
|
|
31
|
+
render?: (rowData: any, rowIndex: number) => HTMLElement | DocumentFragment | HTMLElement[] | string;
|
|
32
|
+
}
|
|
33
|
+
export interface SortOption {
|
|
34
|
+
key: string;
|
|
35
|
+
order: "asc" | "desc";
|
|
36
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { $ as _, iterate as i, $one as r, on as d, off as u } from "ph-utils/dom";
|
|
2
|
+
function g() {
|
|
3
|
+
let n = _(".l-tabs");
|
|
4
|
+
function l(e) {
|
|
5
|
+
const t = e.target.parentElement;
|
|
6
|
+
if (t) {
|
|
7
|
+
const o = t.getAttribute("l-current-tab");
|
|
8
|
+
if (o) {
|
|
9
|
+
const b = r(`.l-tabs__content[l-tab="${o}"]`, t);
|
|
10
|
+
b && b.classList.add("l-tabs__content--hide");
|
|
11
|
+
}
|
|
12
|
+
const s = e.detail.name;
|
|
13
|
+
t.setAttribute("l-current-tab", s);
|
|
14
|
+
const c = r(`.l-tabs__content[l-tab="${s}"]`, t);
|
|
15
|
+
c && c.classList.remove("l-tabs__content--hide");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n && n.length > 0 && i(n, (e) => {
|
|
19
|
+
const a = r(".l-tabs__bar", e);
|
|
20
|
+
if (a) {
|
|
21
|
+
d(a, "change", l);
|
|
22
|
+
const t = a.getAttribute("name");
|
|
23
|
+
t && e.setAttribute("l-current-tab", t);
|
|
24
|
+
const o = _(".l-tabs__content[l-tab]", e);
|
|
25
|
+
i(o, (s) => {
|
|
26
|
+
s.getAttribute("l-tab") === t ? s.classList.remove("l-tabs__content--hide") : s.classList.add("l-tabs__content--hide");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
function f() {
|
|
31
|
+
n && n.length > 0 && i(n, (e) => {
|
|
32
|
+
const a = r(".l-tabs__bar", e);
|
|
33
|
+
a && (console.log("destroy"), u(a, "change", l));
|
|
34
|
+
}), n = void 0;
|
|
35
|
+
}
|
|
36
|
+
return { destroy: f };
|
|
37
|
+
}
|
|
38
|
+
const m = {
|
|
39
|
+
init: g
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
m as default
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import BaseComponent from "../base";
|
|
2
|
+
export default class Tag extends BaseComponent {
|
|
3
|
+
#private;
|
|
4
|
+
static baseName: string;
|
|
5
|
+
type: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
closeable?: boolean;
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
static get observedAttributes(): string[];
|
|
10
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
11
|
+
render(): DocumentFragment;
|
|
12
|
+
afterInit(): void;
|
|
13
|
+
_toggleTypeClass(): void;
|
|
14
|
+
_toggleColorStyle(): void;
|
|
15
|
+
beforeDestroy(): void;
|
|
16
|
+
}
|
package/lib/tag/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import s from "../base.js";
|
|
2
|
+
import { parseAttrValue as i } from "../utils/index.js";
|
|
3
|
+
import { isBlank as c } from "ph-utils";
|
|
4
|
+
import { adjust as n } from "ph-utils/color";
|
|
5
|
+
import { $one as g, $$ as l, shouldEventNext as d, on as f, off as h } from "ph-utils/dom";
|
|
6
|
+
const p = ":host{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;vertical-align:middle;height:var(--l-tag-height, 22px);padding:0 8px;font-size:12px;line-height:1;border:1px solid var(--l-tag-border-color, var(--l-border-color, #dedede));border-radius:4px;background:var(--l-tag-background, #fff);white-space:nowrap;color:var(--l-tag-color, #333)}:host(.l-tag--primary){--l-tag-border-color: var(--l-primary-color-light3, #d3adf7);--l-tag-background: var(--l-primary-color-light5, #f9f0ff);--l-tag-color: var(--l-primary-color-light3, #d3adf7)}:host(.l-tag--error){--l-tag-color: var(--l-error-color, #ed3f13);--l-tag-background: var(--l-error-color-light5, #fff1f0);--l-tag-border-color: var(--l-error-color, #ed3f13)}:host(.l-tag--success){--l-tag-color: var(--l-success-color, #a0d911);--l-tag-background: var(--l-success-color-light5, #fcffe6);--l-tag-border-color: var(--l-success-color, #a0d911)}:host(.l-tag--info){--l-tag-color: var(--l-info-color, #999999);--l-tag-background: var(--l-info-color-light9, #f5f5f5);--l-tag-border-color: var(--l-border-color, #dedede)}:host(.l-tag--warning){--l-tag-color: var(--l-warning-color, #ff9900);--l-tag-background: var(--l-warning-color-light5, #fff5e6);--l-tag-border-color: var(--l-warning-color, #ff9900)}.l-tag-close{margin-left:3px;font-size:12px;width:14px;height:14px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;transition:color .3s,background-color .3s;cursor:pointer}.l-tag-close:hover{background-color:var(--l-tag-color, #1890ff);color:#fff}";
|
|
7
|
+
class x extends s {
|
|
8
|
+
static baseName = "tag";
|
|
9
|
+
type = "primary";
|
|
10
|
+
color;
|
|
11
|
+
closeable = !1;
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.loadStyleText(p), super.connectedCallback();
|
|
14
|
+
}
|
|
15
|
+
static get observedAttributes() {
|
|
16
|
+
return ["type", "color", "closeable"];
|
|
17
|
+
}
|
|
18
|
+
attributeChangedCallback(o, t, e) {
|
|
19
|
+
const r = i(
|
|
20
|
+
e,
|
|
21
|
+
this[o],
|
|
22
|
+
o
|
|
23
|
+
);
|
|
24
|
+
switch (r !== this[o] && (this[o] = r), o) {
|
|
25
|
+
case "type":
|
|
26
|
+
this._toggleTypeClass();
|
|
27
|
+
break;
|
|
28
|
+
case "color":
|
|
29
|
+
this._toggleColorStyle();
|
|
30
|
+
break;
|
|
31
|
+
case "closable":
|
|
32
|
+
if (!this.rendered) return;
|
|
33
|
+
const a = g(".l-tag-close", this.root);
|
|
34
|
+
a ? a.remove() : this.root.appendChild(this.#o());
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
render() {
|
|
39
|
+
const o = document.createDocumentFragment();
|
|
40
|
+
return o.appendChild(
|
|
41
|
+
l("div", { class: "l-tag-content", innerHTML: "<slot></slot>" })
|
|
42
|
+
), this.closeable && o.appendChild(this.#o()), o.appendChild(l("slot", { name: "suffix" })), o;
|
|
43
|
+
}
|
|
44
|
+
#o() {
|
|
45
|
+
return l("div", {
|
|
46
|
+
class: "l-tag-close",
|
|
47
|
+
innerHTML: "<l-close-icon></l-close-icon>",
|
|
48
|
+
"data-action": "close"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
#t = (o) => {
|
|
52
|
+
const [t, e, r] = d(o, "data-action", this);
|
|
53
|
+
t && e === "close" && this.emit("close", { detail: { ...r.dataset } });
|
|
54
|
+
};
|
|
55
|
+
afterInit() {
|
|
56
|
+
this._toggleTypeClass(), this._toggleColorStyle(), f(this.root, "click", this.#t);
|
|
57
|
+
}
|
|
58
|
+
_toggleTypeClass() {
|
|
59
|
+
if (!this.rendered) return;
|
|
60
|
+
let o = !1;
|
|
61
|
+
for (const t of this.classList)
|
|
62
|
+
if (t.startsWith("l-tag--")) {
|
|
63
|
+
this.classList.replace(t, `l-tag--${this.type}`), o = !0;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
o || this.classList.add(`l-tag--${this.type}`);
|
|
67
|
+
}
|
|
68
|
+
_toggleColorStyle() {
|
|
69
|
+
this.rendered && (c(this.color) ? (this.style.removeProperty("--l-tag-color"), this.style.removeProperty("--l-tag-border-color"), this.style.removeProperty("--l-tag-background")) : (this.style.setProperty("--l-tag-color", this.color), this.style.setProperty("--l-tag-border-color", this.color), this.style.setProperty(
|
|
70
|
+
"--l-tag-background",
|
|
71
|
+
n(this.color, 5, !0)
|
|
72
|
+
)));
|
|
73
|
+
}
|
|
74
|
+
beforeDestroy() {
|
|
75
|
+
h(this.root, "click", this.#t);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
x as default
|
|
80
|
+
};
|
package/lib/theme/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import l from "../base.js";
|
|
2
|
-
import { initAttr as
|
|
2
|
+
import { initAttr as r } from "../utils/index.js";
|
|
3
3
|
import { create as i, $one as c, on as o, off as s } from "ph-utils/dom";
|
|
4
|
-
import { getTheme as
|
|
5
|
-
const u = ":host{display:inline-flex;width:auto}.l-theme-btn::part(default){--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-text-color: #9ca3af;--l-btn-hover-text-color: #666666;width:var(--l-form-
|
|
4
|
+
import { getTheme as h, applyTheme as a } from "ph-utils/theme";
|
|
5
|
+
const u = ":host{display:inline-flex;width:auto;box-sizing:border-box}.l-theme-btn::part(default){--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-text-color: #9ca3af;--l-btn-hover-text-color: #666666;width:var(--l-form-control-height, 32px);padding:0;font-size:18px}.l-theme-switch.l-switch--checked{background-color:#65757129;border-color:#3c3f44}.l-theme-switch.l-switch--checked::part(action){background-color:#000;color:#fff}html.dark .l-theme-btn{--l-btn-hover-text-color: #ffffff}", d = [
|
|
6
6
|
{ value: "auto", text: "跟随系统", icon: "l-theme-default-icon" },
|
|
7
7
|
{ value: "light", text: "浅色模式", icon: "l-sun-icon" },
|
|
8
8
|
{ value: "dark", text: "深色模式", icon: "l-moon-icon" }
|
|
@@ -14,7 +14,7 @@ class k extends l {
|
|
|
14
14
|
theme;
|
|
15
15
|
#t;
|
|
16
16
|
connectedCallback() {
|
|
17
|
-
|
|
17
|
+
r(this), this.theme = h(), this.loadStyleText(u), super.connectedCallback(), this.#r();
|
|
18
18
|
}
|
|
19
19
|
disconnectedCallback() {
|
|
20
20
|
super.disconnectedCallback(), this.#c();
|
|
@@ -75,9 +75,9 @@ class k extends l {
|
|
|
75
75
|
const n = t.target.value;
|
|
76
76
|
this.type !== "switch" ? e = n : e = n ? "dark" : "light";
|
|
77
77
|
}
|
|
78
|
-
await
|
|
78
|
+
await a(e), this.theme = e, this.type === "button" && this.#n(this.#t), this.dispatchEvent(new CustomEvent("change", { detail: e }));
|
|
79
79
|
};
|
|
80
|
-
#
|
|
80
|
+
#r() {
|
|
81
81
|
this.#t = c(".l-theme-inner", this.root), this.type === "button" ? o(this.#t, "click", this.#e) : o(this.#t, "change", this.#e);
|
|
82
82
|
}
|
|
83
83
|
#c() {
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -28,34 +28,6 @@ export declare function initAttr(el: HTMLElement): void;
|
|
|
28
28
|
export declare function tagAttr(attr: string, value: string | undefined | boolean): string;
|
|
29
29
|
export declare function tagAttrs(attr: [string, string | undefined | boolean][]): string;
|
|
30
30
|
export declare function setAttrs(el: HTMLElement, attrs: [string, string | undefined | boolean][]): void;
|
|
31
|
-
/**
|
|
32
|
-
* 初始化元素过渡, 同时会监听 l-transition-emit 变化自动执行隐藏动画, show - 显示元素, hide - 隐藏元素
|
|
33
|
-
*
|
|
34
|
-
* 注意需要在页面结束后调用 destroy 销毁监听
|
|
35
|
-
*
|
|
36
|
-
* @param els 需要初始化的元素列表, 如果不传则会自动查找页面中带有 l-transition 属性的元素
|
|
37
|
-
* @returns
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* // html
|
|
41
|
-
* <div
|
|
42
|
-
* l-transition="l-opacity"
|
|
43
|
-
* l-transition-emit="show"
|
|
44
|
-
* l-transition-method="hide"
|
|
45
|
-
* >
|
|
46
|
-
* Hello World
|
|
47
|
-
* </div>
|
|
48
|
-
* // js
|
|
49
|
-
* const trans = createTransition();
|
|
50
|
-
*
|
|
51
|
-
* // 销毁监听
|
|
52
|
-
* transition.destroy();
|
|
53
|
-
*/
|
|
54
|
-
export declare function createTransition(): {
|
|
55
|
-
destroy: () => void;
|
|
56
|
-
add: (elems: HTMLElement[]) => void;
|
|
57
|
-
init: (els?: HTMLElement[]) => void;
|
|
58
|
-
};
|
|
59
31
|
/**
|
|
60
32
|
* 获取悬浮窗 y 偏移
|
|
61
33
|
* @param targetRect
|
|
@@ -80,4 +52,10 @@ export declare function impactDetect(targetRect: DOMRect, popoverRect: DomRectPo
|
|
|
80
52
|
mainAlign: string;
|
|
81
53
|
crossAlign: string;
|
|
82
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* 短横线命名(kebab-case) 转换为 驼峰命名(camelCase
|
|
57
|
+
* @param attr 待转换的属性名
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export declare function kebabToCamel(attr: string): string;
|
|
83
61
|
export {};
|