Add tier indicator to the tabs component as optional - #3790
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 92a32ff 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 |
|
Size Change: +131 B (+0.02%) Total Size: 850 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3790 +/- ##
=======================================
Coverage 93.56% 93.57%
=======================================
Files 208 208
Lines 4614 4619 +5
Branches 1808 1807 -1
=======================================
+ Hits 4317 4322 +5
Misses 268 268
Partials 29 29
🚀 New features to boost your workflow:
|
| import { | ||
| TierIndicator, | ||
| type TierIndicatorProps, | ||
| } from '../../../TierIndicator/TierIndicator.js'; |
There was a problem hiding this comment.
Importing the TierIndicator in the Tab component causes it to be bundled whether the trailingComponent prop is used or not.
When we discussed this feature a while ago, we had agreed that the component should be injected to avoid this bundle size increase. What happened to that approach?
There was a problem hiding this comment.
You're right, and I'd forgotten we'd agreed on that.
One thing, though: injecting the component moves the size="s" restriction from compile time to runtime, but I think 🤔 that should be fine - we can still enforce it, just not via the type system.
There was a problem hiding this comment.
I think it should still be possible to enforce this with types. I imagine the trailingComponent to by typed like so:
trailingComponent: ComponentType<Omit<TierIndicatorProps, 'size'>>| "@sumup-oss/circuit-ui": minor | ||
| --- | ||
|
|
||
| Added a `trailingComponent` prop to the Tab component to display a TierIndicator badge next to a tab's label to indicate features that are part of the plus plan. |
There was a problem hiding this comment.
trailingComponent seems like a broad prop name when in reality it only accepts a specific component.
There was a problem hiding this comment.
@missating and I had discussed the prop name and opted to keep it generic in case we want to open it up to other content (e.g. the Status component) in the future.
| const content = TrailingComponent ? ( | ||
| <span className={classes.content}> | ||
| {children} | ||
| <TrailingComponent variant="plus" size="s" /> |
There was a problem hiding this comment.
currently we only have one variant, but what if we added more in the future ?
There was a problem hiding this comment.
The variant could be passed like so:
<Tab trailingComponent={(props) => <TierIndicator {...props} variant="new-variant" />} />| ]} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('Services')).toBeVisible(); |
There was a problem hiding this comment.
shouldn't we test for the visibility of the tier indicator too ?
| expect(screen.getByText('Services')).toBeVisible(); | |
| expect(screen.getByText('Services')).toBeVisible(); | |
| expect(screen.getByText('plus')).toBeVisible(); |
|
|
||
| export const WithTierIndicator = (args: TabsProps) => <Tabs {...args} />; | ||
|
|
||
| WithTierIndicator.args = { |
There was a problem hiding this comment.
maybe we can disable the snapshots on the other stories and keep them only for this one to reduce chromatic consumption
| <Tab trailingComponent={TierIndicator}>Services</Tab>, | ||
| ); | ||
| expect(screen.getByText('Services')).toBeVisible(); | ||
| expect(container.querySelector('svg')).toHaveAttribute('height', '16'); |
There was a problem hiding this comment.
The height attribute doesn't necessarily reflect the true size of the SVG as it could be resized using CSS.
Testing styles in unit tests is unreliable, that's why we have snapshot tests. Unit tests should focus on the UI logic, semantics, and public API.
| const content = TrailingComponent ? ( | ||
| <span className={classes.content}> | ||
| {children} | ||
| <TrailingComponent variant="plus" size="s" /> |
There was a problem hiding this comment.
The variant could be passed like so:
<Tab trailingComponent={(props) => <TierIndicator {...props} variant="new-variant" />} />
Addresses DSYS-1824
Purpose
This adds an optional
trailingComponentprop to Tab that renders a TierIndicator badge next to the tab's label to indicate that a feature is behind a paid plan.Approach and changes
trailingComponent?: ComponentType<TierIndicatorProps>to TabProps. Consumers inject theTierIndicatorcomponent itself rather than passing rendered JSX or a props object.Tab.tsxnow destructures children explicitly (it previously flowed through implicitly via the props spread)Tabs. tsxitems mapping now forwardstrailingComponenttoo (previously onlyid/tabmade it through), so the badge works via the top-levelitemsAPI, not justTabList'stabs propDefinition of done