@gzmjs/button 0.1.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.
- package/dist/010-btn/00-btnBase.d.ts +39 -0
- package/dist/010-btn/03-btnClick.d.ts +18 -0
- package/dist/010-btn/06-btnLink.d.ts +19 -0
- package/dist/010-btn/09-btnCheck.d.ts +21 -0
- package/dist/010-btn/12-btnRadio.d.ts +33 -0
- package/dist/010-btn/20-btnText.d.ts +30 -0
- package/dist/010-btn/23-btnNum.d.ts +27 -0
- package/dist/010-btn/26-btnDate.d.ts +29 -0
- package/dist/010-btn/29-btnMenu.d.ts +24 -0
- package/dist/010-btn/50-btnGroup.d.ts +54 -0
- package/dist/010-btn/53-btnBar.d.ts +18 -0
- package/dist/button.es.js +1139 -0
- package/dist/button.es.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/package.json +31 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Badge, Icon } from '@gzmjs/ui-basic';
|
|
2
|
+
import { ViewModel, ViewElement } from '@gzmjs/mvvm';
|
|
3
|
+
export declare const styleSheet: CSSStyleSheet;
|
|
4
|
+
export interface BtnOptions<E extends BtnBase<BtnOptions<E>>> extends ViewModel<E> {
|
|
5
|
+
label?: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
iconOnly?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class BtnBase<T extends BtnOptions<BtnBase<T>>> extends ViewElement<T> {
|
|
10
|
+
constructor(noShadow?: boolean);
|
|
11
|
+
protected $ele: HTMLElement;
|
|
12
|
+
protected $ipt?: HTMLInputElement;
|
|
13
|
+
protected $lbl?: HTMLElement;
|
|
14
|
+
protected $icn?: Icon;
|
|
15
|
+
protected $bdg?: Badge;
|
|
16
|
+
/**
|
|
17
|
+
* 以下所有的 create* 方法都是直接或者间接在构造函数中调用。
|
|
18
|
+
* 所以不应该判断 attributes 的值。
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* 生成 thie.$ele,由子类重写。
|
|
22
|
+
* 只在构造函数中调用一次。
|
|
23
|
+
*/
|
|
24
|
+
protected abstract createButton(): HTMLElement;
|
|
25
|
+
protected _createInputFirst(inputType: string): HTMLElement;
|
|
26
|
+
protected _createInputLast(inputType: string): HTMLElement;
|
|
27
|
+
protected _createLabel($ele: HTMLElement): void;
|
|
28
|
+
protected _createIcon($ele: HTMLElement): void;
|
|
29
|
+
protected _createInput(inputType: string, $ele: HTMLElement): HTMLInputElement;
|
|
30
|
+
protected _iptChanged(): void;
|
|
31
|
+
accessor label: string | undefined;
|
|
32
|
+
accessor icon: string | undefined;
|
|
33
|
+
accessor iconOnly: boolean;
|
|
34
|
+
accessor badge: string | undefined;
|
|
35
|
+
_label_set(newval: string | null): void;
|
|
36
|
+
_icon_set(newval: string | null): void;
|
|
37
|
+
_icon_only_set(): void;
|
|
38
|
+
_badge_set(newval: string | null): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AttributeHandlers } from '@gzmjs/ui-basic';
|
|
2
|
+
import * as BTN from './00-btnBase';
|
|
3
|
+
export declare const tagName = "GZM-BTN-CLICK";
|
|
4
|
+
declare global {
|
|
5
|
+
interface HTMLElementTagNameMap {
|
|
6
|
+
[tagName]: ClickButton;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface ClickBtnOptions extends BTN.BtnOptions<ClickButton> {
|
|
10
|
+
readonly tag?: 'click';
|
|
11
|
+
badge?: string;
|
|
12
|
+
onclick?: (this: ClickBtnOptions, ev: MouseEvent, vm: ClickBtnOptions) => unknown;
|
|
13
|
+
}
|
|
14
|
+
declare const mutableAttributes: readonly ["label", "icon", "icon-only", "badge"];
|
|
15
|
+
export declare class ClickButton extends BTN.BtnBase<ClickBtnOptions> implements AttributeHandlers<typeof mutableAttributes[number]> {
|
|
16
|
+
protected createButton(): HTMLElement;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as BTN from './00-btnBase';
|
|
2
|
+
export declare const tagName = "GZM-BTN-LINK";
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
[tagName]: LinkButton;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface LinkBtnOptions extends BTN.BtnOptions<LinkButton> {
|
|
9
|
+
readonly tag?: 'link';
|
|
10
|
+
badge?: string;
|
|
11
|
+
href: string;
|
|
12
|
+
target?: string;
|
|
13
|
+
onclick?: (this: LinkBtnOptions, ev: MouseEvent, vm: LinkBtnOptions) => unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare class LinkButton extends BTN.BtnBase<LinkBtnOptions> {
|
|
16
|
+
protected createButton(): HTMLElement;
|
|
17
|
+
accessor href: string | undefined;
|
|
18
|
+
accessor target: string | undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AttributeHandlers } from '@gzmjs/ui-basic';
|
|
2
|
+
import * as BTN from './00-btnBase';
|
|
3
|
+
export declare const tagName = "GZM-BTN-CHECK";
|
|
4
|
+
declare global {
|
|
5
|
+
interface HTMLElementTagNameMap {
|
|
6
|
+
[tagName]: CheckButton;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface CheckBtnOptions extends BTN.BtnOptions<CheckButton> {
|
|
10
|
+
readonly tag?: 'check';
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
onclick?: (this: CheckBtnOptions, ev: MouseEvent, vm: CheckBtnOptions) => unknown;
|
|
13
|
+
}
|
|
14
|
+
declare const mutableAttributes: readonly ["label", "icon", "icon-only"];
|
|
15
|
+
export declare class CheckButton extends BTN.BtnBase<CheckBtnOptions> implements AttributeHandlers<typeof mutableAttributes[number]> {
|
|
16
|
+
protected createButton(): HTMLElement;
|
|
17
|
+
protected _iptChanged(): void;
|
|
18
|
+
get checked(): boolean;
|
|
19
|
+
set checked(v: boolean);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AttributeHandlers } from '@gzmjs/ui-basic';
|
|
2
|
+
import * as BTN from './00-btnBase';
|
|
3
|
+
/**
|
|
4
|
+
* 此组件不宜单独使用,应该配合 btnGroup 使用。原因有2:
|
|
5
|
+
* 1 - <input type=radio> 在各自的 shadow dom 中,即使 name 属性相同,也不会形成一个互斥组。
|
|
6
|
+
* 所以只能不使用 shadow dom,封装性被破坏。
|
|
7
|
+
* 2 - radio 的特性:单个 radio 选中后就无法取消选中,没有实用价值。
|
|
8
|
+
*/
|
|
9
|
+
export declare const tagName = "GZM-BTN-RADIO";
|
|
10
|
+
declare global {
|
|
11
|
+
interface HTMLElementTagNameMap {
|
|
12
|
+
[tagName]: RadioButton;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export interface RadioBtnOptions extends BTN.BtnOptions<RadioButton> {
|
|
16
|
+
readonly tag?: 'radio';
|
|
17
|
+
checked?: boolean;
|
|
18
|
+
onclick?: (this: RadioBtnOptions, ev: MouseEvent, vm: RadioBtnOptions) => unknown;
|
|
19
|
+
}
|
|
20
|
+
declare const mutableAttributes: readonly ["label", "icon", "icon-only"];
|
|
21
|
+
/**
|
|
22
|
+
* 因为没有使用 shadow,所以需要输出 .gzm-btn 的样式定义。
|
|
23
|
+
* 这样就允许网页上的任意一个按钮使用 .gzm-btn 类名,就会获得相同的样式。
|
|
24
|
+
*/
|
|
25
|
+
export declare class RadioButton extends BTN.BtnBase<RadioBtnOptions> implements AttributeHandlers<typeof mutableAttributes[number]> {
|
|
26
|
+
constructor();
|
|
27
|
+
connectedCallback(): void;
|
|
28
|
+
protected createButton(): HTMLElement;
|
|
29
|
+
protected _iptChanged(): void;
|
|
30
|
+
get checked(): boolean;
|
|
31
|
+
set checked(v: boolean);
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as BTN from './00-btnBase';
|
|
2
|
+
export declare const tagName = "GZM-BTN-TEXT";
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
[tagName]: TextButton;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface TextBtnOptions extends BTN.BtnOptions<TextButton> {
|
|
9
|
+
readonly tag?: 'text';
|
|
10
|
+
type?: 'text' | 'tel' | 'url' | 'email' | 'search' | 'password';
|
|
11
|
+
maxlength?: number;
|
|
12
|
+
minlength?: number;
|
|
13
|
+
pattern?: string;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
value?: string;
|
|
17
|
+
onclick?: (this: TextBtnOptions, ev: MouseEvent, vm: TextBtnOptions) => unknown;
|
|
18
|
+
}
|
|
19
|
+
export declare class TextButton extends BTN.BtnBase<TextBtnOptions> {
|
|
20
|
+
protected createButton(): HTMLElement;
|
|
21
|
+
protected _iptChanged(): void;
|
|
22
|
+
accessor type: string | undefined;
|
|
23
|
+
accessor maxlength: number | undefined;
|
|
24
|
+
accessor minlength: number | undefined;
|
|
25
|
+
accessor pattern: string | undefined;
|
|
26
|
+
accessor placeholder: string | undefined;
|
|
27
|
+
accessor size: number | undefined;
|
|
28
|
+
get value(): string;
|
|
29
|
+
set value(v: string);
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as BTN from './00-btnBase';
|
|
2
|
+
export declare const tagName = "GZM-BTN-NUM";
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
[tagName]: NumButton;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface NumBtnOptions extends BTN.BtnOptions<NumButton> {
|
|
9
|
+
readonly tag?: 'num';
|
|
10
|
+
type?: 'number';
|
|
11
|
+
max?: string;
|
|
12
|
+
min?: string;
|
|
13
|
+
step?: string;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
value?: number;
|
|
16
|
+
onclick?: (this: NumBtnOptions, ev: MouseEvent, vm: NumBtnOptions) => unknown;
|
|
17
|
+
}
|
|
18
|
+
export declare class NumButton extends BTN.BtnBase<NumBtnOptions> {
|
|
19
|
+
protected createButton(): HTMLElement;
|
|
20
|
+
protected _iptChanged(): void;
|
|
21
|
+
accessor max: string | undefined;
|
|
22
|
+
accessor min: string | undefined;
|
|
23
|
+
accessor step: string | undefined;
|
|
24
|
+
accessor placeholder: string | undefined;
|
|
25
|
+
get value(): number;
|
|
26
|
+
set value(v: number);
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as BTN from './00-btnBase';
|
|
2
|
+
export declare const tagName = "GZM-BTN-DATE";
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
[tagName]: DateButton;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface DateBtnOptions extends BTN.BtnOptions<DateButton> {
|
|
9
|
+
readonly tag?: 'date';
|
|
10
|
+
type?: 'date' | 'datetime-local' | 'time' | 'week' | 'month';
|
|
11
|
+
max?: string;
|
|
12
|
+
min?: string;
|
|
13
|
+
step?: string;
|
|
14
|
+
value?: string;
|
|
15
|
+
onclick?: (this: DateBtnOptions, ev: MouseEvent, vm: DateBtnOptions) => unknown;
|
|
16
|
+
}
|
|
17
|
+
export declare class DateButton extends BTN.BtnBase<DateBtnOptions> {
|
|
18
|
+
protected createButton(): HTMLElement;
|
|
19
|
+
protected _iptChanged(): void;
|
|
20
|
+
accessor type: string | undefined;
|
|
21
|
+
accessor max: string | undefined;
|
|
22
|
+
accessor min: string | undefined;
|
|
23
|
+
accessor step: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* 考虑过使用 <input>.valueAsDate 属性,但是在 type=datetime-local 时发生异常
|
|
26
|
+
*/
|
|
27
|
+
get value(): string;
|
|
28
|
+
set value(v: string);
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AttributeHandlers } from '@gzmjs/ui-basic';
|
|
2
|
+
import { MiOptions } from '@gzmjs/menu';
|
|
3
|
+
import * as BTN from './00-btnBase';
|
|
4
|
+
export declare const tagName = "GZM-BTN-MENU";
|
|
5
|
+
declare global {
|
|
6
|
+
interface HTMLElementTagNameMap {
|
|
7
|
+
[tagName]: MenuButton;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface MenuBtnOptions extends BTN.BtnOptions<MenuButton> {
|
|
11
|
+
readonly tag?: 'menu';
|
|
12
|
+
badge?: string;
|
|
13
|
+
subItems?: MiOptions[];
|
|
14
|
+
/**
|
|
15
|
+
* 如果没有设置 subItems,那么就会调用此函数来获得菜单。
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
beforeShowMenu?: () => MiOptions[];
|
|
19
|
+
}
|
|
20
|
+
declare const mutableAttributes: readonly ["label", "icon", "icon-only", "badge"];
|
|
21
|
+
export declare class MenuButton extends BTN.BtnBase<MenuBtnOptions> implements AttributeHandlers<typeof mutableAttributes[number]> {
|
|
22
|
+
protected createButton(): HTMLElement;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AttributeHandlers } from '@gzmjs/ui-basic';
|
|
2
|
+
import { ViewListModel, ViewListElement } from '@gzmjs/mvvm';
|
|
3
|
+
import { CheckBtnOptions } from './09-btnCheck';
|
|
4
|
+
import { ClickBtnOptions } from './03-btnClick';
|
|
5
|
+
import { DateBtnOptions } from './26-btnDate';
|
|
6
|
+
import { LinkBtnOptions } from './06-btnLink';
|
|
7
|
+
import { MenuBtnOptions } from './29-btnMenu';
|
|
8
|
+
import { NumBtnOptions } from './23-btnNum';
|
|
9
|
+
import { RadioBtnOptions } from './12-btnRadio';
|
|
10
|
+
import { TextBtnOptions } from './20-btnText';
|
|
11
|
+
import * as BB from './00-btnBase';
|
|
12
|
+
export type AllBtnOptions = ClickBtnOptions | LinkBtnOptions | CheckBtnOptions | RadioBtnOptions | TextBtnOptions | NumBtnOptions | DateBtnOptions | MenuBtnOptions;
|
|
13
|
+
/**
|
|
14
|
+
* 当在 btn-bar 中且有许多按钮,导致无法在一行中显示的时候,就需要折叠按钮组。
|
|
15
|
+
* 一开始是正常状态:normal,每一个按钮都按 AllBtnOptions 的设置显示。
|
|
16
|
+
* 调用 fold() 开始折叠,从 normal -> icon-only,即只要有 icon,就强制设置 icon-only。
|
|
17
|
+
* 从 icon-only -> menu-btn,即只显示一个按钮,其他按钮都作为菜单项,点击后才显示。
|
|
18
|
+
* 由于菜单项只能是 click | link | check | radio,所以只有这 4 种按钮可以折叠。
|
|
19
|
+
*/
|
|
20
|
+
declare const foldStates: readonly ["normal", "icon-only", "menu-btn"];
|
|
21
|
+
type FoldStateType = typeof foldStates[number];
|
|
22
|
+
export declare const btnBarAlign: readonly ["left", "center", "right"];
|
|
23
|
+
type BtnBarAlign = typeof btnBarAlign[number];
|
|
24
|
+
export declare const tagName = "GZM-BTN-GROUP";
|
|
25
|
+
export interface BtnGroupOptions extends ViewListModel<AllBtnOptions, BB.BtnBase<AllBtnOptions>, BtnGroup> {
|
|
26
|
+
/**
|
|
27
|
+
* 缩成一个 btn-menu 时显示的文本
|
|
28
|
+
*/
|
|
29
|
+
label?: string;
|
|
30
|
+
/**
|
|
31
|
+
* 在 btn-bar 中使用时对应的 slot.name
|
|
32
|
+
*/
|
|
33
|
+
slot: BtnBarAlign;
|
|
34
|
+
/**
|
|
35
|
+
* 折叠状态
|
|
36
|
+
*/
|
|
37
|
+
foldState?: FoldStateType;
|
|
38
|
+
}
|
|
39
|
+
declare const mutableAttributes: readonly ["fold-state"];
|
|
40
|
+
export declare class BtnGroup extends ViewListElement<AllBtnOptions, BB.BtnBase<AllBtnOptions>, BtnGroupOptions> implements AttributeHandlers<typeof mutableAttributes[number]> {
|
|
41
|
+
#private;
|
|
42
|
+
constructor();
|
|
43
|
+
readonly shadowRoot: ShadowRoot;
|
|
44
|
+
protected _getViewItemTagName(options: AllBtnOptions): string;
|
|
45
|
+
accessor foldState: FoldStateType;
|
|
46
|
+
_fold_state_set(nv: string | null): void;
|
|
47
|
+
unfold(): boolean;
|
|
48
|
+
fold(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 判断是否可以处于某一个折叠状态
|
|
51
|
+
*/
|
|
52
|
+
private canFold2State;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ViewListModel, ViewListElement } from '@gzmjs/mvvm';
|
|
2
|
+
import { BtnGroupOptions, BtnGroup } from './50-btnGroup';
|
|
3
|
+
export declare const tagName = "GZM-BTN-BAR";
|
|
4
|
+
declare global {
|
|
5
|
+
interface HTMLElementTagNameMap {
|
|
6
|
+
[tagName]: BtnBar;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface BtnBarOptions extends ViewListModel<BtnGroupOptions, BtnGroup, BtnBar> {
|
|
10
|
+
tagName?: typeof tagName;
|
|
11
|
+
}
|
|
12
|
+
export declare class BtnBar extends ViewListElement<BtnGroupOptions, BtnGroup, BtnBarOptions> {
|
|
13
|
+
#private;
|
|
14
|
+
constructor();
|
|
15
|
+
protected _getViewItemTagName(): string;
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
18
|
+
}
|