From 01e350fa95da65f0f9f189902b6da94e595adf74 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 May 2023 18:43:09 +0800 Subject: [PATCH 1/4] fix: allow more props passed to Rate --- package.json | 2 +- src/Rate.tsx | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 2199d48..962b0d7 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@types/jest": "^26.0.0", "@types/react": "^17.0.15", "@types/react-dom": "^17.0.9", - "@umijs/fabric": "^2.0.0", + "@umijs/fabric": "^4.0.1", "cross-env": "^7.0.0", "dumi": "^2.1.2", "enzyme": "^3.1.1", diff --git a/src/Rate.tsx b/src/Rate.tsx index 81762db..8b20fc7 100644 --- a/src/Rate.tsx +++ b/src/Rate.tsx @@ -1,10 +1,9 @@ +import classNames from 'classnames'; import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; -import useMergedState from 'rc-util/lib/hooks/useMergedState'; import KeyCode from 'rc-util/lib/KeyCode'; +import useMergedState from 'rc-util/lib/hooks/useMergedState'; import pickAttrs from 'rc-util/lib/pickAttrs'; import React from 'react'; -import classNames from 'classnames'; - import type { StarProps } from './Star'; import Star from './Star'; import useRefs from './useRefs'; @@ -41,8 +40,6 @@ function Rate(props: RateProps, ref: React.Ref) { // Base prefixCls = 'rc-rate', className, - style, - id, // Value defaultValue, @@ -67,7 +64,6 @@ function Rate(props: RateProps, ref: React.Ref) { onFocus, onBlur, onKeyDown, - onMouseEnter, onMouseLeave, ...restProps @@ -239,16 +235,15 @@ function Rate(props: RateProps, ref: React.Ref) { ); }); + const classString = classNames(prefixCls, className, { + [`${prefixCls}-disabled`]: disabled, + [`${prefixCls}-rtl`]: direction === 'rtl', + }); + // >>> Node return (
    ) { onKeyDown={disabled ? null : onInternalKeyDown} ref={rateRef} role="radiogroup" - {...pickAttrs(restProps, { aria: true, data: true })} + {...pickAttrs(restProps, { aria: true, data: true, attr: true })} > {starNodes}
From e001eedcc8130dbacc2cb9632cfb64169451333e Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 May 2023 19:11:44 +0800 Subject: [PATCH 2/4] chore: fix lint --- .eslintrc.js | 27 ++++++++++----------------- package.json | 2 +- src/Rate.tsx | 11 ++++++----- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f255ae9..2124552 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,21 +1,14 @@ -const base = require("@umijs/fabric/dist/eslint"); - module.exports = { - ...base, + extends: [require.resolve('@umijs/fabric/dist/eslint')], rules: { - ...base.rules, - "arrow-parens": 0, - "react/no-array-index-key": 0, - "react/sort-comp": 0, - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/no-empty-interface": 0, - "@typescript-eslint/no-inferrable-types": 0, - "react/no-find-dom-node": 0, - "react/require-default-props": 0, - "no-confusing-arrow": 0, - "import/no-named-as-default-member": 0, - "jsx-a11y/label-has-for": 0, - "jsx-a11y/label-has-associated-control": 0, - "import/no-extraneous-dependencies": 0, + 'jsx-a11y/no-autofocus': 0, }, + overrides: [ + { + files: ['docs/**/*.tsx'], + rules: { + 'no-console': 0, + }, + }, + ], }; diff --git a/package.json b/package.json index 962b0d7..5b52e05 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@types/jest": "^26.0.0", "@types/react": "^17.0.15", "@types/react-dom": "^17.0.9", - "@umijs/fabric": "^4.0.1", + "@umijs/fabric": "^3.0.0", "cross-env": "^7.0.0", "dumi": "^2.1.2", "enzyme": "^3.1.1", diff --git a/src/Rate.tsx b/src/Rate.tsx index 8b20fc7..05ca8bb 100644 --- a/src/Rate.tsx +++ b/src/Rate.tsx @@ -1,7 +1,7 @@ import classNames from 'classnames'; import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; -import KeyCode from 'rc-util/lib/KeyCode'; import useMergedState from 'rc-util/lib/hooks/useMergedState'; +import KeyCode from 'rc-util/lib/KeyCode'; import pickAttrs from 'rc-util/lib/pickAttrs'; import React from 'react'; import type { StarProps } from './Star'; @@ -98,6 +98,7 @@ function Rate(props: RateProps, ref: React.Ref) { const reverse = direction === 'rtl'; let starValue = index + 1; if (allowHalf) { + // eslint-disable-next-line react/no-find-dom-node const starEle = findDOMNode(getStarRef(index)); const leftDis = getOffsetLeft(starEle); const width = starEle.clientWidth; @@ -215,8 +216,9 @@ function Rate(props: RateProps, ref: React.Ref) { // =========================== Render =========================== // >>> Star - const starNodes = new Array(count).fill(0).map((_, index) => { - return ( + const starNodes = new Array(count) + .fill(0) + .map((_, index) => ( ) { characterRender={characterRender} focused={focused} /> - ); - }); + )); const classString = classNames(prefixCls, className, { [`${prefixCls}-disabled`]: disabled, From 1e34245d57b3fb13883ac6a355441f6b067b2f28 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 May 2023 19:14:52 +0800 Subject: [PATCH 3/4] chore: remove findDOMNode --- src/Rate.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Rate.tsx b/src/Rate.tsx index 05ca8bb..98f64ed 100644 --- a/src/Rate.tsx +++ b/src/Rate.tsx @@ -1,5 +1,4 @@ import classNames from 'classnames'; -import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; import useMergedState from 'rc-util/lib/hooks/useMergedState'; import KeyCode from 'rc-util/lib/KeyCode'; import pickAttrs from 'rc-util/lib/pickAttrs'; @@ -98,8 +97,8 @@ function Rate(props: RateProps, ref: React.Ref) { const reverse = direction === 'rtl'; let starValue = index + 1; if (allowHalf) { - // eslint-disable-next-line react/no-find-dom-node - const starEle = findDOMNode(getStarRef(index)); + console.log(getStarRef(index)); + const starEle = getStarRef(index); const leftDis = getOffsetLeft(starEle); const width = starEle.clientWidth; if (reverse && x - leftDis > width / 2) { From 188be6a98cfacb69a74535cd9760eb4c64070a43 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 May 2023 19:16:04 +0800 Subject: [PATCH 4/4] chore: fix eslint warning --- src/Rate.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Rate.tsx b/src/Rate.tsx index 98f64ed..ad8e18e 100644 --- a/src/Rate.tsx +++ b/src/Rate.tsx @@ -97,7 +97,6 @@ function Rate(props: RateProps, ref: React.Ref) { const reverse = direction === 'rtl'; let starValue = index + 1; if (allowHalf) { - console.log(getStarRef(index)); const starEle = getStarRef(index); const leftDis = getOffsetLeft(starEle); const width = starEle.clientWidth; @@ -217,7 +216,7 @@ function Rate(props: RateProps, ref: React.Ref) { // >>> Star const starNodes = new Array(count) .fill(0) - .map((_, index) => ( + .map((item, index) => ( ) { value={hoverValue === null ? value : hoverValue} onClick={onClick} onHover={onHover} - key={index} + key={item || index} character={character} characterRender={characterRender} focused={focused}