-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
…customization, and Tailwind IntelliSense
🦋 Changeset detectedLatest commit: aaf6eaa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
5 Skipped Deployments
|
📦 Next.js Bundle Analysis for @blobscan/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖
|
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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! 💪
Co-authored-by: Francisco Jiménez Aguilera <[email protected]>
There was a problem hiding this 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
.
Co-authored-by: elessar.eth <[email protected]>
There was a problem hiding this 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
Description
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.
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.
Adding a tailwind class to the
className
already defined inside the component can cause uncertainty about whichclassName
will be applied. To solve this now, we are using tailwind-merge, which merges tailwind classes and keeps the lastclassName
added. With this, we can guarantee that theclassName
defined by the user will be theclassName
used.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
andxs
could be passed to the size prop, but we did not account for them. Additionally, we only handledxl
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.Enable tailwind intellisense inside variant definition using
.vscode/setting.json
(VSCode only config)