Skip to content

Commit

Permalink
Adds hover state to carousels (ZcashFoundation#318)
Browse files Browse the repository at this point in the history
This adds a nice hover state to carousels so they darken when you hover
over them.

<img width="982" alt="Screen Shot 2024-07-20 at 10 47 18 AM"
src="https://github.com/user-attachments/assets/50f9039a-b81c-4949-828b-0651566b0a70">

---------

Co-authored-by: Skylar Saveland <skylar.saveland@gmail.com>
  • Loading branch information
birdify and skyl authored Aug 3, 2024
1 parent 287701d commit c6f8193
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
15 changes: 3 additions & 12 deletions ts/react/free2z/src/components/CreatorCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import SwiperLoadingAnimation from './SwiperLoadingAnimation';
import { useTransitionNavigate } from '../hooks/useTransitionNavigate';
import { HOME_CAROUSEL_BREAKPOINTS } from './HomeCarouselConstants';
import HoverCard from './common/HoverCard';

SwiperCore.use([Autoplay, Navigation]);

Expand Down Expand Up @@ -130,17 +131,7 @@ export default function CreatorCarousel(props: CreatorCarouselProps) {
<div
ref={index === creators.length - 1 ? lastElement : null}
>
<Card
style={{
width: '90%',
maxWidth: '400px',
minHeight: 220,
position: 'relative',
marginLeft: 'auto',
marginRight: 'auto',
cursor: 'pointer',
marginBottom: "0.5em",
}}
<HoverCard
onClick={() => {
navigate(`/${creator.username}`)
}}
Expand Down Expand Up @@ -199,7 +190,7 @@ export default function CreatorCarousel(props: CreatorCarouselProps) {
{truncate(creator.full_name || creator.username, 33)}
</Typography>
</CardContent>
</Card>
</HoverCard>
</div>
</SwiperSlide>
))}
Expand Down
27 changes: 27 additions & 0 deletions ts/react/free2z/src/components/common/HoverCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { styled } from '@mui/material/styles';
import { Card, CardProps } from '@mui/material';

const StyledCard = styled(Card)(({ theme }) => ({
transition: 'background-color 0.3s',
'&:hover': {
backgroundColor: theme.palette.action.hover,
},
}));

const HoverCard: React.FC<CardProps> = (props) => {
return <StyledCard {...props}
style={{
width: '90%',
maxWidth: '400px',
minHeight: 220,
position: 'relative',
marginLeft: 'auto',
marginRight: 'auto',
cursor: 'pointer',
marginBottom: '0.5em',
}}

/>;
};

export default HoverCard;
16 changes: 3 additions & 13 deletions ts/react/free2z/src/components/zPageCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PageInterface } from './PageRenderer';
import SwiperLoadingAnimation from './SwiperLoadingAnimation';
import { useTransitionNavigate } from '../hooks/useTransitionNavigate';
import { HOME_CAROUSEL_BREAKPOINTS } from './HomeCarouselConstants';

import HoverCard from './common/HoverCard';

SwiperCore.use([Autoplay, Navigation]);

Expand Down Expand Up @@ -120,17 +120,7 @@ export default function ZPageCarousel(props: ZPageCarouselProps) {
ref={index === zpages.length - 1 ? lastElement : null}
>

<Card
style={{
width: '90%',
maxWidth: '400px',
minHeight: 220,
position: 'relative',
marginLeft: 'auto',
marginRight: 'auto',
cursor: 'pointer',
marginBottom: '0.5em',
}}
<HoverCard
onClick={() => {
navigate(zpage.get_url);
}}
Expand Down Expand Up @@ -214,7 +204,7 @@ export default function ZPageCarousel(props: ZPageCarouselProps) {
{zpage.content}
</Typography>
</CardContent>
</Card>
</HoverCard>
</div>
</SwiperSlide>

Expand Down

0 comments on commit c6f8193

Please sign in to comment.