From 121e2de3758a14feed676ee81492acbe914221b2 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 29 Nov 2017 18:00:08 +0800 Subject: [PATCH] [Improvement] add type definition files (#361) --- package.json | 1 + packages/dialog/index.js | 3 ++ packages/mixins/popup/Modal.vue | 4 +- packages/toast/index.js | 4 +- types/component.d.ts | 3 ++ types/dialog.d.ts | 20 +++++++++ types/image-preview.d.ts | 12 ++++++ types/index.d.ts | 73 +++++++++++++++++++++++++++++++++ types/lazyload.d.ts | 7 ++++ types/mixins/popup.d.ts | 4 ++ types/toast.d.ts | 18 ++++++++ types/waterfall.d.ts | 8 ++++ 12 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 types/component.d.ts create mode 100644 types/dialog.d.ts create mode 100644 types/image-preview.d.ts create mode 100644 types/index.d.ts create mode 100644 types/lazyload.d.ts create mode 100644 types/mixins/popup.d.ts create mode 100644 types/toast.d.ts create mode 100644 types/waterfall.d.ts diff --git a/package.json b/package.json index 0585e85f3..88c765529 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "lib/vant.js", "style": "lib/vant-css/index.css", "unpkg": "lib/index.js", + "typings": "types/index.d.ts", "files": [ "lib", "src", diff --git a/packages/dialog/index.js b/packages/dialog/index.js index 1b9e04996..39b11aa8c 100644 --- a/packages/dialog/index.js +++ b/packages/dialog/index.js @@ -7,8 +7,11 @@ const defaultConfig = { value: true, title: '', message: '', + overlay: true, + lockOnScroll: true, confirmButtonText: '', cancelButtonText: '', + showConfirmButton: true, showCancelButton: false, closeOnClickOverlay: false, callback: action => { diff --git a/packages/mixins/popup/Modal.vue b/packages/mixins/popup/Modal.vue index a9c663a73..ad0092866 100644 --- a/packages/mixins/popup/Modal.vue +++ b/packages/mixins/popup/Modal.vue @@ -15,7 +15,7 @@ export default { props: { zIndex: Number, className: String, - customStyle: Object, + customStyle: Object }, computed: { @@ -23,7 +23,7 @@ export default { return { zIndex: this.zIndex, ...this.customStyle - } + }; } } }; diff --git a/packages/toast/index.js b/packages/toast/index.js index 9117458e1..f2a42f5ce 100644 --- a/packages/toast/index.js +++ b/packages/toast/index.js @@ -4,11 +4,11 @@ import VueToast from './toast'; let instance; const defaultOptions = { - visible: true, type: 'text', mask: false, - position: 'middle', + visible: true, duration: 3000, + position: 'middle', forbidClick: false, clear: () => { instance.visible = false; diff --git a/types/component.d.ts b/types/component.d.ts new file mode 100644 index 000000000..cba56dde6 --- /dev/null +++ b/types/component.d.ts @@ -0,0 +1,3 @@ +export class VanComponent { + static name: string; +} diff --git a/types/dialog.d.ts b/types/dialog.d.ts new file mode 100644 index 000000000..1405327d1 --- /dev/null +++ b/types/dialog.d.ts @@ -0,0 +1,20 @@ +export type DialogOptions = { + title?: string; + message?: string; + overlay?: boolean; + lockOnScroll?: boolean; + confirmButtonText?: string; + cancelButtonText?: string; + showConfirmButton?: boolean; + showCancelButton?: boolean; + closeOnClickOverlay?: boolean; +} + +export interface Dialog { + (options: DialogOptions): Promise; + alert(options: DialogOptions): Promise; + confirm(options: DialogOptions): Promise; + close(): void; +} + +export const Dialog: Dialog; diff --git a/types/image-preview.d.ts b/types/image-preview.d.ts new file mode 100644 index 000000000..6260d9752 --- /dev/null +++ b/types/image-preview.d.ts @@ -0,0 +1,12 @@ +import { VanPopupMixin } from './mixins/popup'; + +export class VanImagePreview extends VanPopupMixin { + images: string[]; + startPosition: number; +} + +export interface ImagePreview { + (images: string[], startPosition?: number): VanImagePreview; +} + +export const ImagePreview: ImagePreview; diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 000000000..c84daa30a --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,73 @@ +import Vue from 'vue'; +import { VanComponent } from './component'; +import { Toast } from './toast'; +import { Dialog } from './dialog'; +import { Lazyload } from './lazyload'; +import { Waterfall } from './waterfall'; +import { ImagePreview } from './image-preview'; + +export const version: string +export function install (vue: typeof Vue): void +export class Actionsheet extends VanComponent {} +export class AddressEdit extends VanComponent {} +export class AddressList extends VanComponent {} +export class Area extends VanComponent {} +export class Badge extends VanComponent {} +export class BadgeGroup extends VanComponent {} +export class Button extends VanComponent {} +export class Card extends VanComponent {} +export class Cell extends VanComponent {} +export class CellGroup extends VanComponent {} +export class CellSwipe extends VanComponent {} +export class Checkbox extends VanComponent {} +export class CheckboxGroup extends VanComponent {} +export class Col extends VanComponent {} +export class ContactCard extends VanComponent {} +export class ContactEdit extends VanComponent {} +export class ContactList extends VanComponent {} +export class CouponCell extends VanComponent {} +export class CouponList extends VanComponent {} +export class DatetimePicker extends VanComponent {} +export class Field extends VanComponent {} +export class GoodsAction extends VanComponent {} +export class GoodsActionBigBtn extends VanComponent {} +export class GoodsActionMiniBtn extends VanComponent {} +export class Icon extends VanComponent {} +export class Loading extends VanComponent {} +export class NavBar extends VanComponent {} +export class NoticeBar extends VanComponent {} +export class NumberKeyboard extends VanComponent {} +export class Pagination extends VanComponent {} +export class Panel extends VanComponent {} +export class PasswordInput extends VanComponent {} +export class Picker extends VanComponent {} +export class Popup extends VanComponent {} +export class Progress extends VanComponent {} +export class PullRefresh extends VanComponent {} +export class Radio extends VanComponent {} +export class RadioGroup extends VanComponent {} +export class Row extends VanComponent {} +export class Search extends VanComponent {} +export class Sku extends VanComponent {} +export class Step extends VanComponent {} +export class Stepper extends VanComponent {} +export class Steps extends VanComponent {} +export class SubmitBar extends VanComponent {} +export class Swipe extends VanComponent {} +export class SwipeItem extends VanComponent {} +export class Switch extends VanComponent {} +export class SwitchCell extends VanComponent {} +export class Tab extends VanComponent {} +export class Tabbar extends VanComponent {} +export class TabbarItem extends VanComponent {} +export class Tabs extends VanComponent {} +export class Tag extends VanComponent {} +export class TreeSelect extends VanComponent {} +export class Uploader extends VanComponent {} +export { + Toast, + Dialog, + Lazyload, + Waterfall, + ImagePreview +} diff --git a/types/lazyload.d.ts b/types/lazyload.d.ts new file mode 100644 index 000000000..11baba3e8 --- /dev/null +++ b/types/lazyload.d.ts @@ -0,0 +1,7 @@ +import Vue, { PluginFunction } from 'vue'; + +export interface Lazyload { + install: PluginFunction +} + +export const Lazyload: Lazyload; diff --git a/types/mixins/popup.d.ts b/types/mixins/popup.d.ts new file mode 100644 index 000000000..5d225340a --- /dev/null +++ b/types/mixins/popup.d.ts @@ -0,0 +1,4 @@ +export class VanPopupMixin { + open(): void; + close(): void; +} diff --git a/types/toast.d.ts b/types/toast.d.ts new file mode 100644 index 000000000..28896e3ff --- /dev/null +++ b/types/toast.d.ts @@ -0,0 +1,18 @@ +export type ToastOptions = { + type?: string; + mask?: boolean; + message?: string; + position?: string; + duration?: number; + forbidClick?: boolean; +} + +export interface Toast { + (message: ToastOptions | string, options?: ToastOptions): void; + loading(options?: ToastOptions): void; + success(options?: ToastOptions): void; + fail(options?: ToastOptions): void; + clear(): void; +} + +export const Toast: Toast; diff --git a/types/waterfall.d.ts b/types/waterfall.d.ts new file mode 100644 index 000000000..412a7d634 --- /dev/null +++ b/types/waterfall.d.ts @@ -0,0 +1,8 @@ +import Vue, { DirectiveFunction, PluginFunction } from 'vue'; + +export interface Waterfall { + (type: string): DirectiveFunction; + install: PluginFunction +} + +export const Waterfall: Waterfall;