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

40 lines
1.2 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'
2023-12-31 05:01:34 +00:00
import { translit } from '../../../utils/ru2en'
2024-02-04 17:40:15 +00:00
import { isCyrillic } from '../../../utils/translate'
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(() => {
2024-06-24 17:50:27 +00:00
return lang() === 'en' && isCyrillic(props.author.name || '')
? translit(capitalize(props.author.name || ''))
2023-12-19 09:34:24 +00:00
: props.author.name
})
return (
2023-11-20 21:31:52 +00:00
<div
2024-06-24 17:50:27 +00:00
class={clsx(styles.AuthorLink, props.class, styles[(props.size ?? 'M') as keyof Props['size']], {
2024-06-26 08:22:05 +00:00
[styles.authorLinkFloorImportant]: props.isFloorImportant
2023-11-20 21:31:52 +00:00
})}
>
<a class={styles.link} href={`/author/${props.author.slug}`}>
2024-06-24 17:50:27 +00:00
<Userpic size={props.size ?? 'M'} name={name() || ''} userpic={props.author.pic || ''} />
2023-12-19 09:34:24 +00:00
<div class={styles.name}>{name()}</div>
</a>
</div>
)
}