@rh-support/components 2.1.31 → 2.1.32
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/lib/cjs/hooks/index.d.ts +1 -0
- package/lib/cjs/hooks/index.d.ts.map +1 -1
- package/lib/cjs/hooks/index.js +1 -0
- package/lib/cjs/hooks/useSessionStorage.d.ts +5 -0
- package/lib/cjs/hooks/useSessionStorage.d.ts.map +1 -0
- package/lib/cjs/hooks/useSessionStorage.js +33 -0
- package/lib/esm/hooks/index.d.ts +1 -0
- package/lib/esm/hooks/index.d.ts.map +1 -1
- package/lib/esm/hooks/index.js +1 -0
- package/lib/esm/hooks/useSessionStorage.d.ts +5 -0
- package/lib/esm/hooks/useSessionStorage.d.ts.map +1 -0
- package/lib/esm/hooks/useSessionStorage.js +30 -0
- package/package.json +2 -2
package/lib/cjs/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC"}
|
package/lib/cjs/hooks/index.js
CHANGED
|
@@ -24,3 +24,4 @@ __exportStar(require("./useLRUCache"), exports);
|
|
|
24
24
|
__exportStar(require("./useBreakpoint"), exports);
|
|
25
25
|
__exportStar(require("./useOnScreen"), exports);
|
|
26
26
|
__exportStar(require("./useSelectKeyboardNavigator"), exports);
|
|
27
|
+
__exportStar(require("./useSessionStorage"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare type Dispatch<A> = (value: A) => void;
|
|
2
|
+
declare type SetStateAction<S> = S | ((prevState: S) => S);
|
|
3
|
+
declare const useSessionStorage: <T>(key: string, initialValue?: T, raw?: boolean) => [T, Dispatch<SetStateAction<T>>];
|
|
4
|
+
export { useSessionStorage };
|
|
5
|
+
//# sourceMappingURL=useSessionStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionStorage.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSessionStorage.ts"],"names":[],"mappings":"AAEA,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACtC,aAAK,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnD,QAAA,MAAM,iBAAiB,WAAY,MAAM,0BAA0B,OAAO,qCA0BzE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSessionStorage = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useSessionStorage = (key, initialValue, raw) => {
|
|
6
|
+
const [state, setState] = react_1.useState(() => {
|
|
7
|
+
try {
|
|
8
|
+
const sessionStorageValue = sessionStorage.getItem(key);
|
|
9
|
+
if (typeof sessionStorageValue !== 'string') {
|
|
10
|
+
sessionStorage.setItem(key, raw ? String(initialValue) : JSON.stringify(initialValue));
|
|
11
|
+
return initialValue;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return raw ? sessionStorageValue : JSON.parse(sessionStorageValue || 'null');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return initialValue;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
react_1.useEffect(() => {
|
|
22
|
+
try {
|
|
23
|
+
const serializedState = raw ? String(state) : JSON.stringify(state);
|
|
24
|
+
sessionStorage.setItem(key, serializedState);
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
//
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, [state]);
|
|
31
|
+
return [state, setState];
|
|
32
|
+
};
|
|
33
|
+
exports.useSessionStorage = useSessionStorage;
|
package/lib/esm/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC"}
|
package/lib/esm/hooks/index.js
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare type Dispatch<A> = (value: A) => void;
|
|
2
|
+
declare type SetStateAction<S> = S | ((prevState: S) => S);
|
|
3
|
+
declare const useSessionStorage: <T>(key: string, initialValue?: T, raw?: boolean) => [T, Dispatch<SetStateAction<T>>];
|
|
4
|
+
export { useSessionStorage };
|
|
5
|
+
//# sourceMappingURL=useSessionStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionStorage.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSessionStorage.ts"],"names":[],"mappings":"AAEA,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACtC,aAAK,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnD,QAAA,MAAM,iBAAiB,WAAY,MAAM,0BAA0B,OAAO,qCA0BzE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
const useSessionStorage = (key, initialValue, raw) => {
|
|
3
|
+
const [state, setState] = useState(() => {
|
|
4
|
+
try {
|
|
5
|
+
const sessionStorageValue = sessionStorage.getItem(key);
|
|
6
|
+
if (typeof sessionStorageValue !== 'string') {
|
|
7
|
+
sessionStorage.setItem(key, raw ? String(initialValue) : JSON.stringify(initialValue));
|
|
8
|
+
return initialValue;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return raw ? sessionStorageValue : JSON.parse(sessionStorageValue || 'null');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (_a) {
|
|
15
|
+
return initialValue;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
try {
|
|
20
|
+
const serializedState = raw ? String(state) : JSON.stringify(state);
|
|
21
|
+
sessionStorage.setItem(key, serializedState);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
//
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, [state]);
|
|
28
|
+
return [state, setState];
|
|
29
|
+
};
|
|
30
|
+
export { useSessionStorage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.32",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"defaults and supports es6-module",
|
|
117
117
|
"maintained node versions"
|
|
118
118
|
],
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "462d269eaba23f3e9b735caf2157f24f2a841da2"
|
|
120
120
|
}
|