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

Added Button Colour Handling to CTA card #1418

Merged
merged 2 commits into from
Jan 24, 2025
Merged

Added Button Colour Handling to CTA card #1418

merged 2 commits into from
Jan 24, 2025

Conversation

ronaldlangeveld
Copy link
Member

@ronaldlangeveld ronaldlangeveld commented Jan 24, 2025

ref https://linear.app/ghost/issue/PLG-316/implement-button-colour-handling-on-cta-card

Summary by CodeRabbit

  • New Features

    • Added button text color customization for Call to Action (CTA) card
    • Introduced ability to change button text color dynamically
    • Expanded CTA card styling options
  • Tests

    • Added comprehensive test cases for button color and text color functionality
    • Verified default and custom button color behaviors

Copy link

coderabbitai bot commented Jan 24, 2025

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.

packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js

Oops! Something went wrong! :(

ESLint: 8.57.0

Error: Failed to load parser '@babel/eslint-parser' declared in 'packages/kg-default-nodes/.eslintrc.js': Cannot find module '@babel/eslint-parser'
Require stack:

  • /packages/kg-default-nodes/.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

Walkthrough

The pull request introduces a new buttonTextColor property to the Call To Action (CTA) node and card components across multiple packages. This enhancement allows for more granular customization of button styling by enabling users to specify the text color of the button. The changes span from the node definition in the default nodes package to the Lexical-based implementation, including updates to the component, tests, and related functionality.

Changes

File Change Summary
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js Added buttonTextColor property to node class with default value
packages/kg-default-nodes/test/nodes/call-to-action.test.js Updated tests to include buttonTextColor property and assertions
packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx Cleaned up function parameter comments
packages/koenig-lexical/src/nodes/CallToActionNode.jsx Added buttonTextColor prop to node component
packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx Introduced buttonTextColor prop and handleButtonColorChange method
packages/koenig-lexical/test/e2e/cards/cta-card.test.js Added comprehensive tests for button color and text color functionality

Sequence Diagram

sequenceDiagram
    participant User
    participant CtaCard
    participant CallToActionNode
    participant CallToActionNodeComponent

    User->>CtaCard: Select/Change Button Color
    CtaCard->>CallToActionNodeComponent: Trigger handleButtonColorChange
    CallToActionNodeComponent->>CallToActionNode: Update buttonColor
    CallToActionNodeComponent->>CallToActionNode: Update buttonTextColor
    CallToActionNode-->>CtaCard: Render Updated Button
Loading

Possibly related PRs

Poem

🐰 A button's hue, a colorful delight,
Text dancing bold, now shining bright
With rainbow strokes and color's might
Our CTA leaps to a new height
Code rabbits cheer with pure delight! 🎨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

@ronaldlangeveld ronaldlangeveld marked this pull request as ready for review January 24, 2025 05:34
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)
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (2)

12-12: Unify default values for buttonTextColor.

Currently, this property’s default is set to an empty string here, but the constructor fallback is 'none'. Consider unifying them for consistency.

-        {name: 'buttonTextColor', default: ''},
+        {name: 'buttonTextColor', default: 'none'},

42-42: Confirm 'none' as the intended fallback.

Using 'none' may be semantically ambiguous for a text color—if it’s truly invalid or a placeholder. Consider using something like '#000000' or '#ffffff' if you want a failsafe color, or keep 'none' if it’s an explicit design decision.

Do you want me to propose a more descriptive fallback approach for text color?

packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (1)

58-65: Synchronizing button color and text color.

Linking button color to a matching text color is a neat approach for theming consistency. However, watch out for accessibility (sufficient contrast) when pairing these colors.

packages/koenig-lexical/test/e2e/cards/cta-card.test.js (3)

128-133: Adopt consistent spelling for color/colour.

These lines mix "colour" in the test description with "color" in the code. Choose one spelling throughout the codebase to maintain clarity and consistency.


135-143: Use dedicated data attributes instead of 'title'.

Selecting the element by title="Black" may break if the title attribute changes. Prefer stable, semantically named data attributes (e.g., data-color="black") to make maintenance and testing more robust.


145-153: Abstract the repeated color-change steps.

You’re duplicating similar color-change logic across multiple tests (e.g., black, grey, etc.). Consider factoring this into a helper function that receives a color parameter and checks the resulting styles, improving maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c774ce2 and 7f1a1b0.

📒 Files selected for processing (6)
  • packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (3 hunks)
  • packages/kg-default-nodes/test/nodes/call-to-action.test.js (3 hunks)
  • packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/CallToActionNode.jsx (1 hunks)
  • packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (2 hunks)
  • packages/koenig-lexical/test/e2e/cards/cta-card.test.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx
🔇 Additional comments (10)
packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js (1)

28-28: Constructor parameter validation.

This new constructor parameter aligns with the overall approach, but ensure upstream calls consistently pass a valid color or undefined to correctly trigger the fallback.

packages/koenig-lexical/src/nodes/CallToActionNode.jsx (1)

59-59: Passing new buttonTextColor prop.

Great to see the new color prop passed consistently. Ensure all references, including styling logic, handle the fallback scenario.

packages/koenig-lexical/src/nodes/CallToActionNodeComponent.jsx (3)

24-25: Added buttonTextColor prop to the component.

This prop extension looks straightforward. Confirm that other usage sites (if any) also handle this prop as intended.


71-71: Propagating buttonTextColor to CtaCard.

Good addition for ensuring text color is directly controlled. This should make the CTA card fully themeable.


74-74: Wiring handleButtonColor callback.

The callback pattern is consistent and keeps the parent’s state in sync.

packages/kg-default-nodes/test/nodes/call-to-action.test.js (3)

37-37: Default test dataset text color.

Including 'none' here matches the constructor fallback, but consider updating the default in the property definition for total consistency.


64-64: Verifying extended property coverage.

Adding an assertion ensures the new buttonTextColor property is adequately tested.


99-102: Testing setter functionality.

Excellent addition to ensure buttonTextColor mutates properly and remains consistent with the rest of the node’s state.

packages/koenig-lexical/test/e2e/cards/cta-card.test.js (2)

155-162: Nice coverage of the color picker flow.

This test does a good job verifying the end-to-end workflow for custom colors via the color picker, ensuring correct UI output without extraneous complexity.


164-176: Validate additional edge cases for text color changes.

Currently, the test verifies correct text color for white and black backgrounds. It may be beneficial to test borderline scenarios (e.g., very light greys or invalid color entries) to ensure robust functionality.

@ronaldlangeveld ronaldlangeveld merged commit e3d763e into main Jan 24, 2025
2 checks passed
@ronaldlangeveld ronaldlangeveld deleted the plg-316 branch January 24, 2025 05:40
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.

1 participant