Skip to content

Commit

Permalink
feat(types): Expose component props and emits types
Browse files Browse the repository at this point in the history
  • Loading branch information
MorevM committed Sep 10, 2022
1 parent 51864f3 commit e7f1ce1
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/exports-last */
import type { PluginObject } from 'vue';

// Helpers
Expand Down Expand Up @@ -81,6 +82,83 @@ type CommonProps = {
noMove: boolean;
};

export type Emits = {
/**
* Called before the element is inserted into the DOM.
*
* @param el Animated element(s).
*
* @returns Nothing.
*/
onBeforeEnter: (el: HTMLElement) => void;

/**
* Called one frame after the element is inserted.
*
* @param el Animated element(s).
* @param done Callback function used to indicate transition end.
*
* @returns Nothing.
*/
onEnter: (el: HTMLElement, done: () => void) => void;

/**
* Called when the enter transition has finished.
*
* @param el Animated element(s).
*
* @returns Nothing.
*/
onAfterEnter: (el: HTMLElement) => void;

/**
* Called if the enter transition was cancelled.
*
* @param el Animated element(s).
*
* @returns Nothing.
*/
onEnterCancelled: (el: HTMLElement) => void;

/**
* Called before the leave hook.
*
* @param el Animated element(s).
*
* @returns Nothing.
*/
onBeforeLeave: (el: HTMLElement) => void;

/**
* Called when the leave transition starts.
*
* @param el Animated element(s).
* @param done Callback function used to indicate transition end.
*
* @returns Nothing.
*/
onLeave: (el: HTMLElement, done: () => void) => void;

/**
* Called when the leave transition has finished and the element has been removed from the DOM.
*
* @param el Animated element(s).
*
* @returns Nothing.
*/
onAfterLeave: (el: HTMLElement) => void;

/**
* Called if the leave transition was cancelled. \
* Only available with `v-show` transitions
*
* @param el Animated element(s).
*
* @returns Nothing.
*/
onLeaveCancelled: (el: HTMLElement) => void;
};

// Unique props
type PropExpandAxisValue = 'x' | 'y';
type PropSlideOffsetValue = [number | string, number | string];
Expand Down Expand Up @@ -134,13 +212,20 @@ type UniqueProps = {
};
};

type ComponentProps = {
export type ComponentProps = {
TransitionFade: CommonProps;
TransitionExpand: CommonProps & UniqueProps['TransitionExpand'];
TransitionSlide: CommonProps & UniqueProps['TransitionSlide'];
TransitionScale: CommonProps & UniqueProps['TransitionScale'];
};

export type ComponentPropsAndEmits = {
TransitionFade: CommonProps & Emits;
TransitionExpand: CommonProps & UniqueProps['TransitionExpand'] & Emits;
TransitionSlide: CommonProps & UniqueProps['TransitionSlide'] & Emits;
TransitionScale: CommonProps & UniqueProps['TransitionScale'] & Emits;
};

type PluginOptions = Partial<{
/**
* Components for global registration. \
Expand Down

0 comments on commit e7f1ce1

Please sign in to comment.