Created
February 17, 2020 04:33
-
-
Save gustav1105/acd65fd709e83bd70df2f9565b1ba1cb to your computer and use it in GitHub Desktop.
composite-decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { EditorContext } from "./EditorContext"; | |
export function DecoratedLink({ | |
className, | |
children, | |
entityKey, | |
target | |
}: { | |
className: string; | |
children: React.ReactNode; | |
entityKey: string; | |
target?: string; | |
}) { | |
const editorState = React.useContext(EditorContext); | |
const entity = editorState.getCurrentContent().getEntity(entityKey); | |
const entityData = entity ? entity.getData() : undefined; | |
const href = (entityData && entityData.url) || undefined; | |
return ( | |
<a | |
className={className} | |
title={href} | |
href={href} | |
target={target} | |
rel="noopener" | |
> | |
{children} | |
</a> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment