Skip to content

Commit d0499ae

Browse files
committed
🪲 Star margin
1 parent 37dcd09 commit d0499ae

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/Icon.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,26 @@ class Icon extends React.PureComponent<Props> {
2626
emptyIcon,
2727
icon,
2828
direction,
29-
} = this.props
29+
} = this.props;
3030
const showbgIcon = percent < 100;
3131
const bgIconContainerStyle = showbgIcon
3232
? {}
33-
: {
34-
visibility: 'hidden'
35-
} as CSSProperties;
33+
: ({
34+
visibility: 'hidden',
35+
} as CSSProperties);
3636
const iconContainerStyle = {
3737
display: 'inline-block',
3838
position: 'absolute',
3939
overflow: 'hidden',
4040
top: 0,
4141
[direction === 'rtl' ? 'right' : 'left']: 0,
42-
width: `${percent}%`
42+
width: `${percent}%`,
4343
} as CSSProperties;
4444
const style = {
4545
cursor: !readOnly ? 'pointer' : 'inherit',
4646
display: 'inline-block',
4747
position: 'relative',
48+
marginLeft: 5,
4849
} as CSSProperties;
4950

5051
function handleMouseClick(event: any) {
@@ -66,22 +67,18 @@ class Icon extends React.PureComponent<Props> {
6667
}
6768
}
6869

69-
return(
70+
return (
7071
<span
71-
style={style}
72+
style={index === 0 ? Object.assign({}, style, { marginLeft: 0 }) : style}
7273
onClick={handleMouseClick}
7374
onMouseMove={handleMouseMove}
7475
onTouchMove={handleMouseMove}
7576
onTouchEnd={handleTouchEnd}
7677
>
77-
<span style={bgIconContainerStyle}>
78-
{renderIcon(emptyIcon)}
79-
</span>
80-
<span style={iconContainerStyle}>
81-
{renderIcon(icon)}
82-
</span>
78+
<span style={bgIconContainerStyle}>{renderIcon(emptyIcon)}</span>
79+
<span style={iconContainerStyle}>{renderIcon(icon)}</span>
8380
</span>
84-
)
81+
);
8582
}
8683
}
8784

src/Star.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,27 @@ interface Props {
3838
onChange: (index?: number, event?: any) => void;
3939
}
4040

41-
interface State { value: number; }
41+
interface State {
42+
value: number;
43+
}
4244

4345
class Star extends React.PureComponent<Props, State> {
4446
static defaultProps: Partial<Props> = {
4547
min: DEFAULT_MIN,
4648
max: DEFAULT_MAX,
4749
step: DEFAULT_STEP,
4850
readOnly: DEFAULT_READONLY,
49-
quiet: DEFAULT_QUIET,
5051
fraction: DEFAULT_FRACTION,
51-
emptyIcon: <ThinStar style={{ fill: '#000000', stroke: '#000000', opacity: '26%' }} />,
52+
emptyIcon: (
53+
<ThinStar
54+
style={{ fill: '#000000', stroke: '#000000', opacity: '26%' }}
55+
/>
56+
),
5257
icon: <ThinStar style={{ fill: '#ffb400', stroke: '#ffb400' }} />,
53-
placeholderIcon: <ThinStar style={{ fill: '#ffb400', stroke: '#ffb400' }} />,
58+
placeholderIcon: (
59+
<ThinStar style={{ fill: '#ffb400', stroke: '#ffb400' }} />
60+
),
61+
quiet: DEFAULT_QUIET,
5462
direction: 'ltr',
5563
onHover: NO_OPERATION,
5664
onClick: NO_OPERATION,
@@ -133,7 +141,11 @@ class Star extends React.PureComponent<Props, State> {
133141
className={className}
134142
tabIndex={tabIndex || 0}
135143
// aria-label={this.props['aria-label']}
136-
totalIcons={calculateTotalIcons(min || DEFAULT_MIN, max || DEFAULT_MAX, step || DEFAULT_STEP)}
144+
totalIcons={calculateTotalIcons(
145+
min || DEFAULT_MIN,
146+
max || DEFAULT_MAX,
147+
step || DEFAULT_STEP,
148+
)}
137149
value={this.tranlateValueToDisplayValue(this.state.value)}
138150
placeholderValue={this.tranlateValueToDisplayValue(
139151
this.props.placeholderRating || 0,

0 commit comments

Comments
 (0)