-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support page background in the playground
- Loading branch information
Showing
9 changed files
with
97 additions
and
15 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './useDefaultViewportColor'; | ||
export * from './useDevView'; | ||
export * from './useThemeMode'; |
36 changes: 36 additions & 0 deletions
36
packages/widget-playground/src/hooks/useDefaultViewportColor.ts
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,36 @@ | ||
import type { Appearance } from '@lifi/widget'; | ||
import { useMediaQuery, useTheme } from '@mui/material'; | ||
|
||
export const useDefaultViewportColor = () => { | ||
const theme = useTheme(); | ||
|
||
const defaultColor = | ||
theme.palette.mode === 'light' | ||
? theme.palette.grey[100] | ||
: theme.palette.common.black; | ||
|
||
return { | ||
defaultColor, | ||
}; | ||
}; | ||
|
||
export const useDefaultViewportColorForMode = () => { | ||
const theme = useTheme(); | ||
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)'); | ||
|
||
const defaultViewportColors = { | ||
light: theme.palette.grey[100], | ||
dark: theme.palette.common.black, | ||
}; | ||
|
||
const getDefaultViewportForAppearance = (appearance: Appearance) => { | ||
const mode = | ||
appearance === 'auto' ? (prefersDarkMode ? 'dark' : 'light') : appearance; | ||
|
||
return defaultViewportColors[mode]; | ||
}; | ||
|
||
return { | ||
getDefaultViewportForAppearance, | ||
}; | ||
}; |
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
22 changes: 22 additions & 0 deletions
22
packages/widget-playground/src/store/editTools/useSetViewportBackgroundColor.ts
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,22 @@ | ||
import { useConfigActions, useThemeHeader } from '../widgetConfig'; | ||
import { useEditToolsActions } from './useEditToolsActions'; | ||
|
||
export const useSetViewportBackgroundColor = () => { | ||
const { header } = useThemeHeader(); | ||
const { setHeader } = useConfigActions(); | ||
const { setViewportBackgroundColor: setViewportColorEditTools } = | ||
useEditToolsActions(); | ||
|
||
const setViewportBackgroundColor = (color: string | undefined) => { | ||
if (header) { | ||
setHeader({ | ||
...header, | ||
pageBackground: color, | ||
}); | ||
} | ||
|
||
setViewportColorEditTools(color); | ||
}; | ||
|
||
return { setViewportBackgroundColor }; | ||
}; |
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