Skip to content

Commit

Permalink
fix: ignore combinations of lead and small
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Oct 16, 2024
1 parent 5d2e835 commit 1e67440
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-phones-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@utrecht/component-library-react": major
---

Ignore combinations of `lead` and `small` appearances for paragraph via deprecated boolean properties.
34 changes: 16 additions & 18 deletions packages/component-library-react/src/Paragraph.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ describe('Paragraph', () => {
});

describe('deprecated', () => {
it('ignores combinations of lead and small', () => {
const { container } = render(
<>
<Paragraph lead small />
<Paragraph appearance="lead" small />
<Paragraph appearance="small" lead />
</>,
);

const leadParagraph = container.querySelector('.utrecht-paragraph--lead');
const smallParagraph = container.querySelector('.utrecht-paragraph--lead');

expect(leadParagraph).not.toBeInTheDocument();
expect(smallParagraph).not.toBeInTheDocument();
});

it('has a lead paragraph variant with a `lead` flag', () => {
const { container } = render(<Paragraph lead />);

Expand All @@ -119,24 +135,6 @@ describe('Paragraph', () => {

expect(leadParagraph).toHaveClass('utrecht-paragraph--small');
});

it('favors `appearance="lead"` over deprecated equivalent API', () => {
const { container } = render(<Paragraph appearance="lead" small />);

const leadParagraph = container.querySelector(':only-child');

expect(leadParagraph).toHaveClass('utrecht-paragraph--lead');
expect(leadParagraph).not.toHaveClass('utrecht-paragraph--small');
});

it('favors `appearance="small"` over deprecated equivalent API', () => {
const { container } = render(<Paragraph appearance="small" lead />);

const leadParagraph = container.querySelector(':only-child');

expect(leadParagraph).toHaveClass('utrecht-paragraph--small');
expect(leadParagraph).not.toHaveClass('utrecht-paragraph--lead');
});
});

describe('appearance type guard', () => {
Expand Down
12 changes: 8 additions & 4 deletions packages/component-library-react/src/Paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ export const Paragraph = forwardRef(
{ children, className, lead, small, appearance, ...restProps }: PropsWithChildren<ParagraphProps>,
ref: ForwardedRef<HTMLParagraphElement>,
) => {
const isLead = appearance === 'lead' || (lead && appearance !== 'small');
const isSmall = appearance === 'small' || (small && appearance !== 'lead');
let isLead = appearance === 'lead' || !!lead;
let isSmall = appearance === 'small' || !!small;

// Ignore combinations of `lead` and `small`
isLead = isLead !== isSmall ? isLead : false;
isSmall = isSmall !== isLead ? isSmall : false;

return (
<p
{...restProps}
ref={ref}
className={clsx(
'utrecht-paragraph',
isLead && 'utrecht-paragraph--lead',
isSmall && 'utrecht-paragraph--small',
isLead && `utrecht-paragraph--lead`,
isSmall && `utrecht-paragraph--small`,
className,
)}
>
Expand Down

0 comments on commit 1e67440

Please sign in to comment.