mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* 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`
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
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>
|
|
);
|
|
}}
|
|
/>
|
|
);
|