-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
0 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 |
---|---|---|
|
@@ -416,6 +416,7 @@ | |
"swap", | ||
"table", | ||
"template", | ||
"theme", | ||
"throttle", | ||
"through", | ||
"tildify", | ||
|
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,15 @@ | ||
## CN | ||
|
||
主题工具库。 | ||
|
||
### on | ||
|
||
绑定 change 事件。 | ||
|
||
### off | ||
|
||
解绑 change 事件。 | ||
|
||
### get | ||
|
||
获取当前主题(light 或 dark)。 |
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,49 @@ | ||
/* Theme helper. | ||
* | ||
* ### on | ||
* | ||
* Bind change event. | ||
* | ||
* ### off | ||
* | ||
* Unbind change event. | ||
* | ||
* ### get | ||
* | ||
* Get current theme(light or dark). | ||
*/ | ||
|
||
/* example | ||
* theme.on('change', function(theme) { | ||
* console.log(theme); // -> 'dark' | ||
* }); | ||
* theme.get(); // -> 'light' | ||
*/ | ||
|
||
/* module | ||
* env: browser | ||
*/ | ||
|
||
/* typescript | ||
* export declare namespace theme { | ||
* interface ITheme extends Emitter { | ||
* get(): string; | ||
* } | ||
* } | ||
* export declare const theme: theme.ITheme; | ||
*/ | ||
|
||
_('Emitter MediaQuery'); | ||
|
||
const m = new MediaQuery('(prefers-color-scheme: dark)'); | ||
|
||
exports = { | ||
get() { | ||
return m.isMatch() ? 'dark' : 'light'; | ||
} | ||
}; | ||
|
||
Emitter.mixin(exports); | ||
|
||
m.on('match', () => exports.emit('change', 'dark')); | ||
m.on('unmatch', () => exports.emit('change', 'light')); |
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,2 @@ | ||
const t = util.isDarkMode() ? 'dark' : 'light'; | ||
expect(theme.get()).to.equal(t); |