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

104 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-12-20 11:45:33 +09:00
import { Center, Text, UnstyledButton } from '@mantine/core';
2022-12-04 17:36:30 +01:00
import { NextLink } from '@mantine/next';
import { createStyles } from '@mantine/styles';
2023-01-02 02:52:12 +09:00
import { motion } from 'framer-motion';
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 (
<>
<Text align="center" weight={500} size="md" className={classes.appName}>
{app.name}
</Text>
<Center style={{ height: '85%', flex: 1 }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<motion.img
className={classes.image}
src={app.appearance.iconUrl}
alt={app.name}
whileHover={{
scale: 1.2,
transition: { duration: 0.2 },
}}
initial={{ opacity: 0, scale: 0.5 }}
animate={{ scale: 1, opacity: 1 }}
transition={{ duration: 0.3 }}
/>
</Center>
</>
);
}
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' }}
component={NextLink}
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: {
ref: getRef('image'),
2023-01-03 22:32:00 +09:00
maxHeight: '90%',
maxWidth: '90%',
2022-12-11 00:00:11 +01:00
},
appName: {
ref: getRef('appName'),
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,
};