webapp/src/components/Author/AhtorLink/AuthorLink.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

import { clsx } from 'clsx'
2023-12-19 09:34:24 +00:00
import { createMemo } from 'solid-js'
2023-12-19 09:34:24 +00:00
import { useLocalize } from '../../../context/localize'
2023-11-28 13:18:25 +00:00
import { Author } from '../../../graphql/schema/core.gen'
2023-12-19 09:34:24 +00:00
import { capitalize } from '../../../utils/capitalize'
import { isCyrillic } from '../../../utils/cyrillic'
import { Userpic } from '../Userpic'
import styles from './AhtorLink.module.scss'
type Props = {
author: Author
size?: 'XS' | 'M' | 'L'
class?: string
2023-11-20 21:31:52 +00:00
isFloorImportant?: boolean
}
export const AuthorLink = (props: Props) => {
2023-12-19 09:34:24 +00:00
const { lang } = useLocalize()
const name = createMemo(() => {
return lang() === 'en' && isCyrillic(props.author.name)
? capitalize(props.author.slug.replace(/-/, ' '))
: props.author.name
})
return (
2023-11-20 21:31:52 +00:00
<div
class={clsx(styles.AuthorLink, props.class, styles[props.size ?? 'M'], {
[styles.authorLinkFloorImportant]: props.isFloorImportant,
})}
>
<a class={styles.link} href={`/author/${props.author.slug}`}>
2023-12-19 09:34:24 +00:00
<Userpic size={props.size ?? 'M'} name={props.author.name} userpic={props.author.pic} />
<div class={styles.name}>{name()}</div>
</a>
</div>
)
}