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

feat: add Typography component #15

Merged
merged 1 commit into from
Apr 17, 2024
Merged

Conversation

Jandiasnow
Copy link
Member

@Jandiasnow Jandiasnow commented Apr 15, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

🔀 变更说明 | Description of Change

feat: add Typography component

📝 补充信息 | Additional Information

@yunti-bot
Copy link
Collaborator

👍 @Jandiasnow


Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

}
return '';
};
const lang = getCookie('intl_locale') || window.localStorage.getItem('intl_locale') || 'zh';
Copy link
Member

Choose a reason for hiding this comment

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

组件的国际化参考下 antd,通过 cookie 判断不太可取


const fmtTime = dayjs(time ? new Date(time) : new Date()).format(format || 'YYYY-MM-DD HH:mm:ss');
if (!relativeTime) {
return <span>{time ? fmtTime : '-'}</span>;
Copy link
Member

Choose a reason for hiding this comment

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

如果指定了 tooltip,这里是不是也应该有 tooltip

time: string;
format?: string;
relativeTime?: boolean;
tooltip?: TooltipPropsWithTitle;
Copy link
Member

Choose a reason for hiding this comment

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

自定义的组件,最基本的属性要支持,比如 classNamestyle 等,建议基于 Text 扩展下,别直接用 span

Comment on lines 81 to 96
const TooltipDom = (currentTime: string) => {
return (
<Tooltip
{...tooltip}
title={tooltip ? tooltip.title : fmtTime(formatTooltip ? format : undefined)}
>
<Typography.Text {...textProps}>{currentTime}</Typography.Text>
</Tooltip>
);
};

if (!relativeTime) {
return TooltipDom(time ? fmtTime(format) : '-');
}

return time ? TooltipDom(showTime) : <Typography.Text {...textProps}>-</Typography.Text>;
Copy link
Member

Choose a reason for hiding this comment

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

这块儿代码需要优化下:

  • tooltip 与 ellipsis.tooltip 可能会导致多个 tooltip,当有外层 tooltip 的时候,ellipsis.tooltip 应该设置为 false
  • 目前的代码为了区分是否有 tooltip,感觉有点儿复杂了,可以考虑外层 tooltip 固定,不需要的时候不设置 title 是否就可以?这样结构也稳定些

}
}, [time, relativeTime]);

const fmtTime = dayjs(time ? new Date(time) : new Date()).format(format || 'YYYY-MM-DD HH:mm:ss');
Copy link
Member

Choose a reason for hiding this comment

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

这儿为啥要加默认值,我们刚说的不是不要默认值吗


const currentTime = relativeTime ? showTime : fmtTime;

const tooltipTitle = tooltip ? tooltip.title : fmtTime;
Copy link
Member

Choose a reason for hiding this comment

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

// 非相对时间时,默认不展示 tooltip,走 Text 默认的溢出展示 tooltip 的逻辑

const tooltipTitle = tooltip.title ??  (relativeTime ? fmtTime : undefined);

@Carrotzpc Carrotzpc merged commit 67eba72 into yuntijs:beta Apr 17, 2024
1 check passed
@yunti-bot
Copy link
Collaborator

❤️ Great PR @Jandiasnow ❤️


The growth of project is inseparable from user feedback and contribution, thanks for your contribution!
项目的成长离不开用户反馈和贡献,感谢您的贡献!

@yunti-bot
Copy link
Collaborator

🎉 This PR is included in version 1.0.0-beta.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants