Files
Homarr/src/components/AppShelf/AppShelf.tsx

93 lines
2.5 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
2022-04-25 23:33:32 +02:00
import { motion } from 'framer-motion';
import { Text, AspectRatio, SimpleGrid, Card, Center, Image, useMantineTheme } from '@mantine/core';
import { useConfig } from '../../tools/state';
import { serviceItem } from '../../tools/types';
2022-05-10 19:02:16 +02:00
import { AppShelfItemWrapper } from './AppShelfItemWrapper';
import AppShelfMenu from './AppShelfMenu';
2022-04-25 00:11:32 +02:00
const AppShelf = () => {
const { config } = useConfig();
2022-04-25 23:33:32 +02:00
2022-04-25 00:11:32 +02:00
return (
<SimpleGrid
cols={5}
spacing="xl"
breakpoints={[
{ maxWidth: 'xl', cols: 4, spacing: 'lg' },
{ maxWidth: 800, cols: 3, spacing: 'md' },
{ maxWidth: 400, cols: 3, spacing: 'sm' },
{ maxWidth: 400, cols: 2, spacing: 'sm' },
]}
>
{config.services.map((service) => (
2022-05-04 10:33:08 +02:00
<AppShelfItem key={service.name} service={service} />
2022-05-04 07:12:22 +02:00
))}
</SimpleGrid>
);
};
export function AppShelfItem(props: any) {
const { service }: { service: serviceItem } = props;
const [hovering, setHovering] = useState(false);
const theme = useMantineTheme();
2022-05-04 07:12:22 +02:00
return (
<motion.div
2022-05-04 07:49:29 +02:00
key={service.name}
onHoverStart={() => {
2022-05-04 07:12:22 +02:00
setHovering(true);
}}
onHoverEnd={() => {
2022-05-04 07:12:22 +02:00
setHovering(false);
}}
>
<Card
style={{
boxShadow: hovering ? '0px 0px 3px rgba(0, 0, 0, 0.5)' : '0px 0px 1px rgba(0, 0, 0, 0.5)',
backgroundColor:
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1],
}}
radius="md"
>
2022-05-04 07:12:22 +02:00
<Card.Section>
<Text mt="sm" align="center" lineClamp={1} weight={500}>
2022-05-04 07:12:22 +02:00
{service.name}
</Text>
<motion.div
style={{
position: 'absolute',
top: 5,
right: 5,
alignSelf: 'flex-end',
}}
animate={{
opacity: hovering ? 1 : 0,
}}
>
<AppShelfMenu service={service} />
</motion.div>
2022-05-04 07:12:22 +02:00
</Card.Section>
<Card.Section>
<AspectRatio ratio={5 / 3} m="xl">
<motion.i
whileHover={{
cursor: 'pointer',
scale: 1.1,
}}
>
<Image
onClick={() => {
window.open(service.url);
}}
src={service.icon}
/>
</motion.i>
</AspectRatio>
</Card.Section>
</Card>
2022-05-04 07:12:22 +02:00
</motion.div>
2022-04-25 00:11:32 +02:00
);
2022-05-04 07:12:22 +02:00
}
2022-04-25 00:11:32 +02:00
2022-04-27 03:11:35 +02:00
export default AppShelf;