Box: Offset padding by border width to ensure equal footprint regardless of configuration#74001
Box: Offset padding by border width to ensure equal footprint regardless of configuration#74001jameskoster wants to merge 4 commits intotrunkfrom
Conversation
I feel like if we're making this change, we should get rid of the |
|
I'm kinda okay with trying this. I feel like it's adding some internal complexity, though in doing so shields external consumers from having to consider the conflicts between border and paddings. From a design system perspective, I think it's reasonable to prioritize that these settings work well together in producing some predictable outcome, over enforcing some specific pixel value for individual styles (e.g. padding could end up being different by 1px). |
packages/ui/src/box/box.tsx
Outdated
| borderWidth: Exclude< NonNullable< BoxProps[ 'borderWidth' ] >, number > | ||
| ): string => | ||
| typeof value === 'number' |
There was a problem hiding this comment.
This is a good reminder we need to remove this number support exhaustively from paddings, similar to what we did with Stack gaps in #73852.
|
I removed the |
|
It just occurred to me that we might want to make this behavior optional. I don't think we necessarily need to add that complexity here, but it could be something to keep in mind. |
|
Size Change: -32 B (0%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
What
This PR refactors the
Boxcomponent'sborderWidthprop to only support'xs'and'sm'values (mapping to 1px and 2px respectively), and adjusts padding calculation to account for border width so the total rendered spacing remains consistent.Why
Addresses a fundamental issue we discovered in #73875 where a badge with a border will have a different footprint to a badge without one.
The
'md'and'lg'values map to4pxand8pxwhich I don't think there is any use for currently.How
Padding offset implementation: Modified
getSpacingValueto accept an optionaloffsetValueparameter that subtracts from the base padding value using CSScalc(). The padding calculation now passes the border width value as an offset when both padding and borderWidth are present.To test
npm run storybookpaddingandborderWidthvalues the rendered box will always have the same footprint