Skip to content

fix(fluent-editor): [fluent-editor] change theme #3051

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Mar 10, 2025
Merged

Conversation

James-9696
Copy link
Collaborator

@James-9696 James-9696 commented Mar 6, 2025

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

  • Style

    • Refined the visual presentation of the Fluent Editor with updated hover effects and enhanced color consistency.
    • Introduced a centralized set of theme variables, improving the customization and maintainability of the editor’s appearance.
    • Adjusted visual elements like icons, borders, and box shadows for a more modern and cohesive user experience.
  • Tests

    • Added multiple new test cases to ensure the functionality and behavior of the Fluent Editor, covering basic usage, initialization, data switching, disabled state, image upload, and editor configuration.

Copy link

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request updates the styling for the Fluent Editor component. It introduces a new LESS file that defines CSS custom properties scoped to the component and updates the main styling file to import these variables and apply them via a mixin. The modifications adjust the toolbar, picker, and icon styles by replacing hardcoded values with variable-driven definitions, enabling more flexible theming. Additionally, several new test cases are added to verify the functionality and behavior of the Fluent Editor in various scenarios.

Changes

File(s) Change Summary
packages/theme/src/fluent-editor/index.less Added an import for vars.less and invoked the .inject-FluentEditor-vars() mixin. Updated styles for toolbar, picker labels, and hover states to use CSS variables.
packages/theme/src/fluent-editor/vars.less New file defining CSS custom properties (colors, border, radius, shadow, etc.) for the Fluent Editor component.
examples/sites/demos/pc/app/fluent-editor/basic-usage.spec.ts Added a new test case for basic usage of the FluentEditor component.
examples/sites/demos/pc/app/fluent-editor/before-editor-init.spec.ts Introduced a new test for the initialization of the FluentEditor component.
examples/sites/demos/pc/app/fluent-editor/data-switch.spec.ts Added a new test case for data switching functionality in the editor.
examples/sites/demos/pc/app/fluent-editor/disabled.spec.ts Introduced a new test for the disabled state of the FluentEditor component.
examples/sites/demos/pc/app/fluent-editor/image-upload.spec.ts Added a new test case for image upload functionality in the editor.
examples/sites/demos/pc/app/fluent-editor/options.spec.ts Added a new test case for testing editor configuration options.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zzcr

Poem

I'm a bunny in the codefield,
Hopping through variables with zeal.
LESS files twirl like autumn leaves,
Fluent styles now dance and weave.
A carrot cheer for every line—
Coding magic, simply divine!
🥕🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/demos/pc/app/fluent-editor/data-switch.spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 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 8458226 and 9b429aa.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/fluent-editor/data-switch.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/sites/demos/pc/app/fluent-editor/data-switch.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)

🪧 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.
  • @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 bug Something isn't working label Mar 6, 2025
Copy link

Walkthrough

This PR introduces a theme change for the fluent-editor in the TinyVue project. It primarily involves importing a new variables file and updating the styling of the editor components to use CSS variables for colors, borders, and other stylistic elements, enhancing the theme's flexibility and maintainability.

Changes

Files Summary
packages/theme/src/fluent-editor/index.less Updated to import vars.less and utilize CSS variables for styling, replacing hardcoded values.
packages/theme/src/fluent-editor/vars.less New file added containing CSS variable definitions for the fluent-editor theme.

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: 0

🧹 Nitpick comments (1)
packages/theme/src/fluent-editor/index.less (1)

1-321: Reminder: Add Visual Regression Tests and Documentation Updates:
As noted in the PR objectives, tests and documentation updates have not been provided with these theme changes. It is advisable to include visual regression tests or snapshots to capture the new styling and update the component’s style guide documentation to reflect the usage of new CSS custom properties.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 09fef37 and 519d9c2.

📒 Files selected for processing (2)
  • packages/theme/src/fluent-editor/index.less (3 hunks)
  • packages/theme/src/fluent-editor/vars.less (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/theme/src/fluent-editor/vars.less
🔇 Additional comments (8)
packages/theme/src/fluent-editor/index.less (8)

3-3: New Import for CSS Variables:
The addition of @import './vars.less'; imports essential CSS custom properties for the Fluent Editor theme. Ensure that vars.less defines all the required variables (colors, border radius, shadows, etc.) to maintain consistency across the component.


5-6: Prefix Definitions with Interpolation:
The definitions for @editor-wrapper-prefix-cls and @editor-prefix-cls using tilde string interpolation ensure dynamic class naming based on the global @{css-prefix} variable. Double-check that @{css-prefix} is defined in the global scope so that the generated class names are correct.


8-10: Mixin Invocation for Theme Variable Injection:
Invoking .inject-FluentEditor-vars(); inside the editor wrapper applies the theming variables from vars.less to this component. Please verify that the mixin is properly defined in vars.less and that its styles integrate well with the existing layout without causing side effects.


18-27: SVG Icon Styling Enhancements:
The new svg block within .ql-toolbar.ql-snow sets a consistent font size for icons and adjusts the fill color for path elements. The hover/focus states now use CSS variables (--tv-FluentEditor-select-icon-color-hover) to enable dynamic theming. This change enhances maintainability and theme consistency.


64-89: Enhanced Picker Label Styling:
Within the nested .ql-picker-label block (inside picker-related elements), the text color is now set via var(--tv-FluentEditor-selected-text-color). Additionally, the hover state is adjusted using var(--tv-FluentEditor-select-border-color-hover), and the ::after pseudo-element is configured to create a chevron effect with properties (width, height, border, transform) driven by CSS variables. This approach increases flexibility but ensure that the defined variable values offer sufficient contrast and adhere to accessibility guidelines.


92-95: Picker Label Hover State Updates:
The hover style for .ql-picker-label now utilizes the variables --tv-FluentEditor-select-border-color-hover and --tv-FluentEditor-select-text-color for border and text color, respectively. This ensures a cohesive theme across normal and interactive states.


131-133: Picker Options Styling with Theme Variables:
The .ql-picker-options block has been updated to set the background-color, border-radius, and box-shadow using CSS variables. This change will facilitate easier theme adjustments. Please verify that these variables are defined in vars.less with sensible default or fallback values if needed.


135-141: Picker Item Color Customization:
The styling for .ql-picker-item now leverages theme variables for text color (--tv-FluentEditor-select-text-color) and updates its hover state with a background color (--tv-FluentEditor-select-bg-color-hover) and active text color (--tv-FluentEditor-select-active-text-color). This update aligns the item styles with the overall theme changes.

@James-9696 James-9696 changed the title fix(fluent-editor): [fluent-editor] change theme [WIP:]fix(fluent-editor): [fluent-editor] change theme Mar 6, 2025
@github-actions github-actions bot removed the bug Something isn't working label Mar 6, 2025
@James-9696 James-9696 changed the title [WIP:]fix(fluent-editor): [fluent-editor] change theme fix(fluent-editor): [fluent-editor] change theme Mar 6, 2025
@github-actions github-actions bot added the bug Something isn't working label Mar 6, 2025
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: 0

🧹 Nitpick comments (6)
examples/sites/demos/pc/app/fluent-editor/image-upload.spec.ts (1)

1-7: Good implementation of image upload test.

The test is well-structured and follows the Playwright testing pattern. It correctly sets up error handling and navigates to the appropriate page before performing the click operation.

However, consider enhancing this test with additional assertions to verify what happens after clicking the image upload button (e.g., checking if an upload dialog appears or if a placeholder is shown).

examples/sites/demos/pc/app/fluent-editor/options.spec.ts (1)

1-9: Well-implemented test for editor configuration.

The test correctly verifies the presence of the expected number of toolbar buttons (14) in the Fluent Editor. The approach using locators and count verification is appropriate.

For better maintainability, consider adding a comment explaining why the count is expected to be 14, so if toolbar changes are made in the future, it's clear why this test might need to be updated.

examples/sites/demos/pc/app/fluent-editor/disabled.spec.ts (1)

1-9: Good verification of disabled state.

This test effectively verifies that the editor enters the disabled state by checking for the presence of the .ql-disabled class on the editor element.

Consider adding an additional assertion to verify some functional aspect of the disabled state, such as checking that input attempts are blocked when the editor is disabled.

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

1-15: Comprehensive basic usage test with proper formatting verification.

This test thoroughly checks the core functionality of the Fluent Editor by:

  1. Filling the editor with text
  2. Selecting all text
  3. Applying bold formatting
  4. Verifying the CSS properties to confirm the formatting was applied correctly

The approach with multiple steps and a specific verification of the CSS property is excellent.

For even better coverage, consider adding tests for other common formatting operations like italic, underline, or different text alignments.

examples/sites/demos/pc/app/fluent-editor/data-switch.spec.ts (1)

1-15: Test implementation looks functional but could be improved

The test structure is solid but has a few potential improvements:

  1. Consider adding descriptive comments explaining the purpose of the test, especially since the test title is in Chinese ("数据格式转换" = "Data Format Conversion")
  2. The selector strategy using complex nested locators might be brittle if the DOM structure changes
  3. The assertion checks a very specific CSS 'counter-set' value which seems like an implementation detail rather than a functional requirement

Consider refactoring with these improvements:

import { test, expect } from '@playwright/test'

+// Test for verifying data format conversion functionality in the FluentEditor
test('数据格式转换', async ({ page }) => {
  page.on('pageerror', (exception) => expect(exception).toBeNull())
  await page.goto('fluent-editor#data-switch')
  const demo = page.locator('#data-switch')
+  // Find and interact with the editor content
  await page.locator('#data-switch').getByText('Hello FluentEditor!').click()
  await page.locator('#data-switch #editor div').filter({ hasText: 'Hello FluentEditor!' }).press('ControlOrMeta+a')
  await page.locator('#data-switch').getByLabel('clean').click()
+  
+  // Verify the editor is cleaned properly
  const cls = demo.locator('.ql-editor p')
+  // Check counter-set property (representing empty list state)
  await expect(cls).toHaveCSS(
    'counter-set',
    'list-7 0 list-0 0 list-9 0 list-2 0 list-6 0 list-4 0 list-5 0 list-3 0 list-1 0 list-8 0'
  )
+  
+  // Consider adding a more functional assertion that verifies the editor content is empty
+  // await expect(demo.locator('.ql-editor').textContent()).toBe('');
})
examples/sites/demos/pc/app/fluent-editor/before-editor-init.spec.ts (1)

1-21:

❓ Verification inconclusive

Test validates color functionality but has potential theme compatibility issues

The test correctly validates that the "good" and "bad" buttons apply different text colors, but there are some concerns:

  1. The hardcoded RGB color values (green and red) might break if theme colors change, as suggested by the PR title "fix(fluent-editor): [fluent-editor] change theme"
  2. The test uses complex nested locators that could be fragile if the DOM structure changes
  3. There are no comments explaining what the initialization hook is supposed to do

Run this script to check if the color values used in the test match the current theme variables:

Consider these improvements:

import { test, expect } from '@playwright/test'

+// Test for verifying initialization hooks in the FluentEditor
+// This test validates that text formatting works with good/bad buttons
test('初始化前的钩子', async ({ page }) => {
  page.on('pageerror', (exception) => expect(exception).toBeNull())
  await page.goto('fluent-editor#before-editor-init')
  const demo = page.locator('#before-editor-init')
  
+  // Select text in the editor
  await page.locator('#before-editor-init').getByText('Hello FluentEditor!').click()
  await page
    .locator('#before-editor-init #editor div')
    .filter({ hasText: 'Hello FluentEditor!' })
    .press('ControlOrMeta+a')
    
+  // Apply "good" formatting and verify text is green
  await demo.getByLabel('good').click()
  const cls = demo.locator('.ql-editor strong')
-  await expect(cls).toHaveCSS('color', 'rgb(92, 179, 0)')
+  // Consider using a more theme-independent verification method
+  await expect(cls).toHaveCSS('color', 'rgb(92, 179, 0)') // Success color
  
+  // Re-select text
  await page
    .locator('#before-editor-init #editor div')
    .filter({ hasText: 'Hello FluentEditor!' })
    .press('ControlOrMeta+a')
    
+  // Apply "bad" formatting and verify text is red
  await demo.getByLabel('bad').click()
-  await expect(cls).toHaveCSS('color', 'rgb(242, 48, 48)')
+  // Consider using a more theme-independent verification method
+  await expect(cls).toHaveCSS('color', 'rgb(242, 48, 48)') // Error color
})

🏁 Script executed:

#!/bin/bash
# Search for color variables in the fluent-editor theme files
echo "Searching for theme color variables in fluent-editor theme files:"
rg --color always -i -A 1 -B 1 'color.*rgb\(92, 179, 0\)' --glob '*.less' packages/theme/src/
rg --color always -i -A 1 -B 1 'color.*rgb\(242, 48, 48\)' --glob '*.less' packages/theme/src/

Length of output: 333


Action Required: Review Test Fragility Regarding Hardcoded Colors and Locator Complexity

The current test properly validates that the "good" and "bad" buttons apply distinct text colors, but the following concerns remain:

  • The hardcoded RGB values (green: rgb(92, 179, 0) and red: rgb(242, 48, 48)) lack a clear link to theme variables. Our automated search did not locate these color definitions in the expected theme files, so please manually verify whether these colors are indeed fixed or if they rely on theme variables that could change.
  • The use of nested locators might be fragile if the DOM structure changes in future revisions.
  • The test is missing comments to explain the purpose of the initialization hook; adding a brief comment would improve code readability.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 519d9c2 and 8458226.

📒 Files selected for processing (6)
  • examples/sites/demos/pc/app/fluent-editor/basic-usage.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/before-editor-init.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/data-switch.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/disabled.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/image-upload.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/options.spec.ts (1 hunks)

@zzcr zzcr merged commit 615d91b into dev Mar 10, 2025
7 of 10 checks passed
@kagol kagol deleted the fix-fluent-edit-theme branch April 14, 2025 12:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants