Skip to content

Commit a18ec78

Browse files
committed
Merged anchor-with-icon into base anchor component
1 parent 6816418 commit a18ec78

7 files changed

Lines changed: 44 additions & 189 deletions

File tree

src/atoms/anchors/anchor-with-icon.stories.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/atoms/anchors/anchor-with-icon.test.tsx

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/atoms/anchors/anchor-with-icon.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/atoms/anchors/anchor.scss

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
\*------------------------------------*/
66

77
a {
8+
display: flex;
9+
align-items: center;
10+
811
@include font-style(
912
$font-primary,
1013
"small",
@@ -13,27 +16,15 @@ a {
1316
16px
1417
);
1518

16-
&.c-button {
17-
display: inline-block;
18-
text-decoration: none;
19-
20-
&.-icon {
21-
text-align: center;
22-
23-
.c-icon {
24-
margin-top: calc(50% - 6px);
25-
26-
&.-large {
27-
margin-top: calc(50% - 12px);
28-
}
29-
}
30-
}
31-
}
32-
3319
&.-secondary {
3420
color: get-color("links", "secondary");
3521
}
22+
3623
&.-disabled {
3724
cursor: not-allowed;
3825
}
26+
27+
.c-icon {
28+
margin-right: .25em;
29+
}
3930
}

src/atoms/anchors/anchor.stories.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@ import { Anchor } from "./anchor";
33
import Faker from "faker";
44
import { addDecorator } from "@storybook/react";
55
import StoryRouter from "storybook-react-router";
6+
import { Icons } from "../constants/icons";
67

78
addDecorator(StoryRouter());
89

910
export default {
10-
title: "Atoms | Anchors / Anchor",
11+
title: "Atoms | Anchors",
1112
component: Anchor,
1213
};
1314

14-
export const anchorDefault = () => (
15+
export const plain = () => (
1516
<Anchor to="/test">{Faker.lorem.words(5)}</Anchor>
1617
);
18+
19+
export const icon = () => (
20+
<Anchor
21+
icon = {Icons.Share}
22+
to = "/test"
23+
>{Faker.lorem.words(5)}</Anchor>
24+
)
25+
26+
export const external = () => (
27+
<Anchor
28+
external = { true }
29+
target = "_blank"
30+
to = "https://www.humanetech.com/"
31+
>Center For Humane Technology</Anchor>
32+
)

src/atoms/anchors/anchor.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Link } from "react-router-dom";
22
import React, { forwardRef } from "react";
3+
import { Icons } from "../constants/icons";
4+
import { Icon } from "../icons/icon";
35
import "./anchor.scss";
46

57
/*
@@ -13,6 +15,7 @@ export interface AnchorProps {
1315
children?: any;
1416
cssClassName?: string;
1517
external?: boolean;
18+
icon?: keyof typeof Icons;
1619
id?: string;
1720
onClick?: (e: React.MouseEvent<HTMLElement>, value?: any) => void;
1821
onKeyDown?: (e: React.KeyboardEvent<HTMLAnchorElement>) => void;
@@ -49,7 +52,7 @@ const Anchor: React.RefForwardingComponent<Link, AnchorProps> = forwardRef(
4952
relAttribute = "noopener noreferrer";
5053
}
5154

52-
const commonProps = {
55+
const attributes = {
5356
"aria-label": props.ariaLabel,
5457
className: cssClassNames.join(" "),
5558
id: props.id,
@@ -61,17 +64,27 @@ const Anchor: React.RefForwardingComponent<Link, AnchorProps> = forwardRef(
6164
onKeyDown: props.onKeyDown,
6265
};
6366

67+
const content = (
68+
<React.Fragment>
69+
{// if
70+
props.icon && (
71+
<Icon type={props.icon} />
72+
)}
73+
{props.children}
74+
</React.Fragment>
75+
)
76+
6477
if (props.external === true) {
6578
return (
66-
<a href={props.to} {...commonProps}>
67-
{props.children}
79+
<a href={props.to} {...attributes}>
80+
{content}
6881
</a>
6982
);
7083
}
7184

7285
return (
73-
<Link to={props.to} {...commonProps}>
74-
{props.children}
86+
<Link to={props.to} {...attributes}>
87+
{content}
7588
</Link>
7689
);
7790
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// -----------------------------------------------------------------------------------------
44

55
export { Anchor } from "./atoms/anchors/anchor";
6-
export { AnchorWithIcon } from "./atoms/anchors/anchor-with-icon";
76
export { Button } from "./atoms/buttons/button";
87
export { Icon } from "./atoms/icons/icon";
98
export { Image } from "./atoms/images/image";

0 commit comments

Comments
 (0)