-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24227 from storybookjs/charles-mobile-1
UI: Add the new structure for the mobile layout
- Loading branch information
Showing
6 changed files
with
108 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
const useMediaQuery = (query: string) => { | ||
const [matches, setMatches] = useState(false); | ||
// The hook is taken from this library: | ||
// https://usehooks-ts.com/react-hook/use-media-query | ||
// The good thing about it is that is uses window.matchMedia | ||
|
||
useEffect(() => { | ||
const media = window.matchMedia(query); | ||
if (media.matches !== matches) { | ||
setMatches(media.matches); | ||
export function useMediaQuery(query: string): boolean { | ||
const getMatches = (queryMatch: string): boolean => { | ||
// Prevents SSR issues | ||
if (typeof window !== 'undefined') { | ||
return window.matchMedia(queryMatch).matches; | ||
} | ||
const listener = () => setMatches(media.matches); | ||
window.addEventListener('resize', listener); | ||
return () => window.removeEventListener('resize', listener); | ||
}, [matches, query]); | ||
return false; | ||
}; | ||
|
||
return matches; | ||
}; | ||
const [matches, setMatches] = useState<boolean>(getMatches(query)); | ||
|
||
function handleChange() { | ||
setMatches(getMatches(query)); | ||
} | ||
|
||
useEffect(() => { | ||
const matchMedia = window.matchMedia(query); | ||
|
||
export default useMediaQuery; | ||
// Triggered at the first client-side load and if query changes | ||
handleChange(); | ||
|
||
// Listen matchMedia | ||
matchMedia.addEventListener('change', handleChange); | ||
|
||
return () => { | ||
matchMedia.removeEventListener('change', handleChange); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [query]); | ||
|
||
return matches; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
code/ui/manager/src/components/mobile-navigation/MobileNavigation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { styled } from '@storybook/theming'; | ||
|
||
const Container = styled.div(({ theme }) => ({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
bottom: 0, | ||
left: 0, | ||
width: '100%', | ||
height: 40, | ||
zIndex: 10, | ||
background: theme.background.content, | ||
padding: '0 6px', | ||
borderTop: `1px solid ${theme.appBorderColor}`, | ||
})); | ||
|
||
export const MobileNavigation: FC = () => { | ||
return <Container />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const BREAKPOINT_MIN_600 = '(min-width: 600px)'; |