-
Notifications
You must be signed in to change notification settings - Fork 29
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 #32 from markolofsen/dev
Dev
- Loading branch information
Showing
18 changed files
with
356 additions
and
200 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
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,85 @@ | ||
/* Usage | ||
// hooks | ||
import { useMedia } from 'src/hooks/useMedia' | ||
function demo() { | ||
const media = useMedia(); | ||
const isMobile = media.down.sm | ||
console.warn(media) | ||
// Response: | ||
// "up":{"xs":true,"sm":true,"md":true,"lg":false,"xl":false}, | ||
// "down":{"xs":false,"sm":false,"md":true,"lg":true,"xl":true}, | ||
return ( | ||
<div> | ||
{media.up.sm && ( | ||
<div> | ||
Over sm | ||
</div> | ||
)} | ||
{media.down.sm && ( | ||
<div> | ||
Less then sm | ||
</div> | ||
)} | ||
<br /> | ||
{JSON.strinigy(media)} | ||
</div> | ||
) | ||
} | ||
*/ | ||
|
||
// Mui | ||
// import { useTheme, ThemedProps } from '@mui/material/styles'; | ||
import useMediaQuery from '@mui/material/useMediaQuery' | ||
|
||
|
||
interface MediaItem { | ||
xs: boolean | ||
sm: boolean | ||
md: boolean | ||
lg: boolean | ||
xl: boolean | ||
xxl: boolean | ||
[key: string]: boolean | ||
} | ||
|
||
interface MediaDict { | ||
up: MediaItem | ||
down: MediaItem | ||
only: MediaItem | ||
} | ||
|
||
export const useMedia = () => { | ||
// const theme: ThemedProps = useTheme(); | ||
|
||
const matches = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'] | ||
|
||
const chunks: MediaItem = { | ||
xs: false, | ||
sm: false, | ||
md: false, | ||
lg: false, | ||
xl: false, | ||
xxl: false, | ||
} | ||
|
||
const res: MediaDict = { | ||
up: chunks, | ||
down: chunks, | ||
only: chunks, | ||
} | ||
for (const i of matches) { | ||
res.up[i] = useMediaQuery((theme: any) => theme.breakpoints.up(i)) as boolean | ||
res.down[i] = useMediaQuery((theme: any) => theme.breakpoints.down(i)) as boolean | ||
res.only[i] = useMediaQuery((theme: any) => theme.breakpoints.only(i)) as boolean | ||
} | ||
|
||
return res as MediaDict | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.
360d13b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
metaeditor-player – ./
metaeditor-player-git-main-marko5.vercel.app
metaeditor-player.vercel.app
metaeditor-player-marko5.vercel.app
player.metaeditor.io