Skip to content

Commit

Permalink
[@mantine/core] Badge: Fix unexpected change to block layout, fix inc…
Browse files Browse the repository at this point in the history
…orrect alignment when fixed width is set (#6698, #6680)
  • Loading branch information
rtivital committed Aug 26, 2024
1 parent ccc0f3c commit 564d0c1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
16 changes: 14 additions & 2 deletions packages/@mantine/core/src/components/Badge/Badge.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
line-height: var(--badge-lh);
text-decoration: none;
padding: 0 var(--badge-padding-x);
display: grid;
grid-template-columns: auto 1fr auto;
display: inline-grid;
align-items: center;
justify-content: center;
width: fit-content;
Expand All @@ -49,6 +48,18 @@
background: var(--badge-bg);
border: var(--badge-bd);

&:where([data-with-right-section]) {
grid-template-columns: 1fr auto;
}

&:where([data-with-left-section], [data-variant='dot']) {
grid-template-columns: auto 1fr;
}

&:where([data-with-left-section][data-with-right-section]) {
grid-template-columns: auto 1fr auto;
}

&:where([data-block]) {
display: flex;
width: 100%;
Expand Down Expand Up @@ -91,6 +102,7 @@
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
}

.section {
Expand Down
18 changes: 18 additions & 0 deletions packages/@mantine/core/src/components/Badge/Badge.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ export function Usage() {
);
}

export function WithFixedWidth() {
return (
<div style={{ padding: 40 }}>
<Badge w={200} rightSection="R" leftSection="L">
Badge
</Badge>
<Badge w={200} leftSection="L">
Badge
</Badge>
<Badge w={200} rightSection="R">
Badge
</Badge>
<Badge w={200}>Badge</Badge>
<span>Other content</span>
</div>
);
}

export function WithIconInSection() {
return (
<Badge
Expand Down
10 changes: 9 additions & 1 deletion packages/@mantine/core/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ export const Badge = polymorphicFactory<BadgeFactory>((_props, ref) => {
return (
<Box
variant={variant}
mod={[{ block: fullWidth, circle }, mod]}
mod={[
{
block: fullWidth,
circle,
'with-right-section': !!rightSection,
'with-left-section': !!leftSection,
},
mod,
]}
{...getStyles('root', { variant })}
ref={ref}
{...others}
Expand Down

0 comments on commit 564d0c1

Please sign in to comment.