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: ✨ Toast支持横向排版和纵向排版(#780) #881

Merged

Conversation

jiaoxueyan
Copy link
Contributor

@jiaoxueyan jiaoxueyan commented Feb 8, 2025

Toast支持横向排版和纵向排版

Closes: #780

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

#780

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • 新功能
    • Toast 通知组件现支持横向与纵向两种显示模式,用户可自主选择布局展示方式。
  • 文档
    • 更新了组件文档,详细说明了新布局参数及其用法,便于用户了解如何配置通知方向。
  • 样式
    • 优化了组件视觉效果,调整图标间距和整体排版,确保在不同布局模式下均有良好展示效果。

Copy link

vercel bot commented Feb 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2025 9:13am

Copy link

coderabbitai bot commented Feb 8, 2025

Walkthrough

本次 PR 对 Toast 组件进行了改进。文档中新增了“排版方向”的说明及 direction 参数,允许用户通过设置参数调整消息的布局(水平或竖直)。页面模板中新增了两个按钮及对应函数(showHorizonToast 与 showVerticalToast),用于触发不同布局的 Toast。SCSS 文件中新增变量和条件样式以支持竖直布局,组件的逻辑文件、类型定义和模板也作出了相应更新,以便在关闭时仅修改特定属性,保证状态精细管理。

Changes

文件 变更摘要
docs/component/toast.md 更新文档,新增“排版方向”及 direction 参数说明
src/pages/toast/Index.vue 新增 showHorizonToast 与 showVerticalToast 函数及按钮,触发不同布局
src/uni_modules/wot-design-uni/components/.../variable.scss
src/uni_modules/wot-design-uni/components/wd-toast/index.scss
新增 SCSS 变量及条件样式,支持竖直布局的 flex-direction 与边距调整
src/uni_modules/wot-design-uni/components/wd-toast/(index.ts, types.ts, wd-toast.vue) 修改 close 函数、更新 ToastOptions 类型及模板渲染逻辑以支持 direction 参数

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant 页面 as Index.vue
    participant Toast as wd-toast 组件
    用户->>页面: 点击显示水平/竖直 Toast 按钮
    页面->>Toast: 调用 toast.success({ message, direction })
    alt 当 direction 为 "vertical"
        Toast->>Toast: 设置 is-vertical 类,调整布局为竖直
    else 默认水平布局
        Toast->>Toast: 保持默认水平布局
    end
    Toast->>用户: 显示 Toast 消息
Loading

Assessment against linked issues

Objective Addressed Explanation
Toast支持竖直排版及简洁icon样式 (#780)

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

我是一只跳跃的小兔,
见证代码焕然一新美如画,
Toast竖排新姿展风采,
icon简洁似晨曦初露,
代码跳动欢乐不断,
与君共享这美丽时刻!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03f2acb and a5d75d0.

📒 Files selected for processing (2)
  • docs/component/toast.md (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/uni_modules/wot-design-uni/components/wd-toast/types.ts
  • docs/component/toast.md

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Feb 8, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a5d75d0
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67a71ffde8512900089e5ead
😎 Deploy Preview https://deploy-preview-881--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/uni_modules/wot-design-uni/components/wd-toast/wd-toast.vue (2)

11-11: 建议提取重复的条件判断

多处重复使用 toastOption.direction === 'vertical' 判断,建议提取为计算属性。

+const isVertical = computed(() => toastOption.value.direction === 'vertical')
+
 // 在模板中使用
-:custom-class="`wd-toast__icon ${toastOption.direction === 'vertical' ? 'is-vertical' : ''}`"
+:custom-class="`wd-toast__icon ${isVertical.value ? 'is-vertical' : ''}`"

Also applies to: 14-14, 23-23


119-123: 建议增加 direction 值的类型保护

当前实现可能无法优雅地处理拼写错误的 'horizonal',建议添加类型保护。

+const isValidDirection = (dir?: string): dir is 'vertical' | 'horizontal' => {
+  return dir === 'vertical' || dir === 'horizontal'
+}
+
 const rootClass = computed(() => {
+  const direction = toastOption.value.direction
   return `wd-toast ${props.customClass} wd-toast--${position.value} ${
     (iconName.value !== 'loading' || msg.value) && (iconName.value || iconClass.value) ? 'wd-toast--with-icon' : ''
-  } ${iconName.value === 'loading' && !msg.value ? 'wd-toast--loading' : ''} ${toastOption.value.direction === 'vertical' ? 'is-vertical' : ''}`
+  } ${iconName.value === 'loading' && !msg.value ? 'wd-toast--loading' : ''} ${isValidDirection(direction) && direction === 'vertical' ? 'is-vertical' : ''}`
 })
src/uni_modules/wot-design-uni/components/wd-toast/index.ts (1)

69-69: 优化了状态更新方式

直接更新 show 属性而不是替换整个对象是个好的优化,它保留了其他 toast 选项。建议在注释中说明这个行为。

 const close = () => {
+  // 仅更新 show 状态,保留其他 toast 选项
   toastOption.value.show = false
 }
docs/component/toast.md (1)

69-79: 文档中新增“排版方向”说明:
文档对新参数 direction 的说明较为清楚,并提供了示例代码展示如何调用 success toast 时传入 direction: 'vertical'。
【建议】检查可选值描述中 “horizonal” 的拼写,是否应该调整为 “horizontal”,以避免使用者产生困惑。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccf976a and 03f2acb.

📒 Files selected for processing (7)
  • docs/component/toast.md (2 hunks)
  • src/pages/toast/Index.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/index.scss (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/index.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/wd-toast.vue (2 hunks)
🔇 Additional comments (4)
src/pages/toast/Index.vue (1)

26-29: 代码实现清晰,展示了两种调用方式

示例代码结构良好,分别展示了简单调用和对象配置两种使用方式,便于用户理解。

Also applies to: 107-116

src/uni_modules/wot-design-uni/components/wd-toast/index.scss (2)

16-18: 新增竖直排版样式块:
这部分代码利用 @include when(vertical) 来判断是否应用竖直布局,并将 flex-direction 设置为 column,逻辑清晰,符合预期。


29-33: 调整图标边距以适应竖直排版:
在图标样式中新增的 when(vertical) 块,将 margin-right 设为 0 并添加 margin-bottom 使用新变量 $-toast-icon-margin-bottom,很好地解决了横向与竖直布局下图标间距不一致的问题。

src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss (1)

650-650: 新增变量 $-toast-icon-margin-bottom:
新增的 $-toast-icon-margin-bottom 定义合理,为竖直布局下图标提供了适当的下边距支持,能有效增强布局的一致性。

@@ -20,6 +20,7 @@ export type ToastLoadingType = LoadingType // 提示信息加载状态类型
export type ToastOptions = {
msg?: string
duration?: number
direction?: 'vertical' | 'horizonal'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修正 'horizonal' 拼写错误

direction 类型定义中 'horizonal' 拼写错误,应该为 'horizontal'。

-  direction?: 'vertical' | 'horizonal'
+  direction?: 'vertical' | 'horizontal'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
direction?: 'vertical' | 'horizonal'
direction?: 'vertical' | 'horizontal'

 Toast支持横向排版和纵向排版

✅ Closes: Moonofweisheng#780
@Moonofweisheng Moonofweisheng merged commit ed60852 into Moonofweisheng:master Feb 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[新功能需求] Toast支持竖直排版,提供icon简洁样式
2 participants