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

103 lines
2.7 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
2022-04-25 23:33:32 +02:00
import { motion } from 'framer-motion';
2022-05-14 11:40:05 +02:00
import { Text, AspectRatio, SimpleGrid, Card, Image, useMantineTheme } from '@mantine/core';
import { useConfig } from '../../tools/state';
import { serviceItem } from '../../tools/types';
2022-05-10 19:02:16 +02:00
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={[
2022-05-14 11:40:05 +02:00
{ maxWidth: 1400, 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>
2022-05-14 11:40:05 +02:00
<Text mt="sm" align="center" lineClamp={1} weight={500}>
{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>
2022-05-14 11:40:05 +02:00
<AspectRatio
ratio={3 / 5}
m="xl"
style={{
width: 150,
height: 90,
}}
>
2022-05-04 07:12:22 +02:00
<motion.i
whileHover={{
cursor: 'pointer',
scale: 1.1,
}}
>
<Image
2022-05-14 11:40:05 +02:00
style={{
maxWidth: 80,
}}
fit="contain"
2022-05-04 07:12:22 +02:00
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;