Skip to content

Commit 23fa12b

Browse files
authored
fix: allow more props passed to Rate (#152)
* fix: allow more props passed to Rate * chore: fix lint * chore: remove findDOMNode * chore: fix eslint warning
1 parent 02976fd commit 23fa12b

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

.eslintrc.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
const base = require("@umijs/fabric/dist/eslint");
2-
31
module.exports = {
4-
...base,
2+
extends: [require.resolve('@umijs/fabric/dist/eslint')],
53
rules: {
6-
...base.rules,
7-
"arrow-parens": 0,
8-
"react/no-array-index-key": 0,
9-
"react/sort-comp": 0,
10-
"@typescript-eslint/no-explicit-any": 0,
11-
"@typescript-eslint/no-empty-interface": 0,
12-
"@typescript-eslint/no-inferrable-types": 0,
13-
"react/no-find-dom-node": 0,
14-
"react/require-default-props": 0,
15-
"no-confusing-arrow": 0,
16-
"import/no-named-as-default-member": 0,
17-
"jsx-a11y/label-has-for": 0,
18-
"jsx-a11y/label-has-associated-control": 0,
19-
"import/no-extraneous-dependencies": 0,
4+
'jsx-a11y/no-autofocus': 0,
205
},
6+
overrides: [
7+
{
8+
files: ['docs/**/*.tsx'],
9+
rules: {
10+
'no-console': 0,
11+
},
12+
},
13+
],
2114
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@types/jest": "^29.5.1",
5151
"@types/react": "^17.0.15",
5252
"@types/react-dom": "^17.0.9",
53-
"@umijs/fabric": "^2.0.0",
53+
"@umijs/fabric": "^3.0.0",
5454
"cross-env": "^7.0.0",
5555
"dumi": "^2.1.2",
5656
"enzyme": "^3.1.1",

src/Rate.tsx

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
1+
import classNames from 'classnames';
22
import useMergedState from 'rc-util/lib/hooks/useMergedState';
33
import KeyCode from 'rc-util/lib/KeyCode';
44
import pickAttrs from 'rc-util/lib/pickAttrs';
55
import React from 'react';
6-
import classNames from 'classnames';
7-
86
import type { StarProps } from './Star';
97
import Star from './Star';
108
import useRefs from './useRefs';
@@ -41,8 +39,6 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
4139
// Base
4240
prefixCls = 'rc-rate',
4341
className,
44-
style,
45-
id,
4642

4743
// Value
4844
defaultValue,
@@ -67,7 +63,6 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
6763
onFocus,
6864
onBlur,
6965
onKeyDown,
70-
onMouseEnter,
7166
onMouseLeave,
7267

7368
...restProps
@@ -102,7 +97,7 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
10297
const reverse = direction === 'rtl';
10398
let starValue = index + 1;
10499
if (allowHalf) {
105-
const starEle = findDOMNode<HTMLElement>(getStarRef(index));
100+
const starEle = getStarRef(index);
106101
const leftDis = getOffsetLeft(starEle);
107102
const width = starEle.clientWidth;
108103
if (reverse && x - leftDis > width / 2) {
@@ -219,8 +214,9 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
219214

220215
// =========================== Render ===========================
221216
// >>> Star
222-
const starNodes = new Array(count).fill(0).map((_, index) => {
223-
return (
217+
const starNodes = new Array(count)
218+
.fill(0)
219+
.map((item, index) => (
224220
<Star
225221
ref={setStarRef(index)}
226222
index={index}
@@ -231,32 +227,30 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
231227
value={hoverValue === null ? value : hoverValue}
232228
onClick={onClick}
233229
onHover={onHover}
234-
key={index}
230+
key={item || index}
235231
character={character}
236232
characterRender={characterRender}
237233
focused={focused}
238234
/>
239-
);
235+
));
236+
237+
const classString = classNames(prefixCls, className, {
238+
[`${prefixCls}-disabled`]: disabled,
239+
[`${prefixCls}-rtl`]: direction === 'rtl',
240240
});
241241

242242
// >>> Node
243243
return (
244244
<ul
245-
className={classNames(prefixCls, className, {
246-
[`${prefixCls}-disabled`]: disabled,
247-
[`${prefixCls}-rtl`]: direction === 'rtl',
248-
})}
249-
style={style}
250-
id={id}
251-
onMouseEnter={onMouseEnter}
245+
className={classString}
252246
onMouseLeave={onMouseLeaveCallback}
253247
tabIndex={disabled ? -1 : tabIndex}
254248
onFocus={disabled ? null : onInternalFocus}
255249
onBlur={disabled ? null : onInternalBlur}
256250
onKeyDown={disabled ? null : onInternalKeyDown}
257251
ref={rateRef}
258252
role="radiogroup"
259-
{...pickAttrs(restProps, { aria: true, data: true })}
253+
{...pickAttrs(restProps, { aria: true, data: true, attr: true })}
260254
>
261255
{starNodes}
262256
</ul>

0 commit comments

Comments
 (0)