Skip to content

Commit

Permalink
feat: add close
Browse files Browse the repository at this point in the history
  • Loading branch information
unliar committed Jul 9, 2021
1 parent 084010b commit 9374d7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/components/common/Message/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import type {
MessageInstance,
Options,
InstanceComponent,
IntanceOptions,
InstanceOptions,
InstanceHandle,
} from "./type";

const isServer = typeof window === "undefined";

const Queqe: InstanceQueqe = [];
let seed = 5201414;
const Message: MessageInstance = (opts: IntanceOptions) => {
const Message: MessageInstance = (opts: InstanceOptions) => {
if (isServer) return;
let options: Options = {
content: "",
Expand Down Expand Up @@ -60,7 +61,7 @@ const Message: MessageInstance = (opts: IntanceOptions) => {
close: () => {
(vm.component?.proxy as InstanceComponent).visible = false;
},
};
} as InstanceHandle;
};

Message.closeAll = () => {
Expand All @@ -71,7 +72,7 @@ Message.closeAll = () => {
};

(["success", "warn", "info", "error"] as const).forEach(type => {
Message[type] = (options: IntanceOptions) => {
Message[type] = (options: InstanceOptions) => {
if (typeof options === "string") {
options = {
content: options,
Expand Down
18 changes: 11 additions & 7 deletions src/components/common/Message/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { VNode, ComponentPublicInstance } from "vue";
export type MessageType = "warn" | "error" | "success" | "info";

export type MessageInstance = {
(opt: IntanceOptions): void;
warn(opt: IntanceOptions): void;
error(opt: IntanceOptions): void;
success(opt: IntanceOptions): void;
info(opt: IntanceOptions): void;
closeAll(): void;
(opt?: InstanceOptions): InstanceHandle;
warn: (opt: InstanceOptions) => InstanceHandle;
error: (opt: InstanceOptions) => InstanceHandle;
success: (opt: InstanceOptions) => InstanceHandle;
info: (opt: InstanceOptions) => InstanceHandle;
closeAll: () => void;
};

export type Options = {
Expand All @@ -25,4 +25,8 @@ export type InstanceComponent = ComponentPublicInstance<{ visible: boolean }>;

export type InstanceQueqe = Array<VNode>;

export type IntanceOptions = Options | string;
export type InstanceOptions = Options | string;

export interface InstanceHandle {
close: () => void;
}

0 comments on commit 9374d7a

Please sign in to comment.