Skip to content

Commit

Permalink
feat(Link): add inverse variant (with variant prop) (#1972)
Browse files Browse the repository at this point in the history
- update snapshots
  • Loading branch information
booc0mtaco authored Jun 3, 2024
1 parent dc3ae44 commit bdbf9df
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/components/Link/Link-v2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@
text-decoration: none;
}

/**
* Variants
*/
.link.link--variant-inverse {
color: var(--eds-theme-color-text-utility-inverse);

&:active,
&:visited {
color: var(--eds-theme-color-text-utility-inverse);
}
}

/**
* States
Expand Down
17 changes: 17 additions & 0 deletions src/components/Link/Link-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ export const Emphasis: StoryObj<Args> = {
},
};

/**
* We also include an inverse variant, for use on dark backgrounds.
*/
export const InverseRanks: StoryObj<Args> = {
args: {
variant: 'inverse',
},
// TODO: find a cleaner way to decorate with unavailable tokens using parameters:backgounds:
decorators: [
(Story) => (
<div className="w-96 bg-[var(--eds-color-blue-850)] p-1 text-center">
{Story()}
</div>
),
],
};

export const LinkInParagraphContext: StoryObj<ExtendArgs> = {
render: (
args: React.JSX.IntrinsicAttributes &
Expand Down
9 changes: 8 additions & 1 deletion src/components/Link/Link-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export type LinkV2Props<ExtendedElement = unknown> =
* Link size inherits from the surrounding text.
*/
size?: Extract<Size, 'xs' | 'sm' | 'md' | 'lg' | 'xl'>;
// };
/**
* The variant treatment for links (use "inverse" on dark backgrounds).
*
* **Default is `"default"`**.
*/
variant?: 'default' | 'inverse';
} & ExtendedElement;

/**
Expand All @@ -57,6 +62,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkV2Props>(
emphasis = 'default',
icon,
size = 'md',
variant = 'default',
...other
},
ref,
Expand All @@ -68,6 +74,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkV2Props>(
emphasis && styles[`link--emphasis-${emphasis}`],
icon && styles['link--has-right-icon'],
size && styles[`link--size-${size}`],
variant === 'inverse' && styles[`link--variant-${variant}`],
);

const iconSize = size && (['xl', 'lg'].includes(size) ? '1.5rem' : '1rem');
Expand Down
13 changes: 13 additions & 0 deletions src/components/Link/__snapshots__/Link-v2.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ exports[`<Link /> Emphasis story renders snapshot 1`] = `
</div>
`;

exports[`<Link /> InverseRanks story renders snapshot 1`] = `
<div
class="w-96 bg-[var(--eds-color-blue-850)] p-1 text-center"
>
<a
class="link link--emphasis-default link--size-lg link--variant-inverse"
href="https://go.czi.team/eds"
>
Link
</a>
</div>
`;

exports[`<Link /> LinkInParagraphContext story renders snapshot 1`] = `
<div>
Lorem ipsum dolor sit amet,
Expand Down

0 comments on commit bdbf9df

Please sign in to comment.