Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pxweb2 46 link #66

Merged
merged 10 commits into from
Apr 5, 2024
61 changes: 60 additions & 1 deletion libs/pxweb2-ui/src/lib/components/Link/Link.module.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,71 @@
@use '../../../../style-dictionary/dist/scss/fixed-variables.scss' as fixvar;

.link {
font-family: 'Roboto', sans-serif;
text-decoration-line: underline;
color: var(--px-color-text-action);
display: inline-flex;
align-items: flex-start;
gap: 4px;
padding-top: 12px;
padding-bottom: 12px;
align-items: center;

&:hover {
text-decoration: none;
background-color: var(--px-color-surface-subtle-hover);
// padding-top: 0px;
SjurSutterudSagen marked this conversation as resolved.
Show resolved Hide resolved
// padding-bottom: 0px;
}

&:focus {
text-decoration-line: none;
color: var(--px-color-text-on-action-subtle);
background-color: var(--px-color-surface-subtle-active);
}

&:focus-visible {
text-decoration-line: none;
color: var(--px-color-text-on-action-subtle);
background-color: var(--px-color-surface-subtle-active);
}

&:active {
text-decoration-line: none;
color: var(--px-color-text-on-action-subtle);
background-color: var(--px-color-surface-subtle-active);
}
}
.no_underline {
text-decoration-line: none;
}
.inline {
display: inline-flex;
gap: 0px;
padding: 0px;
}

.padding-small {
padding-top: 10px;
padding-bottom: 10px;
}

.padding-medium {
padding-top: 8px;
padding-bottom: 8px;
}

.bodylong-small {
font-family: PxWeb-font-400;
font-style: normal;
font-weight: 400;
font-size: 0.875rem;
line-height: 1.5rem;
}

.bodylong-medium {
font-family: PxWeb-font-400;
font-style: normal;
font-weight: 400;
font-size: 1rem;
line-height: 1.75rem;
}
115 changes: 110 additions & 5 deletions libs/pxweb2-ui/src/lib/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,123 @@
import type { Meta } from '@storybook/react';
import type { Meta, StoryObj, StoryFn } from '@storybook/react';
import { Link } from './Link';
SjurSutterudSagen marked this conversation as resolved.
Show resolved Hide resolved

/* import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest'; */
import { BodyLong } from '../Typography/BodyLong/BodyLong';

const meta: Meta<typeof Link> = {
component: Link,
title: 'Components/Link',
};
export default meta;

export const Primary = {
type Story = StoryObj<typeof Link>;

export const variants: Story = {
args: {
href: '#',
children: 'En godt skrevet lenketekst',
size: 'medium',
},
};

export const inlineAndStandalone: StoryFn<typeof BodyLong> = () => {
return (
<>
<h1>Inline link in BodyLong</h1>

<h2>medium without icon:</h2>
<BodyLong>
This is a story about Little Red Ridinghood. One day she went into the
wood to visit her grandmother. The day after too, She visited her every
day, every week, every month, every year. She never saw a wolf, no even
a little fox. Go to{' '}
<Link href="#" inline>
Statistikkbanken
</Link>{' '}
to read more. This is a story about Little Red Ridinghood. One day she
went into the wood to visit her grandmother. The day after too, She
visited her every day, every week, every month, every year. She never
saw a wolf, no even a little fox.
</BodyLong>

<h2>medium icon right:</h2>
<BodyLong>
This is a story about Little Red Ridinghood. One day she went into the
wood to visit her grandmother. The day after too, She visited her every
day, every week, every month, every year. She never saw a wolf, no even
a little fox. Go to{' '}
<Link href="#" inline icon="FileText" iconPosition="right">
Statistikkbanken
</Link>{' '}
to read more This is a story about Little Red Ridinghood. One day she
went into the wood to visit her grandmother. The day after too, She
visited her every day, every week, every month, every year. She never
saw a wolf, no even a little fox.
</BodyLong>

<h2>small without icon:</h2>
<BodyLong size="small">
This is a story about Little Red Ridinghood. One day she went into the
wood to visit her grandmother. The day after too, She visited her every
day, every week, every month, every year. She never saw a wolf, no even
a little fox. Go to{' '}
<Link href="#" inline>
Statistikkbanken
</Link>{' '}
to read more. This is a story about Little Red Ridinghood. One day she
went into the wood to visit her grandmother. The day after too, She
visited her every day, every week, every month, every year. She never
saw a wolf, no even a little fox.
</BodyLong>

{/* <h2>small icon right:</h2>
<BodyLong size="small">
This is a story about Little Red Ridinghood. One day she went into the
wood to visit her grandmother. The day after too, She visited her every
day, every week, every month, every year. She never saw a wolf, no even
a little fox. Go to{' '}
<Link href="#" inline icon="FileText" iconPosition="right">
Statistikkbanken
</Link>{' '}
to read more This is a story about Little Red Ridinghood. One day she
went into the wood to visit her grandmother. The day after too, She
visited her every day, every week, every month, every year. She never
saw a wolf, no even a little fox.
</BodyLong> */}

<h1>Standalone link </h1>

<h2>medium without icon:</h2>
<Link href="#" size="medium">
Statistikkbanken
</Link>

<h2>medium icon left:</h2>
<Link href="#" icon="FileText" iconPosition="left" size="medium">
Statistikkbanken
</Link>

<h2>medium icon right:</h2>
<Link href="#" icon="FileText" iconPosition="right" size="medium">
Statistikkbanken
</Link>

<h2>small without icon:</h2>
<Link href="#" size="small">
Statistikkbanken
</Link>

<h2>small icon left:</h2>
<Link href="#" icon="FileText" iconPosition="left" size="small">
Statistikkbanken{' '}
</Link>

<h2>small icon right:</h2>
<Link href="#" icon="FileText" iconPosition="right" size="small">
Statistikkbanken
</Link>
<br />
</>
);
};

/* import { within } from '@storybook/testing-library';
SjurSutterudSagen marked this conversation as resolved.
Show resolved Hide resolved
import { expect } from '@storybook/jest'; */
41 changes: 35 additions & 6 deletions libs/pxweb2-ui/src/lib/components/Link/Link.tsx
SjurSutterudSagen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
import React from 'react';
import styles from './Link.module.scss';
import classes from './Link.module.scss';
import cl from 'clsx';
import { Icon, IconProps } from '../Icon/Icon';

interface LinkProps {
interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
size?: 'small' | 'medium';
icon?: IconProps['iconName'];
iconPosition?: 'left' | 'right';
children: React.ReactNode;
href: string;
inline?: boolean;
noUnderline?: boolean;
}
export function Link({
children,
size,
href,
icon,
iconPosition,
inline = false,
noUnderline = false,
...rest
}: LinkProps) {

export const Link: React.FC<LinkProps> = ({ children, href }) => {
return (
<a href={href} className={styles.link}>
<a
href={href}
className={cl(classes.link, {
[classes.no_underline]: noUnderline,
[classes.inline]: inline,
[classes[`bodylong-${size}`]]: size,
[classes[`padding-${size}`]]: size
})}
>
{icon && iconPosition === 'left' && (
<Icon iconName={icon} className=""></Icon>
)}
{children}
{icon && iconPosition === 'right' && (
<Icon iconName={icon} className=""></Icon>
)}
</a>
);
};

}
export default Link;