@expo/styleguide 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,14 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BlockingSetInitialColorMode = exports.getInitialColorMode = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const helpers_1 = require("../utils/helpers");
|
|
9
8
|
function getInitialColorMode() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return preference;
|
|
15
|
-
}
|
|
9
|
+
const preference = window.localStorage.getItem('data-expo-theme');
|
|
10
|
+
let hasPreference = typeof preference === 'string';
|
|
11
|
+
if (hasPreference) {
|
|
12
|
+
return preference;
|
|
16
13
|
}
|
|
17
14
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
18
15
|
const systemPreference = typeof mql.matches === 'boolean';
|
|
@@ -22,7 +22,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.useTheme = exports.ThemeProvider = exports.Themes = void 0;
|
|
23
23
|
const react_1 = __importStar(require("react"));
|
|
24
24
|
const BlockingSetInitialColorMode_1 = require("./BlockingSetInitialColorMode");
|
|
25
|
-
const helpers_1 = require("../utils/helpers");
|
|
26
25
|
var Themes;
|
|
27
26
|
(function (Themes) {
|
|
28
27
|
Themes["AUTO"] = "auto";
|
|
@@ -49,17 +48,12 @@ function ThemeProvider(props) {
|
|
|
49
48
|
mediaQuery.addEventListener('change', onThemeChange);
|
|
50
49
|
}
|
|
51
50
|
catch {
|
|
52
|
-
// Fallback to old-style
|
|
51
|
+
// Fallback to old-style listeing for changes, for Safari and IE
|
|
53
52
|
mediaQuery.addListener(onThemeChange);
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
setThemeName(themePreference);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
setThemeName(Themes.AUTO);
|
|
62
|
-
}
|
|
54
|
+
const themePreference = window.localStorage.getItem('data-expo-theme');
|
|
55
|
+
if (themePreference === Themes.LIGHT || themePreference === Themes.DARK) {
|
|
56
|
+
setThemeName(themePreference);
|
|
63
57
|
}
|
|
64
58
|
else {
|
|
65
59
|
setThemeName(Themes.AUTO);
|
|
@@ -69,7 +63,7 @@ function ThemeProvider(props) {
|
|
|
69
63
|
mediaQuery.removeEventListener('change', onThemeChange);
|
|
70
64
|
}
|
|
71
65
|
catch {
|
|
72
|
-
// Fallback to old-style
|
|
66
|
+
// Fallback to old-style listeing for changes, for Safari and IE
|
|
73
67
|
mediaQuery.removeListener(onThemeChange);
|
|
74
68
|
}
|
|
75
69
|
};
|
|
@@ -85,39 +79,31 @@ function ThemeProvider(props) {
|
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
function onThemeChange(event) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
setDocumentTheme(Themes.LIGHT);
|
|
96
|
-
}
|
|
82
|
+
const themePreference = window.localStorage.getItem('data-expo-theme');
|
|
83
|
+
if (!themePreference) {
|
|
84
|
+
if (event.matches) {
|
|
85
|
+
setDocumentTheme(Themes.DARK);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
setDocumentTheme(Themes.LIGHT);
|
|
97
89
|
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
setDocumentTheme(Themes.AUTO);
|
|
101
90
|
}
|
|
102
91
|
}
|
|
103
92
|
function setDarkMode() {
|
|
104
|
-
|
|
93
|
+
process.browser &&
|
|
105
94
|
window.localStorage.setItem('data-expo-theme', Themes.DARK);
|
|
106
|
-
}
|
|
107
95
|
setDocumentTheme(Themes.DARK);
|
|
108
96
|
setThemeName(Themes.DARK);
|
|
109
97
|
}
|
|
110
98
|
function setLightMode() {
|
|
111
|
-
|
|
99
|
+
process.browser &&
|
|
112
100
|
window.localStorage.setItem('data-expo-theme', Themes.LIGHT);
|
|
113
|
-
}
|
|
114
101
|
setDocumentTheme(Themes.LIGHT);
|
|
115
102
|
setThemeName(Themes.LIGHT);
|
|
116
103
|
}
|
|
117
104
|
function setAutoMode() {
|
|
118
|
-
|
|
105
|
+
process.browser &&
|
|
119
106
|
window.localStorage.removeItem('data-expo-theme');
|
|
120
|
-
}
|
|
121
107
|
const themeName = BlockingSetInitialColorMode_1.getInitialColorMode();
|
|
122
108
|
setDocumentTheme(themeName);
|
|
123
109
|
setThemeName(Themes.AUTO);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/styleguide",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Foundational styles for Expo interfaces.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"homepage": "https://github.com/expo/styleguide",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/expo/styleguide.git"
|
|
19
|
+
"url": "https://github.com/expo/styleguide.git",
|
|
20
|
+
"directory": "packages/styleguide"
|
|
20
21
|
},
|
|
21
22
|
"keywords": [
|
|
22
23
|
"expo"
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@svgr/cli": "^5.5.0",
|
|
31
32
|
"@types/node": "^15.3.1",
|
|
32
|
-
"@types/react": "^17.0.
|
|
33
|
+
"@types/react": "^17.0.6",
|
|
33
34
|
"copyfiles": "^2.4.1",
|
|
34
35
|
"rimraf": "^3.0.2",
|
|
35
36
|
"typescript": "^4.2.4"
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"react": "*"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "a85cfbc1cf2f8cc51d87c67ff2f6528606cf15d0"
|
|
41
42
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isLocalStorageAvailable: () => boolean;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLocalStorageAvailable = void 0;
|
|
4
|
-
// https://gist.github.com/paulirish/5558557
|
|
5
|
-
const isLocalStorageAvailable = () => {
|
|
6
|
-
try {
|
|
7
|
-
if (!window.localStorage || typeof window.localStorage === 'undefined') {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
window.localStorage.setItem('localStorage:test', 'value');
|
|
11
|
-
if (window.localStorage.getItem('localStorage:test') !== 'value') {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
window.localStorage.removeItem('localStorage:test');
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
exports.isLocalStorageAvailable = isLocalStorageAvailable;
|