-
Notifications
You must be signed in to change notification settings - Fork 0
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 #88 from stack-wuh/feat-performance
feat(ColorSchame): 情景模式跟随系统
- Loading branch information
Showing
4 changed files
with
37 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @NOTE 获取浏览器的当前的情景模式 | ||
* | ||
* * 通过prefers-color-schema: dark 来判断用户浏览器是否是暗黑模式 | ||
*/ | ||
interface IOptions { | ||
change: (e: any) => void | ||
} | ||
|
||
const options = { | ||
change () {} | ||
} | ||
|
||
const useSystemColorSchema = (ops: IOptions = options): Boolean => { | ||
const prefersSchema = window.matchMedia('(prefers-color-scheme: dark)') | ||
|
||
if (ops && ops.change) { | ||
prefersSchema.addEventListener('change', function (e) { | ||
ops.change(e) | ||
}) | ||
} | ||
|
||
return prefersSchema.matches | ||
} | ||
|
||
|
||
export default typeof window !== 'undefined' ? useSystemColorSchema : () => {} |
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
ee519ad
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:
wuh-site – ./
wuh-site-git-main-163m.vercel.app
wuh-site-163m.vercel.app
wuh-site-kappa.vercel.app