litos-ui 0.15.8 → 0.16.1
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 +3 -6
- package/lib/button/index.js +61 -68
- package/lib/check/checkbox.js +1 -1
- package/lib/check/index.d.ts +2 -1
- package/lib/check/index.js +25 -12
- package/lib/check/radio.js +1 -1
- package/lib/check-C7YSuH60.js +4 -0
- package/lib/color_picker/index.js +1 -1
- package/lib/description_panel/index.js +4 -9
- package/lib/dialog/dialog_container.js +4 -6
- package/lib/form/form_item.js +3 -3
- package/lib/form/index.js +3 -3
- package/lib/index-DvcllHRh.js +4 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +163 -164
- package/lib/input/index.js +1 -1
- package/lib/mask/index.js +1 -6
- package/lib/message/index.d.ts +11 -12
- package/lib/message/index.js +38 -39
- package/lib/modal/index.js +1 -1
- package/lib/select/index.js +1 -6
- package/lib/select_ori/index.js +1 -1
- package/lib/space/index.d.ts +8 -0
- package/lib/space/index.js +35 -0
- package/lib/table/index.d.ts +2 -2
- package/lib/table/index.js +109 -100
- package/lib/table/types.d.ts +1 -1
- package/lib/tag/index.d.ts +2 -5
- package/lib/tag/index.js +35 -43
- package/lib/utils/index.d.ts +0 -25
- package/lib/utils/index.js +40 -87
- package/lib/utils/popover.js +24 -17
- package/package.json +42 -46
- package/styles/container.css +1 -0
- package/styles/dark.css +13 -0
- package/styles/reset.css +3 -5
- package/styles/vars.css +10 -12
- package/lib/check-A86JxUfd.js +0 -4
- package/lib/index-D4II9KsF.js +0 -4
package/lib/table/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p from "../base.js";
|
|
2
2
|
import { kebabToCamel as b, parseAttrValue as x } from "../utils/index.js";
|
|
3
|
-
import { $one as h, $$ as
|
|
3
|
+
import { $one as h, $$ as d, iterate as g, formatStyle as f, shouldEventNext as y, on as u, off as C } from "ph-utils/dom";
|
|
4
4
|
import { random as _ } from "ph-utils";
|
|
5
|
-
const m = ":host{
|
|
6
|
-
class
|
|
5
|
+
const m = ":host{display:inline-block;width:100%;max-height:var(--l-table-max-height, 100%);overflow:auto;font-size:var(--l-table-font-size, 14px)}.l-table{width:100%;border-collapse:collapse;border-spacing:0;table-layout:var(--l-table-layout, auto)}.l-table th,.l-table td{border-bottom:1px solid var(--l-table-border-color, #e6e6e6)}.l-table th{padding:var(--l-table-th-padding, 10px);text-align:left;background-color:var(--l-table-th-bg, #f2f2f2);color:var(--l-table-th-color, #000000)}.l-table td{background-color:var(--l-table-td-bg, #ffffff);color:var(--l-table-td-color, #000000);padding:var(--l-table-td-padding, 10px);transition:background-color .3s}.l-table tr:hover td{background-color:var(--l-table-row-hover-bg, #f2f2f2)}.l-table .l-table__empty-col{color:var(--l-table-empty-color, #999999);text-align:center}.l-table-stripe tr:nth-child(2n) td{background-color:var(--l-table-stripe-bg, #fafafa)}.l-table-stripe tr:nth-child(2n):hover td{background-color:var(--l-table-row-hover-bg, #f2f2f2)}.l-table-border th,.l-table-border td{border:1px solid var(--l-table-border-color, #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}.l-table .caret-wrapper{display:inline-flex;justify-content:center;align-items:center;vertical-align:middle;height:14px;width:20px;position:relative}.l-table .caret-wrapper .ascending{border-bottom-color:var(--l-table-sort-inactive-color, #c0c4cc);top:-5px}.l-table .caret-wrapper .descending{border-top-color:var(--l-table-sort-inactive-color, #c0c4cc);bottom:-3px}.l-table .sort-caret{display:inline-block;width:0;height:0;border:5px solid transparent;position:absolute;border-radius:3px}.l-table .sort-column{cursor:pointer}.l-table .sort-asc .ascending{border-bottom-color:var(--l-primary-color, #52c41a)}.l-table .sort-desc .descending{border-top-color:var(--l-primary-color, #52c41a)}";
|
|
6
|
+
class H extends p {
|
|
7
7
|
static baseName = "table";
|
|
8
8
|
/** 斑马纹 */
|
|
9
9
|
stripe = !0;
|
|
@@ -25,39 +25,36 @@ class S extends c {
|
|
|
25
25
|
connectedCallback() {
|
|
26
26
|
this.loadStyleText(m), super.connectedCallback();
|
|
27
27
|
}
|
|
28
|
-
setColumns(
|
|
29
|
-
let i = 0,
|
|
30
|
-
this.columns = this._parseColumns(
|
|
28
|
+
setColumns(t) {
|
|
29
|
+
let i = 0, e = 0;
|
|
30
|
+
this.columns = this._parseColumns(t, i, e), this.rerender("all");
|
|
31
31
|
}
|
|
32
|
-
setData(
|
|
33
|
-
this.data =
|
|
32
|
+
setData(t, i) {
|
|
33
|
+
this.data = t, this.sortInfo = i, this.columns && this.columns.length > 0 && this.rerender(i ? "all" : "body");
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
this.sortInfo = e, this.rerender("all");
|
|
37
|
-
}
|
|
38
|
-
changeFixed(e) {
|
|
35
|
+
changeFixed(t) {
|
|
39
36
|
const i = {
|
|
40
37
|
fixedHead: this.fixedHead,
|
|
41
38
|
fixedColumn: this.fixedColumn,
|
|
42
|
-
...
|
|
39
|
+
...t
|
|
43
40
|
};
|
|
44
41
|
if (this.fixedHead = i.fixedHead, this.fixedColumn = i.fixedColumn, this.rendered) {
|
|
45
|
-
const
|
|
46
|
-
|
|
42
|
+
const e = h(".l-table", this.root);
|
|
43
|
+
e && (this.fixedHead || this.fixedColumn ? e.classList.add("l-table-fixed") : e.classList.remove("l-table-fixed"));
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
static get observedAttributes() {
|
|
50
47
|
return ["stripe", "border", "fixed-head", "max-height", "table-layout"];
|
|
51
48
|
}
|
|
52
|
-
attributeChangedCallback(
|
|
53
|
-
|
|
49
|
+
attributeChangedCallback(t, i, e) {
|
|
50
|
+
t = b(t);
|
|
54
51
|
const s = x(
|
|
55
|
-
|
|
56
|
-
this[
|
|
57
|
-
|
|
52
|
+
e,
|
|
53
|
+
this[t],
|
|
54
|
+
t
|
|
58
55
|
);
|
|
59
|
-
if (s !== this[
|
|
60
|
-
switch (this[
|
|
56
|
+
if (s !== this[t])
|
|
57
|
+
switch (this[t] = s, t) {
|
|
61
58
|
case "stripe":
|
|
62
59
|
this._classAttrChannge("stripe", s);
|
|
63
60
|
break;
|
|
@@ -76,7 +73,7 @@ class S extends c {
|
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
render() {
|
|
79
|
-
const
|
|
76
|
+
const t = d("table", {
|
|
80
77
|
class: [
|
|
81
78
|
"l-table",
|
|
82
79
|
this.stripe ? "l-table-stripe" : "",
|
|
@@ -84,43 +81,43 @@ class S extends c {
|
|
|
84
81
|
this.fixedHead || this.fixedColumn ? "l-table-fixed" : ""
|
|
85
82
|
]
|
|
86
83
|
});
|
|
87
|
-
return
|
|
84
|
+
return t.appendChild(this._headRender()), t.appendChild(this._bodyRender()), t;
|
|
88
85
|
}
|
|
89
|
-
rerender(
|
|
86
|
+
rerender(t) {
|
|
90
87
|
if (this.rendered) {
|
|
91
|
-
if (
|
|
88
|
+
if (t === "all" || t === "head") {
|
|
92
89
|
const i = h("thead", this.root);
|
|
93
90
|
i && i.replaceWith(this._headRender());
|
|
94
91
|
}
|
|
95
|
-
if (
|
|
92
|
+
if (t === "all" || t === "body") {
|
|
96
93
|
const i = h("tbody", this.root);
|
|
97
94
|
i && i.replaceWith(this._bodyRender());
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
|
-
_changeCssVar(
|
|
98
|
+
_changeCssVar(t, i) {
|
|
102
99
|
if (!this.rendered) return;
|
|
103
|
-
const
|
|
104
|
-
i ? this.style.setProperty(
|
|
100
|
+
const e = `--l-table-${t}`;
|
|
101
|
+
i ? this.style.setProperty(e, i) : this.style.removeProperty(e);
|
|
105
102
|
}
|
|
106
103
|
_changeMaxHeight() {
|
|
107
|
-
let
|
|
108
|
-
|
|
104
|
+
let t = this.maxHeight;
|
|
105
|
+
t && typeof t == "number" && (t = `${t}px`), this._changeCssVar("max-height", t);
|
|
109
106
|
}
|
|
110
|
-
_classAttrChannge(
|
|
107
|
+
_classAttrChannge(t, i) {
|
|
111
108
|
if (this.rendered) {
|
|
112
|
-
const
|
|
113
|
-
|
|
109
|
+
const e = h("table", this.root);
|
|
110
|
+
e && e.classList.toggle(`l-table-${t}`, i);
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
113
|
_updateFixedHead() {
|
|
117
114
|
if (this.rendered) {
|
|
118
|
-
const
|
|
119
|
-
|
|
115
|
+
const t = h("thead", this.root);
|
|
116
|
+
t && (t.classList.toggle("l-fixed", this.fixedHead), t.style.top = this.fixedHead ? "0" : "");
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
119
|
_headRender() {
|
|
123
|
-
const
|
|
120
|
+
const t = d("thead", {
|
|
124
121
|
class: {
|
|
125
122
|
"l-fixed": this.fixedHead
|
|
126
123
|
},
|
|
@@ -128,62 +125,62 @@ class S extends c {
|
|
|
128
125
|
top: this.fixedHead ? "0" : void 0
|
|
129
126
|
}
|
|
130
127
|
});
|
|
131
|
-
return this.columns && this._rendHeadRow(
|
|
128
|
+
return this.columns && this._rendHeadRow(t, this.columns), t;
|
|
132
129
|
}
|
|
133
|
-
_rendHeadRow(
|
|
134
|
-
const
|
|
130
|
+
_rendHeadRow(t, i) {
|
|
131
|
+
const e = d("tr");
|
|
135
132
|
for (let s = 0, a = i.length; s < a; s++) {
|
|
136
133
|
const r = i[s];
|
|
137
|
-
|
|
134
|
+
e.appendChild(this._headColRender(r, s)), r.children && this._rendHeadRow(t, r.children);
|
|
138
135
|
}
|
|
139
|
-
|
|
136
|
+
t.appendChild(e);
|
|
140
137
|
}
|
|
141
|
-
_headColRender(
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
textContent:
|
|
138
|
+
_headColRender(t, i) {
|
|
139
|
+
const e = d("th");
|
|
140
|
+
if (t.titleColspan && t.titleColspan > 1 && (e.colSpan = t.titleColspan), t.titleRowspan && t.titleRowspan > 1 && (e.rowSpan = t.titleRowspan), e.style.cssText = this._getColumnStyle(t, "th"), t.fixed && e.classList.add("l-fixed"), e.appendChild(
|
|
141
|
+
d("span", {
|
|
142
|
+
textContent: t.title
|
|
146
143
|
})
|
|
147
|
-
),
|
|
148
|
-
const s =
|
|
149
|
-
s.appendChild(
|
|
144
|
+
), t.sorter) {
|
|
145
|
+
const s = d("span", { class: "caret-wrapper" });
|
|
146
|
+
s.appendChild(d("span", { class: "sort-caret ascending" })), s.appendChild(d("span", { class: "sort-caret descending" })), e.classList.add("sort-column"), e.setAttribute("data-action", "sort"), e.setAttribute("data-col", `${i}`), e.appendChild(s);
|
|
150
147
|
}
|
|
151
|
-
return t;
|
|
148
|
+
return this.sortInfo && this.sortInfo.key === t.key && e.classList.add(this.sortInfo.order === "asc" ? "sort-asc" : "sort-desc"), e;
|
|
152
149
|
}
|
|
153
150
|
_bodyRender() {
|
|
154
|
-
const
|
|
151
|
+
const t = d("tbody");
|
|
155
152
|
if (this.data && this.data.length > 0)
|
|
156
|
-
for (let i = 0,
|
|
153
|
+
for (let i = 0, e = this.data.length; i < e; i++) {
|
|
157
154
|
const s = this.data[i];
|
|
158
155
|
if (this.columns) {
|
|
159
|
-
const a =
|
|
160
|
-
this._bodyRowRender(this.columns, i, s, a),
|
|
156
|
+
const a = d("tr");
|
|
157
|
+
this._bodyRowRender(this.columns, i, s, a), t.appendChild(a);
|
|
161
158
|
}
|
|
162
159
|
}
|
|
163
160
|
else {
|
|
164
|
-
const i =
|
|
161
|
+
const i = d("tr"), e = d("td", {
|
|
165
162
|
class: "l-table__empty-col",
|
|
166
163
|
textContent: "暂无数据"
|
|
167
164
|
});
|
|
168
|
-
this.columns && (
|
|
165
|
+
this.columns && (e.colSpan = this.columns.length), i.appendChild(e), t.appendChild(i);
|
|
169
166
|
}
|
|
170
|
-
return
|
|
167
|
+
return t;
|
|
171
168
|
}
|
|
172
|
-
_bodyRowRender(
|
|
173
|
-
for (let a = 0, r =
|
|
174
|
-
const l =
|
|
169
|
+
_bodyRowRender(t, i, e, s) {
|
|
170
|
+
for (let a = 0, r = t.length; a < r; a++) {
|
|
171
|
+
const l = t[a];
|
|
175
172
|
if (l.children && l.children.length > 0)
|
|
176
|
-
this._bodyRowRender(l.children, i,
|
|
173
|
+
this._bodyRowRender(l.children, i, e, s);
|
|
177
174
|
else {
|
|
178
|
-
const
|
|
179
|
-
if (typeof l.rowspan == "number" && (
|
|
180
|
-
const n = l.render(
|
|
181
|
-
typeof n == "string" ?
|
|
182
|
-
|
|
183
|
-
}) :
|
|
175
|
+
const o = d("td");
|
|
176
|
+
if (typeof l.rowspan == "number" && (o.rowSpan = l.rowspan), typeof l.rowspan == "function" && (o.rowSpan = l.rowspan(e, i)), typeof l.colspan == "number" && (o.colSpan = l.colspan), typeof l.colspan == "function" && (o.colSpan = l.colspan(e, i)), l.fixed && (o.className = "l-fixed"), o.style.cssText = this._getColumnStyle(l), l.render) {
|
|
177
|
+
const n = l.render(e, i);
|
|
178
|
+
typeof n == "string" ? o.innerHTML = n : Array.isArray(n) ? g(n, (c) => {
|
|
179
|
+
o.appendChild(c);
|
|
180
|
+
}) : o.appendChild(n);
|
|
184
181
|
} else
|
|
185
|
-
|
|
186
|
-
s.appendChild(
|
|
182
|
+
o.textContent = l.key ? e[l.key] : "";
|
|
183
|
+
s.appendChild(o);
|
|
187
184
|
}
|
|
188
185
|
}
|
|
189
186
|
}
|
|
@@ -194,23 +191,23 @@ class S extends c {
|
|
|
194
191
|
* @param rightOffset 右边固定列偏移
|
|
195
192
|
* @returns
|
|
196
193
|
*/
|
|
197
|
-
_parseColumns(
|
|
194
|
+
_parseColumns(t, i, e) {
|
|
198
195
|
const s = [];
|
|
199
|
-
for (let a = 0, r =
|
|
200
|
-
const l =
|
|
196
|
+
for (let a = 0, r = t.length; a < r; a++) {
|
|
197
|
+
const l = t[a];
|
|
201
198
|
if (l.id || (l.id = l.key || l.title), l.id || (l.id = `${a}_${_(6)}`), l.fixed) {
|
|
202
|
-
const
|
|
203
|
-
l.fixed === "left" ? (l.left = i, i +=
|
|
199
|
+
const o = Number.parseFloat(`${l.width || 0}`);
|
|
200
|
+
l.fixed === "left" ? (l.left = i, i += o) : l.fixed === "right" && (l.right = e, e += o);
|
|
204
201
|
}
|
|
205
202
|
if (l.children) {
|
|
206
|
-
const
|
|
203
|
+
const o = this._parseColumns(
|
|
207
204
|
l.children,
|
|
208
205
|
i,
|
|
209
|
-
|
|
206
|
+
e
|
|
210
207
|
);
|
|
211
|
-
l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan =
|
|
208
|
+
l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan = o.reduce((n, c) => n + (c.titleColspan || 1), 0)), s.push({ ...l, children: o });
|
|
212
209
|
} else
|
|
213
|
-
l.titleRowspan = l.titleRowspan || this._getMaxDepth(
|
|
210
|
+
l.titleRowspan = l.titleRowspan || this._getMaxDepth(t), l.titleColspan = l.titleColspan || 1, s.push({ ...l });
|
|
214
211
|
}
|
|
215
212
|
return s;
|
|
216
213
|
}
|
|
@@ -219,42 +216,54 @@ class S extends c {
|
|
|
219
216
|
* @param headers 表头配置
|
|
220
217
|
* @returns 最大深度, 最大跨行数
|
|
221
218
|
*/
|
|
222
|
-
_getMaxDepth(
|
|
219
|
+
_getMaxDepth(t) {
|
|
223
220
|
let i = 1;
|
|
224
|
-
for (const
|
|
225
|
-
|
|
221
|
+
for (const e of t)
|
|
222
|
+
e.children && (i = Math.max(i, this._getMaxDepth(e.children) + 1));
|
|
226
223
|
return i;
|
|
227
224
|
}
|
|
228
|
-
_getColumnStyle(
|
|
229
|
-
const
|
|
230
|
-
if (this._globalColStyles &&
|
|
231
|
-
return this._globalColStyles[
|
|
225
|
+
_getColumnStyle(t, i = "td") {
|
|
226
|
+
const e = t.id;
|
|
227
|
+
if (this._globalColStyles && e in this._globalColStyles)
|
|
228
|
+
return this._globalColStyles[e][i];
|
|
232
229
|
const s = {};
|
|
233
|
-
|
|
234
|
-
const a =
|
|
230
|
+
t.width && (typeof t.width == "number" ? s.width = `${t.width}px` : s.width = t.width), t.fixed && (t.fixed === "left" ? (s.left = `${t.left}px`, s["box-shadow"] = "-4px 0 4px -4px #d9d9d9 inset") : t.fixed === "right" && (s.right = `${t.right}px`, s["box-shadow"] = "4px 0 4px -4px #d9d9d9 inset")), this._globalColStyles || (this._globalColStyles = {});
|
|
231
|
+
const a = f(s), r = {
|
|
235
232
|
th: a,
|
|
236
|
-
td: a +
|
|
233
|
+
td: a + f(t.style || "")
|
|
237
234
|
};
|
|
238
|
-
return this._globalColStyles[
|
|
235
|
+
return this._globalColStyles[e] = r, r[i];
|
|
239
236
|
}
|
|
240
|
-
_handleTap = (
|
|
241
|
-
const [i,
|
|
242
|
-
|
|
237
|
+
_handleTap = (t) => {
|
|
238
|
+
const [i, e, s] = y(
|
|
239
|
+
t,
|
|
243
240
|
"data-action",
|
|
244
|
-
|
|
241
|
+
t.currentTarget
|
|
245
242
|
);
|
|
246
243
|
if (i) {
|
|
247
244
|
const a = s.dataset;
|
|
248
|
-
|
|
245
|
+
if (e === "sort") {
|
|
246
|
+
const r = parseInt(a.col), l = this.columns[r], o = this.sortInfo && this.sortInfo.order === "desc" ? "asc" : "desc";
|
|
247
|
+
this.sortInfo = { key: l.key, order: o }, l.sorter === "custom" ? this.emit("sort", { detail: { index: r, key: l.key, dir: o } }) : (this.data = this._dataSort(), this.rerender("all"));
|
|
248
|
+
} else
|
|
249
|
+
this.emit(e, { detail: a });
|
|
249
250
|
}
|
|
250
251
|
};
|
|
251
252
|
afterInit() {
|
|
252
|
-
this._changeMaxHeight(),
|
|
253
|
+
this._changeMaxHeight(), u(this.root, "click", this._handleTap);
|
|
253
254
|
}
|
|
254
255
|
beforeDestroy() {
|
|
255
|
-
|
|
256
|
+
C(this.root, "click", this._handleTap);
|
|
257
|
+
}
|
|
258
|
+
_dataSort() {
|
|
259
|
+
if (!this.sortInfo || !this.data) return;
|
|
260
|
+
const { key: t, order: i } = this.sortInfo;
|
|
261
|
+
return this.data.sort((e, s) => {
|
|
262
|
+
const a = e[t], r = s[t];
|
|
263
|
+
return i === "asc" ? a - r : r - a;
|
|
264
|
+
});
|
|
256
265
|
}
|
|
257
266
|
}
|
|
258
267
|
export {
|
|
259
|
-
|
|
268
|
+
H as default
|
|
260
269
|
};
|
package/lib/table/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface Column {
|
|
|
20
20
|
/** 表头跨列 */
|
|
21
21
|
titleColspan?: number;
|
|
22
22
|
/** 列是否支持排序 */
|
|
23
|
-
sorter?: boolean | "
|
|
23
|
+
sorter?: boolean | "custom";
|
|
24
24
|
/** 列的样式 */
|
|
25
25
|
style?: Record<string, string | null | undefined>;
|
|
26
26
|
/** td colspan */
|
package/lib/tag/index.d.ts
CHANGED
|
@@ -2,15 +2,12 @@ import BaseComponent from "../base";
|
|
|
2
2
|
export default class Tag extends BaseComponent {
|
|
3
3
|
#private;
|
|
4
4
|
static baseName: string;
|
|
5
|
-
type: string;
|
|
6
|
-
color?: string;
|
|
7
|
-
closeable?: boolean;
|
|
8
5
|
connectedCallback(): void;
|
|
9
6
|
static get observedAttributes(): string[];
|
|
10
7
|
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
11
8
|
render(): DocumentFragment;
|
|
12
9
|
afterInit(): void;
|
|
13
|
-
_toggleTypeClass(): void;
|
|
14
|
-
_toggleColorStyle(): void;
|
|
10
|
+
_toggleTypeClass(type: string): void;
|
|
11
|
+
_toggleColorStyle(color?: string | null): void;
|
|
15
12
|
beforeDestroy(): void;
|
|
16
13
|
}
|
package/lib/tag/index.js
CHANGED
|
@@ -1,80 +1,72 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { parseAttrValue as
|
|
3
|
-
import { isBlank as
|
|
4
|
-
import { adjust as
|
|
5
|
-
import { $one as
|
|
6
|
-
const
|
|
7
|
-
class
|
|
1
|
+
import i from "../base.js";
|
|
2
|
+
import { parseAttrValue as c } from "../utils/index.js";
|
|
3
|
+
import { isBlank as n } from "ph-utils";
|
|
4
|
+
import { adjust as g } from "ph-utils/color";
|
|
5
|
+
import { $one as d, $$ as l, shouldEventNext as f, on as h, off as p } from "ph-utils/dom";
|
|
6
|
+
const b = ":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 5px;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 C extends i {
|
|
8
8
|
static baseName = "tag";
|
|
9
|
-
type = "primary";
|
|
10
|
-
color;
|
|
11
|
-
closeable = !1;
|
|
12
9
|
connectedCallback() {
|
|
13
|
-
this.loadStyleText(
|
|
10
|
+
this.loadStyleText(b), super.connectedCallback();
|
|
14
11
|
}
|
|
15
12
|
static get observedAttributes() {
|
|
16
13
|
return ["type", "color", "closeable"];
|
|
17
14
|
}
|
|
18
|
-
attributeChangedCallback(
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
this[o],
|
|
22
|
-
o
|
|
23
|
-
);
|
|
24
|
-
switch (r !== this[o] && (this[o] = r), o) {
|
|
15
|
+
attributeChangedCallback(t, o, r) {
|
|
16
|
+
const e = r.trim();
|
|
17
|
+
switch (t) {
|
|
25
18
|
case "type":
|
|
26
|
-
this._toggleTypeClass();
|
|
19
|
+
this._toggleTypeClass(e);
|
|
27
20
|
break;
|
|
28
21
|
case "color":
|
|
29
|
-
this._toggleColorStyle();
|
|
22
|
+
this._toggleColorStyle(e);
|
|
30
23
|
break;
|
|
31
24
|
case "closable":
|
|
32
25
|
if (!this.rendered) return;
|
|
33
|
-
const a =
|
|
34
|
-
|
|
26
|
+
const a = c(e, !1, "closeable"), s = d(".l-tag-close", this.root);
|
|
27
|
+
if (s) {
|
|
28
|
+
if (a) return;
|
|
29
|
+
s.remove();
|
|
30
|
+
} else
|
|
31
|
+
a && this.root.appendChild(this.#t());
|
|
35
32
|
break;
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
render() {
|
|
39
|
-
const
|
|
40
|
-
return
|
|
41
|
-
l("div", { class: "l-tag-content", innerHTML: "<slot></slot>" })
|
|
42
|
-
), this.closeable && o.appendChild(this.#o()), o.appendChild(l("slot", { name: "suffix" })), o;
|
|
36
|
+
const t = document.createDocumentFragment();
|
|
37
|
+
return t.appendChild(l("div", { class: "l-tag-content", innerHTML: "<slot></slot>" })), this.getAttr("closeable", !1) && t.appendChild(this.#t()), t.appendChild(l("slot", { name: "suffix" })), t;
|
|
43
38
|
}
|
|
44
|
-
#
|
|
39
|
+
#t() {
|
|
45
40
|
return l("div", {
|
|
46
41
|
class: "l-tag-close",
|
|
47
42
|
innerHTML: "<l-close-icon></l-close-icon>",
|
|
48
43
|
"data-action": "close"
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
|
-
#
|
|
52
|
-
const [
|
|
53
|
-
|
|
46
|
+
#r = (t) => {
|
|
47
|
+
const [o, r, e] = f(t, "data-action", this);
|
|
48
|
+
o && r === "close" && this.emit("close", { detail: { ...e.dataset } });
|
|
54
49
|
};
|
|
55
50
|
afterInit() {
|
|
56
|
-
this.
|
|
51
|
+
this.classList.add(`l-tag--${this.getAttr("type", "info")}`), this._toggleColorStyle(), h(this.root, "click", this.#r);
|
|
57
52
|
}
|
|
58
|
-
_toggleTypeClass() {
|
|
53
|
+
_toggleTypeClass(t) {
|
|
59
54
|
if (!this.rendered) return;
|
|
60
55
|
let o = !1;
|
|
61
|
-
for (const
|
|
62
|
-
if (
|
|
63
|
-
this.classList.replace(
|
|
56
|
+
for (const r of this.classList)
|
|
57
|
+
if (r.startsWith("l-tag--")) {
|
|
58
|
+
this.classList.replace(r, `l-tag--${t}`), o = !0;
|
|
64
59
|
break;
|
|
65
60
|
}
|
|
66
|
-
o || this.classList.add(`l-tag--${
|
|
61
|
+
o || this.classList.add(`l-tag--${t}`);
|
|
67
62
|
}
|
|
68
|
-
_toggleColorStyle() {
|
|
69
|
-
this.rendered && (
|
|
70
|
-
"--l-tag-background",
|
|
71
|
-
n(this.color, 5, !0)
|
|
72
|
-
)));
|
|
63
|
+
_toggleColorStyle(t) {
|
|
64
|
+
this.rendered && (n(t) ? (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", t), this.style.setProperty("--l-tag-border-color", t), this.style.setProperty("--l-tag-background", g(t, 5, !0))));
|
|
73
65
|
}
|
|
74
66
|
beforeDestroy() {
|
|
75
|
-
|
|
67
|
+
p(this.root, "click", this.#r);
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
export {
|
|
79
|
-
|
|
71
|
+
C as default
|
|
80
72
|
};
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -28,34 +28,9 @@ 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
|
-
* 获取悬浮窗 y 偏移
|
|
33
|
-
* @param targetRect
|
|
34
|
-
* @param popoverRect
|
|
35
|
-
* @param mainAlign
|
|
36
|
-
* @param crossAlign
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
export declare function getPopoverOffsetY(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, offset?: number): number;
|
|
40
|
-
type DomRectPos = {
|
|
41
|
-
x: number;
|
|
42
|
-
y: number;
|
|
43
|
-
width: number;
|
|
44
|
-
height: number;
|
|
45
|
-
left: number;
|
|
46
|
-
top: number;
|
|
47
|
-
};
|
|
48
|
-
export declare function getPopoverOffsetX(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, offset?: number): number;
|
|
49
|
-
export declare function impactDetect(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, scrollLeft: number, scrollTop: number, leftDiff: number, topDiff: number, offset?: number, position?: string): {
|
|
50
|
-
x: number;
|
|
51
|
-
y: number;
|
|
52
|
-
mainAlign: string;
|
|
53
|
-
crossAlign: string;
|
|
54
|
-
};
|
|
55
31
|
/**
|
|
56
32
|
* 短横线命名(kebab-case) 转换为 驼峰命名(camelCase
|
|
57
33
|
* @param attr 待转换的属性名
|
|
58
34
|
* @returns
|
|
59
35
|
*/
|
|
60
36
|
export declare function kebabToCamel(attr: string): string;
|
|
61
|
-
export {};
|