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

[공통] useMediaQuery 추가 및 공통 페이지 모바일 뷰 추가 #169

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/layout/SideBar/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css } from '@emotion/react';
import { colors } from 'const/colors/style';
import { mobile } from 'util/hooks/useMediaQuery';

export const sideBar = css`
display: flex;
Expand All @@ -8,6 +9,10 @@ export const sideBar = css`
background-color: ${colors.gray};
border-right: 1px solid ${colors.borderGray};
box-sizing: border-box;

${mobile} {
width: 175px;
}
`;

export const topBar = css`
Expand Down
17 changes: 17 additions & 0 deletions src/layout/TopBar/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css } from '@emotion/react';
import { colors } from 'const/colors/style';
import { mobile } from 'util/hooks/useMediaQuery';

export const top = css`
width: 100%;
Expand All @@ -10,6 +11,13 @@ export const top = css`
padding-right: 30px;
border-bottom: 1px solid ${colors.borderGray};
box-sizing: border-box;

${mobile} {
h1 {
font-size: 18px;
}
padding-right: 10px;
}
`;

export const flex = css`
Expand All @@ -22,6 +30,15 @@ export const buttonContainer = css`
display: flex;
justify-content: flex-end;
gap: 20px;

${mobile} {
button {
font-size: 12px;
width: 65px;
height: 35px;
padding: 0;
}
}
`;

export const syncButton = css`
Expand Down
27 changes: 27 additions & 0 deletions src/util/hooks/useMediaQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect, useRef, useState } from 'react';

const MOBILE_MEDIA_QUERY = '(max-width: 576px)';

export const mobile = `@media ${MOBILE_MEDIA_QUERY}`;

const useMediaQuery = () => {
const [matches, setMatches] = useState(() => window.matchMedia(MOBILE_MEDIA_QUERY).matches);
const matchMediaRef = useRef<MediaQueryList | null>(null);
dooohun marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
const matchMedia = window.matchMedia(MOBILE_MEDIA_QUERY);
matchMediaRef.current = matchMedia;
function handleChange() {
setMatches(window.matchMedia(MOBILE_MEDIA_QUERY).matches);
}
matchMediaRef.current.addEventListener('change', handleChange);

return () => {
matchMediaRef.current?.removeEventListener('change', handleChange);
};
}, []);

return { isMobile: matches };
};

export default useMediaQuery;
Loading