-
Notifications
You must be signed in to change notification settings - Fork 594
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
refactor(Rating): upgrade to ts #4717
refactor(Rating): upgrade to ts #4717
Conversation
Signed-off-by: Simba Luo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是您为 Fusion/Next 提的第一个 pr,感谢您为 Fusion 做出的贡献,我们会尽快进行处理。
iconSpace: number; | ||
iconSize: number; | ||
clicked: boolean; | ||
disabled: boolean; | ||
} | ||
|
||
export default class Rating extends React.Component<RatingProps, any> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个可以移除了
@@ -52,7 +52,7 @@ export interface RatingProps extends HTMLAttributesWeak, CommonProps { | |||
/** | |||
* 用户hover评分时触发的回调 | |||
*/ | |||
onHoverChange?: (value: number) => void; | |||
onHoverChange?: (value?: number) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然效果差不多,但是不是(value: number | undefined) => void
更准确一点
{overlay} | ||
</div> | ||
</div> | ||
{showGrade ? ( | ||
<div className={`${prefix}rating-info`} style={infoStyle}> | ||
{readAs(value)} | ||
{readAs ? readAs(value) : 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readAs在 defaultProps 内定义了默认值,这里直接 readAs!(value) 断言存在即可,不要改动原有逻辑
className={`${prefix}rating-icon`} | ||
> | ||
{iconNode} | ||
{enableA11y ? <span className={`${prefix}sr-only`}>{readAs(i + 1)}</span> : null} | ||
{enableA11y ? ( | ||
<span className={`${prefix}sr-only`}>{readAs ? readAs(i + 1) : 0}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readAs在 defaultProps 内定义了默认值,这里直接 readAs!(i + 1) 断言存在即可,不要改动原有逻辑
aria-checked={i + 1 === parseInt(hoverValue)} | ||
checked={i + 1 === parseInt(hoverValue)} | ||
aria-checked={i + 1 === Number(hoverValue)} | ||
checked={i + 1 === Number(hoverValue)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt() 的效果跟 Number() 不一样,不要改动原有逻辑,有问题的类型通过断言、ts注释等方式注明
iconRefs: React.RefObject<HTMLElement>[] = Array(this.props.count) | ||
.fill(null) | ||
.map(() => createRef()); | ||
private spanRefs: React.RefObject<HTMLSpanElement>[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 spanRefs 是不是多余的
|
||
if (icon && this.underlayNode) { | ||
if (this.iconRefs[0].current && this.underlayNodeRef.current) { | ||
const icon = this.iconRefs[0].current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要修改原有逻辑,只做类型补全,你这里完全可以
const icon = (this as unknown as Record<string, HTMLSpanElement | null>)['refs-rating-icon-0']
static getDerivedStateFromProps(nextProps, prevState) { | ||
const state = {}; | ||
static getDerivedStateFromProps(nextProps: RatingProps, prevState: any) { | ||
const state: any = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no any
@@ -130,14 +65,15 @@ class Rating extends Component { | |||
iconSpace: 0, | |||
iconSize: 0, | |||
clicked: false, // 标记组件是否被点击过 | |||
disabled: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要修改原来行为
@@ -19,80 +21,13 @@ const ICON_SIZE_MAP = { | |||
}; | |||
|
|||
/** Rating */ | |||
class Rating extends Component { | |||
static propTypes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
propTypes 下面代码要用的,为啥删掉了
@TATATATATAT 麻烦及时跟进一下 review comments |
Stale |
Upgrade rating component to ts