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

update links #2093

Merged
merged 24 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c95e688
style links with inline
JulianNymark Jul 4, 2023
a19455d
tweak css spacing for inline links with SVG
JulianNymark Jul 4, 2023
20ad6ab
add break-all prop to link
JulianNymark Jul 4, 2023
b3d88e0
wrap link in span to allow for spacing
JulianNymark Jul 4, 2023
7641c03
more obvious spacing example
JulianNymark Jul 4, 2023
449f8f2
remove spacing prop from link
JulianNymark Jul 4, 2023
a43890b
implement pr review comments
JulianNymark Jul 5, 2023
3cc7965
add random icon visual fuzz testing in stories
JulianNymark Jul 6, 2023
e8aba24
remove console.log
JulianNymark Jul 6, 2023
ba85af5
changeset
JulianNymark Jul 6, 2023
047de54
add examples to aksel.nav.no
JulianNymark Jul 6, 2023
1f76891
Merge branch 'main' into inline-link
KenAJoh Jul 6, 2023
b2dba6a
:art: make inline-flex version opt-in, improve prop naming
JulianNymark Aug 8, 2023
89a6938
Merge branch 'main' into inline-link
KenAJoh Aug 8, 2023
8e95d1a
:bug: Fixed comments
KenAJoh Aug 8, 2023
ac9cbe7
:art: Oppdatert props
KenAJoh Aug 9, 2023
e837bd6
:art: refactor links, add examples (remove underline & inline)
JulianNymark Aug 9, 2023
fd73a00
change is no longer major (pr review comment)
JulianNymark Aug 9, 2023
d10d005
cleaner changeset (pr review comment)
JulianNymark Aug 9, 2023
0a49c70
norwegian changeset (pr review comment)
JulianNymark Aug 9, 2023
a52d385
update changeset (pr review comment)
JulianNymark Aug 9, 2023
66ad247
use neutral token for neutral link variant
JulianNymark Aug 9, 2023
0f63ad2
use neutral token for neutral link variant
JulianNymark Aug 9, 2023
4eac6c2
Update .changeset/proud-tigers-share.md
KenAJoh Aug 9, 2023
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
7 changes: 7 additions & 0 deletions .changeset/proud-tigers-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@navikt/ds-css": minor
"@navikt/ds-react": minor
---

Link: La til 'variant', 'underline' og 'inlineText'-prop

39 changes: 36 additions & 3 deletions @navikt/core/css/link.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,36 @@
gap: var(--a-spacing-1);
}

.navds-alert .navds-link,
.navds-confirmation-panel .navds-link {
color: var(--a-text-default);
.navds-link.navds-link--inline-text {
display: inline;
}

.navds-link.navds-link--inline-text > svg {
margin: 0.1em 0.1em -0.1em;
transform: translateY(0.05em);
}

.navds-link:visited {
color: var(--ac-link-visited-text, var(--a-text-visited));
}

.navds-link:hover {
text-decoration: none;
}

.navds-link.navds-link--remove-underline {
text-decoration: none;
}

.navds-link.navds-link--remove-underline:hover {
text-decoration: underline;
}

.navds-alert .navds-link,
.navds-confirmation-panel .navds-link {
color: var(--a-text-default);
}

.navds-link:focus-visible {
outline: none;
color: var(--ac-link-focus-text, var(--a-text-on-action));
Expand Down Expand Up @@ -45,3 +66,15 @@
color: inherit;
flex-shrink: 0;
}

.navds-link--action {
color: var(--ac-link-action-text, var(--a-text-action));
}

.navds-link--neutral {
color: var(--ac-link-neutral-text, var(--a-text-default));
}

.navds-link--subtle {
color: var(--ac-link-subtle-text, var(--a-text-subtle));
}
6 changes: 5 additions & 1 deletion @navikt/core/css/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@
"--ac-link-focus-border": "--a-border-focus",
"--ac-link-active-text": "--a-text-on-action",
"--ac-link-active-bg": "--a-border-focus",
"--ac-link-active-border": "--a-border-focus"
"--ac-link-active-border": "--a-border-focus",
"--ac-link-action-text": "--a-text-action",
"--ac-link-neutral-text": "--a-text-default",
"--ac-link-subtle-text": "--a-text-subtle",
"--ac-link-visited-text": "--a-text-visited"
},
"list": {
"--ac-list-marker-ul-color": "--ac-list-marker-color",
Expand Down
50 changes: 47 additions & 3 deletions @navikt/core/react/src/link/Link.tsx
JulianNymark marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import { OverridableComponent } from "../util/OverridableComponent";

export interface LinkProps
extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
/**
* Inverts when the underline appears. If this is false,
* the underline does not appear by default, but does appear when the link is hovered.
* This makes it more suitable for use when inlined in text.
* @default true
*/
underline?: boolean;
/**
* Renders link with `display: inline` for better wrapping in text.
* @default false
*/
inlineText?: boolean;
/**
* Variant of the component to use.
* @default "action"
*/
variant?: "action" | "neutral" | "subtle";
/**
* Link text
*/
Expand All @@ -22,10 +39,37 @@ export interface LinkProps
* <Link href="#">lenke til ny side</Link>
* <Link as={ReactRouter.Link} to="#">lenke til ny side</Link>
* ```
* @example
* ```jsx
* <BodyLong>
* ...
* <Link href="#" inlineText>lenke til ny side</Link>
* ...
* </BodyLong>
* ```
*/
export const Link: OverridableComponent<LinkProps, HTMLAnchorElement> =
forwardRef(({ as: Component = "a", className, ...rest }, ref) => (
<Component {...rest} ref={ref} className={cl("navds-link", className)} />
));
forwardRef(
(
{
as: Component = "a",
className,
underline = true,
variant = "action",
inlineText = false,
...rest
},
ref
) => (
<Component
{...rest}
ref={ref}
className={cl("navds-link", className, `navds-link--${variant}`, {
"navds-link--remove-underline": !underline,
"navds-link--inline-text": inlineText,
})}
/>
)
);

export default Link;
140 changes: 127 additions & 13 deletions @navikt/core/react/src/link/link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,76 @@ import {
ConfirmationPanel as DsConfirmationPanel,
Link,
} from "..";
import { RandomIcon } from "../util/RandomIcon";

export default {
title: "ds-react/Link",
component: Link,
};

const LinkWrapper = ({
children = "Ex aliqua incididunt",
iconRight = false,
iconLeft = false,
variant = "action",
underline = false,
inlineText = true,
}) => (
<>
{" "}
<Link
href="#"
underline={underline}
variant={variant as "action" | "neutral" | "subtle"}
inlineText={inlineText}
>
{iconLeft && (
<>
<RandomIcon />{" "}
</>
)}
{children}
{iconRight && (
<>
{" "}
<RandomIcon />
</>
)}
</Link>{" "}
</>
);

export const Default = {
render: (props) => {
render: ({ icon, inline }) => {
const LinkD = () => (
<Link href="#">
{props.icon && <PlusCircleFillIcon />}Ex aliqua incididunt{" "}
{props.icon && <PlusCircleFillIcon />}
</Link>
<>
{" "}
<Link href="#" underline={!inline} inlineText={inline}>
{icon && <PlusCircleFillIcon />}Ex aliqua incididunt
{icon && <PlusCircleFillIcon />}
</Link>{" "}
</>
);

if (props.inline) {
if (inline) {
return (
<BodyLong>
Incididunt laborum nisi nisi Lorem <LinkD /> in. Laborum aute fugiat
officia adipisicing non veniam dolor nulla non ex consectetur fugiat
eiusmod aute. Culpa sit aute est duis minim in in voluptate velit
fugiat. Laboris est id deserunt ut ea Lorem eu. Esse elit laboris aute
commodo sint laborum fugiat aliqua.
</BodyLong>
<div
className="colgap"
style={{
width: "800px",
border: "1px solid black",
borderRadius: "8px",
}}
>
<BodyLong>
Incididunt laborum nisi nisi Lorem
<LinkD />
in. Laborum aute fugiat officia adipisicing non veniam dolor nulla
non ex consectetur fugiat eiusmod aute. Culpa sit aute est duis
minim in in voluptate velit fugiat. Laboris est id deserunt ut ea
Lorem eu. Esse elit laboris aute commodo sint laborum fugiat aliqua.
</BodyLong>
</div>
);
}
return <LinkD />;
Expand All @@ -40,6 +87,49 @@ export const Default = {
},
};

export const InlineInsideBodyLong = {
render: ({ iconLeft, iconRight }) => {
return (
<div
className="colgap"
style={{
width: "800px",
border: "1px solid black",
borderRadius: "8px",
}}
>
<style>{`.storybook-custom-spacing { white-space: pre;}`}</style>
<BodyLong>
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight} />
Eiusmod aute.
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight} />
Culpa sit aute est duis minim in in voluptate velit Incididunt laborum
nisi nisi Lorem officia adipisicing non veniam
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight}>
blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah
</LinkWrapper>
dolor eu. Esse elit laboris aute commodo sint laborum fugiat aliqua.
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight}>
Link
</LinkWrapper>
</BodyLong>
<BodyLong className="storybook-custom-spacing">
Custom{" "}
<LinkWrapper underline iconLeft={iconLeft} iconRight={iconRight}>
link
</LinkWrapper>
{" "}spacing.
</BodyLong>
</div>
);
},
args: {
iconLeft: false,
iconRight: false,
},
};

const DemoLink = () => (
<Link href="#">
<PlusCircleFillIcon aria-hidden /> Ex aliqua incididunt{" "}
Expand Down Expand Up @@ -83,3 +173,27 @@ export const ConfirmationPanel = () => {
</div>
);
};

export const Variants = {
render: ({ iconLeft, iconRight }) => {
return (
<div className="colgap">
{["action", "neutral", "subtle"].map((variant) => (
<>
<div>
<LinkWrapper
iconLeft={iconLeft}
iconRight={iconRight}
variant={variant}
/>
</div>
</>
))}
</div>
);
},
args: {
iconLeft: false,
iconRight: false,
},
};
9 changes: 9 additions & 0 deletions @navikt/core/react/src/util/RandomIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as AllIcons from "@navikt/aksel-icons";
import React from "react";

const icons = Object.keys(AllIcons).map((key) => AllIcons[key]);

export const RandomIcon = () => {
const Icon = icons[Math.floor(Math.random() * icons.length)];
return <Icon />;
};
30 changes: 30 additions & 0 deletions aksel.nav.no/website/pages/eksempler/link/inline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PlusCircleFillIcon } from "@navikt/aksel-icons";
import { BodyLong, Link } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";

const Example = () => {
return (
<BodyLong>
Officia incididunt Culpa sit aute est duis minim in in voluptate velit
Incididunt laborum nisi nisi Lorem officia adipisicing non veniam{" "}
<Link href="#" inlineText={true}>
lenke til ny side
<PlusCircleFillIcon aria-hidden />
</Link>{" "}
Culpa sit aute est duis minim in in voluptate velit Incididunt laborum
nisi nisi Lorem officia adipisicing non veniam occaecat commodo id ad
aliquip.
</BodyLong>
);
};

export default withDsExample(Example);

/* Storybook story */
export const Demo = {
render: Example,
};

export const args = {
index: 0,
};
25 changes: 25 additions & 0 deletions aksel.nav.no/website/pages/eksempler/link/remove-underline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BodyLong, Link } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";

const Example = () => {
return (
<BodyLong>
Officia incididunt{" "}
<Link href="#" underline={false}>
lenke til ny side
</Link>{" "}
occaecat commodo id ad aliquip.
</BodyLong>
);
};

export default withDsExample(Example);

/* Storybook story */
export const Demo = {
render: Example,
};

export const args = {
index: 0,
};
Loading