litos-ui 0.14.0 → 0.15.0

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.
@@ -4,7 +4,10 @@ export default class Button extends BaseComponent {
4
4
  htmlType: "submit" | "reset" | "button";
5
5
  /** 加载中文本 */
6
6
  loadingText: string;
7
- disabled: boolean;
7
+ _disabled: boolean;
8
+ get disabled(): boolean;
9
+ set disabled(value: boolean);
10
+ setDisabled(value: boolean): void;
8
11
  static get observedAttributes(): string[];
9
12
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
10
13
  connectedCallback(): void;
@@ -1,32 +1,47 @@
1
- import { parseAttrValue as b, initAttr as s } from "../utils/index.js";
2
- import c from "../base.js";
3
- import { $one as h, addClass as g, removeClass as f, on as p, off as v, formatClass as u, formatStyle as m, getAttr as k } from "ph-utils/dom";
4
- import { adjust as i } from "ph-utils/color";
1
+ import { parseAttrValue as b, initAttr as c } from "../utils/index.js";
2
+ import h from "../base.js";
3
+ import { $one as i, addClass as g, removeClass as f, on as p, off as v, formatClass as u, formatStyle as m, getAttr as k } from "ph-utils/dom";
4
+ import { adjust as s } from "ph-utils/color";
5
5
  import { a as x } from "../animation-DttknHkX.js";
6
6
  const y = ":host{--l-btn-text-color: #ffffff;--l-btn-hover-text-color: var(--l-btn-text-color);--l-btn-active-text-color: var(--l-btn-text-color);--l-btn-border-color: var(--l-primary-color, #722ed1);--l-btn-background: var(--l-btn-border-color);--l-btn-hover-border-color: var(--l-primary-color-light1, #9254de);--l-btn-hover-background: var(--l-btn-hover-border-color);--l-btn-active-border-color: var(--l-primary-color-dark1, #531dab);--l-btn-active-background: var(--l-btn-active-border-color);--l-btn-disabled-color: #c9c9c9;--l-btn-disabled-background: #fbfbfb;--l-btn-disabled-border-color: #e6e6e6;display:inline-block;width:auto;height:var(--l-form-edit-height, 32px);font-size:0}:host([block]){width:100%}.l-btn{width:100%;display:inline-flex;justify-content:center;align-items:center;cursor:pointer;outline:none;box-sizing:border-box;vertical-align:middle;padding:0 15px;line-height:1;height:100%;border-radius:3px;font-size:14px;color:var(--l-btn-text-color);background:var(--l-btn-background);border:1px solid var(--l-btn-border-color);position:relative;gap:5px;transition:border-color .3s,background-color .3s,color .3s}.l-btn:hover{border-color:var(--l-btn-hover-border-color, var(--l-btn-hover-background));color:var(--l-btn-hover-text-color);background:var(--l-btn-hover-background)}.l-btn:active{border-color:var(--l-btn-active-border-color, var(--l-btn-active-background));color:var(--l-btn-active-text-color);background:var(--l-btn-active-background)}.l-btn-normal{--l-btn-text-color: auto;--l-btn-background: transparent;--l-btn-border-color: #d9d9d9;--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab);--l-btn-hover-background: #fff;--l-btn-active-background: #fff;--l-btn-hover-border-color: var(--l-btn-hover-text-color);--l-btn-active-border-color: var(--l-btn-active-text-color)}.l-btn-primary{--l-btn-background: var(--l-primary-color, #722ed1);--l-btn-hover-background: var(--l-primary-color-light1, #9254de);--l-btn-active-background: var(--l-primary-color-dark1, #531dab);--l-btn-disabled-border-color: var(--l-primary-color-light2, #b37feb);--l-btn-disabled-background: var(--l-primary-color-light2, #b37feb);--l-btn-disabled-color: #ffffff}.l-btn:disabled{border-color:var(--l-btn-disabled-border-color);background:var(--l-btn-disabled-background);color:var(--l-btn-disabled-color);cursor:not-allowed;opacity:1}.l-btn.l-btn-loading{cursor:default}.l-btn-text{--l-btn-background: transparent;--l-btn-border-color: transparent;--l-btn-hover-border-color: transparent;--l-btn-active-border-color: transparent;--l-btn-disabled-background: transparent;--l-btn-disabled-border-color: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;padding:5px}.l-btn-primary.l-btn-text{--l-btn-text-color: var(--l-primary-color, #722ed1);--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab)}.l-btn-ghost{--l-btn-text-color: var(--l-btn-border-color);--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;--l-btn-hover-text-color: var(--l-btn-hover-border-color);--l-btn-active-text-color: var(--l-btn-active-border-color)}.l-btn-round{border-radius:calc(var(--l-form-edit-height, 32px) / 2)}.l-btn-circle{border-radius:50%;width:var(--l-form-edit-height, 32px);padding:0}.l-btn:not(.l-btn-text)+.l-btn{margin-left:10px}html.dark .l-btn:disabled{--l-btn-disabled-background: rgba(255, 255, 255, .08);--l-btn-disabled-color: rgba(255, 255, 255, .3);--l-btn-disabled-border-color: rgba(255, 255, 255, .3)}";
7
- class M extends c {
7
+ class L extends h {
8
8
  static baseName = "button";
9
9
  htmlType = "button";
10
10
  /** 加载中文本 */
11
11
  loadingText = "";
12
- disabled = !1;
12
+ _disabled = !1;
13
+ get disabled() {
14
+ return this._disabled;
15
+ }
16
+ set disabled(r) {
17
+ this.setDisabled(r);
18
+ }
19
+ setDisabled(r) {
20
+ this._disabled = r;
21
+ const t = i(".l-btn", this.root);
22
+ t && (t.disabled = r);
23
+ }
13
24
  // 初始化属性观察器
14
25
  static get observedAttributes() {
15
26
  return ["loading", "color", "disabled"];
16
27
  }
17
28
  // 当属性发生变化时调用的回调函数
18
29
  attributeChangedCallback(r, t, o) {
19
- const l = h(".l-btn", this.root);
20
- if (l)
30
+ const l = i(".l-btn", this.root);
31
+ if (l) {
21
32
  if (r === "loading")
22
33
  b(o, !1, r) ? (g(l, "l-btn-loading"), l.disabled = !0, l.innerHTML = this.loadingBody()) : (f(l, "l-btn-loading"), l.disabled = this.disabled, l.innerHTML = "<slot></slot>");
23
34
  else if (r === "color") {
24
35
  const e = this.getAttr("text", !1), n = this.getAttr("ghost", !1);
25
36
  l.style.cssText = this.applyColor(o, e, n);
26
- } else r === "disabled" && (l.disabled = b(o, !1, "disabled"));
37
+ } else if (r === "disabled") {
38
+ const e = b(o, !1, "disabled");
39
+ this.setDisabled(e);
40
+ }
41
+ }
27
42
  }
28
43
  connectedCallback() {
29
- s(this), this.loadStyleText([x, y]), this.render(), (this.htmlType === "reset" || this.htmlType === "submit") && p(this, "click", this._handleClick);
44
+ c(this), this.loadStyleText([x, y]), this.render(), (this.htmlType === "reset" || this.htmlType === "submit") && p(this, "click", this._handleClick);
30
45
  }
31
46
  disconnectedCallback() {
32
47
  super.disconnectedCallback(), (this.htmlType === "reset" || this.htmlType === "submit") && v(this, "click", this._handleClick);
@@ -41,7 +56,7 @@ class M extends c {
41
56
  e ? "l-btn-text" : "",
42
57
  o ? "l-btn-loading" : ""
43
58
  ];
44
- t.className = u(d), t.disabled = this.getAttr("disabled", !1) || o, t.type = this.getAttr("html-type", "button");
59
+ t.className = u(d), t.disabled = this.disabled || o, t.type = this.getAttr("html-type", "button");
45
60
  const a = this.applyColor(this.getAttr("color"), e, n);
46
61
  a && (t.style.cssText = a), o ? t.innerHTML = this.loadingBody() : t.innerHTML = "<slot></slot>", t.setAttribute("part", "default"), this.root.appendChild(t);
47
62
  }
@@ -51,7 +66,7 @@ class M extends c {
51
66
  }
52
67
  applyColor(r, t = !1, o = !1) {
53
68
  if (!r) return "";
54
- const l = i(r, 1, !0), e = i(r, 3, !1);
69
+ const l = s(r, 1, !0), e = s(r, 3, !1);
55
70
  return m({
56
71
  "--l-btn-border-color": t ? "transparent" : r,
57
72
  "--l-btn-text-color": o || t ? r : "#ffffff",
@@ -86,5 +101,5 @@ class M extends c {
86
101
  }
87
102
  }
88
103
  export {
89
- M as default
104
+ L as default
90
105
  };
package/lib/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export { default as List } from "./list";
45
45
  export { default as Polygon } from "./polygon";
46
46
  export { default as ColorPicker } from "./color_picker";
47
47
  export { default as Tabbar } from "./tabbar";
48
+ export { default as TabbarItem } from "./tabbar/item";
48
49
  export { default as Theme } from "./theme";
49
50
  export { default as ThemeColor } from "./theme/theme_color";
50
51
  export { default as DatePicker } from "./date_picker";
@@ -100,6 +101,7 @@ declare global {
100
101
  "l-polygon": import("./polygon").default
101
102
  "l-color-picker": import("./color_picker").default
102
103
  "l-tabbar": import("./tabbar").default
104
+ "l-tabbar-item": import("./tabbar/item").default
103
105
  "l-theme": import("./theme").default
104
106
  "l-theme-color": import("./theme/theme_color").default
105
107
  "l-date-picker": import("./date_picker").default
package/lib/index.js CHANGED
@@ -2,11 +2,11 @@ import { createTransition as t, getPopoverOffsetX as r, getPopoverOffsetY as a,
2
2
  import { set as c, remove as I } from "./utils/clickoutside.js";
3
3
  import { default as C } from "./base.js";
4
4
  import { default as h } from "./message/index.js";
5
- import { default as M } from "./popover/index.js";
6
- import { default as R } from "./popconfirm/index.js";
7
- import { default as k } from "./dialog/index.js";
8
- import { default as D } from "./dialog/dialog_container.js";
9
- import { default as b } from "./loading/index.js";
5
+ import { default as b } from "./popover/index.js";
6
+ import { default as P } from "./popconfirm/index.js";
7
+ import { default as S } from "./dialog/index.js";
8
+ import { default as k } from "./dialog/dialog_container.js";
9
+ import { default as D } from "./loading/index.js";
10
10
  import { default as L } from "./modal/index.js";
11
11
  import { default as B } from "./icon/base.js";
12
12
  import { default as G } from "./icon/arrow_down.js";
@@ -29,10 +29,10 @@ import { default as co } from "./icon/close.js";
29
29
  import { default as io } from "./icon/info.js";
30
30
  import { default as go } from "./icon/success.js";
31
31
  import { default as Ao } from "./icon/warn.js";
32
- import { default as Po } from "./icon/close_filled.js";
33
- import { default as So } from "./form/index.js";
34
- import { default as wo } from "./form/form_item.js";
35
- import { default as To } from "./check/radio_group.js";
32
+ import { default as Mo } from "./icon/close_filled.js";
33
+ import { default as Ro } from "./form/index.js";
34
+ import { default as To } from "./form/form_item.js";
35
+ import { default as wo } from "./check/radio_group.js";
36
36
  import { default as vo } from "./check/radio.js";
37
37
  import { default as Oo } from "./check/checkbox.js";
38
38
  import { default as Fo } from "./check/checkbox_group.js";
@@ -45,14 +45,15 @@ import { default as Ho } from "./list/index.js";
45
45
  import { default as Ko } from "./polygon/index.js";
46
46
  import { default as Qo } from "./color_picker/index.js";
47
47
  import { default as _o } from "./tabbar/index.js";
48
- import { default as oe } from "./theme/index.js";
49
- import { default as te } from "./theme/theme_color.js";
50
- import { default as ae } from "./date_picker/index.js";
51
- import { default as se } from "./menu/index.js";
52
- import { default as le } from "./menu/menu_item.js";
53
- import { default as pe } from "./menu/sub_menu.js";
54
- import { default as xe } from "./carousel/index.js";
55
- import { default as ce } from "./carousel/item.js";
48
+ import { default as oe } from "./tabbar/item.js";
49
+ import { default as te } from "./theme/index.js";
50
+ import { default as ae } from "./theme/theme_color.js";
51
+ import { default as se } from "./date_picker/index.js";
52
+ import { default as le } from "./menu/index.js";
53
+ import { default as pe } from "./menu/menu_item.js";
54
+ import { default as xe } from "./menu/sub_menu.js";
55
+ import { default as ce } from "./carousel/index.js";
56
+ import { default as ie } from "./carousel/item.js";
56
57
  export {
57
58
  G as ArrowDownIcon,
58
59
  U as ArrowLeftIcon,
@@ -63,48 +64,49 @@ export {
63
64
  yo as Button,
64
65
  E as CaretBottomIcon,
65
66
  q as CaretTopIcon,
66
- xe as Carousel,
67
- ce as CarouselItem,
67
+ ce as Carousel,
68
+ ie as CarouselItem,
68
69
  Oo as Checkbox,
69
70
  Fo as CheckboxGroup,
70
- Po as CloseFilledIcon,
71
+ Mo as CloseFilledIcon,
71
72
  co as CloseIcon,
72
73
  Qo as ColorPicker,
73
- ae as DatePicker,
74
- k as Dialog,
75
- D as DialogContainer,
74
+ se as DatePicker,
75
+ S as Dialog,
76
+ k as DialogContainer,
76
77
  J as FontIcon,
77
- So as Form,
78
- wo as FormItem,
78
+ Ro as Form,
79
+ To as FormItem,
79
80
  io as InfoIcon,
80
81
  Vo as Input,
81
82
  Ho as List,
82
- b as Loading,
83
+ D as Loading,
83
84
  N as LoadingIcon,
84
85
  zo as MdInput,
85
- se as Menu,
86
- le as MenuItem,
86
+ le as Menu,
87
+ pe as MenuItem,
87
88
  h as Message,
88
89
  L as Modal,
89
90
  eo as MoonIcon,
90
91
  Ko as Polygon,
91
- R as Popconfirm,
92
- M as Popover,
92
+ P as Popconfirm,
93
+ b as Popover,
93
94
  vo as Radio,
94
- To as RadioGroup,
95
+ wo as RadioGroup,
95
96
  ro as ReductionIcon,
96
97
  fo as RefreshLeftIcon,
97
98
  uo as RefreshRightIcon,
98
99
  Z as SearchIcon,
99
100
  Xo as SelectOri,
100
101
  mo as SortIcon,
101
- pe as SubMenu,
102
+ xe as SubMenu,
102
103
  go as SuccessIcon,
103
104
  $ as SunIcon,
104
105
  jo as Switch,
105
106
  _o as Tabbar,
106
- oe as Theme,
107
- te as ThemeColor,
107
+ oe as TabbarItem,
108
+ te as Theme,
109
+ ae as ThemeColor,
108
110
  xo as ThemeDefaultIcon,
109
111
  Ao as WarnIcon,
110
112
  c as addClickOutside,
@@ -1,9 +1,4 @@
1
1
  import BaseComponent from "../base";
2
- type TabbarItem = {
3
- name: string;
4
- text?: string | (() => string | HTMLElement);
5
- icon?: string | (() => string | HTMLElement);
6
- };
7
2
  export default class Tabbar extends BaseComponent {
8
3
  #private;
9
4
  static baseName: string;
@@ -17,26 +12,12 @@ export default class Tabbar extends BaseComponent {
17
12
  name?: string;
18
13
  gap?: string;
19
14
  private $line?;
20
- constructor();
21
15
  connectedCallback(): void;
22
16
  static get observedAttributes(): string[] | null | undefined;
23
17
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
24
- disconnectedCallback(): void;
25
18
  render(): any;
26
- /**
27
- * 设置选项卡栏的项目列表。
28
- * @param items - 选项卡栏项目的数组。
29
- * 该方法首先清空选项卡栏的包装器元素,然后根据传入的项目数组创建并追加新的选项卡项目。
30
- */
31
- setItems(items: TabbarItem[]): void;
32
- /**
33
- * 向标签栏添加项目。
34
- * @param items 要添加的标签栏项目数组。
35
- * @returns 无返回值。
36
- */
37
- addItems(items: TabbarItem[]): void;
38
- private _init;
39
- private _destroy;
19
+ afterInit(): void;
20
+ beforeDestroy(): void;
40
21
  private _handleClick;
41
22
  private _updateActive;
42
23
  /**
@@ -45,4 +26,3 @@ export default class Tabbar extends BaseComponent {
45
26
  */
46
27
  private _updateLine;
47
28
  }
48
- export {};
@@ -1,9 +1,9 @@
1
- import { isBlank as p, isNumeric as g } from "ph-utils";
2
- import v from "../base.js";
3
- import { initAttr as y, parseAttrValue as m } from "../utils/index.js";
4
- import { addClass as h, removeClass as f, $one as l, create as b, $ as u, iterate as x, on as $, off as C, shouldEventNext as k, isVisible as w, formatStyle as _, formatClass as A } from "ph-utils/dom";
5
- const L = ":host{--l-tabbar-hover-color: var(--l-primary-color-light1, #9254de);--l-tabbar-active-color: var(--l-primary-color, #722ed1);--l-tabbar-item-gap: 0;--l-tabbar-height: 38px;position:relative;overflow:hidden;height:var(--l-tabbar-height);background-color:#fff;display:block}.l-tabbar-wrapper{display:flex;flex-wrap:nowrap;height:100%;align-items:stretch;gap:var(--l-tabbar-item-gap)}.l-tabbar-item{color:#666;transition:all .3s ease-in-out;cursor:pointer;display:inline-flex;justify-content:center;align-items:center}.l-tabbar-item:hover{color:var(--l-tabbar-hover-color)}.l-tabbar-item.active{color:var(--l-tabbar-active-color)}.l-tabbar-item-icon{font-size:18px;margin-bottom:5px;display:flex;justify-content:center;align-items:center}.l-tabbar-item-icon.only{font-size:24px;margin-bottom:0}:host(.l-tabbar--nav){--l-tabbar-height: 50px;width:100%}:host(.l-tabbar--nav) .l-tabbar-item{flex-grow:1;display:inline-flex;flex-direction:column;justify-content:center;align-items:center;font-size:12px;line-height:1}:host(.l-tabbar--bar){--l-tabbar-bar-vertical-padding: 10px;--l-tabbar-item-gap: 30px;--l-tabbar-line-color: var(--l-primary-color, #722ed1);overflow:auto;white-space:nowrap}.l-tabbar--bar-line{position:absolute;width:32px;left:0;bottom:0;border-radius:1px;height:2px;background-color:var(--l-tabbar-line-color);transition:all .3s ease-in-out}:host(.l-tabbar--card){--l-tabbar-card-border-color: #f5f7fa;--l-tabbar-line-color: #fff;--l-tabbar-item-gap: 0;--l-tabbar-card-border-radius: 5px}.l-tabbar-card-border{position:absolute;left:0;right:0;bottom:0;height:1px;background-color:var(--l-tabbar-card-border-color)}:host(.l-tabbar--card) .l-tabbar-item{padding:0 15px;background:#f5f7fa;border:1px solid #f0f0f0}:host(.l-tabbar--card) .l-tabbar-item:first-child{border-top-left-radius:var(--l-tabbar-card-border-radius)}:host(.l-tabbar--card) .l-tabbar-item:last-child{border-top-right-radius:var(--l-tabbar-card-border-radius)}:host(.l-tabbar-gap) .l-tabbar-item{border-top-left-radius:var(--l-tabbar-card-border-radius);border-top-right-radius:var(--l-tabbar-card-border-radius)}:host(.l-tabbar--card) .l-tabbar-item.active{background:#fff}";
6
- class R extends v {
1
+ import { isBlank as h, isNumeric as c } from "ph-utils";
2
+ import d from "../base.js";
3
+ import { parseAttrValue as l } from "../utils/index.js";
4
+ import { addClass as b, removeClass as o, $one as r, create as n, $$ as p, on as f, off as m, shouldEventNext as u, isVisible as v } from "ph-utils/dom";
5
+ const g = ":host{--l-tabbar-hover-color: var(--l-primary-color-light1, #9254de);--l-tabbar-active-color: var(--l-primary-color, #722ed1);--l-tabbar-item-gap: 0;--l-tabbar-height: 38px;position:relative;overflow:hidden;height:var(--l-tabbar-height);background-color:#fff;display:flex;flex-wrap:nowrap;align-items:stretch;gap:var(--l-tabbar-item-gap);box-sizing:border-box}:host(.l-tabbar--nav){--l-tabbar-height: 50px;--l-tabbar-item-grow: 1;width:100%}:host(.l-tabbar--bar){--l-tabbar-bar-vertical-padding: 10px;--l-tabbar-item-gap: 30px;--l-tabbar-line-color: var(--l-primary-color, #722ed1);overflow:auto;white-space:nowrap}.l-tabbar--bar-line{position:absolute;width:32px;left:0;bottom:0;border-radius:1px;height:2px;background-color:var(--l-tabbar-line-color);transition:all .3s ease-in-out}:host(.l-tabbar--card){--l-tabbar-card-border-color: #f5f7fa;--l-tabbar-line-color: #fff;--l-tabbar-item-gap: 0;--l-tabbar-card-border-radius: 5px}.l-tabbar-card-border{position:absolute;left:0;right:0;bottom:0;height:1px;background-color:var(--l-tabbar-card-border-color)}";
6
+ class _ extends d {
7
7
  static baseName = "tabbar";
8
8
  /**
9
9
  * 标签类型:
@@ -15,96 +15,46 @@ class R extends v {
15
15
  name;
16
16
  gap;
17
17
  $line;
18
- constructor() {
19
- super(), y(this);
20
- }
21
18
  connectedCallback() {
22
- this.loadStyleText(L), h(this, `l-tabbar--${this.type}`), !p(this.gap) && !this.gap.startsWith("0") && h(this, "l-tabbar-gap"), super.connectedCallback(), this._init();
19
+ this.loadStyleText(g), b(this, `l-tabbar--${this.type}`), this.#t(), super.connectedCallback();
23
20
  }
24
21
  static get observedAttributes() {
25
22
  return ["name", "type", "justify-content", "gap"];
26
23
  }
27
- attributeChangedCallback(e, t, a) {
28
- if (e === "name") {
29
- const r = m(a, void 0);
30
- this.name = r, this._updateActive(), this._updateLine();
31
- } else if (e === "type") {
32
- const r = m(a, "nav");
33
- if (r !== this.type && (f(this, `l-tabbar--${this.type}`), this.type = r, f(this, `l-tabbar--${r}`), r === "card")) {
34
- let i = l(".l-tabbar-card-border", this.root);
35
- i || (i = b("div", { class: "l-tabbar-card-border" }), this.root.appendChild(i));
24
+ attributeChangedCallback(t, e, a) {
25
+ if (t === "name") {
26
+ const i = l(a, void 0);
27
+ this.name = i, this._updateActive(), this._updateLine();
28
+ } else if (t === "type") {
29
+ const i = l(a, "nav");
30
+ if (i !== this.type && (o(this, `l-tabbar--${this.type}`), this.type = i, o(this, `l-tabbar--${i}`), i === "card")) {
31
+ let s = r(".l-tabbar-card-border", this.root);
32
+ s || (s = n("div", { class: "l-tabbar-card-border" }), this.root.appendChild(s));
36
33
  }
37
34
  } else {
38
- const r = m(a, void 0);
39
- this[e] = r;
40
- const i = l(".l-tabbar-wrapper", this.root);
41
- i && (i.style.cssText = this.#t()), e === "gap" && (!p(this.gap) && !this.gap.startsWith("0") ? h(this, "l-tabbar-gap") : f(this, "l-tabbar-gap"));
35
+ const i = l(a, void 0);
36
+ this[t] = i, this.#t();
42
37
  }
43
38
  }
44
- disconnectedCallback() {
45
- super.disconnectedCallback(), this._destroy();
46
- }
47
39
  render() {
48
- const e = document.createDocumentFragment(), t = document.createElement("div");
49
- if (t.className = "l-tabbar-wrapper", t.style.cssText = this.#t(), t.setAttribute("part", "default"), this.getAttr("custom-content", !1)) {
50
- const r = document.createElement("slot");
51
- t.appendChild(r);
52
- } else {
53
- const r = u("[l-name]", this);
54
- r.length > 0 && x(r, (i) => {
55
- const c = i.getAttribute("l-name");
56
- if (c) {
57
- const o = i.cloneNode(!0);
58
- o.classList.add("l-tabbar-item"), o.setAttribute("part", "item"), c === this.name && o.classList.add("active");
59
- const n = l("[l-icon]", o), s = u(":not([l-icon])", o);
60
- if (n) {
61
- const d = b("div", {
62
- class: [
63
- "l-tabbar-item-icon",
64
- s.length === 0 ? "only" : void 0
65
- ]
66
- });
67
- d.appendChild(n.cloneNode(!0)), n.replaceWith(d);
68
- }
69
- t.appendChild(o);
70
- }
71
- });
72
- }
73
- if (e.appendChild(t), this.type === "card") {
74
- const r = b("div", { class: "l-tabbar-card-border" });
75
- e.appendChild(r);
40
+ const t = document.createDocumentFragment();
41
+ if (t.appendChild(p("slot")), this.type === "card") {
42
+ const e = n("div", { class: "l-tabbar-card-border" });
43
+ t.appendChild(e);
76
44
  }
77
- return e;
78
- }
79
- /**
80
- * 设置选项卡栏的项目列表。
81
- * @param items - 选项卡栏项目的数组。
82
- * 该方法首先清空选项卡栏的包装器元素,然后根据传入的项目数组创建并追加新的选项卡项目。
83
- */
84
- setItems(e) {
85
- const t = l(".l-tabbar-wrapper", this.root);
86
- t && (t.innerHTML = "", t.appendChild(this.#e(e)));
87
- }
88
- /**
89
- * 向标签栏添加项目。
90
- * @param items 要添加的标签栏项目数组。
91
- * @returns 无返回值。
92
- */
93
- addItems(e) {
94
- const t = l(".l-tabbar-wrapper", this.root);
95
- t && t.appendChild(this.#e(e));
45
+ return t;
96
46
  }
97
- _init() {
98
- $(this.root, "click", this._handleClick), setTimeout(() => {
47
+ afterInit() {
48
+ f(this.root, "click", this._handleClick), setTimeout(() => {
99
49
  this._updateLine();
100
50
  }, 300);
101
51
  }
102
- _destroy() {
103
- C(this.root, "click", this._handleClick), this.$line = void 0;
52
+ beforeDestroy() {
53
+ m(this.root, "click", this._handleClick), this.$line = void 0;
104
54
  }
105
- _handleClick = (e) => {
106
- const [t, a] = k(e, "l-name", this.root);
107
- t && a !== this.name && (this.name = a, this.dispatchEvent(
55
+ _handleClick = (t) => {
56
+ const [e, a] = u(t, "name", this);
57
+ e && a !== this.name && (this.name = a, console.log(a), this.dispatchEvent(
108
58
  new CustomEvent("change", {
109
59
  detail: {
110
60
  name: a
@@ -113,10 +63,10 @@ class R extends v {
113
63
  ), this._updateActive(), this._updateLine());
114
64
  };
115
65
  _updateActive() {
116
- const t = this.getAttr("custom-content", !1) ? this : this.root, a = l(".active", t);
117
- a && f(a, "active");
118
- const r = l(`[l-name="${this.name}"]`, t);
119
- r && h(r, "active");
66
+ const t = r(".active", this);
67
+ t && o(t, "active");
68
+ const e = r(`[name="${this.name}"]`, this);
69
+ e && b(e, "active");
120
70
  }
121
71
  /**
122
72
  * 初始化线条的方法,在微任务队列中执行。
@@ -125,53 +75,29 @@ class R extends v {
125
75
  _updateLine() {
126
76
  queueMicrotask(() => {
127
77
  if (!this.name || this.type === "nav" || !this.rendered) return;
128
- const e = this.getAttr("custom-content", !1), t = l(".active", e ? this : this.root);
78
+ const t = r(".active", this);
129
79
  if (!t) return;
130
- const a = t.offsetLeft;
80
+ const e = t.offsetLeft;
131
81
  if (!this.$line) {
132
- const r = b("div", { class: "l-tabbar--bar-line" });
133
- r.part = "line", this.root.appendChild(r), this.$line = l(".l-tabbar--bar-line", this.root);
82
+ const a = n("div", { class: "l-tabbar--bar-line" });
83
+ a.part = "line", this.root.appendChild(a), this.$line = r(".l-tabbar--bar-line", this.root);
134
84
  }
135
- this.$line.style.cssText = `width:${t.offsetWidth}px;left:${a}px`, w(t, this) || this.scrollTo({
136
- left: a,
85
+ this.$line.style.cssText = `width:${t.offsetWidth}px;left:${e}px`, v(t, this) || this.scrollTo({
86
+ left: e,
137
87
  behavior: "smooth"
138
88
  });
139
89
  });
140
90
  }
141
91
  #t() {
142
- const e = {}, t = this.getAttr("justify-content");
143
- if (p(t) || (e["justify-content"] = t), !p(this.gap)) {
144
- let a = this.gap;
145
- g(a, { isPositive: !0 }) && (a = `${a}px`), e["--l-tabbar-item-gap"] = a;
146
- }
147
- return _(e);
148
- }
149
- #e(e) {
150
- const t = document.createDocumentFragment();
151
- for (let a = 0, r = e.length; a < r; a++) {
152
- const i = e[a], c = b("div", {
153
- class: A([
154
- "l-tabbar-item",
155
- this.name === i.name ? "active" : void 0
156
- ]),
157
- "l-name": i.name,
158
- part: "item"
159
- }), o = i.icon;
160
- if (o) {
161
- const s = b("div", { class: "l-tabbar-item-icon" });
162
- let d = typeof o == "string" ? o : o();
163
- typeof d == "string" ? s.innerHTML = d : s.appendChild(d), c.appendChild(s);
164
- }
165
- const n = i.text;
166
- if (n) {
167
- let s = typeof n == "string" ? n : n();
168
- typeof s == "string" ? c.appendChild(b(s)) : c.appendChild(s);
169
- }
170
- t.appendChild(c);
92
+ const t = this.getAttr("justify-content");
93
+ if (h(t) ? this.style.removeProperty("justify-content") : this.style.setProperty("justify-content", t), h(this.gap))
94
+ this.style.removeProperty("--l-tabbar-item-gap"), o(this, "l-tabbar-gap");
95
+ else {
96
+ let e = this.gap;
97
+ c(e, { isPositive: !0 }) && (e = `${e}px`), b(this, "l-tabbar-gap"), this.style.setProperty("--l-tabbar-item-gap", e);
171
98
  }
172
- return t;
173
99
  }
174
100
  }
175
101
  export {
176
- R as default
102
+ _ as default
177
103
  };
@@ -0,0 +1,12 @@
1
+ import BaseComponent from "../base";
2
+ export default class TabbarItem extends BaseComponent {
3
+ #private;
4
+ static baseName: string;
5
+ name: string;
6
+ icon?: boolean;
7
+ onlyIcon?: boolean;
8
+ static get observedAttributes(): string[] | null | undefined;
9
+ connectedCallback(): void;
10
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
11
+ render(): DocumentFragment;
12
+ }
@@ -0,0 +1,58 @@
1
+ import l from "../base.js";
2
+ import { parseAttrValue as s } from "../utils/index.js";
3
+ import { addClass as i, $one as a, $$ as r, removeClass as c } from "ph-utils/dom";
4
+ const d = ":host{color:#666;transition:all .3s ease-in-out;cursor:pointer;display:inline-flex;justify-content:center;align-items:center;line-height:1;flex-direction:column;flex-grow:var(--l-tabbar-item-grow, 0);box-sizing:border-box}:host(:hover){color:var(--l-tabbar-hover-color)}:host(.active){color:var(--l-tabbar-active-color)}.icon-wrapper{font-size:18px;margin-bottom:3px;display:flex;justify-content:center;align-items:center}.icon-wrapper.only{font-size:24px;margin-bottom:0}:host(.l-item--card){padding:0 15px;background:#f5f7fa;border:1px solid #f0f0f0}:host(.l-item--card:first-child){border-top-left-radius:var(--l-tabbar-card-border-radius)}:host(.l-item--card:last-child){border-top-right-radius:var(--l-tabbar-card-border-radius)}:host(.l-item--card.active){background:#fff}:host(.l-item--gap){border-top-left-radius:var(--l-tabbar-card-border-radius);border-top-right-radius:var(--l-tabbar-card-border-radius)}";
5
+ class m extends l {
6
+ static baseName = "tabbar-item";
7
+ name;
8
+ icon;
9
+ onlyIcon;
10
+ static get observedAttributes() {
11
+ return ["name", "label", "icon", "only-icon"];
12
+ }
13
+ connectedCallback() {
14
+ this.loadStyleText(d), console.log(this.parentElement);
15
+ const t = this.parentElement;
16
+ t.gap && i(this, "l-item--gap"), t.type === "card" && i(this, "l-item--card"), super.connectedCallback();
17
+ }
18
+ attributeChangedCallback(t, o, e) {
19
+ if (t === "icon" || t === "only-icon") {
20
+ const n = s(e, !1, "icon");
21
+ this[t] = n, this.#t();
22
+ } else
23
+ this[t] = e;
24
+ }
25
+ #t() {
26
+ if (!this.rendered) return;
27
+ let t = a(".icon-wrapper", this.root);
28
+ this.icon ? t ? this.onlyIcon ? i(t, "only") : c(t, "only") : (t = r("div", {
29
+ class: ["icon-wrapper", this.onlyIcon ? "only" : ""],
30
+ innerHTML: "<slot name='icon'></slot>"
31
+ }), this.root.prepend(t)) : t && t.remove();
32
+ let o = a("slot:not([name])", this.root);
33
+ if (this.onlyIcon)
34
+ o && o.remove();
35
+ else if (!o) {
36
+ const e = r("slot");
37
+ this.root.appendChild(e);
38
+ }
39
+ }
40
+ render() {
41
+ const t = document.createDocumentFragment();
42
+ if (this.icon) {
43
+ const o = r("div", {
44
+ class: ["icon-wrapper", this.onlyIcon ? "only" : ""],
45
+ innerHTML: "<slot name='icon'></slot>"
46
+ });
47
+ t.appendChild(o);
48
+ }
49
+ if (!this.onlyIcon) {
50
+ const o = r("slot");
51
+ t.appendChild(o);
52
+ }
53
+ return t;
54
+ }
55
+ }
56
+ export {
57
+ m as default
58
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "litos-ui",
3
3
  "description": "基于 Web Component 的 UI 组件库",
4
- "version": "0.14.0",
4
+ "version": "0.15.0",
5
5
  "type": "module",
6
6
  "devDependencies": {
7
7
  "@eslint/js": "^9.25.0",