diff --git a/.changeset/ten-llamas-unite.md b/.changeset/ten-llamas-unite.md new file mode 100644 index 0000000000..a92e8bbfe1 --- /dev/null +++ b/.changeset/ten-llamas-unite.md @@ -0,0 +1,5 @@ +--- +"@frontify/fondue": patch +--- + +fix: fix padding in badge component which cause the status to be offset diff --git a/packages/fondue/src/components/Badge/Badge.cy.tsx b/packages/fondue/src/components/Badge/Badge.cy.tsx index 6c748520d3..ad1e7eaeb8 100644 --- a/packages/fondue/src/components/Badge/Badge.cy.tsx +++ b/packages/fondue/src/components/Badge/Badge.cy.tsx @@ -14,9 +14,9 @@ const BADGE_DISMISS = '[data-test-id=badge-dismiss]'; const BADGE_BUTTON = '[data-test-id=badge-button]'; const checkMediumSize = () => { - cy.get(BADGE_BUTTON).should('have.class', 'tw-px-2'); + cy.get(BADGE_BUTTON).should('have.class', 'tw-px-2.5'); cy.get(BADGE_BUTTON).should('have.class', 'tw-h-6'); - cy.get(BADGE_BUTTON).should('have.class', 'tw-gap-x-0.5'); + cy.get(BADGE_BUTTON).should('have.class', 'tw-gap-x-1'); }; describe('Badge component', () => { @@ -50,13 +50,13 @@ describe('Badge component', () => { it('should render badge with icon with specific size', () => { cy.mount(}>{BADGE_TEXT}); - cy.get(BADGE_ICON_ID).should('exist').and('have.css', 'width', '20px'); + cy.get(BADGE_ICON_ID).should('exist').and('have.css', 'width', '16px'); }); it('should render with small size', () => { cy.mount({BADGE_TEXT}); - cy.get(BADGE_BUTTON).should('have.class', 'tw-px-1.5'); + cy.get(BADGE_BUTTON).should('have.class', 'tw-px-2'); cy.get(BADGE_BUTTON).should('have.class', 'tw-h-5'); }); @@ -247,16 +247,4 @@ describe('Badge component', () => { cy.get(BADGE_BUTTON).invoke('attr', 'title').should('equal', `${BADGE_TEXT}_1_${BADGE_TEXT}_2_${BADGE_TEXT}`); }); - - it('should have padding between icon and label', () => { - cy.mount(}>{BADGE_TEXT}); - - cy.get(BADGE_ICON_ID).should('have.css', 'padding-right', '4px'); - }); - - it('should have no icon padding if there is no label', () => { - cy.mount(} />); - - cy.get(BADGE_ICON_ID).should('have.css', 'padding-right', '0px'); - }); }); diff --git a/packages/fondue/src/components/Badge/Badge.tsx b/packages/fondue/src/components/Badge/Badge.tsx index c7f2280a5c..f70173b42b 100644 --- a/packages/fondue/src/components/Badge/Badge.tsx +++ b/packages/fondue/src/components/Badge/Badge.tsx @@ -73,17 +73,13 @@ export const Badge = ({ {icon && ( {cloneElement(icon, { size: IconSize.Size16 })} )} {children && ( - + {children} )} diff --git a/packages/fondue/src/components/Badge/BadgeStatusIcon.tsx b/packages/fondue/src/components/Badge/BadgeStatusIcon.tsx index 02b9fbe5ef..1fb8afeadf 100644 --- a/packages/fondue/src/components/Badge/BadgeStatusIcon.tsx +++ b/packages/fondue/src/components/Badge/BadgeStatusIcon.tsx @@ -9,7 +9,7 @@ import { badgeStatusClasses, isBadgeStatus } from './helpers'; import { type BadgeStatusIconProps } from './types'; export const BadgeStatusIcon = ({ status, disabled, 'data-test-id': dataTestId = 'badge' }: BadgeStatusIconProps) => ( -
+
{ const isSmall = size === 'small'; + const hasMaximumTwoComponents = !(children && status && icon); if (isSmall) { - return merge(['tw-h-5 tw-px-1.5', isDismissable && 'tw-pr-5']); + return merge([ + 'tw-h-5 tw-px-2 tw-gap-x-1', + hasMaximumTwoComponents && 'tw-gap-x-1.5', + isDismissable && 'tw-pr-5', + ]); } else { - const hasMaximumTwoComponents = !(children && status && icon); - return merge(['tw-h-6', 'tw-px-2', hasMaximumTwoComponents && 'tw-gap-x-0.5', isDismissable && 'tw-pr-6']); + return merge([ + 'tw-h-6', + 'tw-px-2.5 tw-gap-x-1', + hasMaximumTwoComponents && 'tw-gap-x-2', + isDismissable && 'tw-pr-6', + ]); } };