Work on responsiveness for the AppShelf

This commit is contained in:
Thomas "ajnart" Camlong
2022-05-14 10:10:58 +02:00
parent 09483ada01
commit 2139f48df3
5 changed files with 45 additions and 42 deletions

View File

@@ -25,7 +25,7 @@ export default function AddItemShelfItem(props: any) {
<> <>
<Modal <Modal
size="xl" size="xl"
radius="lg" radius="md"
opened={props.opened || opened} opened={props.opened || opened}
onClose={() => setOpened(false)} onClose={() => setOpened(false)}
title="Add a service" title="Add a service"

View File

@@ -1,3 +1,4 @@
import { SimpleGrid } from '@mantine/core';
import AppShelf, { AppShelfItem } from './AppShelf'; import AppShelf, { AppShelfItem } from './AppShelf';
export default { export default {
@@ -16,3 +17,10 @@ export default {
export const Default = (args: any) => <AppShelf {...args} />; export const Default = (args: any) => <AppShelf {...args} />;
export const One = (args: any) => <AppShelfItem {...args} />; export const One = (args: any) => <AppShelfItem {...args} />;
export const Ten = (args: any) => (
<SimpleGrid>
{Array.from(Array(10)).map((_, i) => (
<AppShelfItem {...args} key={i} />
))}
</SimpleGrid>
);

View File

@@ -1,9 +1,8 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { Text, AspectRatio, SimpleGrid, Card, Image, Group, Space } from '@mantine/core'; import { Text, AspectRatio, SimpleGrid, Card, Center, Image, useMantineTheme } from '@mantine/core';
import { useConfig } from '../../tools/state'; import { useConfig } from '../../tools/state';
import { serviceItem } from '../../tools/types'; import { serviceItem } from '../../tools/types';
import AddItemShelfItem from './AddAppShelfItem';
import { AppShelfItemWrapper } from './AppShelfItemWrapper'; import { AppShelfItemWrapper } from './AppShelfItemWrapper';
import AppShelfMenu from './AppShelfMenu'; import AppShelfMenu from './AppShelfMenu';
@@ -11,11 +10,19 @@ const AppShelf = () => {
const { config } = useConfig(); const { config } = useConfig();
return ( return (
<SimpleGrid m="xl" cols={5} spacing="xl"> <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) => ( {config.services.map((service) => (
<AppShelfItem key={service.name} service={service} /> <AppShelfItem key={service.name} service={service} />
))} ))}
<AddItemShelfItem />
</SimpleGrid> </SimpleGrid>
); );
}; };
@@ -23,6 +30,7 @@ const AppShelf = () => {
export function AppShelfItem(props: any) { export function AppShelfItem(props: any) {
const { service }: { service: serviceItem } = props; const { service }: { service: serviceItem } = props;
const [hovering, setHovering] = useState(false); const [hovering, setHovering] = useState(false);
const theme = useMantineTheme();
return ( return (
<motion.div <motion.div
key={service.name} key={service.name}
@@ -33,27 +41,23 @@ export function AppShelfItem(props: any) {
setHovering(false); setHovering(false);
}} }}
> >
<AppShelfItemWrapper hovering={hovering}> <Card
<Card.Section>
<Group position="apart" mx="lg">
<Space />
<Text
// TODO: #1 Remove this hack to get the text to be centered.
ml={15}
style={{ style={{
alignSelf: 'center', boxShadow: hovering ? '0px 0px 3px rgba(0, 0, 0, 0.5)' : '0px 0px 1px rgba(0, 0, 0, 0.5)',
alignContent: 'center', backgroundColor:
alignItems: 'center', theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1],
justifyContent: 'center',
justifyItems: 'center',
}} }}
mt="sm" radius="md"
weight={500}
> >
<Card.Section>
<Text mt="sm" align="center" lineClamp={1} weight={500}>
{service.name} {service.name}
</Text> </Text>
<motion.div <motion.div
style={{ style={{
position: 'absolute',
top: 5,
right: 5,
alignSelf: 'flex-end', alignSelf: 'flex-end',
}} }}
animate={{ animate={{
@@ -62,7 +66,6 @@ export function AppShelfItem(props: any) {
> >
<AppShelfMenu service={service} /> <AppShelfMenu service={service} />
</motion.div> </motion.div>
</Group>
</Card.Section> </Card.Section>
<Card.Section> <Card.Section>
<AspectRatio ratio={5 / 3} m="xl"> <AspectRatio ratio={5 / 3} m="xl">
@@ -76,16 +79,12 @@ export function AppShelfItem(props: any) {
onClick={() => { onClick={() => {
window.open(service.url); window.open(service.url);
}} }}
style={{
maxWidth: '50%',
marginBottom: 10,
}}
src={service.icon} src={service.icon}
/> />
</motion.i> </motion.i>
</AspectRatio> </AspectRatio>
</Card.Section> </Card.Section>
</AppShelfItemWrapper> </Card>
</motion.div> </motion.div>
); );
} }

View File

@@ -8,10 +8,6 @@ export function AppShelfItemWrapper(props: any) {
style={{ style={{
boxShadow: hovering ? '0px 0px 3px rgba(0, 0, 0, 0.5)' : '0px 0px 1px rgba(0, 0, 0, 0.5)', 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], backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1],
//TODO: #3 Fix this temporary fix and make the width and height dynamic / responsive
width: 200,
height: 180,
}} }}
radius="md" radius="md"
> >

View File

@@ -6,7 +6,7 @@ export default function Navbar() {
return ( return (
<MantineNavbar <MantineNavbar
height="100%" height="100%"
hiddenBreakpoint="md" hiddenBreakpoint="lg"
hidden hidden
width={{ width={{
base: 'auto', base: 'auto',