Skip to content

Commit eb93671

Browse files
Fran McDadeFran McDade
authored andcommitted
feat: added carousel arrows (#66)
1 parent 072d36e commit eb93671

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

app/components/Home/components/Section/components/SectionHero/components/Carousel/carousel.styles.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ export const Carousel = styled.div`
3535
${mediaTabletUp} {
3636
height: ${CAROUSEL_HEIGHT}px;
3737
}
38+
39+
.MuiIconButton-root {
40+
opacity: 0;
41+
transition: opacity 150ms ease-in-out;
42+
}
43+
44+
&:hover {
45+
> .MuiIconButton-root {
46+
opacity: 1;
47+
}
48+
}
3849
`;
3950

4051
export const StyledBullets = styled(Bullets)`

app/components/Home/components/Section/components/SectionHero/components/Carousel/carousel.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { SWIPE_ACTION } from "../../../../../../../../hooks/useSwipeInteraction/common/entities";
12
import {
23
Carousel as CarouselCards,
34
CarouselView,
45
StyledBullets,
56
} from "./carousel.styles";
7+
import { Arrow } from "./components/Arrow/arrow";
68
import { Cards } from "./components/Cards/cards";
79
import { useInteractiveCarousel } from "./hooks/useInteractiveCarousel";
810

@@ -13,11 +15,20 @@ export const Carousel = (): JSX.Element => {
1315
interactiveCards,
1416
interactiveIndexes,
1517
onSetActiveIndex,
18+
onSetSwipeAction,
1619
} = useInteractiveCarousel();
1720
return (
1821
<CarouselView>
1922
<CarouselCards {...interactiveAction}>
23+
<Arrow
24+
onClick={(): void => onSetSwipeAction(SWIPE_ACTION.SWIPE_BACKWARD)}
25+
swipeAction={SWIPE_ACTION.SWIPE_BACKWARD}
26+
/>
2027
<Cards activeIndex={activeIndex} cards={interactiveCards} />
28+
<Arrow
29+
onClick={(): void => onSetSwipeAction(SWIPE_ACTION.SWIPE_FORWARD)}
30+
swipeAction={SWIPE_ACTION.SWIPE_FORWARD}
31+
/>
2132
<StyledBullets
2233
activeBullet={activeIndex}
2334
bullets={interactiveIndexes}

app/components/Home/components/Section/components/SectionHero/components/Carousel/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export const CAROUSEL_HEIGHT_SM =
99
MAX_CARD_HEIGHT_SM + MAX_DECK_SIZE * CARD_OFFSET_Y;
1010
export const TRANSITION_DELAY = 100;
1111
export const TRANSITION_DURATION = 100;
12+
export const ARROW_OFFSET_Y = (CARD_OFFSET_Y * MAX_DECK_SIZE) / 2;

app/components/Home/components/Section/components/SectionHero/components/Carousel/common/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { SWIPE_ACTION } from "../../../../../../../../../hooks/useSwipeInteraction/common/entities";
12
import {
3+
ARROW_OFFSET_Y,
24
CARD_OFFSET_Y,
35
CARD_SCALE_X,
46
MAX_CARD_WIDTH,
@@ -7,6 +9,17 @@ import {
79
TRANSITION_DURATION,
810
} from "./constants";
911

12+
/**
13+
* Returns the arrow's transform scaleX and translateY.
14+
* @param swipeAction - Swipe action.
15+
* @returns arrow's transform.
16+
*/
17+
export function getArrowTransform(swipeAction: SWIPE_ACTION): string {
18+
return swipeAction === SWIPE_ACTION.SWIPE_FORWARD
19+
? `translate(24px, calc(${ARROW_OFFSET_Y}px - 50%)) scaleX(-1)`
20+
: `translate(-24px, calc(${ARROW_OFFSET_Y}px - 50%))`;
21+
}
22+
1023
/**
1124
* Returns the carousel card's position in the deck.
1225
* @param index - Card index.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { mediaTabletDown } from "@databiosphere/findable-ui/lib/styles/common/mixins/breakpoints";
2+
import {
3+
inkMain,
4+
smokeDark,
5+
smokeLightest,
6+
white,
7+
} from "@databiosphere/findable-ui/lib/styles/common/mixins/colors";
8+
import { black08 } from "@databiosphere/findable-ui/lib/theme/common/palette";
9+
import { css } from "@emotion/react";
10+
import styled from "@emotion/styled";
11+
import { IconButton as MIconButton } from "@mui/material";
12+
import {
13+
SwipeAction,
14+
SWIPE_ACTION,
15+
} from "../../../../../../../../../../hooks/useSwipeInteraction/common/entities";
16+
import { MAX_DECK_SIZE } from "../../common/constants";
17+
import { getArrowTransform } from "../../common/utils";
18+
19+
interface Props {
20+
swipeAction: SwipeAction;
21+
}
22+
23+
export const IconButton = styled(MIconButton, {
24+
shouldForwardProp: (props) => props !== "swipeAction",
25+
})<Props>`
26+
& {
27+
background-color: ${white};
28+
border-radius: 50%;
29+
box-shadow: inset 0 0 0 1px ${smokeDark}, 0 1px 0 0 ${black08};
30+
color: ${inkMain};
31+
position: absolute;
32+
top: 50%;
33+
transform: ${({ swipeAction }) => getArrowTransform(swipeAction)};
34+
z-index: ${MAX_DECK_SIZE + 1};
35+
36+
&:hover {
37+
background-color: ${smokeLightest};
38+
}
39+
40+
&:active {
41+
box-shadow: inset 0 0 0 1px ${smokeDark};
42+
}
43+
44+
${mediaTabletDown} {
45+
display: none;
46+
}
47+
}
48+
49+
${({ swipeAction }) =>
50+
swipeAction === SWIPE_ACTION.SWIPE_BACKWARD &&
51+
css`
52+
left: 0;
53+
`}
54+
55+
${({ swipeAction }) =>
56+
swipeAction === SWIPE_ACTION.SWIPE_FORWARD &&
57+
css`
58+
right: 0;
59+
`}
60+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { SouthIcon } from "@databiosphere/findable-ui/lib/components/common/CustomIcon/components/SouthIcon/southIcon";
2+
import { SwipeAction } from "../../../../../../../../../../hooks/useSwipeInteraction/common/entities";
3+
import { IconButton } from "./arrow.styles";
4+
5+
interface ArrowProps {
6+
onClick: () => void;
7+
swipeAction: SwipeAction;
8+
}
9+
10+
export const Arrow = ({ onClick, swipeAction }: ArrowProps): JSX.Element => {
11+
return (
12+
<IconButton
13+
color="secondary"
14+
onClick={onClick}
15+
size="large"
16+
swipeAction={swipeAction}
17+
>
18+
<SouthIcon fontSize="small" />
19+
</IconButton>
20+
);
21+
};

0 commit comments

Comments
 (0)