Files
Homarr/src/components/Dashboard/Tiles/Service/ServiceTile.tsx

95 lines
2.7 KiB
TypeScript
Raw Normal View History

import { Card, Center, Text, UnstyledButton } from '@mantine/core';
2022-12-04 17:36:30 +01:00
import { NextLink } from '@mantine/next';
import { createStyles } from '@mantine/styles';
import { ServiceType } from '../../../../types/service';
import { useCardStyles } from '../../../layout/useCardStyles';
2022-12-04 19:10:07 +01:00
import { useEditModeStore } from '../../Views/useEditModeStore';
2022-12-11 15:04:05 +01:00
import { HomarrCardWrapper } from '../HomarrCardWrapper';
2022-12-04 17:36:30 +01:00
import { BaseTileProps } from '../type';
2022-12-11 00:00:11 +01:00
import { ServiceMenu } from './ServiceMenu';
2022-12-11 13:58:28 +01:00
import { ServicePing } from './ServicePing';
2022-12-04 17:36:30 +01:00
interface ServiceTileProps extends BaseTileProps {
service: ServiceType;
}
export const ServiceTile = ({ className, service }: ServiceTileProps) => {
const isEditMode = useEditModeStore((x) => x.enabled);
const { cx, classes } = useStyles();
const {
classes: { card: cardClass },
} = useCardStyles();
const inner = (
<>
<Text align="center" weight={500} size="md" className={classes.serviceName}>
{service.name}
</Text>
<Center style={{ height: '75%', flex: 1 }}>
2022-12-11 00:00:11 +01:00
{/* eslint-disable-next-line @next/next/no-img-element */}
2022-12-04 17:36:30 +01:00
<img className={classes.image} src={service.appearance.iconUrl} alt="" />
</Center>
</>
);
return (
<HomarrCardWrapper className={className}>
2022-12-10 22:14:31 +01:00
{/* TODO: add service menu */}
2022-12-11 00:00:11 +01:00
<div style={{ position: 'absolute', top: 10, right: 10 }}>
<ServiceMenu service={service} />
</div>
2022-12-04 17:36:30 +01:00
{!service.url || isEditMode ? (
<UnstyledButton
className={classes.button}
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
>
{inner}
</UnstyledButton>
) : (
<UnstyledButton
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
component={NextLink}
href={service.url}
target={service.behaviour.isOpeningNewTab ? '_blank' : '_self'}
className={cx(classes.button, classes.link)}
>
{inner}
</UnstyledButton>
)}
2022-12-11 13:58:28 +01:00
<ServicePing service={service} />
2022-12-11 15:04:05 +01:00
</HomarrCardWrapper>
2022-12-04 17:36:30 +01:00
);
};
2022-12-11 00:00:11 +01:00
const useStyles = createStyles((theme, _params, getRef) => ({
image: {
ref: getRef('image'),
maxHeight: '80%',
maxWidth: '80%',
transition: 'transform 100ms ease-in-out',
},
serviceName: {
ref: getRef('serviceName'),
},
button: {
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 4,
},
link: {
[`&:hover .${getRef('image')}`]: {
// TODO: add styles for image when hovering card
2022-12-04 17:36:30 +01:00
},
2022-12-11 00:00:11 +01:00
[`&:hover .${getRef('serviceName')}`]: {
// TODO: add styles for service name when hovering card
2022-12-04 17:36:30 +01:00
},
2022-12-11 00:00:11 +01:00
},
}));