Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Create and use external link component

Mateusz Stanielewicz34c0b18000f5
diff --git a/saleor/static/dashboard-next/components/ExternalLink/ExternalLink.tsx b/saleor/static/dashboard-next/components/ExternalLink/ExternalLink.tsx
new file mode 100644
index 0000000000..e69d4f194c
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ExternalLink/ExternalLink.tsx
@@ -0,0 +1,34 @@
+import { withStyles } from "@material-ui/core/styles";
+import Typography, { TypographyProps } from "@material-ui/core/Typography";
+import blue from "@material-ui/core/colors/blue";
+import * as classNames from "classnames";
+import * as React from "react";
+
+interface ExternalLinkProps extends React.HTMLProps<HTMLAnchorElement> {
+ href: string,
+ className?: string;
+ typographyProps?: TypographyProps;
+}
+
+const decorate = withStyles({
+ link: {
+ color: blue[500],
+ cursor: "pointer",
+ textDecoration: "none",
+ },
+});
+const ExternalLink = decorate<ExternalLinkProps>(
+ ({ classes, className, children, href, theme, typographyProps, ...props }) => (
+ <>
+ <a
+ href={href}
+ className={classNames(classes.link, className)}
+ {...props}
+ >
+ <Typography {...typographyProps}>{children}</Typography>
+ </a>
+ </>
+ )
+);
+ExternalLink.displayName = "ExternalLink";
+export default ExternalLink;
diff --git a/saleor/static/dashboard-next/components/ExternalLink/index.ts b/saleor/static/dashboard-next/components/ExternalLink/index.ts
new file mode 100644
index 0000000000..ec7bc81ba8
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ExternalLink/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ExternalLink";
+export * from "./ExternalLink";
diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
index e6f077ac50..d26c98b235 100644
--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
@@ -1,12 +1,12 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
-import blue from "@material-ui/core/colors/blue";
import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
+import ExternalLink from "../../../components/ExternalLink";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
@@ -46,11 +46,6 @@ const decorate = withStyles(
height: 1,
width: "100%"
},
- link: {
- color: blue[500],
- cursor: "pointer",
- textDecoration: "none"
- }
}),
{ name: "OrderCustomer" }
);
@@ -90,14 +85,9 @@ const OrderCustomer = decorate<OrderCustomerProps>(
) : client === null ? (
<Typography>{i18n.t("Anonymous customer")}</Typography>
) : (
- <>
- <a
- href={`mailto:${client.email}`}
- className={classes.link}
- >
- <Typography>{client.email}</Typography>
- </a>
- </>
+ <ExternalLink href={`mailto:${client.email}`}>
+ {client.email}
+ </ExternalLink>
)}
</CardContent>
<hr className={classes.hr} />
diff --git a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
index 3181b6ae9d..c9e95f6da1 100644
--- a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
+++ b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
@@ -4632,16 +4632,16 @@ exports[`Storyshots Orders / OrderCustomer when loaded data 1`] = `
<div
class="MuiCardContent-root-id"
>
- <p
- class="MuiTypography-root-id MuiTypography-body1-id"
- >
- </p>
- <p
- class="MuiTypography-root-id MuiTypography-body1-id OrderCustomer-link-id"
+ <a
+ class="Component-link-id"
+ href="mailto:[email protected]"
>
- </p>
+ <p
+ class="MuiTypography-root-id MuiTypography-body1-id"
+ >
+ </p>
+ </a>
</div>
<hr
class="OrderCustomer-hr-id"
@@ -4849,16 +4849,16 @@ exports[`Storyshots Orders / OrderCustomer with different addresses 1`] = `
<div
class="MuiCardContent-root-id"
>
- <p
- class="MuiTypography-root-id MuiTypography-body1-id"
- >
- </p>
- <p
- class="MuiTypography-root-id MuiTypography-body1-id OrderCustomer-link-id"
+ <a
+ class="Component-link-id"
+ href="mailto:[email protected]"
>
- </p>
+ <p
+ class="MuiTypography-root-id MuiTypography-body1-id"
+ >
+ </p>
+ </a>
</div>
<hr
class="OrderCustomer-hr-id"
diff --git a/saleor/static/dashboard-next/storybook/stories/components/ExternalLink.tsx b/saleor/static/dashboard-next/storybook/stories/components/ExternalLink.tsx
new file mode 100644
index 0000000000..cf3297c515
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/components/ExternalLink.tsx
@@ -0,0 +1,9 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import ExternalLink from "../../../components/ExternalLink";
+import Decorator from "../../Decorator";
+
+storiesOf("Generics / ExternalLink", module)
+ .addDecorator(Decorator)
+ .add("default", () => <ExternalLink href="http://www.google.pl" />);