Spaces:
Build error
Build error
File size: 1,541 Bytes
a8b3f00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import s from './index.module.css'
import cn from '@/utils/classnames'
import type { DataSourceNotionPage } from '@/models/common'
type IconTypes = 'workspace' | 'page'
type NotionIconProps = {
type?: IconTypes
name?: string | null
className?: string
src?: string | null | DataSourceNotionPage['page_icon']
}
const NotionIcon = ({
type = 'workspace',
src,
name,
className,
}: NotionIconProps) => {
if (type === 'workspace') {
if (typeof src === 'string') {
if (src.startsWith('https://') || src.startsWith('http://')) {
return (
<img
alt='workspace icon'
src={src}
className={cn('block object-cover w-5 h-5', className)}
/>
)
}
return (
<div className={cn('flex items-center justify-center w-5 h-5', className)}>{src}</div>
)
}
return (
<div className={cn('flex items-center justify-center w-5 h-5 bg-gray-200 text-xs font-medium text-gray-500 rounded', className)}>{name?.[0].toLocaleUpperCase()}</div>
)
}
if (typeof src === 'object' && src !== null) {
if (src?.type === 'url') {
return (
<img
alt='page icon'
src={src.url || ''}
className={cn('block object-cover w-5 h-5', className)}
/>
)
}
return (
<div className={cn('flex items-center justify-center w-5 h-5', className)}>{src?.emoji}</div>
)
}
return (
<div className={cn(s['default-page-icon'], className)} />
)
}
export default NotionIcon
|