Add new types for yahoo/react-stickynode 1.4 (#25565)

This commit is contained in:
Tim Stirrat
2018-05-08 02:05:07 +10:00
committed by Andy
parent e453232df5
commit 7ff376ea8e
4 changed files with 138 additions and 0 deletions

79
types/react-stickynode/index.d.ts vendored Normal file
View File

@@ -0,0 +1,79 @@
// Type definitions for react-stickynode 1.4
// Project: https://github.com/yahoo/react-stickynode
// Definitions by: Tim Stirrat <https://github.com/tstirrat>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from "react";
export = Sticky;
/** A performant and comprehensive React sticky component. */
declare class Sticky extends React.Component<Sticky.Props> {
static defaultProps: Sticky.Props;
static STATUS_ORIGINAL: Sticky.StatusCode.STATUS_ORIGINAL;
static STATUS_RELEASED: Sticky.StatusCode.STATUS_RELEASED;
static STATUS_FIXED: Sticky.StatusCode.STATUS_FIXED;
}
declare namespace Sticky {
enum StatusCode {
/** The default status, located at the original position. */
STATUS_ORIGINAL = 0,
/**
* The released status, located at somewhere on document, but not
* default one.
*/
STATUS_RELEASED = 1,
STATUS_FIXED = 2
}
interface Status {
status: StatusCode;
}
interface Props {
/** The switch to enable or disable Sticky (true by default ). */
enabled?: boolean;
/**
* The offset from the top of window where the top of the element will
* be when sticky state is triggered(0 by default ).If it is a selector
* to a target(via `querySelector()`), the offset will be the height of
* the target.
*/
top?: number | string;
/**
* The offset from the top of document which release state will be
* triggered when the bottom of the element reaches at.If it is a
* selector to a target(via `querySelector()`), the offset will be the
* bottom of the target.
*/
bottomBoundary?: number | string;
/** z - index of the sticky */
innerZ?: number | string;
/** Enable the use of CSS3 transforms (true by default ). */
enableTransforms?: boolean;
/**
* Class name to be applied to the element when the sticky state is
* active (active by default ).
*/
activeClass?: string;
/**
* Class name to be applied to the element when the sticky state is
* released (released by default ).
*/
releasedClass?: string;
/** Callback for when the sticky state changes.See below. */
onStateChange?: (status: Status) => void;
shouldFreeze?: () => boolean;
}
}

View File

@@ -0,0 +1,34 @@
import * as Sticky from "react-stickynode";
import * as React from "react";
const StickyAllOptions: JSX.Element = (
<Sticky
enabled={true}
top={10}
bottomBoundary={120}
innerZ={1000}
enableTransforms={true}
activeClass="active"
releasedClass="released"
onStateChange={s => s.status === Sticky.StatusCode.STATUS_ORIGINAL}
shouldFreeze={() => false}
>
<div />
</Sticky>
);
const StickyOptionalStringOptions: JSX.Element = (
<Sticky
top="#elem"
bottomBoundary="#bottom"
innerZ="1234"
>
<div />
</Sticky>
);
const StickyNoOptions: JSX.Element = (
<Sticky>
<div />
</Sticky>
);

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"jsx": "react",
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"react-stickynode-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }