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: button component - improve props, variants, sizing, icons, … #486

Merged
merged 11 commits into from
Aug 26, 2024

Conversation

luis-herasme
Copy link
Member

@luis-herasme luis-herasme commented Aug 5, 2024

Description

  1. The current situation with button props could be better. We manually add only a subset of the possible props to the button component. With this change, all the possible button attributes can be passed to the button Component.

  2. Adding new variants used to be challenging. Previously, we had to define two types to add a new variant: the variant type key and the variant object. Then, we would add a new property to the button props type. Now, to add a new variant, we only need to add a new value to the CVA object.

  3. Adding a tailwind class to the className already defined inside the component can cause uncertainty about which className will be applied. To solve this now, we are using tailwind-merge, which merges tailwind classes and keeps the last className added. With this, we can guarantee that the className defined by the user will be the className used.

  4. We previously had a size enum defined externally, which led to several issues. The enum did not have a complete definition to cover all cases. For instance, 2xl and xs could be passed to the size prop, but we did not account for them. Additionally, we only handled xl when it was an icon. Our sizing logic became very complex because we had to consider the icons, even though currently, all icons are the same size.

  5. Enable tailwind intellisense inside variant definition using .vscode/setting.json (VSCode only config)

Copy link

changeset-bot bot commented Aug 5, 2024

🦋 Changeset detected

Latest commit: aaf6eaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@blobscan/web Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Aug 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blobscan-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 26, 2024 10:35pm
5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
blobscan-docs ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 10:35pm
blobscan-gnosis ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 10:35pm
blobscan-holesky ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 10:35pm
blobscan-mainnet ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 10:35pm
blobscan-sepolia ⬜️ Ignored (Inspect) Visit Preview Aug 26, 2024 10:35pm

Copy link
Contributor

github-actions bot commented Aug 5, 2024

📦 Next.js Bundle Analysis for @blobscan/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 271.12 KB (🟡 +25.5 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Eleven Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/ 352.27 KB 623.39 KB 178.11% (🟢 -4.88%)
/address/[address] 26.71 KB 297.82 KB 85.09% (🟢 -4.86%)
/blob/[hash] 26.08 KB 297.19 KB 84.91% (🟢 -4.67%)
/blobs 15.82 KB 286.94 KB 81.98% (🟢 -4.86%)
/block/[id] 12.6 KB 283.72 KB 81.06% (🟢 -4.65%)
/blocks 13.55 KB 284.67 KB 81.33% (🟢 -4.86%)
/stats/blob 336.48 KB 607.6 KB 173.60% (🟢 -4.80%)
/stats/block 337.51 KB 608.63 KB 173.89% (🟢 -4.79%)
/stats/tx 336.61 KB 607.73 KB 173.64% (🟢 -4.80%)
/tx/[hash] 14.04 KB 285.15 KB 81.47% (🟡 +0.23%)
/txs 20.09 KB 291.21 KB 83.20% (🟢 -4.86%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.83%. Comparing base (9666239) to head (c73a5b0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #486      +/-   ##
==========================================
- Coverage   89.84%   89.83%   -0.02%     
==========================================
  Files         146      146              
  Lines        9630     9630              
  Branches     1022     1020       -2     
==========================================
- Hits         8652     8651       -1     
- Misses        978      979       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@xFJA xFJA left a comment

Choose a reason for hiding this comment

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

Good job! 💪

@PabloCastellano PabloCastellano changed the base branch from next to main August 6, 2024 16:03
Copy link
Member

@PJColombo PJColombo left a comment

Choose a reason for hiding this comment

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

Great job!.

I really like idea of using of CVA for defining component variants and the integration of tailwind-merge to effectively combine Tailwind classes.

However, I have some concerns about the introduction of md-icon as it seems to disrupt the overall sizing logic, making it feel more like an ad hoc solution. To address this, I suggest abstracting the icon variant logic into a separate IconButton component. This component would manage its own size definitions (e.g., sm =h-3 w-3, md = h-5 w-5, etc.) which would then be passed down to the children icon prop. This way, we wouldn’t need to define the Tailwind size classes explicitly in each icon, as we have been doing so far. The provided icon children would be wrapped within a div using the following Tailwind classes: flex items-center justify-center.

.changeset/mighty-balloons-camp.md Outdated Show resolved Hide resolved
Copy link
Member

@PJColombo PJColombo left a comment

Choose a reason for hiding this comment

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

Pushed a last refactoring change to the IconButton component

LGTM, feel free to merge

@luis-herasme luis-herasme merged commit be191ba into main Aug 26, 2024
8 checks passed
@PabloCastellano PabloCastellano deleted the button branch August 27, 2024 14:18
@github-actions github-actions bot mentioned this pull request Sep 3, 2024
@PJColombo PJColombo restored the button branch October 29, 2024 11:30
@PJColombo PJColombo deleted the button branch October 29, 2024 11:33
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.

3 participants