react-alp-connection-state 5.0.2 → 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/CHANGELOG.md CHANGED
@@ -3,6 +3,27 @@
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
+
6
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)
7
28
 
8
29
  **Note:** Version bump only for package react-alp-connection-state
@@ -1,21 +1,86 @@
1
- import React, { useContext, useRef, useEffect } from 'react';
2
- import ReactAlpContext from 'react-alp-context';
3
- import { T } from 'react-alp-translate';
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
- function ConnectionState(_ref) {
7
- var state = _ref.state;
8
- var ctx = useContext(ReactAlpContext);
9
- var notLoggedIn = !ctx.sanitizedState.user;
10
- var unloadingRef = useRef(false);
11
- var currentStateRef = useRef(state);
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
- if (!unloadingRef.current) {
14
- currentStateRef.current = state;
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__*/React.createElement("div", {
29
- hidden: !state || notLoggedIn || currentState === 'connected',
30
- className: "alp-connection-state"
31
- }, !state || notLoggedIn ? null : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(T, {
32
- id: "connectionState." + currentState
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 { ConnectionState as default };
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 React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (!unloadingRef.current) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\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 return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener"],"mappings":";;;;;AAYe,SAASA,eAAT,OAEwB;AAAA,MADrCC,KACqC,QADrCA,KACqC;AACrC,MAAMC,GAAG,GAAGC,UAAU,CAACC,eAAD,CAAtB;AACA,MAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,MAAMC,YAAY,GAAGC,MAAM,CAAU,KAAV,CAA3B;AACA,MAAMC,eAAe,GAAGD,MAAM,CAACR,KAAD,CAA9B;;AACA,MAAI,CAACO,YAAY,CAACG,OAAlB,EAA2B;AACzBD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,MAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,SAAS,CAAC,YAAoB;AAC5B,QAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,YAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACE;AACE,IAAA,MAAM,EAAE,CAACb,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACC,8CACE,oBAAC,CAAD;AAAG,IAAA,EAAE,uBAAqBO;AAA1B,IADF,CALJ,CADF;AAYD;;;;"}
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,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,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAkB;AAC5C,MAAMC,UAAU,GAAGC,mBAAmB,EAAtC;AACA,SAAO,UAACC,OAAD,EAAUC,UAAV;AAAA,WAAyBA,UAAU,CAACH,UAAD,CAAnC;AAAA,GAAP;AACD,CAHD;;AAIA,IAAMI,gBAAgB,GAAG,SAAnBA,gBAAmB,GAAkB;AACzC,SAAO,UAACF,OAAD;AAAA,qBAAqBA,OAArB;AAAA,GAAP;AACD,CAFD;;AAGA,IAAMG,aAAa,GACjBC,QAAQ,CAACC,EAAT,KAAgB,KAAhB,GAAwBH,gBAAxB,GAA2CL,mBAD7C;;AAKA,IAAMS,MAAM,GAAGC,UAAU,CAACC,MAAX,CAAkB;AAC/BC,EAAAA,wBAAwB,EAAE;AACxBpB,IAAAA,e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,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 React, { useContext, useRef, useEffect } from 'react';
2
- import ReactAlpContext from 'react-alp-context';
3
- import { T } from 'react-alp-translate';
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
- state
62
+ theme,
63
+ forceHidden,
64
+ state,
65
+ children
8
66
  }) {
9
- const ctx = useContext(ReactAlpContext);
10
- const notLoggedIn = !ctx.sanitizedState.user;
67
+ console.log({
68
+ state,
69
+ forceHidden
70
+ });
11
71
  const unloadingRef = useRef(false);
12
- const currentStateRef = useRef(state);
13
-
14
- if (!unloadingRef.current) {
15
- currentStateRef.current = state;
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__*/React.createElement("div", {
30
- hidden: !state || notLoggedIn || currentState === 'connected',
31
- className: "alp-connection-state"
32
- }, !state || notLoggedIn ? null : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(T, {
33
- id: `connectionState.${currentState}`
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 { ConnectionState as default };
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 React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (!unloadingRef.current) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\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 return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener"],"mappings":";;;;;AAYe,SAASA,eAAT,CAAyB;AACtCC,EAAAA;AADsC,CAAzB,EAEwB;AACrC,QAAMC,GAAG,GAAGC,UAAU,CAACC,eAAD,CAAtB;AACA,QAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,QAAMC,YAAY,GAAGC,MAAM,CAAU,KAAV,CAA3B;AACA,QAAMC,eAAe,GAAGD,MAAM,CAACR,KAAD,CAA9B;;AACA,MAAI,CAACO,YAAY,CAACG,OAAlB,EAA2B;AACzBD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,QAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,SAAS,CAAC,MAAoB;AAC5B,UAAMC,mBAAmB,GAAG,MAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,MAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACE;AACE,IAAA,MAAM,EAAE,CAACb,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACC,8CACE,oBAAC,CAAD;AAAG,IAAA,EAAE,EAAG,mBAAkBO,YAAuB;AAAjD,IADF,CALJ,CADF;AAYD;;;;"}
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,QAAM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,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;AAAF,OANK,CADT;AAAA,gBAUGc;AAVH;AAXJ,IADF;AA2BD;;;;"}
@@ -1,21 +1,82 @@
1
- import React, { useContext, useRef, useEffect } from 'react';
2
- import ReactAlpContext from 'react-alp-context';
3
- import { T } from 'react-alp-translate';
1
+ import { useRef, useEffect } from 'react';
2
+ import { Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
3
+ import { jsx } from 'react/jsx-runtime.js';
4
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
+ });
5
61
  function ConnectionState({
6
- state
62
+ theme,
63
+ forceHidden,
64
+ state,
65
+ children
7
66
  }) {
8
- const ctx = useContext(ReactAlpContext);
9
- const notLoggedIn = !ctx.sanitizedState.user;
67
+ console.log({
68
+ state,
69
+ forceHidden
70
+ });
10
71
  const unloadingRef = useRef(false);
11
- const currentStateRef = useRef(state);
12
-
13
- if (!unloadingRef.current) {
14
- currentStateRef.current = state;
15
- }
72
+ const createCalc = useCreateCalc();
73
+ const left = createCalc('50% - 100px', ({
74
+ width
75
+ }) => width / 2 - 100); // TODO use calc() in web ?
16
76
 
17
- const currentState = currentStateRef.current;
18
77
  useEffect(() => {
78
+ if (typeof window === 'undefined') return;
79
+
19
80
  const beforeUnloadHandler = () => {
20
81
  unloadingRef.current = true;
21
82
  };
@@ -25,13 +86,22 @@ function ConnectionState({
25
86
  window.removeEventListener('beforeunload', beforeUnloadHandler);
26
87
  };
27
88
  }, []);
28
- return /*#__PURE__*/React.createElement("div", {
29
- hidden: !state || notLoggedIn || currentState === 'connected',
30
- className: "alp-connection-state"
31
- }, !state || notLoggedIn ? null : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(T, {
32
- id: `connectionState.${currentState}`
33
- })));
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
+ });
34
104
  }
35
105
 
36
- export { ConnectionState as default };
106
+ export { ConnectionState };
37
107
  //# sourceMappingURL=index-node14.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-node14.mjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (!unloadingRef.current) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\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 return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener"],"mappings":";;;;AAYe,SAASA,eAAT,CAAyB;AACtCC,EAAAA;AADsC,CAAzB,EAEwB;AACrC,QAAMC,GAAG,GAAGC,UAAU,CAACC,eAAD,CAAtB;AACA,QAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,QAAMC,YAAY,GAAGC,MAAM,CAAU,KAAV,CAA3B;AACA,QAAMC,eAAe,GAAGD,MAAM,CAACR,KAAD,CAA9B;;AACA,MAAI,CAACO,YAAY,CAACG,OAAlB,EAA2B;AACzBD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,QAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,SAAS,CAAC,MAAoB;AAC5B,UAAMC,mBAAmB,GAAG,MAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,MAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACE;AACE,IAAA,MAAM,EAAE,CAACb,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACC,8CACE,oBAAC,CAAD;AAAG,IAAA,EAAE,EAAG,mBAAkBO,YAAuB;AAAjD,IADF,CALJ,CADF;AAYD;;;;"}
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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EI,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,KAAK,EAAEpC,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;AAAF,OANK,CADT;AAAA,gBAUGc;AAVH;AAXJ,IADF;AA2BD;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,25 @@
1
- import type { ReactElement } from 'react';
2
- import '../ConnectionState.global.scss';
3
- declare type State = null | 'connecting' | 'connected' | 'disconnected';
4
- interface ConnectionStateProps {
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 default function ConnectionState({ state, }: ConnectionStateProps): ReactElement;
23
+ export declare function ConnectionState({ theme, forceHidden, state, children, }: ConnectionStateProps): ReactElement | null;
8
24
  export {};
9
25
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAI1C,OAAO,gCAAgC,CAAC;AAExC,aAAK,KAAK,GAAG,IAAI,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,CAAC;AAEhE,UAAU,oBAAoB;IAC5B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,KAAK,GACN,EAAE,oBAAoB,GAAG,YAAY,CAkCrC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-alp-connection-state",
3
- "version": "5.0.2",
3
+ "version": "6.0.0",
4
4
  "description": "connection state",
5
5
  "keywords": [],
6
6
  "author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
@@ -87,23 +87,26 @@
87
87
  },
88
88
  "peerDependencies": {
89
89
  "react": "^17.0.2",
90
- "ynnub": "^1.0.0 || ^2.0.0"
90
+ "react-native": "*"
91
+ },
92
+ "peerDependenciesMeta": {
93
+ "react-native": {
94
+ "optional": true
95
+ }
91
96
  },
92
97
  "dependencies": {
93
- "@babel/runtime": "^7.17.0",
94
- "alp-types": "3.1.0",
95
- "react-alp-context": "4.0.2",
96
- "react-alp-translate": "6.0.2"
98
+ "@babel/runtime": "^7.17.2"
97
99
  },
98
100
  "devDependencies": {
99
- "@babel/core": "7.17.0",
101
+ "@babel/core": "7.17.2",
100
102
  "@babel/preset-env": "7.16.11",
101
103
  "@babel/preset-react": "7.16.7",
104
+ "@types/react-native": "0.66.15",
102
105
  "babel-preset-modern-browsers": "15.0.2",
103
- "pob-babel": "31.0.0",
106
+ "pob-babel": "32.0.1",
104
107
  "react": "17.0.2",
105
- "typescript": "4.5.5",
106
- "ynnub": "2.0.0"
108
+ "react-native": "0.67.2",
109
+ "typescript": "4.5.5"
107
110
  },
108
- "gitHead": "1af3cf2eb4bba25ab23f174cda860416ff68a63d"
111
+ "gitHead": "1617223e61c2b76e0613a49012792fbf6d3b872b"
109
112
  }
@@ -2,7 +2,7 @@
2
2
  "root": true,
3
3
  "parser": "@typescript-eslint/parser",
4
4
  "parserOptions": {
5
- "project": "packages/react-alp-connection-state/tsconfig.json"
5
+ "project": "packages/react-alp-connection-state/tsconfig.eslint.json"
6
6
  },
7
7
  "plugins": ["@typescript-eslint"],
8
8
  "extends": [
package/src/index.tsx CHANGED
@@ -1,29 +1,96 @@
1
- import type { ReactElement } from 'react';
2
- import React, { useContext, useEffect, useRef } from 'react';
3
- import ReactAlpContext from 'react-alp-context';
4
- import { T } from 'react-alp-translate';
5
- import '../ConnectionState.global.scss';
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import { useEffect, useRef } from 'react';
3
+ import type { ScaledSize } from 'react-native';
4
+ import { View, StyleSheet, Platform, useWindowDimensions } from 'react-native';
6
5
 
7
- type State = null | 'connecting' | 'connected' | 'disconnected';
6
+ const defaultTheme = {
7
+ container: {
8
+ backgroundColor: 'rgba(247, 25, 0, 0.8)',
9
+ color: '#fff',
10
+ textShadowColor: '#111',
11
+ textShadowOffset: { width: 0, height: -1 },
12
+ textShadowRadius: 1,
13
+ },
14
+ backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',
15
+ };
8
16
 
9
- interface ConnectionStateProps {
17
+ export type ConnectionStateTheme = typeof defaultTheme;
18
+ export type State = null | 'connecting' | 'connected' | 'disconnected';
19
+
20
+ export interface ConnectionStateProps {
21
+ theme?: ConnectionStateTheme;
22
+ forceHidden?: boolean;
10
23
  state: State;
24
+ children: NonNullable<ReactNode>;
11
25
  }
12
26
 
13
- export default function ConnectionState({
14
- state,
15
- }: ConnectionStateProps): ReactElement {
16
- const ctx = useContext(ReactAlpContext);
17
- const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;
27
+ const zDepth1 =
28
+ '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';
29
+
30
+ type CreateCalc = (
31
+ webCalc: string,
32
+ createCalc: (dimensions: ScaledSize) => number,
33
+ ) => string | number;
34
+
35
+ const useCreateCalcNative = (): CreateCalc => {
36
+ const dimensions = useWindowDimensions();
37
+ return (webCalc, createCalc) => createCalc(dimensions);
38
+ };
39
+ const useCreateCalcWeb = (): CreateCalc => {
40
+ return (webCalc) => `calc(${webCalc})`;
41
+ };
42
+ const useCreateCalc =
43
+ Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;
44
+
45
+ // example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
18
46
 
47
+ const styles = StyleSheet.create({
48
+ connectionStateContainer: {
49
+ backgroundColor: defaultTheme.container.backgroundColor,
50
+ position: 'absolute',
51
+ top: 0,
52
+ right: 0,
53
+ left: 0,
54
+ height: 2,
55
+ color: defaultTheme.container.color,
56
+ textShadowOffset: defaultTheme.container.textShadowOffset,
57
+ textShadowRadius: defaultTheme.container.textShadowRadius,
58
+ boxShadow: zDepth1,
59
+ zIndex: 9,
60
+ transition: 'top .8s, background-color .2s',
61
+ },
62
+ hide: {
63
+ top: -24,
64
+ },
65
+ connectionStateText: {
66
+ backgroundColor: defaultTheme.container.backgroundColor,
67
+ position: 'absolute',
68
+ width: 200,
69
+ height: 22,
70
+ lineHeight: 22,
71
+ top: 2,
72
+ textAlign: 'center',
73
+ borderBottomLeftRadius: 5,
74
+ borderBottomRightRadius: 5,
75
+ transition: 'background-color .2s',
76
+ },
77
+ });
78
+
79
+ export function ConnectionState({
80
+ theme,
81
+ forceHidden,
82
+ state,
83
+ children,
84
+ }: ConnectionStateProps): ReactElement | null {
85
+ console.log({ state, forceHidden });
19
86
  const unloadingRef = useRef<boolean>(false);
20
- const currentStateRef = useRef(state);
21
- if (!unloadingRef.current) {
22
- currentStateRef.current = state;
23
- }
24
- const currentState = currentStateRef.current;
25
87
 
26
- useEffect((): (() => void) => {
88
+ const createCalc = useCreateCalc();
89
+ const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?
90
+
91
+ useEffect((): (() => void) | undefined => {
92
+ if (typeof window === 'undefined') return;
93
+
27
94
  const beforeUnloadHandler = (): void => {
28
95
  unloadingRef.current = true;
29
96
  };
@@ -34,16 +101,33 @@ export default function ConnectionState({
34
101
  };
35
102
  }, []);
36
103
 
104
+ const shouldHide = forceHidden || !state || state === 'connected';
105
+
37
106
  return (
38
- <div
39
- hidden={!state || notLoggedIn || currentState === 'connected'}
40
- className="alp-connection-state"
107
+ <View
108
+ style={[
109
+ styles.connectionStateContainer,
110
+ shouldHide && styles.hide,
111
+ theme?.container,
112
+ state === 'connected' && {
113
+ backgroundColor: (theme || defaultTheme).backgroundColorConnected,
114
+ },
115
+ ]}
41
116
  >
42
- {!state || notLoggedIn ? null : (
43
- <div>
44
- <T id={`connectionState.${currentState as string}`} />
45
- </div>
117
+ {!state ? null : (
118
+ <View
119
+ style={[
120
+ styles.connectionStateText,
121
+ theme && { backgroundColor: theme.container.backgroundColor },
122
+ state === 'connected' && {
123
+ backgroundColor: (theme || defaultTheme).backgroundColorConnected,
124
+ },
125
+ { left },
126
+ ]}
127
+ >
128
+ {children}
129
+ </View>
46
130
  )}
47
- </div>
131
+ </View>
48
132
  );
49
133
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+
4
+ "compilerOptions": {
5
+ "noEmit": true
6
+ }
7
+ }
@@ -1,37 +0,0 @@
1
- @import '~ynnub/mixins/block';
2
- @import '~ynnub/mixins/typography';
3
-
4
- $connection-state-background: rgba(247, 25, 0, 0.8) !default;
5
- $connection-state-color: #fff !default;
6
- $connection-state-text-shadow: #111 0 1px 1px !default;
7
-
8
- .alp-connection-state {
9
- background: $connection-state-background;
10
- position: fixed;
11
- top: 0;
12
- right: 0;
13
- left: 0;
14
- height: 2px;
15
- color: $connection-state-color;
16
- text-shadow: $connection-state-text-shadow;
17
- @include bold();
18
- @include z-depth-1();
19
- z-index: 9;
20
-
21
- > div {
22
- background: $connection-state-background;
23
- position: fixed;
24
- width: 200px;
25
- height: 22px;
26
- line-height: 22px;
27
- // top: 50%;
28
- top: 2px;
29
- left: 50%;
30
- // overflow: hidden;
31
- // margin-top: -25px;
32
- margin-left: -100px;
33
- text-align: center;
34
-
35
- border-radius: 0 0 5px 5px;
36
- }
37
- }