Skip to content

Commit 491ae9c

Browse files
committed
Add AnchorWithIcon component
1 parent 6ec2f65 commit 491ae9c

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from "react";
2+
import Faker from "faker";
3+
import { addDecorator } from "@storybook/react";
4+
import StoryRouter from "storybook-react-router";
5+
import { AnchorWithIcon } from "./anchor-with-icon";
6+
import { select, text } from "@storybook/addon-knobs";
7+
import { ButtonSizes } from "../constants/button-sizes";
8+
import { ButtonStyles } from "../constants/button-styles";
9+
import { Icons } from "../constants/icons";
10+
import { IconUtils } from "../../utilities/icon-utils";
11+
import { SvgIcons } from "../constants/svg-icons";
12+
13+
addDecorator(StoryRouter());
14+
15+
export default {
16+
component: AnchorWithIcon,
17+
title: "Atoms | Anchors / AnchorWithIcon",
18+
};
19+
20+
export const anchorIconWithChevronDownIcon = () => {
21+
IconUtils.register(SvgIcons);
22+
23+
return (
24+
<AnchorWithIcon
25+
accessibleText="Text for screen reader"
26+
size={ButtonSizes.Medium}
27+
style={ButtonStyles.Primary}
28+
icon={Icons.Checkmark}
29+
to="/test">
30+
{Faker.lorem.words(5)}
31+
</AnchorWithIcon>
32+
);
33+
};
34+
35+
export const anchorIconKnobs = () => {
36+
IconUtils.register(SvgIcons);
37+
38+
return (
39+
<AnchorWithIcon
40+
accessibleText={text("accessibleText", "Text for screen reader")}
41+
size={select("size", ButtonSizes, ButtonSizes.Medium)}
42+
style={select("style", ButtonStyles, ButtonStyles.Primary)}
43+
icon={select("icon", Icons, Icons.Checkmark)}
44+
to="/test">
45+
{text("text", "Anchor text")}
46+
</AnchorWithIcon>
47+
);
48+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
describe("AnchorWithIcon", () => {
4+
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/4", () => {});
5+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import { ButtonSizes } from "../constants/button-sizes";
3+
import { ButtonStyles } from "../constants/button-styles";
4+
import { Icons } from "../constants/icons";
5+
import { Anchor } from "../anchors/anchor";
6+
import { Icon } from "../icons/icon";
7+
8+
export interface AnchorWithIconProps {
9+
accessibleText?: string;
10+
children: any;
11+
icon: keyof typeof Icons;
12+
size?: ButtonSizes;
13+
style?: ButtonStyles;
14+
to: string;
15+
}
16+
17+
const AnchorWithIcon: React.FC<AnchorWithIconProps> = (
18+
props: AnchorWithIconProps
19+
) => {
20+
const size: ButtonSizes =
21+
props.size != null ? props.size : ButtonSizes.Medium;
22+
const { accessibleText, icon, to } = props;
23+
24+
// Defaulting all AnchorWithIcon components to be styled as a button for now.
25+
const cssClassNames = ["c-button", "-icon-left", size];
26+
27+
if (props.style != null) {
28+
cssClassNames.push(props.style);
29+
}
30+
31+
return (
32+
<Anchor cssClassName={cssClassNames.join(" ")} to={to}>
33+
<Icon type={icon} /> {props.children}
34+
{// if
35+
accessibleText != null && (
36+
<span className="sr-only">{accessibleText}</span>
37+
)}
38+
</Anchor>
39+
);
40+
};
41+
42+
export { AnchorWithIcon };

src/index.ts

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

55
export { Anchor } from "./atoms/anchors/anchor";
6+
export { AnchorWithIcon } from "./atoms/anchors/anchor-with-icon";
67
export { Button } from "./atoms/buttons/button";
78

89
// Icons

0 commit comments

Comments
 (0)