@equinor/cpl-loading-react 0.2.5
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/LICENCE +21 -0
- package/README.md +9 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +109 -0
- package/dist/index.mjs +72 -0
- package/package.json +44 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Equinor ASA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
interface LoadingContainerProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
isInitialLoading: boolean;
|
|
7
|
+
isFetching: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* @default
|
|
10
|
+
* tokens.colors.ui.background__default.rgba
|
|
11
|
+
*/
|
|
12
|
+
loadingOverlayBackgroundColor?: CSSProperties['backgroundColor'];
|
|
13
|
+
}
|
|
14
|
+
declare function LoadingContainer({ isInitialLoading, isFetching, children, loadingOverlayBackgroundColor, }: LoadingContainerProps): react_jsx_runtime.JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { LoadingContainer, type LoadingContainerProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
interface LoadingContainerProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
isInitialLoading: boolean;
|
|
7
|
+
isFetching: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* @default
|
|
10
|
+
* tokens.colors.ui.background__default.rgba
|
|
11
|
+
*/
|
|
12
|
+
loadingOverlayBackgroundColor?: CSSProperties['backgroundColor'];
|
|
13
|
+
}
|
|
14
|
+
declare function LoadingContainer({ isInitialLoading, isFetching, children, loadingOverlayBackgroundColor, }: LoadingContainerProps): react_jsx_runtime.JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { LoadingContainer, type LoadingContainerProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
LoadingContainer: () => LoadingContainer
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/LoadingContainer.tsx
|
|
38
|
+
var import_eds_core_react = require("@equinor/eds-core-react");
|
|
39
|
+
var import_eds_tokens = require("@equinor/eds-tokens");
|
|
40
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
function LoadingContainer({
|
|
43
|
+
isInitialLoading = false,
|
|
44
|
+
isFetching = false,
|
|
45
|
+
children,
|
|
46
|
+
loadingOverlayBackgroundColor = import_eds_tokens.tokens.colors.ui.background__default.rgba
|
|
47
|
+
}) {
|
|
48
|
+
const isLoading = isInitialLoading || isFetching;
|
|
49
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Wrapper, { children: [
|
|
50
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
51
|
+
LoadingOverlay,
|
|
52
|
+
{
|
|
53
|
+
className: isLoading ? "open" : void 0,
|
|
54
|
+
$isInitialLoading: isInitialLoading,
|
|
55
|
+
$backgroundColor: loadingOverlayBackgroundColor,
|
|
56
|
+
children: isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_eds_core_react.CircularProgress, { size: 32 })
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockInteractionContainer, { children }) : children
|
|
60
|
+
] });
|
|
61
|
+
}
|
|
62
|
+
var Wrapper = import_styled_components.default.div`
|
|
63
|
+
position: relative;
|
|
64
|
+
z-index: 0;
|
|
65
|
+
`;
|
|
66
|
+
var BlockInteractionContainer = import_styled_components.default.div`
|
|
67
|
+
pointer-events: none;
|
|
68
|
+
user-select: none;
|
|
69
|
+
`;
|
|
70
|
+
var LoadingOverlay = import_styled_components.default.div`
|
|
71
|
+
position: absolute;
|
|
72
|
+
z-index: 10;
|
|
73
|
+
top: 0;
|
|
74
|
+
left: 0;
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: 100%;
|
|
77
|
+
|
|
78
|
+
display: none;
|
|
79
|
+
opacity: 0;
|
|
80
|
+
background-color: rgb(from ${({ $backgroundColor }) => $backgroundColor} r g b / 0);
|
|
81
|
+
|
|
82
|
+
transition-property: background-color, opacity, display, backdrop-filter;
|
|
83
|
+
transition-duration: 0.25s;
|
|
84
|
+
transition-behavior: allow-discrete;
|
|
85
|
+
|
|
86
|
+
&.open {
|
|
87
|
+
// Default prettier formatting results in ts-styled-plugin error
|
|
88
|
+
// prettier-ignore
|
|
89
|
+
background-color: rgb(from ${({ $backgroundColor }) => $backgroundColor} r g b /${({
|
|
90
|
+
$isInitialLoading
|
|
91
|
+
}) => $isInitialLoading ? 1 : 0.8});
|
|
92
|
+
opacity: 1;
|
|
93
|
+
display: flex;
|
|
94
|
+
${({ $isInitialLoading }) => $isInitialLoading ? "" : "backdrop-filter: blur(1px)"};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
align-items: center;
|
|
98
|
+
justify-content: center;
|
|
99
|
+
|
|
100
|
+
@starting-style {
|
|
101
|
+
&.open {
|
|
102
|
+
opacity: ${({ $isInitialLoading }) => $isInitialLoading ? 1 : 0};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
LoadingContainer
|
|
109
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/LoadingContainer.tsx
|
|
2
|
+
import { CircularProgress } from "@equinor/eds-core-react";
|
|
3
|
+
import { tokens } from "@equinor/eds-tokens";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function LoadingContainer({
|
|
7
|
+
isInitialLoading = false,
|
|
8
|
+
isFetching = false,
|
|
9
|
+
children,
|
|
10
|
+
loadingOverlayBackgroundColor = tokens.colors.ui.background__default.rgba
|
|
11
|
+
}) {
|
|
12
|
+
const isLoading = isInitialLoading || isFetching;
|
|
13
|
+
return /* @__PURE__ */ jsxs(Wrapper, { children: [
|
|
14
|
+
/* @__PURE__ */ jsx(
|
|
15
|
+
LoadingOverlay,
|
|
16
|
+
{
|
|
17
|
+
className: isLoading ? "open" : void 0,
|
|
18
|
+
$isInitialLoading: isInitialLoading,
|
|
19
|
+
$backgroundColor: loadingOverlayBackgroundColor,
|
|
20
|
+
children: isLoading && /* @__PURE__ */ jsx(CircularProgress, { size: 32 })
|
|
21
|
+
}
|
|
22
|
+
),
|
|
23
|
+
isLoading ? /* @__PURE__ */ jsx(BlockInteractionContainer, { children }) : children
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
var Wrapper = styled.div`
|
|
27
|
+
position: relative;
|
|
28
|
+
z-index: 0;
|
|
29
|
+
`;
|
|
30
|
+
var BlockInteractionContainer = styled.div`
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
user-select: none;
|
|
33
|
+
`;
|
|
34
|
+
var LoadingOverlay = styled.div`
|
|
35
|
+
position: absolute;
|
|
36
|
+
z-index: 10;
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
width: 100%;
|
|
40
|
+
height: 100%;
|
|
41
|
+
|
|
42
|
+
display: none;
|
|
43
|
+
opacity: 0;
|
|
44
|
+
background-color: rgb(from ${({ $backgroundColor }) => $backgroundColor} r g b / 0);
|
|
45
|
+
|
|
46
|
+
transition-property: background-color, opacity, display, backdrop-filter;
|
|
47
|
+
transition-duration: 0.25s;
|
|
48
|
+
transition-behavior: allow-discrete;
|
|
49
|
+
|
|
50
|
+
&.open {
|
|
51
|
+
// Default prettier formatting results in ts-styled-plugin error
|
|
52
|
+
// prettier-ignore
|
|
53
|
+
background-color: rgb(from ${({ $backgroundColor }) => $backgroundColor} r g b /${({
|
|
54
|
+
$isInitialLoading
|
|
55
|
+
}) => $isInitialLoading ? 1 : 0.8});
|
|
56
|
+
opacity: 1;
|
|
57
|
+
display: flex;
|
|
58
|
+
${({ $isInitialLoading }) => $isInitialLoading ? "" : "backdrop-filter: blur(1px)"};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
|
|
64
|
+
@starting-style {
|
|
65
|
+
&.open {
|
|
66
|
+
opacity: ${({ $isInitialLoading }) => $isInitialLoading ? 1 : 0};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
export {
|
|
71
|
+
LoadingContainer
|
|
72
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/cpl-loading-react",
|
|
3
|
+
"version": "0.2.5",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/**"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@equinor/eds-tokens": "^0.9.2"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@equinor/eds-core-react": "^0.42.5",
|
|
16
|
+
"@storybook/react": "^8.5.2",
|
|
17
|
+
"@storybook/test": "^8.5.2",
|
|
18
|
+
"@types/react": "^18.3.18",
|
|
19
|
+
"@types/react-dom": "^18.3.5",
|
|
20
|
+
"@types/styled-components": "^5.1.34",
|
|
21
|
+
"eslint": "^9.21.0",
|
|
22
|
+
"react": "^18.2.0",
|
|
23
|
+
"react-dom": "^18.2.0",
|
|
24
|
+
"styled-components": "^6.1.14",
|
|
25
|
+
"tsup": "^8.3.6",
|
|
26
|
+
"eslint-config-custom": "0.0.7",
|
|
27
|
+
"tsconfig": "0.0.1"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@equinor/eds-core-react": ">=0.42.1",
|
|
31
|
+
"react": ">=18.2.0",
|
|
32
|
+
"react-dom": ">=18.2.0",
|
|
33
|
+
"styled-components": ">=5.3.11"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
|
40
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
41
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
|
|
42
|
+
"lint": "TIMING=1 eslint . --fix"
|
|
43
|
+
}
|
|
44
|
+
}
|