Skip to content

Conversation

@HimonRana
Copy link
Contributor

@HimonRana HimonRana commented Apr 22, 2025

Minor UI/UX improvement, preset colors added in color-picker, strokeField is shown in pen/line/arrow, pin color icon in modal is more aligned.

Preset colors added and pin color aligned:
image

Stroke field is always shown for pen/line/arrow for better user experience:
image

Summary by CodeRabbit

  • New Features
    • Added the ability to hide stroke-related options in annotation tools, allowing for a more streamlined interface in certain annotation modes.
  • Improvements
    • Default pinned colors are now available in the color picker even if no custom colors are saved.
  • Style
    • Adjusted color picker modal styles for improved layout consistency.

…ield is shown in pen/line/arrow, pin color icon in modal is more aligned.
@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

This update introduces a new prop, hideStrokeField, to the AnnotationOptions component, allowing conditional hiding of stroke-related UI and logic. The prop is now passed as true from several annotation tool option components, such as ellipse, polygon, rectangle, text, and image tools. The logic within AnnotationOptions is refactored to respect this prop, affecting which options are displayed and how annotation properties are updated. Additionally, a numeric input synchronized with the stroke width slider is added to the stroke controls. The color input component now initializes pinned colors from a default set if none are stored, and a minor style rule is removed from the color picker modal.

Changes

File(s) Change Summary
.../AnnotationOptions/index.jsx Added hideStrokeField boolean prop to control visibility and logic of stroke-related UI and annotation updates. Refactored option inclusion and rendering logic accordingly. Updated prop types and defaults.
.../Ellipse/EllipseOptions.jsx, .../Polygon/PolygonOptions.jsx, .../Rect/RectOptions.jsx,
.../Text/TextOptions/TextControls.jsx, .../Image/ImageControls.jsx
Passed hideStrokeField prop (as true) to AnnotationOptions in ellipse, polygon, rectangle, text, and image tool option components, altering their annotation UI to hide stroke controls.
.../AnnotationOptions/StrokeFields.jsx Added a numeric input (StyledSliderInput) for stroke width, synchronized with the slider and using the same change handler, allowing direct value entry between 0 and 100.
.../ColorInput/index.jsx Introduced default pinned colors for color selection; initializes state from localStorage or defaults if unavailable. Refactored logic for updating and saving pinned colors, removing previous limit on saved colors count.
.../ColorPickerModal/ColorPickerModal.styled.js Removed a CSS rule setting the width of a color picker input, making no other style or logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant ToolOption as Tool Option Component (e.g., EllipseOptions)
    participant AnnotationOptions
    participant StrokeFields
    participant ColorInput

    ToolOption->>AnnotationOptions: Render with hideStrokeField=true
    AnnotationOptions-->>AnnotationOptions: Hide stroke option logic/UI
    AnnotationOptions-->>StrokeFields: (Only if hideStrokeField=false) Render StrokeFields
    StrokeFields->>StrokeFields: Render Slider and StyledSliderInput (sync strokeWidth)
    AnnotationOptions-->>ColorInput: Render ColorInput for fill (if not hidden)
    ColorInput-->>ColorInput: Load pinned colors (from localStorage or default)
Loading

Poem

In the meadow of code, a new flag appears,
Hiding stroke fields and UI with cheers.
Colors now pinned, with defaults in tow,
Sliders and inputs in harmony flow.
A gentle hop, a style tweak,
The rabbit’s work is never weak!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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.

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)
packages/react-filerobot-image-editor/src/components/common/ColorInput/index.jsx (1)

44-57: Code formatting issue in the conditional

The code looks functionally sound with good localStorage handling, but there's a formatting issue with the if statement indentation.

-    if (JSON.stringify(newPinnedColors) !== JSON.stringify(currentPinnedColors)) {
+    if (
+      JSON.stringify(newPinnedColors) !== JSON.stringify(currentPinnedColors)
+    ) {
🧰 Tools
🪛 ESLint

[error] 52-53: Replace ⏎····if·(JSON.stringify(newPinnedColors)·!==·JSON.stringify(currentPinnedColors) with ····if·(⏎······JSON.stringify(newPinnedColors)·!==·JSON.stringify(currentPinnedColors)⏎····

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (2)

10-10: Fix import ordering to follow project conventions

The import statement for StyledSliderInput should be placed before the local imports.

/** Internal Dependencies */
import restrictNumber from 'utils/restrictNumber';
import ColorInput from 'components/common/ColorInput';
+import { StyledSliderInput } from 'components/tools/tools.styled';
import { StyledSpacedOptionFields } from './AnnotationOptions.styled';
import Slider from '../Slider';
-import { StyledSliderInput } from 'components/tools/tools.styled';
🧰 Tools
🪛 ESLint

[error] 10-10: components/tools/tools.styled import should occur before import of ./AnnotationOptions.styled

(import/order)


34-37: Great enhancement: Added numeric input field for precise stroke width control

Adding a direct input field alongside the slider improves usability by allowing users to enter exact stroke width values. However, there are some formatting issues with indentation.

-      <StyledSliderInput
-          value={strokeWidth}
-          onChange={({ target: { value } }) => changeStrokeWidth(value)}
-        />
+      <StyledSliderInput
+        value={strokeWidth}
+        onChange={({ target: { value } }) => changeStrokeWidth(value)}
+      />
🧰 Tools
🪛 ESLint

[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Delete ··

(prettier/prettier)


[error] 37-37: Delete ··

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (1)

129-130: Fix formatting issues with conditional rendering

There are some formatting issues with the conditional rendering of StrokeFields and spacing before the hideFillOption conditional.

-      { !hideStrokeField && <StrokeFields annotation={annotation} updateAnnotation={updateAnnotation} /> }
-      { !hideFillOption && (
+      {!hideStrokeField && (
+        <StrokeFields 
+          annotation={annotation} 
+          updateAnnotation={updateAnnotation} 
+        />
+      )}
+      {!hideFillOption && (
🧰 Tools
🪛 ESLint

[error] 129-129: Replace ·!hideStrokeField·&&·<StrokeFields·annotation={annotation}·updateAnnotation={updateAnnotation}·/>· with !hideStrokeField·&&·(⏎········<StrokeFields⏎··········annotation={annotation}⏎··········updateAnnotation={updateAnnotation}⏎········/>⏎······)

(prettier/prettier)


[error] 130-130: Delete ·

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d198dd and 19bab1a.

📒 Files selected for processing (9)
  • packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (2 hunks)
  • packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (6 hunks)
  • packages/react-filerobot-image-editor/src/components/common/ColorInput/index.jsx (2 hunks)
  • packages/react-filerobot-image-editor/src/components/common/ColorPickerModal/ColorPickerModal.styled.js (0 hunks)
  • packages/react-filerobot-image-editor/src/components/tools/Ellipse/EllipseOptions.jsx (1 hunks)
  • packages/react-filerobot-image-editor/src/components/tools/Image/ImageControls.jsx (1 hunks)
  • packages/react-filerobot-image-editor/src/components/tools/Polygon/PolygonOptions.jsx (1 hunks)
  • packages/react-filerobot-image-editor/src/components/tools/Rect/RectOptions.jsx (1 hunks)
  • packages/react-filerobot-image-editor/src/components/tools/Text/TextOptions/TextControls.jsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/react-filerobot-image-editor/src/components/common/ColorPickerModal/ColorPickerModal.styled.js
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (1)
packages/react-filerobot-image-editor/src/components/tools/tools.styled.js (1)
  • StyledSliderInput (41-55)
🪛 ESLint
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx

[error] 10-10: components/tools/tools.styled import should occur before import of ./AnnotationOptions.styled

(import/order)


[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Delete ··

(prettier/prettier)


[error] 37-37: Delete ··

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/common/ColorInput/index.jsx

[error] 52-53: Replace ⏎····if·(JSON.stringify(newPinnedColors)·!==·JSON.stringify(currentPinnedColors) with ····if·(⏎······JSON.stringify(newPinnedColors)·!==·JSON.stringify(currentPinnedColors)⏎····

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx

[error] 56-65: Do not nest ternary expressions.

(no-nested-ternary)


[error] 62-64: Replace ⏎············{·titleKey:·'shadow',·name:·POPPABLE_OPTIONS.SHADOW,·Icon:·Shadow·},⏎·········· with {·titleKey:·'shadow',·name:·POPPABLE_OPTIONS.SHADOW,·Icon:·Shadow·}

(prettier/prettier)


[error] 129-129: Replace ·!hideStrokeField·&&·<StrokeFields·annotation={annotation}·updateAnnotation={updateAnnotation}·/>· with !hideStrokeField·&&·(⏎········<StrokeFields⏎··········annotation={annotation}⏎··········updateAnnotation={updateAnnotation}⏎········/>⏎······)

(prettier/prettier)


[error] 130-130: Delete ·

(prettier/prettier)

🔇 Additional comments (11)
packages/react-filerobot-image-editor/src/components/common/ColorInput/index.jsx (2)

13-20: Excellent addition of preset color options!

Adding default preset colors improves the user experience by providing immediate color choices without requiring users to have previously pinned colors. The selection includes basic colors that cover primary use cases and matches the PR objective of enhancing UI/UX.


35-41: Good implementation of localStorage fallback mechanism

The state initialization now properly uses a lazy initializer with the new preset colors as fallback. This ensures users always have color options available even on first use.

packages/react-filerobot-image-editor/src/components/tools/Ellipse/EllipseOptions.jsx (1)

20-20: Appropriate hiding of stroke field for ellipse tool

Adding the hideStrokeField prop aligns with the PR's objective to improve UI consistency across different tools. This ensures that stroke-related UI elements are properly controlled based on the tool type.

packages/react-filerobot-image-editor/src/components/tools/Polygon/PolygonOptions.jsx (1)

28-28: Consistent UI handling with hideStrokeField

Adding the hideStrokeField prop maintains consistency with other shape tools and improves the overall UI experience by controlling visibility of stroke-related options.

packages/react-filerobot-image-editor/src/components/tools/Image/ImageControls.jsx (1)

15-15: Appropriate UI control for image tool

Adding hideStrokeField prop to match the pattern used in other tool components ensures consistent UI behavior across the application. This change properly aligns with the PR's UI/UX improvement goals.

packages/react-filerobot-image-editor/src/components/tools/Text/TextOptions/TextControls.jsx (1)

128-128: LGTM: Added hideStrokeField prop to hide stroke controls for text tools

This addition makes sense as text tools typically work with fill color rather than stroke properties, aligning with the PR objective to make stroke fields consistently display only for relevant tools.

packages/react-filerobot-image-editor/src/components/tools/Rect/RectOptions.jsx (1)

26-26: LGTM: Added hideStrokeField prop to hide stroke controls for rectangle tools

Adding the prop is consistent with the implementation in other shape tools, improving UI consistency across the application.

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (4)

34-34: LGTM: Added hideStrokeField prop for controlling stroke field visibility

This prop allows for more granular control over which annotation tools display stroke-related UI elements, improving the user experience.


66-74: LGTM: Simplified conditional for position fields

Good refactoring of the position fields logic, making it more concise and readable.


97-106: LGTM: Updated annotation fill handler based on hideStrokeField flag

This change intelligently updates either stroke or fill property based on the hideStrokeField flag, which aligns with the PR objective of improving stroke field visibility for relevant tools.


188-188: LGTM: Added default prop and prop type for hideStrokeField

Properly defined the default value (false) and prop type (bool) for the new hideStrokeField prop.

Also applies to: 198-198

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

🧹 Nitpick comments (4)
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (1)

34-37: Good UX improvement: Added numeric input for precise stroke width control.

Adding a numeric input alongside the slider provides users with a more precise way to control stroke width. This improves usability by allowing exact numeric values to be entered directly.

However, there are spacing/indentation issues flagged by ESLint that should be fixed:

-      <StyledSliderInput
-          value={strokeWidth}
-          onChange={({ target: { value } }) => changeStrokeWidth(value)}
-        />
+      <StyledSliderInput
+        value={strokeWidth}
+        onChange={({ target: { value } }) => changeStrokeWidth(value)}
+      />
🧰 Tools
🪛 ESLint

[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Delete ··

(prettier/prettier)


[error] 37-37: Delete ··

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (3)

95-99: Behavior change in changeAnnotationFill function.

The function now updates either the stroke or fill property based on the hideStrokeField flag. While this works, the function name changeAnnotationFill doesn't accurately reflect its dual purpose, which could be confusing for future maintenance.

Consider renaming the function to better reflect its purpose or refactoring to separate concerns:

-  const changeAnnotationFill = useCallback(
+  const changeAnnotationColor = useCallback(
     (newFill) => {
       if (!hideStrokeField) {
         updateAnnotation({ stroke: newFill });
       } else {
         updateAnnotation({ fill: newFill });
       }
     },
-    [updateAnnotation],
+    [updateAnnotation, hideStrokeField],
   );

125-130: Good conditional rendering of StrokeFields component.

The conditional rendering of the StrokeFields component based on the hideStrokeField prop is correctly implemented, though there are some formatting issues:

-      { !hideStrokeField && (
-        <StrokeFields 
-          annotation={annotation} 
-          updateAnnotation={updateAnnotation} 
-        /> 
-      )}
+      {!hideStrokeField && (
+        <StrokeFields
+          annotation={annotation}
+          updateAnnotation={updateAnnotation}
+        />
+      )}
🧰 Tools
🪛 ESLint

[error] 125-125: Delete ·

(prettier/prettier)


[error] 126-126: Delete ·

(prettier/prettier)


[error] 127-127: Delete ·

(prettier/prettier)


[error] 128-128: Delete ·

(prettier/prettier)


[error] 129-129: Delete ·

(prettier/prettier)


131-131: Formatting issue in conditional rendering.

There's an extra space before the opening brace:

-      { !hideFillOption && (
+      {!hideFillOption && (
🧰 Tools
🪛 ESLint

[error] 131-131: Delete ·

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 19bab1a and 6da5be7.

📒 Files selected for processing (2)
  • packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (2 hunks)
  • packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (1)
packages/react-filerobot-image-editor/src/components/tools/tools.styled.js (1)
  • StyledSliderInput (41-55)
🪛 ESLint
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx

[error] 35-35: Delete ··

(prettier/prettier)


[error] 36-36: Delete ··

(prettier/prettier)


[error] 37-37: Delete ··

(prettier/prettier)

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx

[error] 58-58: Replace ·?·[{·titleKey:·'stroke',·name:·POPPABLE_OPTIONS.STROKE,·Icon:·Stroke·}] with ⏎··············?·[⏎··················{⏎····················titleKey:·'stroke',⏎····················name:·POPPABLE_OPTIONS.STROKE,⏎····················Icon:·Stroke,⏎··················},⏎················]⏎·············

(prettier/prettier)


[error] 125-125: Delete ·

(prettier/prettier)


[error] 126-126: Delete ·

(prettier/prettier)


[error] 127-127: Delete ·

(prettier/prettier)


[error] 128-128: Delete ·

(prettier/prettier)


[error] 129-129: Delete ·

(prettier/prettier)


[error] 131-131: Delete ·

(prettier/prettier)

🔇 Additional comments (4)
packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/StrokeFields.jsx (1)

8-8: Good import addition for the new input component.

The import for StyledSliderInput is correctly added to support the new numeric input field for stroke width.

packages/react-filerobot-image-editor/src/components/common/AnnotationOptions/index.jsx (3)

34-34: Good addition of new configuration prop.

Adding the hideStrokeField prop provides a clean way to control the visibility of stroke-related UI elements across different annotation tools.


62-70: Good simplification of conditional rendering for position fields.

The refactored code improves readability by using a more straightforward conditional spread operator pattern for position-related options.


189-189: Properly added default prop and prop type.

The hideStrokeField prop is correctly added to both defaultProps and propTypes, with a sensible default value of false.

Also applies to: 199-199


return (
<StyledSpacedOptionFields>
<StyledSliderInput
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the difference between this and the next Slider call?

Copy link
Contributor Author

@HimonRana HimonRana Sep 9, 2025

Choose a reason for hiding this comment

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

This is an Input that shows the width makes it easier to write strokeWidth if the slider is to hard to slide and find a specific width. Also you dont know exactly what width you have unless you hover over so that helps too(specially in mobile mode).
image

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.

2 participants