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(alert): [alert] Adapting to the SMB theme #2169

Merged
merged 1 commit into from
Sep 24, 2024
Merged

feat(alert): [alert] Adapting to the SMB theme #2169

merged 1 commit into from
Sep 24, 2024

Conversation

Youyou-smiles
Copy link
Collaborator

@Youyou-smiles Youyou-smiles commented Sep 24, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Introduced a new alert type, "simple," represented by an icon.
  • Style
    • Updated CSS properties for alert boxes, including background and border colors.
    • Adjusted the height for the large alert size.
    • Enhanced vertical alignment of alert components and modified spacing properties.
  • Bug Fixes
    • Corrected CSS variable definitions for alert icon margins and colors.

Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes in this pull request primarily focus on updates to the alert component's styling and structure. This includes modifications to CSS properties in test files, adjustments to the alert component's size, and enhancements to the corresponding LESS files. Additionally, a new constant for a "simple" alert type has been introduced in the Vue component, expanding the alert's categorization options.

Changes

Files Change Summary
examples/sites/demos/pc/app/alert/*.spec.ts Updated expected CSS properties for alert boxes, including background and border-bottom colors for four alert types, and modified the expected height for the tiny-alert--large class.
packages/theme/src/alert/*.less Added align-items: center; to the alert container, removed margins for the alert icon and title, and updated the is-center class for content alignment.
packages/theme/src/alert/vars.less Removed and updated several CSS variables related to the alert component's styling, including icon margin, font size, and title margin.
packages/vue/src/alert/src/index.ts Introduced a new constant simple with the value 'icon-help' to the $constants object, adding a new alert type.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zzcr

Poem

🐰 In the meadow, bright alerts do sing,
Colors changing, oh what joy they bring!
With icons simple, and styles anew,
Our alerts now dance in a vibrant hue.
Hooray for updates, let’s hop and cheer,
For every change brings us closer, my dear! 🌼


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 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.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label Sep 24, 2024
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: 2

Outside diff range and nitpick comments (3)
examples/sites/demos/pc/app/alert/basic-usage.spec.ts (1)

Line range hint 1-41: Consider enhancing test maintainability and readability.

The test structure is sound and covers essential aspects of the alert component. However, consider the following suggestions to improve maintainability and readability:

  1. Extract color values into constants at the top of the file. This would make it easier to update colors in the future and improve readability.

  2. Consider using a loop or a custom function to test the colors for all alert types. This would reduce code duplication and make it easier to add or modify alert types in the future.

  3. Add comments to clearly separate different sections of the test (e.g., color testing, visibility testing, functionality testing).

Here's an example of how you could implement suggestions 1 and 2:

const ALERT_COLORS = {
  info: 'rgb(222, 236, 255)',
  error: 'rgb(252, 227, 225)',
  success: 'rgb(230, 242, 213)',
  warning: 'rgb(255, 235, 209)'
};

// ... existing imports and test setup ...

// Test colors for all alert types
Object.entries(ALERT_COLORS).forEach(([type, color], index) => {
  await expect(alertBox.nth(index)).toHaveCSS('background-color', color);
  await expect(alertBox.nth(index)).toHaveCSS('border-bottom-color', color);
});

// ... rest of the test ...

These changes would make the test more maintainable and easier to update in the future.

packages/theme/src/alert/index.less (1)

152-152: LGTM: Enhanced centering for alerts with is-center class

The addition of align-items: center; to the .is-center class improves the centering of alert contents. This change, combined with the existing justify-content: center;, ensures both horizontal and vertical centering, which is an improvement over the previous text-align: center; approach.

Consider adding text-align: center; back to ensure inline content within the alert is also centered:

.is-center {
  justify-content: center;
  align-items: center;
+ text-align: center;
}

This will ensure that any inline text or elements are also centered horizontally within the alert.

packages/theme/src/alert/vars.less (1)

Line range hint 1-159: Summary of Alert Component Theme Changes

The changes to the alert component's theme variables appear to be in line with adapting to the SMB theme, as mentioned in the PR objectives. However, there are a few points that need attention:

  1. The change to --ti-alert-large-icon-font-size should be verified to ensure it meets the design specifications for the SMB theme.
  2. The use of a hard-coded color value for --ti-alert-simple-icon-color may reduce theme flexibility. Consider using a theme variable instead.
  3. The removal of margin-related variables needs to be verified to ensure it doesn't negatively impact the component's layout and responsiveness.

Please address these points and provide any necessary visual confirmations to ensure the alert component meets the SMB theme requirements while maintaining flexibility and consistency.

When adapting components to new themes, it's generally better to introduce new theme-specific variables rather than modifying existing ones or using hard-coded values. This approach allows for better maintainability and easier theme switching in the future.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f559970 and aff6b1b.

Files selected for processing (5)
  • examples/sites/demos/pc/app/alert/basic-usage.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/alert/size.spec.ts (1 hunks)
  • packages/theme/src/alert/index.less (3 hunks)
  • packages/theme/src/alert/vars.less (2 hunks)
  • packages/vue/src/alert/src/index.ts (1 hunks)
Additional comments not posted (6)
examples/sites/demos/pc/app/alert/size.spec.ts (1)

9-9: Approved: Height adjustment for large alert

The change from 68px to 77px for the large alert's height aligns with the PR objective of adapting to the SMB theme.

Consider adding a comment explaining the reason for this height change, which could be helpful for future maintenance. For example:

// Height increased to 77px to accommodate new SMB theme requirements
await expect(largeAlert).toHaveCSS('height', '77px')

Please verify if this height change affects other components or layouts that might be using the large alert. You may want to check:

  1. Any parent components that contain the alert
  2. Responsive designs that might be affected by this height increase
  3. Other test cases that might need updating

To help with this verification, you can run the following script:

This will help identify other places in the code that might need adjustment due to this change.

Verification successful

Verified: Height adjustment for large alert

The change from 68px to 77px for the large alert's height appears to be isolated to the test files, and there are no other occurrences that might affect other components or layouts.

It is recommended to add a comment explaining the reason for this height change for future maintenance. For example:

// Height increased to 77px to accommodate new SMB theme requirements
await expect(largeAlert).toHaveCSS('height', '77px')
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of the alert height in the codebase
rg --type typescript --type vue "tiny-alert--large"
rg --type typescript --type vue "68px"

Length of output: 160


Script:

#!/bin/bash
# Search for other occurrences of the alert height in the codebase
rg --type ts --type vue "tiny-alert--large"
rg --type ts --type vue "68px"

Length of output: 130


Script:

#!/bin/bash
# Search for other occurrences of the alert height in the codebase
rg "tiny-alert--large" --glob "*.ts" --glob "*.vue"
rg "68px" --glob "*.ts" --glob "*.vue"

Length of output: 698

examples/sites/demos/pc/app/alert/basic-usage.spec.ts (1)

11-18: Color updates for alert boxes align with SMB theme adaptation.

The changes to the background and border colors for the alert boxes are consistent with the PR objective of adapting to the SMB theme. The new colors appear to be more muted and cohesive, which likely improves the overall visual design.

Some observations:

  1. The background and border-bottom colors are now the same for each alert type, creating a more unified look.
  2. The color changes are applied consistently across all four alert types (info, error, success, and warning).
  3. The color differences between alert types are still distinct, maintaining their separate visual identities.

To ensure these color changes are consistent with the design system, let's check if these colors are defined in a central theme file:

packages/theme/src/alert/index.less (2)

34-34: LGTM: Improved vertical alignment for normal alerts

The addition of align-items: center; to the normal-sized alert improves the vertical alignment of its contents. This change is consistent with the PR objective of adapting to the SMB theme and enhances the overall appearance of the alert component.


192-192: LGTM: Improved title styling with specific line-height

The addition of line-height: 20px; to the alert title improves the consistency and potentially the readability of the text. This change contributes to a more polished appearance of the alert component.

Please confirm that the 20px line-height aligns with the SMB theme design system. If there's a design token or variable for title line-heights, consider using that instead of a hard-coded value:

Verification successful

Verified: 20px line-height aligns with the SMB theme design system

The line-height: 20px; in packages/theme/src/alert/index.less conforms to the design system's specifications. No further changes are required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for design tokens or variables related to line-height in the theme
rg --type less "line-height.*20px" packages/theme/
rg --type less "ti-.*-line-height.*20px" packages/theme/

Length of output: 1994

packages/theme/src/alert/vars.less (2)

90-90: LGTM. Verify the intended icon size.

The change from --ti-common-font-size-5 to --ti-common-font-size-4 for the large icon font size looks good. This adjustment might align better with the SMB theme mentioned in the PR objectives.

Please confirm that this change achieves the desired icon size for large alerts in the SMB theme. You may want to visually inspect the rendered component to ensure it meets the design specifications.


Line range hint 1-159: Verify layout after removal of margin variables.

The variables --ti-alert-icon-margin-top and --ti-alert-title-margin-top have been removed. While this may simplify the component's styling, it's important to ensure that the alert's layout remains correct and consistent across different sizes and types.

Please confirm that:

  1. The alert icon and title are still properly aligned without these margin variables.
  2. The layout looks correct in all alert types (success, warning, error, info, simple).
  3. The component remains responsive and maintains its appearance across different screen sizes.

Consider providing before and after screenshots to demonstrate that the layout has not been negatively impacted by this change.

Comment on lines +20 to +21
warning: 'icon-warning',
simple: 'icon-help'
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Incomplete implementation of the new 'simple' alert type

The addition of the 'simple' alert type in the ICON_MAP is not fully supported across the codebase. The TITLE_MAP and type prop definitions do not include 'simple', and no other references to the 'simple' type were found. Please ensure that the 'simple' type is consistently implemented throughout the codebase to avoid potential inconsistencies and user confusion.

Analysis chain

Consider refining the implementation of the new 'simple' alert type

The addition of a 'simple' alert type aligns with the PR objective of adapting to the SMB theme. However, there are a few points to consider:

  1. The 'simple' type uses the same icon as 'info' (icon-help). This might lead to confusion for users. Consider using a distinct icon for 'simple' to differentiate it from 'info'.

  2. The TITLE_MAP object hasn't been updated to include a title for the 'simple' type. This might cause issues when trying to display a title for a 'simple' alert.

  3. The type prop definition in alertProps still defaults to 'info' and doesn't mention 'simple' as a possible value. This should be updated to include the new 'simple' type.

To address these points, consider the following changes:

  1. Use a distinct icon for 'simple':
 ICON_MAP: {
   success: 'icon-success',
   error: 'icon-error',
   info: 'icon-help',
   warning: 'icon-warning',
-  simple: 'icon-help'
+  simple: 'icon-simple' // Replace with an appropriate icon
 },
  1. Add a title for 'simple' in TITLE_MAP:
 TITLE_MAP: {
   success: 'ui.alert.success',
   error: 'ui.alert.error',
   info: 'ui.alert.info',
-  warning: 'ui.alert.warning'
+  warning: 'ui.alert.warning',
+  simple: 'ui.alert.simple'
 },
  1. Update the type prop definition:
 type: {
   type: String,
-  default: 'info'
+  default: 'info',
+  validator: (value: string) => ['success', 'error', 'info', 'warning', 'simple'].includes(value)
 },

To ensure full compatibility with the new 'simple' type, run the following script to check for any other occurrences of alert types that might need updating:

This will help identify any other locations where the alert types are used or checked, ensuring comprehensive implementation of the new 'simple' type.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for alert type references in the codebase

echo "Searching for alert type references:"
rg --type typescript --type vue "type.*(?:success|error|info|warning)" -g '!**/index.ts'

Length of output: 208


Script:

#!/bin/bash
# Description: Search for alert type references in the codebase

echo "Searching for alert type references:"
rg --type ts --type tsx --type vue "type.*(?:success|error|info|warning)" -g '!**/index.ts'

Length of output: 204


Script:

#!/bin/bash
# Description: Search for alert type references in the codebase

echo "Searching for alert type references:"
rg --type typescript --type typescriptreact --type vue "type.*(?:success|error|info|warning)" -g '!**/index.ts'

Length of output: 231


Script:

#!/bin/bash
# Description: Search for alert type references in the codebase using file extensions

echo "Searching for alert type references:"
rg "type.*(?:success|error|info|warning)" -g "*.ts" -g "*.tsx" -g "*.vue" -g "!**/index.ts"

Length of output: 70336

@@ -150,7 +146,7 @@
// simple类型边框色
--ti-alert-simple-border-color: var(--ti-common-color-info-border, #d3d4d6);
// simple类型图标色
--ti-alert-simple-icon-color: var(--ti-common-color-text-secondary, #575d6c);
--ti-alert-simple-icon-color: #808080;
Copy link

Choose a reason for hiding this comment

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

Consider using a theme variable instead of a hard-coded color.

The change from var(--ti-common-color-text-secondary, #575d6c) to #808080 for the simple icon color reduces theme flexibility. While this may align with the SMB theme requirements, it could lead to inconsistencies if the theme is updated in the future.

Consider one of the following alternatives:

  1. Use an existing theme variable that matches the desired color.
  2. Create a new theme variable for this specific use case.

For example:

--ti-alert-simple-icon-color: var(--ti-theme-simple-icon-color, #808080);

This approach maintains flexibility while still achieving the desired color for the SMB theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants