This commit is contained in:
Sebastian Seedorf
2022-08-18 09:20:00 +02:00
parent 92b762bbd2
commit de95f57b18
60 changed files with 3450 additions and 994 deletions

View File

@@ -1,18 +1,18 @@
import {FC, HTMLProps, useMemo} from "react"
import {Entity} from "../../../src/types"
import {useFactories} from "../../../src/hooks/useFactories"
import { FC, HTMLProps, useMemo } from 'react'
import { Entity } from '../../../src/types'
import { useFactories } from '../../../src/hooks/useFactories'
import styles from './EntityIcon.module.css'
import cx from "classnames";
import cx from 'classnames'
interface Props extends Omit<HTMLProps<HTMLSpanElement>, 'value'> {
value: Entity|string
value: Entity | string
amount?: number
}
export const EntityIcon: FC<Props> = ({className, value, amount, ...rest}) => {
const {findFactory} = useFactories()
export const EntityIcon: FC<Props> = ({ className, value, amount, ...rest }) => {
const { findFactory } = useFactories()
const entity = useMemo<Entity>(() => {
return typeof value === "object"
return typeof value === 'object'
? value
: value === '/Time'
? {
@@ -29,9 +29,15 @@ export const EntityIcon: FC<Props> = ({className, value, amount, ...rest}) => {
}
}, [findFactory, value])
return <span {...rest} className={cx(className, styles.span)} title={entity.name}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className={cx(styles.img, amount === undefined ? styles.noAmount : undefined)} src={`https://wiki.factorio.com${entity.image}`} alt={entity.name}/>
{amount !== undefined && <span className={styles.amount}>{amount}</span>}
</span>
return (
<span {...rest} className={cx(className, styles.span)} title={entity.name}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
className={cx(styles.img, amount === undefined ? styles.noAmount : undefined)}
src={`https://wiki.factorio.com${entity.image}`}
alt={entity.name}
/>
{amount !== undefined && <span className={styles.amount}>{amount}</span>}
</span>
)
}