@expo/styleguide 4.0.1 → 4.0.2
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,11 +5,14 @@ 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");
|
|
8
9
|
function getInitialColorMode() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (helpers_1.isLocalStorageAvailable()) {
|
|
11
|
+
const preference = window.localStorage.getItem('data-expo-theme');
|
|
12
|
+
let hasPreference = typeof preference === 'string';
|
|
13
|
+
if (hasPreference) {
|
|
14
|
+
return preference;
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
17
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
15
18
|
const systemPreference = typeof mql.matches === 'boolean';
|
|
@@ -22,6 +22,7 @@ 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");
|
|
25
26
|
var Themes;
|
|
26
27
|
(function (Themes) {
|
|
27
28
|
Themes["AUTO"] = "auto";
|
|
@@ -48,12 +49,17 @@ function ThemeProvider(props) {
|
|
|
48
49
|
mediaQuery.addEventListener('change', onThemeChange);
|
|
49
50
|
}
|
|
50
51
|
catch {
|
|
51
|
-
// Fallback to old-style
|
|
52
|
+
// Fallback to old-style listening for changes, for Safari and IE
|
|
52
53
|
mediaQuery.addListener(onThemeChange);
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
if (helpers_1.isLocalStorageAvailable()) {
|
|
56
|
+
const themePreference = window.localStorage.getItem('data-expo-theme');
|
|
57
|
+
if (themePreference === Themes.LIGHT || themePreference === Themes.DARK) {
|
|
58
|
+
setThemeName(themePreference);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
setThemeName(Themes.AUTO);
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
else {
|
|
59
65
|
setThemeName(Themes.AUTO);
|
|
@@ -63,7 +69,7 @@ function ThemeProvider(props) {
|
|
|
63
69
|
mediaQuery.removeEventListener('change', onThemeChange);
|
|
64
70
|
}
|
|
65
71
|
catch {
|
|
66
|
-
// Fallback to old-style
|
|
72
|
+
// Fallback to old-style listening for changes, for Safari and IE
|
|
67
73
|
mediaQuery.removeListener(onThemeChange);
|
|
68
74
|
}
|
|
69
75
|
};
|
|
@@ -79,31 +85,39 @@ function ThemeProvider(props) {
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
function onThemeChange(event) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
if (helpers_1.isLocalStorageAvailable()) {
|
|
89
|
+
const themePreference = window.localStorage.getItem('data-expo-theme');
|
|
90
|
+
if (!themePreference) {
|
|
91
|
+
if (event.matches) {
|
|
92
|
+
setDocumentTheme(Themes.DARK);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
setDocumentTheme(Themes.LIGHT);
|
|
96
|
+
}
|
|
89
97
|
}
|
|
90
98
|
}
|
|
99
|
+
else {
|
|
100
|
+
setDocumentTheme(Themes.AUTO);
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
function setDarkMode() {
|
|
93
|
-
|
|
104
|
+
if (helpers_1.isLocalStorageAvailable()) {
|
|
94
105
|
window.localStorage.setItem('data-expo-theme', Themes.DARK);
|
|
106
|
+
}
|
|
95
107
|
setDocumentTheme(Themes.DARK);
|
|
96
108
|
setThemeName(Themes.DARK);
|
|
97
109
|
}
|
|
98
110
|
function setLightMode() {
|
|
99
|
-
|
|
111
|
+
if (helpers_1.isLocalStorageAvailable()) {
|
|
100
112
|
window.localStorage.setItem('data-expo-theme', Themes.LIGHT);
|
|
113
|
+
}
|
|
101
114
|
setDocumentTheme(Themes.LIGHT);
|
|
102
115
|
setThemeName(Themes.LIGHT);
|
|
103
116
|
}
|
|
104
117
|
function setAutoMode() {
|
|
105
|
-
|
|
118
|
+
if (helpers_1.isLocalStorageAvailable()) {
|
|
106
119
|
window.localStorage.removeItem('data-expo-theme');
|
|
120
|
+
}
|
|
107
121
|
const themeName = BlockingSetInitialColorMode_1.getInitialColorMode();
|
|
108
122
|
setDocumentTheme(themeName);
|
|
109
123
|
setThemeName(Themes.AUTO);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isLocalStorageAvailable: () => boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/styleguide",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Foundational styles for Expo interfaces.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "*"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "8bc8fee4c0708453a5f6345e6a346385d0f98c4e"
|
|
41
41
|
}
|