Add type label to battlesuit show page

This commit is contained in:
Sakura Knoll
2021-12-31 18:27:38 +09:00 Unverified
parent 8f061250e7
commit 30bac56aa3
2 changed files with 41 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
import { Flex, Text } from '@theme-ui/components'
import SquareImageBox from './SquareImageBox'
interface TypeLabelProps {
type: string
}
const TypeLabel = ({ type }: TypeLabelProps) => {
const label = type.replace(/^\w/, (c) => c.toUpperCase())
return (
<Flex sx={{ alignItems: 'center' }}>
{isValidType(type) && (
<SquareImageBox
size={30}
src={`/assets/honkai3rd/type-icons/${type}.png`}
alt={label}
mr={1}
/>
)}
<Text>{label}</Text>
</Flex>
)
}
export default TypeLabel
function isValidType(type: string): boolean {
switch (type) {
case 'mecha':
case 'biologic':
case 'psychic':
case 'quantum':
case 'imginary':
return true
}
return false
}