Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/link-underline-prop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@launchpad-ui/components": minor
---

Add `underline` prop to Link component with `'always' | 'hover' | 'none'` values
14 changes: 14 additions & 0 deletions packages/components/__tests__/Link.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ describe('Link', () => {
expect(screen.getByRole('link')).toBeVisible();
expect(screen.getByRole('link')).toHaveAttribute('href', 'https://www.test.com');
});

it('renders with underline="always"', () => {
const navigate = vi.fn();
render(
<RouterProvider navigate={navigate} useHref={useHref}>
<MemoryRouter>
<Link href="/test" underline="always">
Link
</Link>
</MemoryRouter>
</RouterProvider>,
);
expect(screen.getByRole('link')).toBeVisible();
});
});
12 changes: 10 additions & 2 deletions packages/components/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ const linkStyles = cva(styles.base, {
default: styles.default,
subtle: styles.subtle,
},
underline: {
always: styles.underlineAlways,
hover: styles.underlineHover,
none: styles.underlineNone,
},
},
defaultVariants: {
variant: 'default',
underline: 'hover',
},
});

interface LinkProps extends AriaLinkProps, VariantProps<typeof linkStyles>, DOMProps {
ref?: Ref<HTMLAnchorElement>;
/** Controls when the link is underlined. */
underline?: 'always' | 'hover' | 'none';
}

const LinkContext = createContext<ContextValue<LinkProps, HTMLAnchorElement>>(null);
Expand All @@ -35,14 +43,14 @@ const LinkContext = createContext<ContextValue<LinkProps, HTMLAnchorElement>>(nu
*/
const Link = ({ ref, ...props }: LinkProps) => {
[props, ref] = useLPContextProps(props, ref, LinkContext);
const { variant = 'default' } = props;
const { variant = 'default', underline = 'hover' } = props;

return (
<AriaLink
{...props}
ref={ref}
className={composeRenderProps(props.className, (className, renderProps) =>
linkStyles({ ...renderProps, variant, className }),
linkStyles({ ...renderProps, variant, underline, className }),
)}
/>
);
Expand Down
15 changes: 15 additions & 0 deletions packages/components/src/styles/Link.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,18 @@
composes: link;
color: var(--lp-color-text-ui-secondary);
}

.underlineAlways {
text-decoration: underline;
}

.underlineHover {
}

.underlineNone {
text-decoration: none;

&[data-hovered] {
text-decoration: none;
}
}
16 changes: 16 additions & 0 deletions packages/components/stories/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ export const Subtle: Story = {
},
};

export const UnderlineAlways: Story = {
args: {
children: 'Link',
href: '/test',
underline: 'always',
},
};

export const UnderlineNone: Story = {
args: {
children: 'Link',
href: '/test',
underline: 'none',
},
};

export const States: Story = {
render: (args) => {
const styles = { width: 'fit-content' };
Expand Down
Loading