Skip to content

feat: Added Stars Spacing props to rc-star NEED REVIEW #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ ReactDOM.render(
| character | ReactNode \| (props) => ReactNode | ★ | The each character of rate |
| disabled | boolean | false | |
| direction | string | `ltr` | The direction of rate |
| starsSpacing | string | 0 | defines the spacing between stars |

## Test Case

Expand Down
4 changes: 4 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
float: right;
}

&:last-child {
margin-right: 0;
}

&-first,
&-second {
transition: all .3s;
Expand Down
1 change: 1 addition & 0 deletions docs/examples/characterRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default () => (
<div style={{ margin: 100 }}>
<Rate
defaultValue={3}
starsSpacing="8px"
characterRender={(node, props) => (
<Tooltip placement="top" overlay={props.index}>
{node}
Expand Down
4 changes: 4 additions & 0 deletions src/Rate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface RateProps extends Pick<StarProps, "count" | "character" | "char
defaultValue?: number;
allowClear?: boolean;
style?: React.CSSProperties;
starsSpacing?: React.CSSProperties;
prefixCls?: string;
onChange?: (value: number) => void;
onHoverChange?: (value: number) => void;
Expand All @@ -39,6 +40,7 @@ class Rate extends React.Component<RateProps, RateState> {
allowHalf: false,
allowClear: true,
style: {},
starsStyle: {},
prefixCls: 'rc-rate',
onChange: noop,
character: '★',
Expand Down Expand Up @@ -249,6 +251,7 @@ class Rate extends React.Component<RateProps, RateState> {
characterRender,
tabIndex,
direction,
starsSpacing,
} = this.props;
const { value, hoverValue, focused } = this.state;
const stars = [];
Expand All @@ -266,6 +269,7 @@ class Rate extends React.Component<RateProps, RateState> {
onClick={this.onClick}
onHover={this.onHover}
key={index}
spacing={starsSpacing}
character={character}
characterRender={characterRender}
focused={focused}
Expand Down
5 changes: 3 additions & 2 deletions src/Star.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
export interface StarProps {
value?: number;
index?: number;
spacing?: string;
prefixCls?: string;
allowHalf?: boolean;
disabled?: boolean;
Expand Down Expand Up @@ -57,10 +58,10 @@ export default class Star extends React.Component<StarProps> {

render() {
const { onHover, onClick, onKeyDown } = this;
const { disabled, prefixCls, character, characterRender, index, count, value } = this.props;
const { disabled, prefixCls, character, characterRender, index, count, spacing, value } = this.props;
const characterNode = typeof character === 'function' ? character(this.props) : character;
let start: React.ReactNode = (
<li className={this.getClassName()}>
<li className={this.getClassName()} style={{marginRight: spacing}}>
<div
onClick={disabled ? null : onClick}
onKeyDown={disabled ? null : onKeyDown}
Expand Down