Add types for react-native-star-rating

This commit is contained in:
Kyle Roach
2018-03-18 14:02:09 -04:00
parent e8bc07e649
commit ad4e2fd444
4 changed files with 183 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
// Type definitions for react-native-star-rating 1.0
// Project: https://github.com/djchie/react-native-star-rating
// Definitions by: iRoachie <https://github.com/iRoachie>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
import * as React from 'react';
import { ImageURISource, StyleProp, ViewStyle } from 'react-native';
export interface StarRatingProps {
/**
* Style of the button containing the star.
*/
buttonStyle?: StyleProp<ViewStyle>;
/**
* Style of the element containing the star rating component.
*/
containerStyle?: StyleProp<ViewStyle>;
/**
* Sets the interactivity of the star buttons.
*
* Default is false
*/
disabled?: boolean;
/**
* The name of the icon to represent an empty star.
* Refer to react-native-vector-icons.
* Also can be a image object, both {uri:xxx.xxx} and require('xx/xx/xx.xxx').
*
* Default is "star-o"
*/
emptyStar?: string | ImageURISource;
/**
* Color of an empty star.
*
* Default is gray
*/
emptyStarColor?: string;
/**
* The name of the icon to represent a full star.
* Refer to react-native-vector-icons.
* Also can be a image object, both {uri:xxx.xxx} and require('xx/xx/xx.xxx')
*
* Default is "star"
*/
fullStar?: string | ImageURISource;
/**
* Color of a filled star.
*
* Default is black
*/
fullStarColor?: string;
/**
* The name of the icon to represent an half star.
* Refer to react-native-vector-icons.
* Also can be a image object, both {uri:xxx.xxx} and require('xx/xx/xx.xxx').
*
* Default is "star-half-o"
*/
halfStar?: string | ImageURISource;
/**
* Color of a half-filled star.
*
* Defaults to fullStarColor.
*/
halfStarColor?: string;
/**
* Sets ability to select half stars
*
* Default is false
*/
halfStarEnabled?: boolean;
/**
* The name of the icon set the star image belongs to.
* Refer to react-native-vector-icons.
*
* Default is "FontAwesome"
*/
iconSet?: string;
/**
* The maximum number of stars possible.
*
* Default is 5
*/
maxStars?: number;
/**
* The current rating to show.
*
* Default is 0
*/
rating?: number;
/**
* Renders stars from right to left
*
* Default is false
*/
reversed?: boolean;
/**
* Size of the star.
*
* Default is 40
*/
starSize?: number;
/**
* Style to apply to the star.
*/
starStyle?: StyleProp<ViewStyle>;
/**
* A function to handle star button presses.
*/
selectedStar?(rating: number): void;
}
export default class StarRating extends React.Component<StarRatingProps> {}

View File

@@ -0,0 +1,35 @@
import * as React from 'react';
import StarRating from 'react-native-star-rating';
interface State {
starCount: number;
}
class GeneralStarExample extends React.Component<{}, State> {
constructor(props: {}) {
super(props);
this.state = {
starCount: 3.5
};
}
onStarRatingPress = (rating: number) => {
this.setState({
starCount: rating
});
}
render() {
return (
<StarRating
disabled={false}
maxStars={5}
rating={this.state.starCount}
selectedStar={this.onStarRatingPress}
/>
);
}
}
export default GeneralStarExample;

View File

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

View File

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