Files
Homarr/src/components/Dashboard/Tiles/Apps/AppTile.tsx

120 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-01-31 22:10:27 +01:00
import { Box, Stack, Title, UnstyledButton } from '@mantine/core';
2022-12-04 17:36:30 +01:00
import { createStyles } from '@mantine/styles';
2023-01-02 02:52:12 +09:00
import { motion } from 'framer-motion';
2023-01-23 01:34:36 +09:00
import Link from 'next/link';
import { AppType } from '../../../../types/app';
2022-12-04 17:36:30 +01:00
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';
import { AppMenu } from './AppMenu';
import { AppPing } from './AppPing';
2022-12-04 17:36:30 +01:00
interface AppTileProps extends BaseTileProps {
app: AppType;
2022-12-04 17:36:30 +01:00
}
export const AppTile = ({ className, app }: AppTileProps) => {
2022-12-04 17:36:30 +01:00
const isEditMode = useEditModeStore((x) => x.enabled);
const { cx, classes } = useStyles();
const {
classes: { card: cardClass },
2022-12-30 17:58:12 +01:00
} = useCardStyles(false);
2022-12-04 17:36:30 +01:00
2023-01-03 22:32:00 +09:00
function Inner() {
return (
<>
<Stack
m={0}
p={0}
spacing="xs"
justify="space-around"
align="center"
style={{ height: '100%', width: '100%' }}
className="dashboard-tile-app"
>
<Box hidden={false}>
2023-03-03 00:37:22 +09:00
<Title
order={5}
size="md"
ta="center"
lineClamp={1}
className={cx(classes.appName, 'dashboard-tile-app-title')}
>
{app.name}
</Title>
</Box>
2023-01-03 22:32:00 +09:00
<motion.img
className={classes.image}
height="85%"
width="85%"
style={{
objectFit: 'contain',
}}
2023-01-03 22:32:00 +09:00
src={app.appearance.iconUrl}
alt={app.name}
whileHover={{
scale: 1.2,
transition: { duration: 0.2 },
}}
/>
</Stack>
2023-01-03 22:32:00 +09:00
</>
);
}
2022-12-04 17:36:30 +01:00
return (
<HomarrCardWrapper className={className}>
<AppMenu app={app} />
{!app.url || isEditMode ? (
2022-12-04 17:36:30 +01:00
<UnstyledButton
className={classes.button}
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
>
2023-01-03 22:32:00 +09:00
<Inner />
2022-12-04 17:36:30 +01:00
</UnstyledButton>
) : (
<UnstyledButton
style={{ pointerEvents: isEditMode ? 'none' : 'auto' }}
2023-01-23 01:34:36 +09:00
component={Link}
2022-12-30 16:58:05 +01:00
href={app.behaviour.externalUrl.length > 0 ? app.behaviour.externalUrl : app.url}
target={app.behaviour.isOpeningNewTab ? '_blank' : '_self'}
2023-01-03 22:32:00 +09:00
className={cx(classes.button)}
2022-12-04 17:36:30 +01:00
>
2023-01-03 22:32:00 +09:00
<Inner />
2022-12-04 17:36:30 +01:00
</UnstyledButton>
)}
<AppPing app={app} />
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: {
2023-01-03 22:32:00 +09:00
maxHeight: '90%',
maxWidth: '90%',
2022-12-11 00:00:11 +01:00
},
appName: {
2023-01-20 12:57:45 +09:00
wordBreak: 'break-word',
2022-12-11 00:00:11 +01:00
},
button: {
2023-01-03 22:32:00 +09:00
paddingBottom: 10,
2022-12-11 00:00:11 +01:00
height: '100%',
width: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 4,
},
}));
export const appTileDefinition = {
component: AppTile,
2023-01-03 22:32:00 +09:00
minWidth: 1,
minHeight: 1,
maxWidth: 12,
maxHeight: 12,
};