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

[WEB-4100] Add LinkButton component, migrate new buttons to PricingCards component #575

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

jamiehenson
Copy link
Member

@jamiehenson jamiehenson commented Dec 12, 2024

Jira Ticket Link / Motivation

Supporting component for the ongoing docs navigation rewrite.

The LinkButton component is functionally identical to Button, but is based around an a tag instead of a button tag - this means that thinks like linking are natively supported. I considered having a prop modify Button, but figured that introduces unnecessary complexity when the two elements serve different roles.

Also contains fixes for incorrect hover colouring on PricingCards buttons, and a fix to the hover behaviour for high priority buttons by taking the animated fade from the legacy buttons.

Note, the Storybook test runner is timing out here and I'm not sure why. As far as I can see all the stories and components display just fine.

How do you manually test this?

Book

Reviewer Tasks (optional)

Merge/Deploy Checklist

  • Written automated tests for implemented features/fixed bugs
  • Rebased and squashed commits
  • Commits have clear descriptions of their changes
  • Checked for any performance regressions

Frontend Checklist

  • No frontend changes in this PR
  • Added before/after screenshots for changes
  • Tested on different platforms/browsers with Browserstack
  • Compared with the initial design / our brand guidelines
  • Checked the code for accessibility issues (VoiceOver User Guide)?

Summary by CodeRabbit

  • New Features

    • Introduced a new LinkButton component that behaves like a button while rendering as a link.
    • Updated PricingCards to utilize the new LinkButton for call-to-action buttons.
  • Bug Fixes

    • Improved styling for disabled buttons to ensure appropriate cursor behavior.
  • Style

    • Enhanced button styles, including hover and active states for priority buttons.
  • Documentation

    • Added Storybook stories for the LinkButton component, showcasing its various states.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request involve significant updates to the Button component and the introduction of a new LinkButton component. The Button component's properties are restructured for better organization, and utility functions are added to streamline class name generation and rendering. The new LinkButton component extends button functionality by rendering an anchor element, allowing for link-like behavior. Additionally, Storybook stories for LinkButton are created, and existing components are updated to use LinkButton instead of FeaturedLink. CSS styles for buttons are also refined to enhance visual feedback.

Changes

File Change Summary
src/core/Button.tsx - Created ButtonPropsBase type.
- Updated ButtonProps to extend ButtonPropsBase.
- Added commonButtonProps and commonButtonInterior functions.
- Updated Button component signature.
src/core/LinkButton.tsx - Added new LinkButton component.
- Introduced LinkButtonProps type with additional attributes.
src/core/LinkButton/LinkButton.stories.tsx - Created Storybook configuration for LinkButton with stories: Default, External, Disabled.
src/core/Pricing/PricingCards.tsx - Replaced FeaturedLink with LinkButton in the PricingCards component.
src/core/Pricing/data.tsx - Modified cta object for "Enterprise" pricing plan to change class name.
src/core/styles/buttons.css - Updated button styles, including changes to .ui-button-base, .ui-button-disabled, and .ui-button-priority-base.

Assessment against linked issues

Objective Addressed Explanation
Implement new header and footer for docs (WEB-4100) No changes related to header/footer.

Possibly related PRs

Suggested labels

review

Suggested reviewers

  • aralovelace
  • kennethkalmer

Poem

In the meadow, buttons shine,
With links that leap and intertwine.
A click, a tap, they dance and play,
Enhancing joy in every way!
So hop along, let's celebrate,
The changes made, oh, isn't it great! 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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
Contributor

@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: 3

🧹 Outside diff range and nitpick comments (8)
src/core/Button.tsx (3)

68-79: Consider memoizing the commonButtonProps function

The function generates class names based on props. Consider memoizing it to prevent unnecessary recalculations, especially when used in both Button and LinkButton components.

-export const commonButtonProps = (props: ButtonPropsBase) => {
+export const commonButtonProps = React.memo((props: ButtonPropsBase) => {
   const { variant = "primary", size, leftIcon, rightIcon, className } = props;

   return {
     className: cn(
       buttonClasses[variant][size ?? "md"],
       { [iconModifierClasses[size ?? "md"].left]: leftIcon },
       { [iconModifierClasses[size ?? "md"].right]: rightIcon },
       className,
     ),
   };
-};
+});

81-92: Enhance accessibility for button content

While the interior layout is consistent, consider adding aria-hidden to decorative icons and proper spacing for screen readers.

 export const commonButtonInterior = (
   props: PropsWithChildren<ButtonPropsBase>,
 ) => {
   const { leftIcon, rightIcon, children } = props;
   return (
     <>
-      {leftIcon ? <Icon name={leftIcon} /> : null}
+      {leftIcon ? <Icon name={leftIcon} aria-hidden="true" /> : null}
       {children}
-      {rightIcon ? <Icon name={rightIcon} /> : null}
+      {rightIcon ? <Icon name={rightIcon} aria-hidden="true" /> : null}
     </>
   );
 };

105-108: Consider removing type assertion for better type safety

The type assertion on rest props could be avoided since ButtonProps already includes ButtonHTMLAttributes.

-      {...(rest as React.ButtonHTMLAttributes<HTMLButtonElement>)}
+      {...rest}
src/core/LinkButton/LinkButton.stories.tsx (3)

5-16: Good story configuration with clear documentation!

Consider adding more detailed usage examples in the description, such as when to use LinkButton vs Button.


20-33: Well-structured stories with security best practices!

Consider adding more examples showcasing different variants and sizes.

export const WithIcon = Template.bind({});
WithIcon.args = {
  href: "#",
  variant: "primary",
  children: "Button with Icon",
  leftIcon: "arrow-right"
};

35-40: Add interaction testing for disabled state

Consider adding an interaction test to verify that clicks are prevented when disabled.

// Add to story metadata
parameters: {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    const button = canvas.getByText('Disabled Link Button');
    await userEvent.click(button);
    // Verify no navigation occurred
  },
}
src/core/styles/buttons.css (1)

126-132: Consider consolidating disabled styles

You've introduced new .ui-button-disabled classes while maintaining similar styles in .ui-button-disabled-base. This could lead to confusion about which disabled styles to use.

Consider consolidating these styles to avoid duplication:

- .ui-button-disabled {
-   @apply select-none pointer-events-none bg-gui-unavailable text-gui-unavailable-dark hover:bg-gui-unavailable;
- }

- .ui-theme-dark .ui-button-disabled {
-   @apply select-none pointer-events-none bg-gui-unavailable-dark text-gui-unavailable hover:bg-gui-unavailable-dark;
- }

  .ui-button-disabled-base {
-   @apply disabled:cursor-not-allowed disabled:bg-gui-unavailable disabled:text-gui-unavailable-dark disabled:hover:bg-gui-unavailable;
+   @apply disabled:cursor-not-allowed disabled:bg-gui-unavailable disabled:text-gui-unavailable-dark disabled:hover:bg-gui-unavailable disabled:select-none disabled:pointer-events-none;
  }
src/core/Pricing/PricingCards.tsx (1)

188-190: Consider explicit variant mapping

The variant="primary" is hardcoded while className is being passed from cta. This might lead to style conflicts.

Consider allowing variant override through props:

 <LinkButton
   className={cn("w-full", cta.className)}
-  variant="primary"
+  variant={cta.variant ?? "primary"}
   href={cta.url}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 581566e and 15ceed5.

📒 Files selected for processing (6)
  • src/core/Button.tsx (4 hunks)
  • src/core/LinkButton.tsx (1 hunks)
  • src/core/LinkButton/LinkButton.stories.tsx (1 hunks)
  • src/core/Pricing/PricingCards.tsx (2 hunks)
  • src/core/Pricing/data.tsx (1 hunks)
  • src/core/styles/buttons.css (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/core/Pricing/data.tsx
🔇 Additional comments (3)
src/core/Button.tsx (1)

Line range hint 10-31: Well-structured type definition with clear documentation!

Good architectural decision to extract ButtonPropsBase as it enables proper type sharing between Button and LinkButton components while maintaining clear documentation.

src/core/styles/buttons.css (2)

31-35: Nice improvement on button hover animation!

The new gradient animation with bg-[size:300%] and hover:bg-right creates a smooth fade effect for priority buttons. This matches the PR objective of improving hover behavior with an animated fade effect.


23-27: Good refactor of disabled state handling

Moving disabled:cursor-not-allowed to the specific disabled base classes improves organization and maintainability. This change centralizes disabled state styling.

src/core/LinkButton.tsx Outdated Show resolved Hide resolved
src/core/LinkButton.tsx Outdated Show resolved Hide resolved
src/core/Pricing/PricingCards.tsx Outdated Show resolved Hide resolved
Copy link
Member

@kennethkalmer kennethkalmer left a comment

Choose a reason for hiding this comment

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

@jamiehenson jamiehenson force-pushed the link-button-component branch 2 times, most recently from 3c4d5c2 to 3b44850 Compare December 12, 2024 14:37
@jamiehenson jamiehenson force-pushed the link-button-component branch from 3b44850 to 4529c14 Compare December 12, 2024 14:43
@jamiehenson jamiehenson merged commit c418c28 into main Dec 12, 2024
4 checks passed
@jamiehenson jamiehenson deleted the link-button-component branch December 12, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants