generated from OlegWock/webpack-react-web-extension-template
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to automatically enable compact mode #14
- Loading branch information
Showing
13 changed files
with
81 additions
and
47 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 |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
label { | ||
cursor: not-allowed; | ||
} | ||
|
||
color: var(--text-disabled); | ||
} | ||
|
||
&-root { | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ReactNode, createContext, useContext, useEffect, useState } from "react"; | ||
import { useBrowserStorageValue } from "./storage"; | ||
|
||
const CompactModeContext = createContext(false); | ||
|
||
export const applyCompactMode = (isCompact: boolean) => { | ||
const root = document.documentElement; | ||
const size = isCompact ? 14 : 16; | ||
root.style.setProperty('font-size', size + 'px'); | ||
}; | ||
|
||
export const CompactModeProvider = ({children}: {children: ReactNode}) => { | ||
const [isAutomaticCompact] = useBrowserStorageValue('automaticCompactMode', true); | ||
const [isManualCompact] = useBrowserStorageValue('compactMode', false); | ||
const [screenWidth, setScreenWidth] = useState(() => window.screen.width); | ||
const isCompact = isAutomaticCompact ? screenWidth < 1500 : isManualCompact; | ||
|
||
useEffect(() => { | ||
const tid = setInterval(() => { | ||
// If screen size is same, this won't do re-render | ||
setScreenWidth(window.screen.width); | ||
}, 50); | ||
|
||
return () => clearInterval(tid); | ||
}, []); | ||
|
||
useEffect(() => { | ||
applyCompactMode(isCompact); | ||
}, [isCompact]); | ||
|
||
return (<CompactModeContext.Provider value={isCompact}> | ||
{children} | ||
</CompactModeContext.Provider>); | ||
}; | ||
|
||
export const useSizeSettings = () => { | ||
const isCompact = useContext(CompactModeContext); | ||
const fontSize = isCompact ? 14 : 16; | ||
const rem = (n: number) => fontSize * n; | ||
|
||
return { | ||
isCompact, | ||
blockSize: isCompact ? 140 : 180, | ||
gapSize: isCompact ? 8 : 16, | ||
fontSize: fontSize, | ||
rem, | ||
}; | ||
}; |
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