diff --git a/types/react-star-rating-component/index.d.ts b/types/react-star-rating-component/index.d.ts new file mode 100644 index 0000000000..916f5bbe4f --- /dev/null +++ b/types/react-star-rating-component/index.d.ts @@ -0,0 +1,53 @@ +// Type definitions for react-star-rating-component 1.4 +// Project: https://github.com/voronianski/react-star-rating-component#readme +// Definitions by: Cody Sand +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from "react"; + +interface StarRatingComponentProps { + /** name of the radio input */ + name: string; + + /** the value of the star rating to display. i.e. the number of filled stars */ + value: number; + + /** number of icons in rating, default `5` */ + starCount?: number; + + onStarClick?: (nextValue: number, prevValue: number, name: string) => void; + + onStarHover?: (nextValue: number, prevValue: number, name: string) => void; + + onStarHoverOut?: (nextValue: number, prevValue: number, name: string) => void; + + /** render method for the full-star icon */ + renderStarIcon?: ( + nextValue: number, + prevValue: number, + name: string + ) => React.ReactNode | string; + + /** render method for the half-star icon */ + renderStarIconHalf?: ( + nextValue: number, + prevValue: number, + name: string + ) => React.ReactNode | string; + + /** color of selected icons */ + starColor?: string; + + /** color of non-selected icons */ + emptyStarColor?: string; + + /** is component available for editing, default `true` */ + editing?: boolean; +} + +declare class StarRatingComponent extends React.Component< + StarRatingComponentProps +> {} + +export = StarRatingComponent; diff --git a/types/react-star-rating-component/react-star-rating-component-tests.tsx b/types/react-star-rating-component/react-star-rating-component-tests.tsx new file mode 100644 index 0000000000..09f8928c8d --- /dev/null +++ b/types/react-star-rating-component/react-star-rating-component-tests.tsx @@ -0,0 +1,49 @@ +import StarRatingComponent from "react-star-rating-component"; +import * as React from "react"; + +const interactionCallback = (next: number, prev: number, name: string) => ({ + next, + prev, + name +}); + +// $ExpectError +const missingRequired = ; + +// $ExpectError +const valueIsNumber = ; + +const validExample = ; + +const fullExample = ( + { + return ( + + + + ); + }} + renderStarIconHalf={(_: number, __: number, ___: string) => { + return ( + + + + + + + + + ); + }} + /> +); diff --git a/types/react-star-rating-component/tsconfig.json b/types/react-star-rating-component/tsconfig.json new file mode 100644 index 0000000000..a010cbdc61 --- /dev/null +++ b/types/react-star-rating-component/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "esModuleInterop": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "jsx": "react", + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-star-rating-component-tests.tsx" + ] +} diff --git a/types/react-star-rating-component/tslint.json b/types/react-star-rating-component/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-star-rating-component/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }