Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapsible Mobile RHS #334

Merged
merged 11 commits into from
Jan 5, 2025
65 changes: 37 additions & 28 deletions src/components/navigation/Carousel/carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ReactJSXElement } from '@emotion/react/types/jsx-namespace';
import { Collapse, useMediaQuery } from '@mui/material';
import { AnimatePresence, motion } from 'framer-motion';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import { TabNavMenu } from '@/components/navigation/tabNavMenu/tabNavMenu';

Expand Down Expand Up @@ -69,41 +70,49 @@ const Carousel = ({ names, children, compareLength }: CarouselProps) => {
});
};

const isSmallScreen = useMediaQuery('(max-width: 600px)');
const [open, setOpen] = useState(!isSmallScreen);
useEffect(() => setOpen(!isSmallScreen), [isSmallScreen]);

return (
<>
<TabNavMenu
value={currentCard}
options={Array.isArray(names) ? names : [names]}
turner={turn}
compareLength={compareLength}
open={open}
setOpen={setOpen}
/>
<AnimatePresence>
<div className="p-4 lg:p-6">
<motion.div
key={currentCard}
custom={direction}
variants={variants}
initial="enter"
animate="center"
exit="exit"
transition={{
x: { type: 'spring', stiffness: 300, damping: 30 },
opacity: { duration: 0.2 },
}}
>
{Array.isArray(children)
? children.map((child, index) => (
<div
key={index}
className={index === currentCard ? 'block' : 'hidden'}
>
{child}
</div>
))
: children}
</motion.div>
</div>
</AnimatePresence>
<Collapse in={open}>
<AnimatePresence>
<div className="p-4 lg:p-6">
<motion.div
key={currentCard}
custom={direction}
variants={variants}
initial="enter"
animate="center"
exit="exit"
transition={{
x: { type: 'spring', stiffness: 300, damping: 30 },
opacity: { duration: 0.2 },
}}
>
{Array.isArray(children)
? children.map((child, index) => (
<div
key={index}
className={index === currentCard ? 'block' : 'hidden'}
>
{child}
</div>
))
: children}
</motion.div>
</div>
</AnimatePresence>
</Collapse>
</>
);
};
Expand Down
70 changes: 46 additions & 24 deletions src/components/navigation/tabNavMenu/tabNavMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Badge, Tab, Tabs } from '@mui/material';
import KeyboardArrowIcon from '@mui/icons-material/KeyboardArrowRight';
import { Badge, IconButton, Tab, Tabs, useMediaQuery } from '@mui/material';
import React from 'react';

/**
Expand All @@ -11,6 +12,8 @@ type TabNavMenuProps = {
turner: (displacement: number) => void;
options: string[];
compareLength: number;
open: boolean;
setOpen: (arg0: boolean) => void;
};

/**
Expand All @@ -19,30 +22,49 @@ type TabNavMenuProps = {
* which are held by the parent and passed to this component to be manipulated by the Tabs component.
*/
export const TabNavMenu = (props: TabNavMenuProps) => {
const isSmallScreen = useMediaQuery('(max-width: 600px)');
return (
<Tabs
value={props.value}
onChange={(event, newValue) => props.turner(newValue - props.value)}
aria-label="Tab switcher"
className="w-full grid grid-flow-row justify-center shadow dark:shadow-lg"
>
{props.options.map((option, index) => (
<Tab
key={index}
className="text-lg text-gray-600 dark:text-gray-200 normal-case"
value={index}
label={
index === props.options.length - 1 && props.compareLength ? (
<div className="flex items-center gap-4">
{option}
<Badge badgeContent={props.compareLength} color="primary" />
</div>
) : (
option
)
<div className="w-full flex items-center">
{isSmallScreen && (
<IconButton
aria-label="open overview"
onClick={() => props.setOpen(!props.open)}
size="medium"
className={
'ml-2 transition-transform' + (props.open ? ' rotate-90' : '')
}
/>
))}
</Tabs>
>
<KeyboardArrowIcon fontSize="inherit" />
</IconButton>
)}
<div className="flex-1 min-w-0 flex justify-center">
<Tabs
value={props.value}
onChange={(event, newValue) => props.turner(newValue - props.value)}
aria-label="Tab switcher"
className="shadow dark:shadow-lg"
variant="scrollable"
>
{props.options.map((option, index) => (
<Tab
key={index}
className="text-lg text-gray-600 dark:text-gray-200 normal-case"
value={index}
label={
index === props.options.length - 1 && props.compareLength ? (
<div className="flex items-center gap-4">
{option}
<Badge badgeContent={props.compareLength} color="primary" />
</div>
) : (
option
)
}
onClick={() => props.setOpen(true)}
/>
))}
</Tabs>
</div>
</div>
);
};
17 changes: 6 additions & 11 deletions src/components/search/SearchResultsTable/searchResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ import type { GenericFetchedData, GradesType } from '@/pages/dashboard/index';
function LoadingRow() {
return (
<TableRow>
<TableCell>
<IconButton aria-label="expand row" size="small" disabled>
<TableCell className="flex gap-1">
<IconButton aria-label="expand row" size="medium" disabled>
<KeyboardArrowIcon />
</IconButton>
</TableCell>
<TableCell>
<Checkbox disabled />
</TableCell>
<TableCell component="th" scope="row" className="w-full">
Expand Down Expand Up @@ -107,22 +105,20 @@ function Row({
onClick={() => setOpen(!open)} // opens/closes the card by clicking anywhere on the row
className="cursor-pointer"
>
<TableCell className="border-b-0">
<TableCell className="border-b-0 flex gap-1">
<Tooltip
title={open ? 'Minimize Result' : 'Expand Result'}
placement="top"
>
<IconButton
aria-label="expand row"
size="small"
size="medium"
onClick={() => setOpen(!open)}
className={'transition-transform' + (open ? ' rotate-90' : '')}
>
<KeyboardArrowIcon />
<KeyboardArrowIcon fontSize="inherit" />
</IconButton>
</Tooltip>
</TableCell>
<TableCell className="border-b-0">
<Tooltip
title={inCompare ? 'Remove from Compare' : 'Add to Compare'}
placement="top"
Expand Down Expand Up @@ -446,8 +442,7 @@ const SearchResultsTable = ({
<Table stickyHeader aria-label="collapsible table">
<TableHead>
<TableRow>
<TableCell />
<TableCell>Compare</TableCell>
<TableCell>Actions</TableCell>
<TableCell>
<TableSortLabel
active={orderBy === 'name'}
Expand Down
Loading