react-alp-connection-state 4.1.3 → 6.0.0
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.
- package/.eslintrc.json +1 -1
- package/CHANGELOG.md +58 -0
- package/dist/index-browser.es.js +94 -20
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +89 -20
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/index-node14.mjs +107 -0
- package/dist/index-node14.mjs.map +1 -0
- package/dist/index.d.ts +21 -5
- package/dist/index.d.ts.map +1 -1
- package/package.json +34 -53
- package/rollup.config.mjs +5 -0
- package/src/.eslintrc.json +19 -2
- package/src/index.tsx +110 -26
- package/tsconfig.eslint.json +7 -0
- package/ConnectionState.global.scss +0 -37
- package/dist/index-browser-dev.cjs.js +0 -46
- package/dist/index-browser-dev.cjs.js.map +0 -1
- package/dist/index-browser-dev.es.js +0 -37
- package/dist/index-browser-dev.es.js.map +0 -1
- package/dist/index-browser.cjs.js +0 -46
- package/dist/index-browser.cjs.js.map +0 -1
- package/dist/index-browsermodern-dev.es.js +0 -38
- package/dist/index-browsermodern-dev.es.js.map +0 -1
- package/dist/index-node12-dev.cjs.js +0 -46
- package/dist/index-node12-dev.cjs.js.map +0 -1
- package/dist/index-node12-dev.mjs +0 -37
- package/dist/index-node12-dev.mjs.map +0 -1
- package/dist/index-node12.cjs.js +0 -46
- package/dist/index-node12.cjs.js.map +0 -1
- package/dist/index-node12.mjs +0 -37
- package/dist/index-node12.mjs.map +0 -1
- package/index.js +0 -6
package/.eslintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,64 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.0.0](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@5.0.2...react-alp-connection-state@6.0.0) (2022-02-13)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* dont override react/react-in-jsx-scope ([5d21c9e](https://github.com/christophehurpeau/alp/commit/5d21c9ece092cd3397d1794211dae17cea6649f8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **react-alp-connection-state:** rewrite with react-native ([4e81a48](https://github.com/christophehurpeau/alp/commit/4e81a48fa2a701794971576236ea4f68bd16a475))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### BREAKING CHANGES
|
|
20
|
+
|
|
21
|
+
* **react-alp-connection-state:** new api, react-native or react-native-web, children with text required
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## [5.0.2](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@5.0.1...react-alp-connection-state@5.0.2) (2022-02-06)
|
|
28
|
+
|
|
29
|
+
**Note:** Version bump only for package react-alp-connection-state
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## [5.0.1](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@5.0.0...react-alp-connection-state@5.0.1) (2022-01-15)
|
|
36
|
+
|
|
37
|
+
**Note:** Version bump only for package react-alp-connection-state
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# [5.0.0](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@4.1.3...react-alp-connection-state@5.0.0) (2022-01-02)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Bug Fixes
|
|
47
|
+
|
|
48
|
+
* update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Features
|
|
52
|
+
|
|
53
|
+
* use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### BREAKING CHANGES
|
|
57
|
+
|
|
58
|
+
* requires node 14 and ESM
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
6
64
|
## [4.1.3](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@4.1.2...react-alp-connection-state@4.1.3) (2021-04-10)
|
|
7
65
|
|
|
8
66
|
**Note:** Version bump only for package react-alp-connection-state
|
package/dist/index-browser.es.js
CHANGED
|
@@ -1,21 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import '../ConnectionState.global.scss';
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime.js';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
var defaultTheme = {
|
|
6
|
+
container: {
|
|
7
|
+
backgroundColor: 'rgba(247, 25, 0, 0.8)',
|
|
8
|
+
color: '#fff',
|
|
9
|
+
textShadowColor: '#111',
|
|
10
|
+
textShadowOffset: {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: -1
|
|
13
|
+
},
|
|
14
|
+
textShadowRadius: 1
|
|
15
|
+
},
|
|
16
|
+
backgroundColorConnected: 'rgba(25, 200, 60, 0.8)'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var useCreateCalcNative = function useCreateCalcNative() {
|
|
20
|
+
var dimensions = useWindowDimensions();
|
|
21
|
+
return function (webCalc, createCalc) {
|
|
22
|
+
return createCalc(dimensions);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var useCreateCalcWeb = function useCreateCalcWeb() {
|
|
27
|
+
return function (webCalc) {
|
|
28
|
+
return "calc(" + webCalc + ")";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
12
31
|
|
|
13
|
-
|
|
14
|
-
|
|
32
|
+
var useCreateCalc = Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative; // example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
33
|
+
|
|
34
|
+
var styles = StyleSheet.create({
|
|
35
|
+
connectionStateContainer: {
|
|
36
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
top: 0,
|
|
39
|
+
right: 0,
|
|
40
|
+
left: 0,
|
|
41
|
+
height: 2,
|
|
42
|
+
color: defaultTheme.container.color,
|
|
43
|
+
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
44
|
+
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
45
|
+
boxShadow: "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)",
|
|
46
|
+
zIndex: 9,
|
|
47
|
+
transition: 'top .8s, background-color .2s'
|
|
48
|
+
},
|
|
49
|
+
hide: {
|
|
50
|
+
top: -24
|
|
51
|
+
},
|
|
52
|
+
connectionStateText: {
|
|
53
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
width: 200,
|
|
56
|
+
height: 22,
|
|
57
|
+
lineHeight: 22,
|
|
58
|
+
top: 2,
|
|
59
|
+
textAlign: 'center',
|
|
60
|
+
borderBottomLeftRadius: 5,
|
|
61
|
+
borderBottomRightRadius: 5,
|
|
62
|
+
transition: 'background-color .2s'
|
|
15
63
|
}
|
|
64
|
+
});
|
|
65
|
+
function ConnectionState(_ref) {
|
|
66
|
+
var theme = _ref.theme,
|
|
67
|
+
forceHidden = _ref.forceHidden,
|
|
68
|
+
state = _ref.state,
|
|
69
|
+
children = _ref.children;
|
|
70
|
+
console.log({
|
|
71
|
+
state: state,
|
|
72
|
+
forceHidden: forceHidden
|
|
73
|
+
});
|
|
74
|
+
var unloadingRef = useRef(false);
|
|
75
|
+
var createCalc = useCreateCalc();
|
|
76
|
+
var left = createCalc('50% - 100px', function (_ref2) {
|
|
77
|
+
var width = _ref2.width;
|
|
78
|
+
return width / 2 - 100;
|
|
79
|
+
}); // TODO use calc() in web ?
|
|
16
80
|
|
|
17
|
-
var currentState = currentStateRef.current;
|
|
18
81
|
useEffect(function () {
|
|
82
|
+
if (typeof window === 'undefined') return;
|
|
83
|
+
|
|
19
84
|
var beforeUnloadHandler = function beforeUnloadHandler() {
|
|
20
85
|
unloadingRef.current = true;
|
|
21
86
|
};
|
|
@@ -25,13 +90,22 @@ function ConnectionState(_ref) {
|
|
|
25
90
|
window.removeEventListener('beforeunload', beforeUnloadHandler);
|
|
26
91
|
};
|
|
27
92
|
}, []);
|
|
28
|
-
return /*#__PURE__*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
93
|
+
return /*#__PURE__*/jsx(View, {
|
|
94
|
+
style: [styles.connectionStateContainer, (forceHidden || !state || state === 'connected') && styles.hide, theme == null ? void 0 : theme.container, state === 'connected' && {
|
|
95
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
96
|
+
}],
|
|
97
|
+
children: !state ? null : /*#__PURE__*/jsx(View, {
|
|
98
|
+
style: [styles.connectionStateText, theme && {
|
|
99
|
+
backgroundColor: theme.container.backgroundColor
|
|
100
|
+
}, state === 'connected' && {
|
|
101
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
102
|
+
}, {
|
|
103
|
+
left: left
|
|
104
|
+
}],
|
|
105
|
+
children: children
|
|
106
|
+
})
|
|
107
|
+
});
|
|
34
108
|
}
|
|
35
109
|
|
|
36
|
-
export
|
|
110
|
+
export { ConnectionState };
|
|
37
111
|
//# sourceMappingURL=index-browser.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport type { ScaledSize } from 'react-native';\nimport { View, StyleSheet, Platform, useWindowDimensions } from 'react-native';\n\nconst defaultTheme = {\n container: {\n backgroundColor: 'rgba(247, 25, 0, 0.8)',\n color: '#fff',\n textShadowColor: '#111',\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = null | 'connecting' | 'connected' | 'disconnected';\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => number,\n) => string | number;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})`;\n};\nconst useCreateCalc =\n Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n transition: 'top .8s, background-color .2s',\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: 'center',\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: 'background-color .2s',\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n console.log({ state, forceHidden });\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof window === 'undefined') return;\n\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n const shouldHide = forceHidden || !state || state === 'connected';\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <View\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </View>\n )}\n </View>\n );\n}\n"],"names":["defaultTheme","container","backgroundColor","color","textShadowColor","textShadowOffset","width","height","textShadowRadius","backgroundColorConnected","useCreateCalcNative","dimensions","useWindowDimensions","webCalc","createCalc","useCreateCalcWeb","useCreateCalc","Platform","OS","styles","StyleSheet","create","connectionStateContainer","position","top","right","left","boxShadow","zIndex","transition","hide","connectionStateText","lineHeight","textAlign","borderBottomLeftRadius","borderBottomRightRadius","ConnectionState","theme","forceHidden","state","children","console","log","unloadingRef","useRef","useEffect","window","beforeUnloadHandler","current","addEventListener","removeEventListener","_jsx"],"mappings":";;;;AAKA,IAAMA,YAAY,GAAG;AACnBC,EAAAA,S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,mBAAsB,GAAY;AACtCJ,MAAAA,YAAY,CAACK,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAF,IAAAA,MAAM,CAACG,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,YAAY;AACjBD,MAAAA,MAAM,CAACI,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GAXQ,EAWN,EAXM,CAAT;AAeA,sBACEI,IAAC,IAAD;AACE,IAAA,KAAK,EAAE,CACLhC,MAAM,CAACG,wBADF,EAEL,CANagB,WAAW,IAAI,CAACC,KAAhB,IAAyBA,KAAK,KAAK,WAMhD,KAAcpB,MAAM,CAACW,IAFhB,EAGLO,KAHK,oBAGLA,KAAK,CAAEpC,SAHF,EAILsC,KAAK,KAAK,WAAV,IAAyB;AACvBrC,MAAAA,eAAe,EAAE,CAACmC,KAAK,IAAIrC,YAAV,EAAwBS;AADlB,KAJpB,CADT;AAAA,cAUG,CAAC8B,KAAD,GAAS,IAAT,gBACCY,IAAC,IAAD;AACE,MAAA,KAAK,EAAE,CACLhC,MAAM,CAACY,mBADF,EAELM,KAAK,IAAI;AAAEnC,QAAAA,eAAe,EAAEmC,KAAK,CAACpC,SAAN,CAAgBC;AAAnC,OAFJ,EAGLqC,KAAK,KAAK,WAAV,IAAyB;AACvBrC,QAAAA,eAAe,EAAE,CAACmC,KAAK,IAAIrC,YAAV,EAAwBS;AADlB,OAHpB,EAML;AAAEiB,QAAAA,IAAI,EAAJA;AAAF,OANK,CADT;AAAA,gBAUGc;AAVH;AAXJ,IADF;AA2BD;;;;"}
|
|
@@ -1,22 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import '../ConnectionState.global.scss';
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime.js';
|
|
5
4
|
|
|
5
|
+
const defaultTheme = {
|
|
6
|
+
container: {
|
|
7
|
+
backgroundColor: 'rgba(247, 25, 0, 0.8)',
|
|
8
|
+
color: '#fff',
|
|
9
|
+
textShadowColor: '#111',
|
|
10
|
+
textShadowOffset: {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: -1
|
|
13
|
+
},
|
|
14
|
+
textShadowRadius: 1
|
|
15
|
+
},
|
|
16
|
+
backgroundColorConnected: 'rgba(25, 200, 60, 0.8)'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const useCreateCalcNative = () => {
|
|
20
|
+
const dimensions = useWindowDimensions();
|
|
21
|
+
return (webCalc, createCalc) => createCalc(dimensions);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const useCreateCalcWeb = () => {
|
|
25
|
+
return webCalc => `calc(${webCalc})`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const useCreateCalc = Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative; // example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
29
|
+
|
|
30
|
+
const styles = StyleSheet.create({
|
|
31
|
+
connectionStateContainer: {
|
|
32
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
top: 0,
|
|
35
|
+
right: 0,
|
|
36
|
+
left: 0,
|
|
37
|
+
height: 2,
|
|
38
|
+
color: defaultTheme.container.color,
|
|
39
|
+
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
40
|
+
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
41
|
+
boxShadow: "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)",
|
|
42
|
+
zIndex: 9,
|
|
43
|
+
transition: 'top .8s, background-color .2s'
|
|
44
|
+
},
|
|
45
|
+
hide: {
|
|
46
|
+
top: -24
|
|
47
|
+
},
|
|
48
|
+
connectionStateText: {
|
|
49
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
width: 200,
|
|
52
|
+
height: 22,
|
|
53
|
+
lineHeight: 22,
|
|
54
|
+
top: 2,
|
|
55
|
+
textAlign: 'center',
|
|
56
|
+
borderBottomLeftRadius: 5,
|
|
57
|
+
borderBottomRightRadius: 5,
|
|
58
|
+
transition: 'background-color .2s'
|
|
59
|
+
}
|
|
60
|
+
});
|
|
6
61
|
function ConnectionState({
|
|
7
|
-
|
|
62
|
+
theme,
|
|
63
|
+
forceHidden,
|
|
64
|
+
state,
|
|
65
|
+
children
|
|
8
66
|
}) {
|
|
9
|
-
|
|
10
|
-
|
|
67
|
+
console.log({
|
|
68
|
+
state,
|
|
69
|
+
forceHidden
|
|
70
|
+
});
|
|
11
71
|
const unloadingRef = useRef(false);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
72
|
+
const createCalc = useCreateCalc();
|
|
73
|
+
const left = createCalc('50% - 100px', ({
|
|
74
|
+
width
|
|
75
|
+
}) => width / 2 - 100); // TODO use calc() in web ?
|
|
17
76
|
|
|
18
|
-
const currentState = currentStateRef.current;
|
|
19
77
|
useEffect(() => {
|
|
78
|
+
if (typeof window === 'undefined') return;
|
|
79
|
+
|
|
20
80
|
const beforeUnloadHandler = () => {
|
|
21
81
|
unloadingRef.current = true;
|
|
22
82
|
};
|
|
@@ -26,13 +86,22 @@ function ConnectionState({
|
|
|
26
86
|
window.removeEventListener('beforeunload', beforeUnloadHandler);
|
|
27
87
|
};
|
|
28
88
|
}, []);
|
|
29
|
-
return /*#__PURE__*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
89
|
+
return /*#__PURE__*/jsx(View, {
|
|
90
|
+
style: [styles.connectionStateContainer, (forceHidden || !state || state === 'connected') && styles.hide, theme === null || theme === void 0 ? void 0 : theme.container, state === 'connected' && {
|
|
91
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
92
|
+
}],
|
|
93
|
+
children: !state ? null : /*#__PURE__*/jsx(View, {
|
|
94
|
+
style: [styles.connectionStateText, theme && {
|
|
95
|
+
backgroundColor: theme.container.backgroundColor
|
|
96
|
+
}, state === 'connected' && {
|
|
97
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
98
|
+
}, {
|
|
99
|
+
left
|
|
100
|
+
}],
|
|
101
|
+
children: children
|
|
102
|
+
})
|
|
103
|
+
});
|
|
35
104
|
}
|
|
36
105
|
|
|
37
|
-
export
|
|
106
|
+
export { ConnectionState };
|
|
38
107
|
//# sourceMappingURL=index-browsermodern.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport type { ScaledSize } from 'react-native';\nimport { View, StyleSheet, Platform, useWindowDimensions } from 'react-native';\n\nconst defaultTheme = {\n container: {\n backgroundColor: 'rgba(247, 25, 0, 0.8)',\n color: '#fff',\n textShadowColor: '#111',\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = null | 'connecting' | 'connected' | 'disconnected';\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => number,\n) => string | number;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})`;\n};\nconst useCreateCalc =\n Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n transition: 'top .8s, background-color .2s',\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: 'center',\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: 'background-color .2s',\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n console.log({ state, forceHidden });\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof window === 'undefined') return;\n\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n const shouldHide = forceHidden || !state || state === 'connected';\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <View\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </View>\n )}\n </View>\n );\n}\n"],"names":["defaultTheme","container","backgroundColor","color","textShadowColor","textShadowOffset","width","height","textShadowRadius","backgroundColorConnected","useCreateCalcNative","dimensions","useWindowDimensions","webCalc","createCalc","useCreateCalcWeb","useCreateCalc","Platform","OS","styles","StyleSheet","create","connectionStateContainer","position","top","right","left","boxShadow","zIndex","transition","hide","connectionStateText","lineHeight","textAlign","borderBottomLeftRadius","borderBottomRightRadius","ConnectionState","theme","forceHidden","state","children","console","log","unloadingRef","useRef","useEffect","window","beforeUnloadHandler","current","addEventListener","removeEventListener","_jsx"],"mappings":";;;;AAKA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,SAAS,EAAE;AACTC,IAAAA,eAAe,EAAE,uBADR;AAETC,IAAAA,KAAK,EAAE,MAFE;AAGTC,IAAAA,eAAe,EAAE,MAHR;AAITC,IAAAA,gBAAgB,EAAE;AAAEC,MAAAA,KAAK,EAAE,CAAT;AAAYC,MAAAA,MAAM,EAAE,CAAC;AAArB,KAJT;AAKTC,IAAAA,gBAAgB,EAAE;AALT,GADQ;AAQnBC,EAAAA,wBAAwB,EAAE;AARP,CAArB;;AA6BA,MAAMC,mBAAmB,GAAG,MAAkB;AAC5C,QAAMC,UAAU,GAAGC,mBAAmB,EAAtC;AACA,SAAO,CAACC,OAAD,EAAUC,UAAV,KAAyBA,UAAU,CAACH,UAAD,CAA1C;AACD,CAHD;;AAIA,MAAMI,gBAAgB,GAAG,MAAkB;AACzC,SAAQF,OAAD,IAAc,QAAOA,OAAQ,GAApC;AACD,CAFD;;AAGA,MAAMG,aAAa,GACjBC,QAAQ,CAACC,EAAT,KAAgB,KAAhB,GAAwBH,gBAAxB,GAA2CL,mBAD7C;;AAKA,MAAMS,MAAM,GAAGC,UAAU,CAACC,MAAX,CAAkB;AAC/BC,EAAAA,wBAAwB,EAAE;AACxBpB,IAAAA,e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ML;AAAEiB,QAAAA;AAAF,OANK,CADT;AAAA,gBAUGc;AAVH;AAXJ,IADF;AA2BD;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime.js';
|
|
4
|
+
|
|
5
|
+
const defaultTheme = {
|
|
6
|
+
container: {
|
|
7
|
+
backgroundColor: 'rgba(247, 25, 0, 0.8)',
|
|
8
|
+
color: '#fff',
|
|
9
|
+
textShadowColor: '#111',
|
|
10
|
+
textShadowOffset: {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: -1
|
|
13
|
+
},
|
|
14
|
+
textShadowRadius: 1
|
|
15
|
+
},
|
|
16
|
+
backgroundColorConnected: 'rgba(25, 200, 60, 0.8)'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const useCreateCalcNative = () => {
|
|
20
|
+
const dimensions = useWindowDimensions();
|
|
21
|
+
return (webCalc, createCalc) => createCalc(dimensions);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const useCreateCalcWeb = () => {
|
|
25
|
+
return webCalc => `calc(${webCalc})`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const useCreateCalc = Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative; // example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
29
|
+
|
|
30
|
+
const styles = StyleSheet.create({
|
|
31
|
+
connectionStateContainer: {
|
|
32
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
top: 0,
|
|
35
|
+
right: 0,
|
|
36
|
+
left: 0,
|
|
37
|
+
height: 2,
|
|
38
|
+
color: defaultTheme.container.color,
|
|
39
|
+
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
40
|
+
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
41
|
+
boxShadow: "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)",
|
|
42
|
+
zIndex: 9,
|
|
43
|
+
transition: 'top .8s, background-color .2s'
|
|
44
|
+
},
|
|
45
|
+
hide: {
|
|
46
|
+
top: -24
|
|
47
|
+
},
|
|
48
|
+
connectionStateText: {
|
|
49
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
width: 200,
|
|
52
|
+
height: 22,
|
|
53
|
+
lineHeight: 22,
|
|
54
|
+
top: 2,
|
|
55
|
+
textAlign: 'center',
|
|
56
|
+
borderBottomLeftRadius: 5,
|
|
57
|
+
borderBottomRightRadius: 5,
|
|
58
|
+
transition: 'background-color .2s'
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
function ConnectionState({
|
|
62
|
+
theme,
|
|
63
|
+
forceHidden,
|
|
64
|
+
state,
|
|
65
|
+
children
|
|
66
|
+
}) {
|
|
67
|
+
console.log({
|
|
68
|
+
state,
|
|
69
|
+
forceHidden
|
|
70
|
+
});
|
|
71
|
+
const unloadingRef = useRef(false);
|
|
72
|
+
const createCalc = useCreateCalc();
|
|
73
|
+
const left = createCalc('50% - 100px', ({
|
|
74
|
+
width
|
|
75
|
+
}) => width / 2 - 100); // TODO use calc() in web ?
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (typeof window === 'undefined') return;
|
|
79
|
+
|
|
80
|
+
const beforeUnloadHandler = () => {
|
|
81
|
+
unloadingRef.current = true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
window.addEventListener('beforeunload', beforeUnloadHandler);
|
|
85
|
+
return () => {
|
|
86
|
+
window.removeEventListener('beforeunload', beforeUnloadHandler);
|
|
87
|
+
};
|
|
88
|
+
}, []);
|
|
89
|
+
return /*#__PURE__*/jsx(View, {
|
|
90
|
+
style: [styles.connectionStateContainer, (forceHidden || !state || state === 'connected') && styles.hide, theme?.container, state === 'connected' && {
|
|
91
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
92
|
+
}],
|
|
93
|
+
children: !state ? null : /*#__PURE__*/jsx(View, {
|
|
94
|
+
style: [styles.connectionStateText, theme && {
|
|
95
|
+
backgroundColor: theme.container.backgroundColor
|
|
96
|
+
}, state === 'connected' && {
|
|
97
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
98
|
+
}, {
|
|
99
|
+
left
|
|
100
|
+
}],
|
|
101
|
+
children: children
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { ConnectionState };
|
|
107
|
+
//# sourceMappingURL=index-node14.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node14.mjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport type { ScaledSize } from 'react-native';\nimport { View, StyleSheet, Platform, useWindowDimensions } from 'react-native';\n\nconst defaultTheme = {\n container: {\n backgroundColor: 'rgba(247, 25, 0, 0.8)',\n color: '#fff',\n textShadowColor: '#111',\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = null | 'connecting' | 'connected' | 'disconnected';\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => number,\n) => string | number;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})`;\n};\nconst useCreateCalc =\n Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n transition: 'top .8s, background-color .2s',\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: 'center',\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: 'background-color .2s',\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n console.log({ state, forceHidden });\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof window === 'undefined') return;\n\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n const shouldHide = forceHidden || !state || state === 'connected';\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <View\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </View>\n )}\n </View>\n );\n}\n"],"names":["defaultTheme","container","backgroundColor","color","textShadowColor","textShadowOffset","width","height","textShadowRadius","backgroundColorConnected","useCreateCalcNative","dimensions","useWindowDimensions","webCalc","createCalc","useCreateCalcWeb","useCreateCalc","Platform","OS","styles","StyleSheet","create","connectionStateContainer","position","top","right","left","boxShadow","zIndex","transition","hide","connectionStateText","lineHeight","textAlign","borderBottomLeftRadius","borderBottomRightRadius","ConnectionState","theme","forceHidden","state","children","console","log","unloadingRef","useRef","useEffect","window","beforeUnloadHandler","current","addEventListener","removeEventListener","_jsx"],"mappings":";;;;AAKA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,SAAS,EAAE;AACTC,IAAAA,eAAe,EAAE,uBADR;AAETC,IAAAA,KAAK,EAAE,MAFE;AAGTC,IAAAA,eAAe,EAAE,MAHR;AAITC,IAAAA,gBAAgB,EAAE;AAAEC,MAAAA,KAAK,EAAE,CAAT;AAAYC,MAAAA,MAAM,EAAE,CAAC;AAArB,KAJT;AAKTC,IAAAA,gBAAgB,EAAE;AALT,GADQ;AAQnBC,EAAAA,wBAAwB,EAAE;AARP,CAArB;;AA6BA,MAAMC,mBAAmB,GAAG,MAAkB;AAC5C,QAAMC,UAAU,GAAGC,mBAAmB,EAAtC;AACA,SAAO,CAACC,OAAD,EAAUC,UAAV,KAAyBA,UAAU,CAACH,UAAD,CAA1C;AACD,CAHD;;AAIA,MAAMI,gBAAgB,GAAG,MAAkB;AACzC,SAAQF,OAAD,IAAc,QAAOA,OAAQ,GAApC;AACD,CAFD;;AAGA,MAAMG,aAAa,GACjBC,QAAQ,CAACC,EAAT,KAAgB,KAAhB,GAAwBH,gBAAxB,GAA2CL,mBAD7C;;AAKA,MAAMS,MAAM,GAAGC,UAAU,CAACC,MAAX,CAAkB;AAC/BC,EAAAA,wBAAwB,EAAE;AACxBpB,IAAAA,eAAe,EAAEF,YAAY,CAACC,SAAb,CAAuBC,eADhB;AAExBqB,IAAAA,QAAQ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ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
declare const defaultTheme: {
|
|
3
|
+
container: {
|
|
4
|
+
backgroundColor: string;
|
|
5
|
+
color: string;
|
|
6
|
+
textShadowColor: string;
|
|
7
|
+
textShadowOffset: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
textShadowRadius: number;
|
|
12
|
+
};
|
|
13
|
+
backgroundColorConnected: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type ConnectionStateTheme = typeof defaultTheme;
|
|
16
|
+
export declare type State = null | 'connecting' | 'connected' | 'disconnected';
|
|
17
|
+
export interface ConnectionStateProps {
|
|
18
|
+
theme?: ConnectionStateTheme;
|
|
19
|
+
forceHidden?: boolean;
|
|
5
20
|
state: State;
|
|
21
|
+
children: NonNullable<ReactNode>;
|
|
6
22
|
}
|
|
7
|
-
export
|
|
23
|
+
export declare function ConnectionState({ theme, forceHidden, state, children, }: ConnectionStateProps): ReactElement | null;
|
|
8
24
|
export {};
|
|
9
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKrD,QAAA,MAAM,YAAY;;;;;;;;;;;;CASjB,CAAC;AAEF,oBAAY,oBAAoB,GAAG,OAAO,YAAY,CAAC;AACvD,oBAAY,KAAK,GAAG,IAAI,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,CAAC;AAEvE,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CAClC;AAsDD,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,WAAW,EACX,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,GAAG,YAAY,GAAG,IAAI,CAiD5C"}
|