Browse Source

[Beta] Show illustration credit on hover/tap (#5188)

* [beta] Show `AuthorCredit` on hover and focus

* Move attribution to top

* Styling and stuff

Co-authored-by: Dan Lebowitz <dan.lebo@me.com>

Co-authored-by: Mayank <9084735+mayank99@users.noreply.github.com>
Co-authored-by: Dan Lebowitz <dan.lebo@me.com>
main
dan 2 years ago
committed by GitHub
parent
commit
0867cc17d3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 78
      beta/src/components/MDX/MDXComponents.tsx

78
beta/src/components/MDX/MDXComponents.tsx

@ -173,28 +173,40 @@ function Recipes(props: any) {
} }
function AuthorCredit({ function AuthorCredit({
author, author = 'Rachel Lee Nabors',
authorLink, authorLink = 'http://rachelnabors.com/',
}: { }: {
author: string; author: string;
authorLink: string; authorLink: string;
}) { }) {
return ( return (
<p className="text-center text-secondary dark:text-secondary-dark text-base mt-2"> <div className="sr-only group-hover:not-sr-only group-focus-within:not-sr-only hover:sr-only">
<cite> <p className="bg-card dark:bg-card-dark text-center text-sm text-secondary dark:text-secondary-dark leading-tight dark:text-secondary-dark p-2 rounded-lg absolute left-1/2 top-0 -translate-x-1/2 -translate-y-full group-hover:flex group-hover:opacity-100 after:content-[''] after:absolute after:left-1/2 after:top-[95%] after:-translate-x-1/2 after:border-8 after:border-x-transparent after:border-b-transparent after:border-t-card after:dark:border-t-card-dark opacity-0 transition-opacity duration-300">
Illustrated by{' '} <cite>
{authorLink ? ( Illustrated by{' '}
<a className="text-link dark:text-link-dark" href={authorLink}> {authorLink ? (
{author} <a
</a> target="_blank"
) : ( rel="noreferrer"
author className="text-link dark:text-link-dark"
)} href={authorLink}>
</cite> {author}
</p> </a>
) : (
author
)}
</cite>
</p>
</div>
); );
} }
const IllustrationContext = React.createContext<{
isInBlock?: boolean;
}>({
isInBlock: false,
});
function Illustration({ function Illustration({
caption, caption,
src, src,
@ -208,8 +220,10 @@ function Illustration({
author: string; author: string;
authorLink: string; authorLink: string;
}) { }) {
const {isInBlock} = React.useContext(IllustrationContext);
return ( return (
<div className="my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl"> <div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
<figure className="my-8 flex justify-center"> <figure className="my-8 flex justify-center">
<img <img
src={src} src={src}
@ -223,11 +237,13 @@ function Illustration({
</figcaption> </figcaption>
) : null} ) : null}
</figure> </figure>
{author ? <AuthorCredit author={author} authorLink={authorLink} /> : null} {!isInBlock && <AuthorCredit author={author} authorLink={authorLink} />}
</div> </div>
); );
} }
const isInBlockTrue = {isInBlock: true};
function IllustrationBlock({ function IllustrationBlock({
sequential, sequential,
author, author,
@ -255,20 +271,22 @@ function IllustrationBlock({
</figure> </figure>
)); ));
return ( return (
<div className="my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl"> <IllustrationContext.Provider value={isInBlockTrue}>
{sequential ? ( <div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
<ol className="mdx-illustration-block flex"> {sequential ? (
{images.map((x: any, i: number) => ( <ol className="mdx-illustration-block flex">
<li className="flex-1" key={i}> {images.map((x: any, i: number) => (
{x} <li className="flex-1" key={i}>
</li> {x}
))} </li>
</ol> ))}
) : ( </ol>
<div className="mdx-illustration-block">{images}</div> ) : (
)} <div className="mdx-illustration-block">{images}</div>
{author ? <AuthorCredit author={author} authorLink={authorLink} /> : null} )}
</div> <AuthorCredit author={author} authorLink={authorLink} />
</div>
</IllustrationContext.Provider>
); );
} }

Loading…
Cancel
Save