mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
add types for react-star-rating-component (#29713)
* add types for react-star-rating-component * react-star-rating-component: set TS version to 2.8 to match react. * use ES-style export and update tsconfig to allow `esModuleInterop`
This commit is contained in:
+53
@@ -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 <https://github.com/marpstar>
|
||||
// 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;
|
||||
@@ -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 = <StarRatingComponent />;
|
||||
|
||||
// $ExpectError
|
||||
const valueIsNumber = <StarRatingComponent name="" value={"5"} />;
|
||||
|
||||
const validExample = <StarRatingComponent name="test" value={3} />;
|
||||
|
||||
const fullExample = (
|
||||
<StarRatingComponent
|
||||
name="app6"
|
||||
starColor="#F3D954"
|
||||
emptyStarColor="#F3D954"
|
||||
starCount={4}
|
||||
value={3.5}
|
||||
onStarClick={interactionCallback}
|
||||
onStarHover={interactionCallback}
|
||||
onStarHoverOut={interactionCallback}
|
||||
editing={false}
|
||||
renderStarIcon={(index: number, value: number, _: string) => {
|
||||
return (
|
||||
<span>
|
||||
<i className={index <= value ? "fas fa-star" : "far fa-star"} />
|
||||
</span>
|
||||
);
|
||||
}}
|
||||
renderStarIconHalf={(_: number, __: number, ___: string) => {
|
||||
return (
|
||||
<span>
|
||||
<span style={{ position: "absolute" }}>
|
||||
<i className="far fa-star" />
|
||||
</span>
|
||||
<span>
|
||||
<i className="fas fa-star-half" />
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user