mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 17:57:48 +02:00
refactor review
This commit is contained in:
parent
1686134d1c
commit
ee4a5f8c09
3 changed files with 33 additions and 42 deletions
|
@ -7,44 +7,12 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import Link, {type Props as LinkProps} from '@docusaurus/Link';
|
|
||||||
import type {Props} from '@theme/Blog/Components/Author/GeneratedImage';
|
import type {Props} from '@theme/Blog/Components/Author/GeneratedImage';
|
||||||
|
|
||||||
function MaybeLink(props: LinkProps): JSX.Element {
|
export default function GeneratedImage({name, className}: Props): JSX.Element {
|
||||||
if (props.href) {
|
|
||||||
return <Link {...props} />;
|
|
||||||
}
|
|
||||||
return <>{props.children}</>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function GeneratedImage({
|
|
||||||
name,
|
|
||||||
link,
|
|
||||||
className,
|
|
||||||
}: Props): JSX.Element {
|
|
||||||
return (
|
return (
|
||||||
<MaybeLink href={link} className="avatar__photo-link">
|
<div className={clsx('avatar__photo', className)}>
|
||||||
<svg
|
{name[0]?.toLocaleUpperCase()}
|
||||||
className={clsx('avatar__photo', className)}
|
</div>
|
||||||
viewBox="0 0 72 72"
|
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<defs>
|
|
||||||
<linearGradient id="greyGradient" x1="0" y1="0" x2="1" y2="1">
|
|
||||||
<stop offset="0%" style={{stopColor: '#ccc', stopOpacity: 1}} />
|
|
||||||
<stop offset="100%" style={{stopColor: '#777', stopOpacity: 1}} />
|
|
||||||
</linearGradient>
|
|
||||||
</defs>
|
|
||||||
<circle cx="36" cy="36" r="36" fill="url(#greyGradient)" />
|
|
||||||
<text
|
|
||||||
x="50%"
|
|
||||||
y="50%"
|
|
||||||
textAnchor="middle"
|
|
||||||
alignmentBaseline="central"
|
|
||||||
fontSize="2rem"
|
|
||||||
fill="#fff">
|
|
||||||
{name[0]?.toLocaleUpperCase()}
|
|
||||||
</text>
|
|
||||||
</svg>
|
|
||||||
</MaybeLink>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,11 +75,13 @@ export default function BlogAuthor({
|
||||||
/>
|
/>
|
||||||
</MaybeLink>
|
</MaybeLink>
|
||||||
) : (
|
) : (
|
||||||
<GeneratedImage
|
<MaybeLink href={link} className="avatar__photo-link">
|
||||||
name={name!}
|
<GeneratedImage
|
||||||
link={link}
|
name={name!}
|
||||||
className={clsx(styles.authorImage)}
|
link={link}
|
||||||
/>
|
className={clsx(styles.authorImage, styles.authorGeneratedImage)}
|
||||||
|
/>
|
||||||
|
</MaybeLink>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(name || title) && (
|
{(name || title) && (
|
||||||
|
|
|
@ -7,13 +7,34 @@
|
||||||
|
|
||||||
.authorImage {
|
.authorImage {
|
||||||
--ifm-avatar-photo-size: 3.6rem;
|
--ifm-avatar-photo-size: 3.6rem;
|
||||||
background: grey;
|
background: var(--ifm-color-emphasis-200);
|
||||||
}
|
}
|
||||||
|
|
||||||
.author-as-h1 .authorImage {
|
.author-as-h1 .authorImage {
|
||||||
--ifm-avatar-photo-size: 7rem;
|
--ifm-avatar-photo-size: 7rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.authorGeneratedImage {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
color: var(--ifm-color-emphasis-0);
|
||||||
|
font-size: 2rem;
|
||||||
|
background: linear-gradient(
|
||||||
|
135deg,
|
||||||
|
var(--ifm-color-emphasis-700) 0%,
|
||||||
|
var(--ifm-color-emphasis-1000) 100%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-theme='dark'] .authorGeneratedImage {
|
||||||
|
background: linear-gradient(
|
||||||
|
135deg,
|
||||||
|
var(--ifm-color-emphasis-800) 0%,
|
||||||
|
var(--ifm-color-emphasis-200) 100%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
.author-as-h2 .authorImage {
|
.author-as-h2 .authorImage {
|
||||||
--ifm-avatar-photo-size: 5.4rem;
|
--ifm-avatar-photo-size: 5.4rem;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue