UNPKG

3.46 kBTypeScriptView Raw
1import { SetupContext, RenderFunction, ComponentPublicInstance } from 'vue'
2import { VXEComponent, VxeComponentBase, VxeEvent, SizeType, ValueOf } from './component'
3
4/* eslint-disable no-use-before-define */
5
6/**
7 * 组件 - 开关
8 * @example import { VxeSwitch } from 'vxe-table'
9 */
10export const VxeSwitch: VXEComponent<VxeSwitchProps, VxeSwitchEventProps, VxeSwitchSlots>
11/**
12 * 组件 - 开关
13 */
14export const Switch: typeof VxeSwitch
15
16export type VxeSwitchInstance = ComponentPublicInstance<VxeSwitchProps, VxeSwitchConstructor>
17
18export interface VxeSwitchConstructor extends VxeComponentBase, VxeSwitchMethods {
19 props: VxeSwitchProps
20 context: SetupContext<VxeSwitchEmits>
21 reactData: SwitchReactData
22 renderVN: RenderFunction
23}
24
25export interface SwitchReactData {
26 isActivated: boolean
27 hasAnimat: boolean
28 offsetLeft: number
29}
30
31export type VxeSwitchProps = {
32 size?: VxeSwitchPropTypes.Size
33 modelValue?: VxeSwitchPropTypes.ModelValue
34 disabled?: VxeSwitchPropTypes.Disabled
35 openLabel?: VxeSwitchPropTypes.OpenLabel
36 closeLabel?: VxeSwitchPropTypes.CloseLabel
37 openValue?: VxeSwitchPropTypes.OpenValue
38 closeValue?: VxeSwitchPropTypes.CloseValue
39 openIcon?: VxeSwitchPropTypes.OpenIcon
40 closeIcon?: VxeSwitchPropTypes.CloseIcon
41 openActiveIcon?: VxeSwitchPropTypes.OpenActiveIcon
42 closeActiveIcon?: VxeSwitchPropTypes.CloseActiveIcon
43}
44
45export namespace VxeSwitchPropTypes {
46 export type Size = SizeType
47 export type ModelValue = string | number | boolean
48 export type Disabled = boolean
49 export type OpenLabel = string
50 export type CloseLabel = string
51 export type OpenValue = string | number | boolean
52 export type CloseValue = string | number | boolean
53 export type OpenIcon = string
54 export type CloseIcon = string
55 export type OpenActiveIcon = string
56 export type CloseActiveIcon = string
57}
58
59export interface SwitchMethods {
60 dispatchEvent(type: ValueOf<VxeSwitchEmits>, params: any, evnt: Event): void
61 /**
62 * 获取焦点
63 */
64 focus(): Promise<any>
65 /**
66 * 失去焦点
67 */
68 blur(): Promise<any>
69}
70export interface VxeSwitchMethods extends SwitchMethods { }
71
72export interface SwitchPrivateMethods { }
73export interface VxeSwitchPrivateMethods extends SwitchPrivateMethods { }
74
75export type VxeSwitchEmits = [
76 'update:modelValue',
77 'change',
78 'focus',
79 'blur'
80]
81
82export namespace VxeSwitchDefines {
83 interface SwitchEventParams extends VxeEvent {
84 $switch: VxeSwitchConstructor
85 }
86
87 export interface ChangeEventParams extends SwitchEventParams { }
88 export interface FocusEventParams extends SwitchEventParams { }
89 export interface BlurEventParams extends SwitchEventParams { }
90}
91
92export type VxeSwitchEventProps = {
93 onChange?: VxeSwitchEvents.Change
94 onFocus?: VxeSwitchEvents.Focus
95 onBlur?: VxeSwitchEvents.Blur
96}
97
98export interface VxeSwitchListeners {
99 change?: VxeSwitchEvents.Change
100 focus?: VxeSwitchEvents.Focus
101 blur?: VxeSwitchEvents.Blur
102}
103
104export namespace VxeSwitchEvents {
105 export type Change = (params: VxeSwitchDefines.ChangeEventParams) => void
106 export type Focus = (params: VxeSwitchDefines.FocusEventParams) => void
107 export type Blur = (params: VxeSwitchDefines.BlurEventParams) => void
108}
109
110export interface VxeSwitchSlots {
111 /**
112 * 自定义插槽模板
113 */
114 [key: string]: ((params: {
115 [key: string]: any
116 }) => any) | undefined
117}