diff --git a/rheostat/index.d.ts b/rheostat/index.d.ts new file mode 100644 index 0000000000..372e5c6f1b --- /dev/null +++ b/rheostat/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for rheostat 2.1 +// Project: https://github.com/airbnb/rheostat +// Definitions by: Sasha Bayan , Wil Lee +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import * as React from 'react'; + +export type Orientation = 'horizontal' | 'vertical'; + +export interface Algorithm { + getPosition(value: number, min: number, max: number): number; + getValue(pos: number, min: number, max: number): number; +} + +export interface PublicState { + max: number; + min: number; + values: number[]; +} + +export interface Events { + onClick?: () => any; + onChange?: (publicState: PublicState) => any; + onKeyPress?: () => any; + onSliderDragEnd?: () => any; + onSliderDragMove?: () => any; + onSliderDragStart?: () => any; + onValuesUpdated?: (publicState: PublicState) => any; +} + +export interface Props extends Events { + algorithm?: Algorithm; + className?: string; + disabled?: boolean; + handle?: React.ReactType; + max?: number; + min?: number; + orientation?: Orientation; + pitComponent?: React.ReactType; + pitPoints?: number[]; + progressBar?: React.ReactType; + snap?: boolean; + snapPoints?: number[]; + values?: number[]; +} + +export default class Rheostat extends React.Component {} + diff --git a/rheostat/rheostat-tests.tsx b/rheostat/rheostat-tests.tsx new file mode 100644 index 0000000000..1116861943 --- /dev/null +++ b/rheostat/rheostat-tests.tsx @@ -0,0 +1,74 @@ +import * as React from 'react'; +import Rheostat, {Orientation, Algorithm, PublicState} from 'rheostat'; + +type Element = React.ReactElement; + +function Basic(props: {}): Element { + return ; +} + +function MultiHandles(props: {}): Element { + return ( + + ); +} + +function CustomAlgorithm(props: {}): Element { + const geometric: Algorithm = { + getPosition(x: number, min: number, max: number) { + return ((max / (max - min)) ** 0.5) * (((x - min) / max) ** 0.5) * 100; + }, + + getValue(x: number, min: number, max: number) { + return (Math.floor(((x / 100) ** 2) * (max - min)) + min); + } + }; + + return ; +} + +function ComponentOverrides(props: {}): Element { + function Bar(props: {}): Element { return
; } + return ( + + ); +} + +function Vertical(props: {}): Element { + return ; +} + +function Pits(props: {}): Element { + function Pit(props: {}): Element { return ; } + return ( + + ); +} + +function CustomValues(props: {}): Element { + return ( + + ); +} + +function Handlers(props: {}): Element { + function handler(data: PublicState): void {} + return ( + + ); +} diff --git a/rheostat/tsconfig.json b/rheostat/tsconfig.json new file mode 100644 index 0000000000..384dce128d --- /dev/null +++ b/rheostat/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "jsx": "react", + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rheostat-tests.tsx" + ] +} diff --git a/rheostat/tslint.json b/rheostat/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/rheostat/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +}