Skip to content
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 docs/examples/simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default () => (
<br />
<Rate
defaultValue={1}
highlightSelectedOnly
onChange={onChange}
style={{ fontSize: 50, marginTop: 24 }}
character={({ index }) => {
Expand Down
5 changes: 4 additions & 1 deletion src/Rate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { StarProps } from './Star';

function noop() {}

export interface RateProps extends Pick<StarProps, "count" | "character" | "characterRender" | "allowHalf" | "disabled"> {
export interface RateProps extends Pick<StarProps, "count" | "character" | "characterRender" | "allowHalf" | "disabled" | "highlightSelectedOnly"> {
value?: number;
defaultValue?: number;
allowClear?: boolean;
Expand Down Expand Up @@ -45,6 +45,7 @@ class Rate extends React.Component<RateProps, RateState> {
onHoverChange: noop,
tabIndex: 0,
direction: 'ltr',
highlightSelectedOnly: false,
};

stars: Record<string, Star>;
Expand Down Expand Up @@ -249,6 +250,7 @@ class Rate extends React.Component<RateProps, RateState> {
characterRender,
tabIndex,
direction,
highlightSelectedOnly
} = this.props;
const { value, hoverValue, focused } = this.state;
const stars = [];
Expand All @@ -269,6 +271,7 @@ class Rate extends React.Component<RateProps, RateState> {
character={character}
characterRender={characterRender}
focused={focused}
highlightSelectedOnly={highlightSelectedOnly}
/>,
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Star.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface StarProps {
characterRender?: (origin: React.ReactElement, props: StarProps) => React.ReactNode;
focused?: boolean;
count?: number;
highlightSelectedOnly?: boolean;
}

export default class Star extends React.Component<StarProps> {
Expand All @@ -36,7 +37,7 @@ export default class Star extends React.Component<StarProps> {
};

getClassName() {
const { prefixCls, index, value, allowHalf, focused } = this.props;
const { prefixCls, index, value, allowHalf, focused, highlightSelectedOnly } = this.props;
const starValue = index + 1;
let className = prefixCls;
if (value === 0 && index === 0 && focused) {
Expand All @@ -46,7 +47,7 @@ export default class Star extends React.Component<StarProps> {
if (focused) {
className += ` ${prefixCls}-focused`;
}
} else {
} else if (!highlightSelectedOnly || value === index + 1) {
className += starValue <= value ? ` ${prefixCls}-full` : ` ${prefixCls}-zero`;
if (starValue === value && focused) {
className += ` ${prefixCls}-focused`;
Expand Down