Skip to content

Commit e867dac

Browse files
Add link component (#1429)
* Added a new `Link` component in `link.tsx`, extending `react-aria-components`'s `Link` with custom styling and focus management for accessibility and design consistency. * Created Storybook stories in `link.stories.tsx` to showcase various usages of the new `Link` component, including default, external, with icon, custom styling, and embedded in text. **Exports and package integration:** * Updated `index.ts` to export the new `Link` component, ensuring it is available from the main package entry point. * Added an export file in the `link` directory to re-export the new `Link` component, supporting modular imports. <img width="1154" height="1014" alt="image" src="https://github.com/user-attachments/assets/9376b1e1-b433-4fa3-bda1-89302387091f" /> Fokus: <img width="407" height="237" alt="image" src="https://github.com/user-attachments/assets/0b60238f-359f-4de3-944e-5bec4ae81b13" /> --------- Co-authored-by: Oscar Carlström <[email protected]>
1 parent e086013 commit e867dac

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

.changeset/moody-knives-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@obosbbl/grunnmuren-react": patch
3+
---
4+
5+
New `<Link>` component in beta. This is a very small style-wrapper for the `<Link>` component from `react-aria-components`.

packages/react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ export * from './tag-group';
2929
export * from './hero';
3030
export * from './carousel';
3131
export * from './tabs';
32+
export * from './link';
3233
export * from './link-list';

packages/react/src/link/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './link';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Download, LinkExternal } from '@obosbbl/grunnmuren-icons-react';
2+
import type { Meta } from '@storybook/react-vite';
3+
import { Link } from './link';
4+
5+
const meta: Meta<typeof Link> = {
6+
title: 'Link',
7+
component: Link,
8+
tags: ['autodocs'],
9+
};
10+
11+
export default meta;
12+
13+
export const Default = () => <Link href="/bolig">Bolig</Link>;
14+
15+
export const External = () => (
16+
<Link
17+
href="https://obos.no"
18+
target="_blank"
19+
rel="noreferrer"
20+
className="group inline-flex items-center gap-1"
21+
>
22+
Ekstern lenke
23+
<LinkExternal className="group-hover:motion-safe:-translate-y-0.5 shrink-0 transition-transform group-hover:motion-safe:translate-x-0.5" />
24+
</Link>
25+
);
26+
27+
export const WithIcon = () => (
28+
<Link
29+
download
30+
href="/document.pdf"
31+
className="group inline-flex items-center gap-1"
32+
>
33+
Last ned dokument{' '}
34+
<Download className="shrink-0 transition-transform group-hover:motion-safe:translate-y-1" />
35+
</Link>
36+
);
37+
38+
export const WithLongerText = () => (
39+
<p>
40+
Dette er et avsnitt med en <Link href="/innebygd">lenke</Link> inni.
41+
</p>
42+
);

packages/react/src/link/link.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { cx } from 'cva';
2+
import type { ReactNode } from 'react';
3+
import { Link, type LinkProps } from 'react-aria-components';
4+
5+
type CustomLinkProps = LinkProps & {
6+
children: ReactNode;
7+
};
8+
9+
/**
10+
* A basic link component that extends react-aria-components Link with consistent styling.
11+
* Provides accessible focus styles and maintains design system consistency.
12+
*/
13+
const CustomLink = ({ children, className, ...restProps }: CustomLinkProps) => {
14+
return (
15+
<Link
16+
{...restProps}
17+
className={cx(
18+
className,
19+
'cursor-pointer font-medium focus-visible:outline-focus-offset',
20+
)}
21+
>
22+
{children}
23+
</Link>
24+
);
25+
};
26+
27+
export { CustomLink as Link, type CustomLinkProps as LinkProps };

0 commit comments

Comments
 (0)