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: refactor font scss to eliminate duplicate code and simplify the code #94

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

kagol
Copy link
Member

@kagol kagol commented Oct 21, 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

  • Chores
    • Restructured font styling definitions for improved organization and maintainability.
    • Consolidated font definitions into a dynamic map structure for easier updates.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes involve a restructuring of font styling definitions in the font.scss file. The previous explicit definitions for various font styles have been replaced with a dynamic map data structure, $font-map, which consolidates font names and their corresponding font-family values. The implementation uses the @each directive to iterate over the map, generating styles for span[data-value]::before and the ql-picker-label, thereby simplifying the control flow and enhancing maintainability.

Changes

File Path Change Summary
packages/fluent-editor/src/assets/font.scss Replaced explicit font style definitions with a $font-map for dynamic styling using @each.

Possibly related PRs

Poem

In the land of fonts so bright,
A map was drawn, a lovely sight.
No more spans, just loops that play,
Styling dreams in a simpler way.
Hops of joy for code so neat,
A rabbit's cheer, a rhythmic beat! 🐇✨


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.

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 (1)
packages/fluent-editor/src/assets/font.scss (1)

29-34: Ensure Consistent Styling for Picker Labels

The styling for span[data-value=#{$font}].ql-picker-label::before sets properties like width, overflow, text-overflow, and white-space. Verify that these styles are necessary for all fonts and do not conflict with existing styles. If only certain fonts require these styles due to longer names, consider applying these properties conditionally.

If applicable, you might want to adjust the width or other properties to accommodate all font names without truncation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8188ef7 and 5533c90.

📒 Files selected for processing (1)
  • packages/fluent-editor/src/assets/font.scss (1 hunks)
🧰 Additional context used

Comment on lines +24 to +26
content: nth($font-value, 1);
font-family: nth($font-value, 2);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify Access to Font Family Values

In the font-family property, you're using nth($font-value, 2), which references a list of font families. Since the list is nested within another list, you might encounter issues when the CSS is compiled. Consider flattening the font-family list to ensure correct CSS output.

Adjust the font-family assignment as follows:

 span[data-value=#{$font}]::before {
   content: nth($font-value, 1);
-  font-family: nth($font-value, 2);
+  font-family: unquote(join(nth($font-value, 2), ', '));
 }

This change uses join to concatenate the font-family list into a comma-separated string and unquote to remove extra quotes, resulting in valid CSS.

📝 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
content: nth($font-value, 1);
font-family: nth($font-value, 2);
}
content: nth($font-value, 1);
font-family: unquote(join(nth($font-value, 2), ', '));
}

Comment on lines +9 to +21
'arial': ('arial', (arial, helvetica, sans-serif)),
'songti': ('宋体', ('宋体', 'SimSun')),
'yahei': ('微软雅黑', ('微软雅黑', 'Microsoft YaHei')),
'kaiti': ('楷体', ('楷体', '楷体_GB2312', 'SimKai')),
'heiti': ('黑体', ('黑体', 'SimHei')),
'lishu': ('隶书', ('隶书', 'SimLi')),
'mono': ('andale mono', 'andale mono'),
'arialblack': ('arial black', ('arial black', 'avant garde')),
'comic': ('comic sans ms', 'comic sans ms'),
'impact': ('impact', ('impact', 'chicago')),
'times': ('times new roman', 'times new roman'),
);

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure Consistent Structure in $font-map

The $font-map currently contains font-family values that are inconsistently structured—some are lists of fonts, while others are single strings. This inconsistency could lead to unexpected behavior when using functions like nth($font-value, 2) in the @each loop. To prevent potential errors and ensure maintainability, it's advisable to standardize the font-family values across all entries.

Apply this diff to standardize the font-family values:

 $font-map: (
   'arial': ('arial', (arial, helvetica, sans-serif)),
   'songti': ('宋体', ('宋体', 'SimSun')),
   'yahei': ('微软雅黑', ('微软雅黑', 'Microsoft YaHei')),
   'kaiti': ('楷体', ('楷体', '楷体_GB2312', 'SimKai')),
   'heiti': ('黑体', ('黑体', 'SimHei')),
   'lishu': ('隶书', ('隶书', 'SimLi')),
-  'mono': ('andale mono', 'andale mono'),
+  'mono': ('andale mono', ('andale mono')),
-  'arialblack': ('arial black', ('arial black', 'avant garde')),
+  'arialblack': ('arial black', ('arial black', 'avant garde')),
-  'comic': ('comic sans ms', 'comic sans ms'),
+  'comic': ('comic sans ms', ('comic sans ms')),
-  'impact': ('impact', ('impact', 'chicago')),
+  'impact': ('impact', ('impact', 'chicago')),
-  'times': ('times new roman', 'times new roman'),
+  'times': ('times new roman', ('times new roman')),
 );
📝 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
'arial': ('arial', (arial, helvetica, sans-serif)),
'songti': ('宋体', ('宋体', 'SimSun')),
'yahei': ('微软雅黑', ('微软雅黑', 'Microsoft YaHei')),
'kaiti': ('楷体', ('楷体', '楷体_GB2312', 'SimKai')),
'heiti': ('黑体', ('黑体', 'SimHei')),
'lishu': ('隶书', ('隶书', 'SimLi')),
'mono': ('andale mono', 'andale mono'),
'arialblack': ('arial black', ('arial black', 'avant garde')),
'comic': ('comic sans ms', 'comic sans ms'),
'impact': ('impact', ('impact', 'chicago')),
'times': ('times new roman', 'times new roman'),
);
$font-map: (
'arial': ('arial', (arial, helvetica, sans-serif)),
'songti': ('宋体', ('宋体', 'SimSun')),
'yahei': ('微软雅黑', ('微软雅黑', 'Microsoft YaHei')),
'kaiti': ('楷体', ('楷体', '楷体_GB2312', 'SimKai')),
'heiti': ('黑体', ('黑体', 'SimHei')),
'lishu': ('隶书', ('隶书', 'SimLi')),
'mono': ('andale mono', ('andale mono')),
'arialblack': ('arial black', ('arial black', 'avant garde')),
'comic': ('comic sans ms', ('comic sans ms')),
'impact': ('impact', ('impact', 'chicago')),
'times': ('times new roman', ('times new roman')),
);

@kagol kagol merged commit 403efdc into main Oct 21, 2024
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 22, 2024
13 tasks
@kagol kagol deleted the kagol/refactor-font-scss branch October 22, 2024 10:34
@coderabbitai coderabbitai bot mentioned this pull request Dec 6, 2024
13 tasks
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.

1 participant