Skip to content
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

Conversation

TATATATATAT
Copy link

Upgrade rating component to ts

Copy link

@github-actions github-actions bot left a 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> {}
Copy link
Contributor

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;
Copy link
Contributor

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}
Copy link
Contributor

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>
Copy link
Contributor

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)}
Copy link
Contributor

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>[] = [];
Copy link
Contributor

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;
Copy link
Contributor

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 = {};
Copy link
Contributor

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,
Copy link
Contributor

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propTypes 下面代码要用的,为啥删掉了

@YSMJ1994
Copy link
Contributor

YSMJ1994 commented Feb 2, 2024

@TATATATATAT 麻烦及时跟进一下 review comments

@eternalsky eternalsky linked an issue Feb 22, 2024 that may be closed by this pull request
@YSMJ1994
Copy link
Contributor

Stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants