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

fix: refactor Button and Anchor #492

Merged
merged 1 commit into from
Apr 14, 2024
Merged

Conversation

aversini
Copy link
Collaborator

@aversini aversini commented Apr 14, 2024

some breaking changes such as link renamed into href but since Anchor is in alpha mode, no bump in main version

Summary by CodeRabbit

  • New Features

    • Updated anchor components across various files to use href attribute instead of link.
    • Introduced new properties like target, className, and noTruncate across different UI components for enhanced customization and functionality.
    • Added new story examples for Anchor and Button components in the documentation to showcase the usage of new properties.
  • Bug Fixes

    • Corrected the import paths and properties for ButtonLink and Anchor components to ensure proper functionality.
  • Documentation

    • Enhanced component stories in documentation with additional arguments and updated existing ones for better clarity and control.
  • Refactor

    • Removed unused properties like onClick and type from Button components to streamline component interfaces.
    • Adjusted utility functions to support new noTruncate property, improving button text handling.

some breaking changes such as link renamed into href but since Anchor is in alpha mode, no bump in main version
Copy link

coderabbitai bot commented Apr 14, 2024

Walkthrough

The recent updates across various components and documentation primarily involve standardizing the use of the href attribute over the previously used link, enhancing prop management, and introducing new functionalities like noTruncate. These changes improve consistency, usability, and customization options in components such as Anchor and Button, aligning with best practices for web development.

Changes

File(s) Change Summary
examples/.../src/main.tsx (both Vite and Webpack versions) Replaced link attribute with href in Anchor component.
packages/documentation/src/Components/... .stories.tsx (Anchor, Button, Header, DarkMode) Updated props usage, added new arguments and stories, standardized href over link.
packages/ui-components/src/components/Anchor/Anchor.tsx Updated import path for ButtonLink.
packages/ui-components/src/components/Anchor/__tests__/Anchor.test.tsx Updated props from link to href, added w-44 class, adjusted related props.
packages/ui-components/src/components/Button/Button.tsx Removed several props, added noTruncate. Changes affect event handling and text truncation.
packages/ui-components/src/components/Button/ButtonLink.tsx Significant updates including added clsx import, removed several props, added new props like noNewWindowIcon.
packages/ui-components/src/components/Button/ButtonTypes.d.ts Added noTruncate to ButtonProps, updated ButtonLinkProps.
packages/ui-components/src/components/Button/__tests__/ButtonLink.test.tsx Updated ButtonLink usage, added className prop, and updated tests.
packages/ui-components/src/components/Button/utilities.ts Added and adjusted noTruncate properties in various utility functions.
packages/ui-components/src/components/index.ts Removed ButtonLink from exported entities.

These modifications ensure the components are more adaptable and maintainable, reflecting modern web standards.


Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between a79b9d6 and 6dea367.
Files selected for processing (14)
  • examples/with-vite/src/main.tsx (1 hunks)
  • examples/with-webpack/src/main.tsx (1 hunks)
  • packages/documentation/src/Components/Anchor.stories.tsx (1 hunks)
  • packages/documentation/src/Components/Button.stories.tsx (2 hunks)
  • packages/documentation/src/Components/Header.stories.tsx (1 hunks)
  • packages/documentation/src/Styles/DarkMode.stories.tsx (1 hunks)
  • packages/ui-components/src/components/Anchor/Anchor.tsx (1 hunks)
  • packages/ui-components/src/components/Anchor/tests/Anchor.test.tsx (9 hunks)
  • packages/ui-components/src/components/Button/Button.tsx (2 hunks)
  • packages/ui-components/src/components/Button/ButtonLink.tsx (3 hunks)
  • packages/ui-components/src/components/Button/ButtonTypes.d.ts (2 hunks)
  • packages/ui-components/src/components/Button/tests/ButtonLink.test.tsx (9 hunks)
  • packages/ui-components/src/components/Button/utilities.ts (7 hunks)
  • packages/ui-components/src/components/index.ts (2 hunks)
Additional Context Used
Learnings (5)
packages/ui-components/src/components/Anchor/Anchor.tsx (1)
User: aversini"
PR: aversini/ui-components#130
File: packages/ui-components/src/components/Button/ButtonLink.tsx:63-63
Timestamp: 2023-12-06T23:24:26.062Z
Learning: The user aversini prefers not to have an empty class attribute in the DOM and has implemented a pattern in the `ButtonLink` component to conditionally add the `className` property only when necessary. The current implementation uses a spread operator with a conditional object to achieve this.
packages/ui-components/src/components/Button/Button.tsx (1)
User: aversini"
PR: aversini/ui-components#130
File: packages/ui-components/src/components/Button/ButtonLink.tsx:63-63
Timestamp: 2023-12-06T23:24:26.062Z
Learning: The user aversini prefers not to have an empty class attribute in the DOM and has implemented a pattern in the `ButtonLink` component to conditionally add the `className` property only when necessary. The current implementation uses a spread operator with a conditional object to achieve this.
packages/ui-components/src/components/index.ts (1)
User: aversini"
PR: aversini/ui-components#130
File: packages/ui-components/src/components/Button/ButtonLink.tsx:63-63
Timestamp: 2023-12-06T23:24:26.062Z
Learning: The user aversini prefers not to have an empty class attribute in the DOM and has implemented a pattern in the `ButtonLink` component to conditionally add the `className` property only when necessary. The current implementation uses a spread operator with a conditional object to achieve this.
packages/ui-components/src/components/Button/ButtonLink.tsx (1)
User: aversini"
PR: aversini/ui-components#130
File: packages/ui-components/src/components/Button/ButtonLink.tsx:63-63
Timestamp: 2023-12-06T23:24:26.062Z
Learning: The user aversini prefers not to have an empty class attribute in the DOM and has implemented a pattern in the `ButtonLink` component to conditionally add the `className` property only when necessary. The current implementation uses a spread operator with a conditional object to achieve this.
packages/ui-components/src/components/Button/__tests__/ButtonLink.test.tsx (1)
User: aversini"
PR: aversini/ui-components#130
File: packages/ui-components/src/components/Button/ButtonLink.tsx:63-63
Timestamp: 2023-12-06T23:24:26.062Z
Learning: The user aversini prefers not to have an empty class attribute in the DOM and has implemented a pattern in the `ButtonLink` component to conditionally add the `className` property only when necessary. The current implementation uses a spread operator with a conditional object to achieve this.
Additional comments not posted (22)
packages/ui-components/src/components/Anchor/Anchor.tsx (1)

3-3: The updated import path for ButtonLink is more specific and should help avoid any potential issues with module resolution. Good improvement.

packages/ui-components/src/components/Button/Button.tsx (1)

20-20: The addition of the noTruncate prop is a useful feature for managing text truncation. Ensure that this new behavior is documented, especially how it interacts with other props and the overall layout.

packages/documentation/src/Components/Anchor.stories.tsx (1)

9-33: The updates to args and argTypes in the storybook configuration enhance the configurability of the Anchor component. Ensure that these changes are well-documented in the storybook to help developers understand how to use these new properties.

packages/ui-components/src/components/Button/ButtonLink.tsx (2)

1-1: The addition of clsx for conditional class assignment is a good practice. It enhances the flexibility of the component by allowing dynamic class names based on props.


35-81: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [20-70]

Significant changes have been made to the ButtonLink component, including the removal of several props and adjustments in the rendering logic. Ensure that these changes are well-documented and that they do not introduce regressions in functionality. Particularly, the handling of new window indicators and link labels should be thoroughly tested.

packages/documentation/src/Components/Button.stories.tsx (2)

9-37: The updates to args and argTypes in the storybook configuration are well-aligned with the changes in the Button component. These updates enhance the configurability and demonstration of the component's capabilities in different scenarios.


64-96: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [44-91]

The introduction of additional text content in the Basic and Truncate stories, as well as the hard-coded variant prop in the Truncate story, are good enhancements. Ensure that the use of the hard-coded variant prop is justified and documented, particularly if it's meant to demonstrate specific behaviors or configurations.

packages/ui-components/src/components/Button/ButtonTypes.d.ts (2)

48-55: The addition of the noTruncate prop to ButtonProps is a useful feature for managing text truncation. Ensure that this behavior is well-documented, especially in scenarios where the button's width is controlled by external factors.


69-73: The addition of the noNewWindowIcon prop to ButtonLinkProps is a thoughtful inclusion for managing the display of icons indicating external links. Ensure that this prop's behavior is clearly documented, particularly in how it affects accessibility and user expectations.

packages/ui-components/src/components/Button/__tests__/ButtonLink.test.tsx (2)

4-4: Updating the tests to use the href prop instead of link is necessary due to the changes in the ButtonLink component. Good to see the tests being kept up-to-date with the component changes.


76-95: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [79-111]

The addition of the className prop in the tests and the assertions related to the truncate class are important to verify the new behavior introduced in the ButtonLink component. Ensure that these tests cover all scenarios where the truncate class might be applied or not, based on the noTruncate prop.

packages/ui-components/src/components/Anchor/__tests__/Anchor.test.tsx (11)

14-14: Updated usage of href instead of link is correct and aligns with the PR objectives.


21-21: Updated usage of href instead of link is correct and aligns with the PR objectives.


31-31: Updated usage of href instead of link is correct and aligns with the PR objectives.


41-41: Updated usage of href instead of link is correct and aligns with the PR objectives.


51-51: Updated usage of href instead of link is correct and aligns with the PR objectives.


63-63: Updated usage of href instead of link is correct and aligns with the PR objectives.


75-75: Updated usage of href instead of link is correct and aligns with the PR objectives.


85-93: Updated usage of href instead of link is correct and aligns with the PR objectives. The test correctly checks for the presence of the truncate class.


98-98: Updated usage of href instead of link is correct and aligns with the PR objectives. The test correctly checks for the rel attribute.


107-107: Updated usage of href instead of link is correct and aligns with the PR objectives. The test correctly checks for the presence of the truncate class.


117-117: Updated usage of href instead of link is correct and aligns with the PR objectives. The test correctly checks for the absence of the truncate class.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Bundle Size (components)

Status File Size (Gzip) Limits
style.css 7.04 KB (+43 B +0.60%) 8 KB
index.js 8.55 KB (+98 B +1.13%) 20 KB
vendor.js 65.16 KB 67 KB

Overall bundle size: 80.75 KB (+141 B +0.17%)
Overall status: ✅

Bundle Size (form components)

Status File Size (Gzip) Limits
index.js 4.74 KB (+8 B +0.17%) 20 KB
vendor.js 44.49 KB 67 KB

Overall bundle size: 49.23 KB (+8 B +0.02%)
Overall status: ✅

Bundle Size (system)

Status File Size (Gzip) Limits
style.css 7.35 KB (+103 B +1.39%) 8 KB
index.js 1.76 KB (+1 B +0.06%) 3 KB
vendor.js 44.49 KB 46 KB

Overall bundle size: 53.6 KB (+104 B +0.19%)
Overall status: ✅

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

Actionable comments outside the diff hunks (1)
packages/ui-components/src/components/index.ts (1)

[!TIP]
Codebase Verification

The search results indicate that ButtonLink is still actively used within the project, particularly in the Anchor component and its associated type definitions, as well as extensively in unit tests for the ButtonLink component itself. This suggests that the removal of ButtonLink from the exports in index.ts could potentially lead to issues if other parts of the project or external consumers rely on this export to use ButtonLink.

Given this context, it is crucial to ensure that the removal of ButtonLink from the exports was intentional and that any necessary refactoring or communication about this change has been handled appropriately to avoid breaking functionality.

Analysis chain

Line range hint 1-1: The removal of ButtonLink from the exports list is a significant change. Confirm that this is intentional and communicate this change clearly in the changelog or migration guide to prevent breaking changes for consumers.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for any remaining imports of ButtonLink that might be affected by its removal from exports.
rg --type typescript "ButtonLink"

Length of output: 68



Script:

#!/bin/bash
# Correcting the previous script to properly search for references to ButtonLink in TypeScript files
rg "ButtonLink" --type ts

Length of output: 3316

@aversini aversini merged commit 58b2df0 into main Apr 14, 2024
5 checks passed
@aversini aversini deleted the fix-refactor-Button-and-Anchor branch April 14, 2024 17:29
@aversini aversini mentioned this pull request Apr 14, 2024
aversini added a commit that referenced this pull request Apr 14, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>ui-components: 5.14.5</summary>

##
[5.14.5](ui-components-v5.14.4...ui-components-v5.14.5)
(2024-04-14)


### Bug Fixes

* refactor Button and Anchor
([#492](#492))
([58b2df0](58b2df0))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: aversini <[email protected]>
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