Skip to content

Commit

Permalink
feat: support provider url
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnyTheCarrot committed Aug 15, 2023
1 parent 271bbf3 commit 03d6a77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/Content/Embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ function Embed({ embed, images }: EmbedProps) {
<Styles.Embed style={{ borderLeftColor: embedColor }} thin={isEmbedThin}>
<Styles.ContentAndThumbnail hasLargeThumbnail={isThumbnailLarge}>
<Styles.Content>
{embed.provider && (
<Styles.Provider>{embed.provider.name}</Styles.Provider>
)}
{embed.provider &&
(embed.provider.url ? (
<ExternalLink href={embed.provider.url}>
<Styles.Provider>{embed.provider.name}</Styles.Provider>
</ExternalLink>
) : (
<Styles.Provider>{embed.provider.name}</Styles.Provider>
))}
{embed.author && (
<Styles.Author>
{embed.author.proxy_icon_url && (
Expand Down
15 changes: 8 additions & 7 deletions src/ExternalLink.tsx → src/ExternalLink/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { HTMLProps } from "react";
import type { ComponentProps } from "react";
import React from "react";
import { useConfig } from "./core/ConfigContext";
import { useConfig } from "../core/ConfigContext";
import * as Styles from "./style";

function ExternalLink(
props: HTMLProps<HTMLAnchorElement> &
Required<Pick<HTMLProps<HTMLAnchorElement>, "href">>
) {
type Props = ComponentProps<typeof Styles.ExternalLink> &
Required<Pick<ComponentProps<typeof Styles.ExternalLink>, "href">>;

function ExternalLink(props: Props) {
const { externalLinkOpenRequested } = useConfig();

return (
<a
<Styles.ExternalLink
{...props}
rel="noreferrer noopener"
target="_blank"
Expand Down
12 changes: 12 additions & 0 deletions src/ExternalLink/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { commonComponentId, styled } from "../Stitches/stitches.config";

export const ExternalLink = styled.withConfig({
displayName: "external-link",
componentId: commonComponentId,
})("a", {
textDecoration: "none",

"&:hover": {
textDecoration: "underline",
},
});

0 comments on commit 03d6a77

Please sign in to comment.