Skip to content

Commit 9ba51d4

Browse files
committed
add d.ts
1 parent 9bdc5d6 commit 9ba51d4

File tree

10 files changed

+222
-5
lines changed

10 files changed

+222
-5
lines changed

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-scroll-anim",
3-
"version": "2.5.5",
3+
"version": "2.5.6",
44
"description": "scroll-anim anim component for react",
55
"keywords": [
66
"react",
@@ -31,7 +31,8 @@
3131
"lib",
3232
"assets/*.css",
3333
"dist",
34-
"es"
34+
"es",
35+
"typings"
3536
],
3637
"licenses": "MIT",
3738
"main": "./lib/index",
@@ -60,15 +61,18 @@
6061
"coverage": "rc-test run coverage"
6162
},
6263
"devDependencies": {
64+
"@types/react": "^16.0.0",
6365
"core-js": "^2.5.1",
6466
"expect.js": "0.3.x",
6567
"pre-commit": "1.x",
68+
"precommit-hook": "1.x",
6669
"rc-test": "6.x",
6770
"rc-tools": "6.x",
6871
"react": "^16.0.0",
6972
"react-dom": "^16.0.0",
7073
"rc-animate": "2.x",
71-
"rc-queue-anim": "^1.3.0"
74+
"rc-queue-anim": "^1.3.0",
75+
"typescript": "3.x"
7276
},
7377
"pre-commit": [
7478
"lint"
@@ -77,7 +81,8 @@
7781
"babel-runtime": "6.x",
7882
"prop-types": "^15.6.0",
7983
"raf": "3.x",
80-
"rc-tween-one": "^2.1.0",
84+
"rc-tween-one": "^2.2.0",
8185
"tween-functions": "1.x"
82-
}
86+
},
87+
"types": "typings/index.d.ts"
8388
}

src/EventDispatcher.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
type ICallback = (e?: { type: string, target: HTMLElement }) => void;
2+
export default class EventDispatcher {
3+
static addEventListener(
4+
type: string,
5+
callback: ICallback,
6+
target: HTMLElement
7+
): void;
8+
static removeEventListener(
9+
type: string,
10+
callback: ICallback,
11+
target: HTMLElement,
12+
force?: boolean
13+
): void;
14+
static removeAllType(type: string, target: HTMLElement): void;
15+
static reAllType(type: string, target: HTMLElement): void
16+
}

src/ScrollElement.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from 'react';
2+
3+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
4+
5+
export declare type IPlayScaleType = number | string | [number | string, number | string];
6+
7+
export declare type IChangeCallBackype = { mode: 'enter' | 'leave', id: string };
8+
9+
export declare type IScrollCallBackype = { id: string, domEvent: Event, scrollTop: number, offsetTop: number, showHeight: number };
10+
11+
export interface IProps<T> extends Omit<React.HTMLAttributes<T>, 'onChange' | 'onScroll'> {
12+
targetId?: string;
13+
playScale?: IPlayScaleType;
14+
replay?: boolean;
15+
location?: string;
16+
onChange?: (e: IChangeCallBackype) => void;
17+
onScroll?: (e: IScrollCallBackype) => void;
18+
component?: string | React.ReactNode;
19+
componentProps?: {};
20+
}
21+
22+
export default class RcScrollElement<T> extends React.Component<IProps<T>> {
23+
24+
}

src/ScrollLink.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
import { Omit } from './ScrollElement';
3+
import { IEaseType } from 'rc-tween-one/typings/AnimObject';
4+
5+
export interface IProps<T> extends Omit<React.HTMLAttributes<T>, 'onFocus'> {
6+
to: string
7+
toHash?: boolean;
8+
duration?: number;
9+
ease?: IEaseType;
10+
active?: string;
11+
showHeightActive?: string | number | [string | number, string | number];
12+
toShowHeight?: boolean;
13+
offsetTop?: number;
14+
targetId?: string;
15+
onFocus?: (e: { target: HTMLElement, to: string }) => void;
16+
onBlur?: () => void;
17+
component?: string | React.ReactNode;
18+
componentProps?: {};
19+
}
20+
21+
export default class RcScrollLink<T> extends React.Component<IProps<T>> {
22+
23+
}

src/ScrollOverPack.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import ScrollElement from './ScrollElement';
3+
4+
export interface IProps {
5+
always?: boolean;
6+
appear?: boolean;
7+
}
8+
9+
export default class RcScrollOverPack extends ScrollElement<IProps> {
10+
}

src/ScrollParallax.d.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as React from 'react';
2+
import { IEaseCallBack, IAnimType, IEaseType, IBezierProps, IChildrenProps, IStyleAnimProps } from 'rc-tween-one/typings/AnimObject';
3+
4+
export interface IAnimProps extends IStyleAnimProps {
5+
playScale?: number[];
6+
type?: IAnimType;
7+
duration?: number;
8+
delay?: number;
9+
// repeat?: number;
10+
// repeatDelay?: number;
11+
appearTo?: number;
12+
// yoyo?: boolean;
13+
ease?: IEaseType;
14+
style?: IStyleAnimProps;
15+
// morphPlugin
16+
points?: string;
17+
d?: string;
18+
// attr svg
19+
cx?: number;
20+
cy?: number;
21+
r?: number;
22+
x1?: number;
23+
y1?: number;
24+
x2?: number;
25+
y2?: number;
26+
rx?: number;
27+
ry?: number;
28+
dx?: number;
29+
dy?: number;
30+
offset?: number | string;
31+
stdDeviation?: number | string;
32+
stopColor?: string;
33+
stopOpacity?: number;
34+
onStart?: () => void;
35+
onStartBack?: () => void;
36+
onUpdate?: (e: number) => void;
37+
onComplete?: () => void;
38+
onCompleteBack?: () => void;
39+
}
40+
export declare type IAnimationType = IAnimProps | IAnimProps[];
41+
42+
export interface IProps<T> extends React.HTMLAttributes<T> {
43+
animation: IAnimationType
44+
location?: string;
45+
always?: boolean;
46+
targetId?: string;
47+
component?: string | React.ReactNode;
48+
componentProps?: {};
49+
}
50+
51+
export default class RcScrollParallax<T> extends React.Component<IProps<T>> {
52+
53+
}

src/ScrollScreen.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { IEaseType } from 'rc-tween-one/typings/AnimObject';
2+
3+
export interface IVarsProps {
4+
duration?: number;
5+
ease?: IEaseType;
6+
docHeight?: number;
7+
loop?: boolean;
8+
scrollInterval?: number;
9+
}
10+
11+
export default class RcSCrollScreen {
12+
static init: (vars?: IVarsProps) => void;
13+
static unMount: () => void;
14+
}

tests/test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react';
2+
// import { Parallax, Element, OverPack, Link, scrollScreen, Event } from '../typings';
3+
import Element from '../src/ScrollElement';
4+
import OverPack from '../src/ScrollOverPack';
5+
import Parallax from '../src/ScrollParallax';
6+
import Link from '../src/ScrollLink';
7+
import Event from '../src/EventDispatcher';
8+
import scrollScreen from '../src/ScrollScreen';
9+
10+
function TCompoent(props: { a?: string, b?: number }) {
11+
return (
12+
<div>
13+
{props.a}
14+
{props.b}
15+
</div>
16+
);
17+
}
18+
19+
function Text() {
20+
scrollScreen.init();
21+
Event.addEventListener('r', () => { }, document.body);
22+
return (
23+
<div>
24+
<Element targetId="a"><div key="1">test</div></Element>
25+
<Parallax
26+
animation={{ x: 100 }}
27+
component={TCompoent}
28+
componentProps={{ a: 'number', b: 100 }}
29+
always
30+
>
31+
abc
32+
</Parallax>
33+
<OverPack playScale={[0, 1]} id="abc"><div key="abc">test</div></OverPack>
34+
<Link to="abc">link</Link>
35+
</div>
36+
);
37+
}

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"strictNullChecks": true,
4+
"moduleResolution": "node",
5+
"jsx": "react",
6+
"target": "es6",
7+
"noImplicitAny": true
8+
}
9+
}

typings/index.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Type definitions for rc-scroll-anim 2.5
2+
// Project: https://github.com/react-component/scroll-anim
3+
// Definitions by: jljsj33 <https://github.com/jljsj33>
4+
// Definitions: https://github.com/react-component/scroll-anim
5+
import ScrollElement from '../src/ScrollElement';
6+
import ScrollOverPack from '../src/ScrollOverPack';
7+
import ScrollParallax from '../src/ScrollParallax';
8+
import ScrollLink from '../src/ScrollLink';
9+
import Screen from '../src/ScrollScreen';
10+
import ScrollEvent from '../src/EventDispatcher';
11+
12+
export const Element: typeof ScrollElement;
13+
export const OverPack: typeof ScrollOverPack;
14+
export const Parallax: typeof ScrollParallax;
15+
export const Link: typeof ScrollLink;
16+
export const scrollScreen: typeof Screen;
17+
export const Event: typeof ScrollEvent;
18+
19+
export default interface RcScrollAnim {
20+
Element: typeof ScrollElement;
21+
OverPack: typeof ScrollOverPack;
22+
Parallax: typeof ScrollOverPack;
23+
Link: typeof ScrollLink;
24+
scrollScreen: typeof Screen;
25+
Event: typeof ScrollEvent;
26+
}

0 commit comments

Comments
 (0)