Skip to content

Commit 73a7fa6

Browse files
authored
Merge pull request #327 from AppQuality/flip-card-mobilize
feat(flip-card): update header buttons based on window size
2 parents b44cea4 + 8f310cb commit 73a7fa6

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/pages/Campaign/widgets/widgetCards/FlipCard/FlipCardHeader.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IconButton } from '@appquality/unguess-design-system';
22
import styled from 'styled-components';
3+
import { theme as globalTheme } from 'src/app/theme';
34
import { ReactComponent as LineGraphIconFill } from 'src/assets/icons/line-graph-fill.svg';
45
import { ReactComponent as ListBulletIconFill } from 'src/assets/icons/list-bullet-fill.svg';
56
import { WidgetCardHeader } from '../common/WidgetCardHeader';
@@ -17,15 +18,20 @@ const FlipButton = styled(IconButton)<{ isActive?: boolean }>`
1718
margin-left: ${(p) => p.theme.space.xs};
1819
`;
1920

21+
export const FlipButtonContainer = styled.div`
22+
display: flex;
23+
`;
24+
2025
export const FlipCardHeader = ({ children, hasBack }: FlipCardHeaderProps) => {
21-
const { visibleFace, setVisibleFace } = useFlipCardContext();
26+
const { visibleFace, setVisibleFace, width } = useFlipCardContext();
27+
const breakpointMd = parseInt(globalTheme.breakpoints.md, 10);
2228

2329
return (
2430
<WidgetCardHeader
2531
title={children}
2632
action={
27-
hasBack === false ? null : (
28-
<div>
33+
hasBack === false || width < breakpointMd ? null : (
34+
<FlipButtonContainer>
2935
<FlipButton
3036
isActive={visibleFace === 'front'}
3137
size="small"
@@ -44,7 +50,7 @@ export const FlipCardHeader = ({ children, hasBack }: FlipCardHeaderProps) => {
4450
color={`${visibleFace === 'back' && 'white'}`}
4551
/>
4652
</FlipButton>
47-
</div>
53+
</FlipButtonContainer>
4854
)
4955
}
5056
/>

src/pages/Campaign/widgets/widgetCards/FlipCard/context/FlipCardContext.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { createContext, useContext, useMemo, useState } from 'react';
2+
import { theme as globalTheme } from 'src/app/theme';
3+
import { isMinMedia } from 'src/common/utils';
4+
import useWindowSize from 'src/hooks/useWindowSize';
25
import { FaceType, FlipCardContextType } from '../types';
36

47
export const FlipCardContext = createContext<FlipCardContextType | null>(null);
@@ -8,15 +11,24 @@ export const FlipCardContextProvider = ({
811
}: {
912
children: React.ReactNode;
1013
}) => {
11-
const [visibleFace, setVisibleFace] = useState<FaceType>('front');
14+
const { width } = useWindowSize();
15+
const breakpointMd = parseInt(globalTheme.breakpoints.md, 10);
1216

13-
const flipCardContextValue = useMemo(
14-
() => ({
17+
const isDesktop = isMinMedia(globalTheme.breakpoints.sm);
18+
const [visibleFace, setVisibleFace] = useState<FaceType>(
19+
isDesktop ? 'front' : 'back'
20+
);
21+
22+
const flipCardContextValue = useMemo(() => {
23+
if (width < breakpointMd) {
24+
setVisibleFace('back');
25+
}
26+
return {
1527
visibleFace,
1628
setVisibleFace,
17-
}),
18-
[visibleFace, setVisibleFace]
19-
);
29+
width,
30+
};
31+
}, [visibleFace, setVisibleFace, width]);
2032

2133
return (
2234
<FlipCardContext.Provider value={flipCardContextValue}>

src/pages/Campaign/widgets/widgetCards/FlipCard/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type FlipCardContextType = {
22
visibleFace: FaceType;
33
setVisibleFace: (face: FaceType) => void;
4+
width: number;
45
};
56

67
export interface FlipCardHeaderProps {

0 commit comments

Comments
 (0)