From 149a0bb1db25763650dbfa5f5041626429271e20 Mon Sep 17 00:00:00 2001 From: Stephen Niedzielski Date: Fri, 15 Dec 2017 19:03:45 -0600 Subject: [PATCH] New: add TypeScript definitions --- package.json | 1 + src/index.d.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/index.d.ts diff --git a/package.json b/package.json index 35c3733..32ac55c 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "url": "http://github.com/developit/preact-css-transition-group/issues" }, "license": "MIT", + "types": "src/index.d.ts", "devDependencies": { "babel-core": "^6.6.4", "babel-eslint": "^6.1.2", diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..c7145dd --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,58 @@ +declare module "preact-css-transition-group" { + import { + Component, + ComponentProps, + FunctionalComponent, + AnyComponent + } from "preact"; + + interface CSSTransitionGroupProps< + C extends Component | FunctionalComponent + > extends ComponentProps { + transitionName: string; + /** Defaults to true. */ + transitionEnter?: boolean; + /** Defaults to true. */ + transitionLeave?: boolean; + transitionEnterTimeout?: number; + transitionLeaveTimeout?: number; + + /** + * The Preact AnyComponent or DOM component string used to render the + * CSSTransitionGroup. Defaults to 'span'. + */ + component?: AnyComponent | string; + + /** + * Any additional properties specified on the CSSTransitionGroup will be + * passed to component. e.g.: + * + * ... children ... + * + * Will render as: + *
... children ...
+ */ + [name: string]: any; + } + + // todo: import from Preact instead pending + // https://github.com/developit/preact/pull/869. + type ComponentChild = JSX.Element | string; + type ComponentChildren = ComponentChild[]; + + interface CSSTransitionGroupState { + children: ComponentChildren; + } + + type Key = string | number | any; + + export default abstract class CSSTransitionGroup extends Component< + CSSTransitionGroupProps, + any + > { + performEnter(key: Key): void; + performLeave(key: Key): void; + stop(key: Key): void; + } +}