@sproutsocial/seeds-react-loader 1.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/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +7 -0
- package/dist/esm/index.js +118 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +43 -0
- package/src/Loader.stories.tsx +32 -0
- package/src/Loader.tsx +27 -0
- package/src/LoaderTypes.ts +21 -0
- package/src/__tests__/Loader.typetest.tsx +13 -0
- package/src/__tests__/features.test.tsx +30 -0
- package/src/index.ts +5 -0
- package/src/styled.d.ts +7 -0
- package/src/styles.ts +102 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +12 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
yarn run v1.22.22
|
|
2
|
+
$ tsup --dts
|
|
3
|
+
CLI Building entry: src/index.ts
|
|
4
|
+
CLI Using tsconfig: tsconfig.json
|
|
5
|
+
CLI tsup v8.0.2
|
|
6
|
+
CLI Using tsup config: /home/runner/work/seeds/seeds/seeds-react/seeds-react-loader/tsup.config.ts
|
|
7
|
+
CLI Target: es2022
|
|
8
|
+
CLI Cleaning output folder
|
|
9
|
+
CJS Build start
|
|
10
|
+
ESM Build start
|
|
11
|
+
CJS dist/index.js 4.52 KB
|
|
12
|
+
CJS dist/index.js.map 4.67 KB
|
|
13
|
+
CJS ⚡️ Build success in 100ms
|
|
14
|
+
ESM dist/esm/index.js 2.58 KB
|
|
15
|
+
ESM dist/esm/index.js.map 4.62 KB
|
|
16
|
+
ESM ⚡️ Build success in 106ms
|
|
17
|
+
DTS Build start
|
|
18
|
+
DTS ⚡️ Build success in 38352ms
|
|
19
|
+
DTS dist/index.d.ts 833.00 B
|
|
20
|
+
DTS dist/index.d.mts 833.00 B
|
|
21
|
+
Done in 43.01s.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/Loader.tsx
|
|
2
|
+
import "react";
|
|
3
|
+
|
|
4
|
+
// src/styles.ts
|
|
5
|
+
import styled, { css, keyframes } from "styled-components";
|
|
6
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
7
|
+
import { visuallyHidden } from "@sproutsocial/seeds-react-mixins";
|
|
8
|
+
var getSize = (size) => {
|
|
9
|
+
const spinnerSize = Math.round(size * 1);
|
|
10
|
+
const borderWidth = Math.round(size * 0.1);
|
|
11
|
+
return css`
|
|
12
|
+
width: ${size}px;
|
|
13
|
+
height: ${size}px;
|
|
14
|
+
box-shadow: ${({ theme }) => `0 0 0 2px ${theme.colors.neutral[600]},
|
|
15
|
+
inset 0 0 0 ${borderWidth + 2}px ${theme.colors.neutral[600]}`};
|
|
16
|
+
|
|
17
|
+
&:after {
|
|
18
|
+
width: ${spinnerSize}px;
|
|
19
|
+
height: ${spinnerSize}px;
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
border-width: ${borderWidth}px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.no-cssanimations &::after {
|
|
25
|
+
background-size: ${spinnerSize}px;
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
};
|
|
29
|
+
var spin = keyframes`
|
|
30
|
+
from {
|
|
31
|
+
transform: translate(-50%,-50%) rotate(0deg);
|
|
32
|
+
}
|
|
33
|
+
to {
|
|
34
|
+
transform: translate(-50%,-50%) rotate(360deg);
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
var delayAnimation = keyframes`
|
|
38
|
+
0% {
|
|
39
|
+
opacity: 0;
|
|
40
|
+
}
|
|
41
|
+
80% {
|
|
42
|
+
opacity: 0;
|
|
43
|
+
}
|
|
44
|
+
100% {
|
|
45
|
+
opacity: 1;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
var Container = styled.div.attrs({
|
|
49
|
+
className: "Loader"
|
|
50
|
+
})`
|
|
51
|
+
position: relative;
|
|
52
|
+
margin: 0 auto;
|
|
53
|
+
padding: 0;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
border-radius: 100%;
|
|
56
|
+
|
|
57
|
+
animation: ${(props) => props.delay ? css`
|
|
58
|
+
${delayAnimation} 2s 1;
|
|
59
|
+
` : "none"};
|
|
60
|
+
|
|
61
|
+
&:after {
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: 50%;
|
|
64
|
+
left: 50%;
|
|
65
|
+
background: transparent;
|
|
66
|
+
border-style: solid;
|
|
67
|
+
border-radius: 100%;
|
|
68
|
+
content: "";
|
|
69
|
+
transition: opacity 250ms;
|
|
70
|
+
border-color: ${({ theme }) => `${theme.colors.neutral[0]} ${theme.colors.neutral[0]} ${theme.colors.neutral[600]} ${theme.colors.neutral[600]}`};
|
|
71
|
+
|
|
72
|
+
animation: ${(props) => props.delay ? css`
|
|
73
|
+
${spin} 2.25s infinite linear, ${delayAnimation} 2s 1
|
|
74
|
+
` : css`
|
|
75
|
+
${spin} 2.25s infinite linear
|
|
76
|
+
`};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
${(props) => props.small ? getSize(20) : getSize(40)}
|
|
80
|
+
${COMMON}
|
|
81
|
+
`;
|
|
82
|
+
var Text = styled.div`
|
|
83
|
+
${visuallyHidden}
|
|
84
|
+
`;
|
|
85
|
+
var styles_default = Container;
|
|
86
|
+
|
|
87
|
+
// src/Loader.tsx
|
|
88
|
+
import { jsx } from "react/jsx-runtime";
|
|
89
|
+
var Loader = ({
|
|
90
|
+
size = "large",
|
|
91
|
+
text = "",
|
|
92
|
+
delay = true,
|
|
93
|
+
color = "dark",
|
|
94
|
+
qa,
|
|
95
|
+
...rest
|
|
96
|
+
}) => {
|
|
97
|
+
return /* @__PURE__ */ jsx(
|
|
98
|
+
styles_default,
|
|
99
|
+
{
|
|
100
|
+
small: size === "small",
|
|
101
|
+
dark: color === "dark",
|
|
102
|
+
delay,
|
|
103
|
+
"data-qa-loader": "",
|
|
104
|
+
...qa,
|
|
105
|
+
...rest,
|
|
106
|
+
children: /* @__PURE__ */ jsx(Text, { children: text || "Loading" })
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
var Loader_default = Loader;
|
|
111
|
+
|
|
112
|
+
// src/index.ts
|
|
113
|
+
var src_default = Loader_default;
|
|
114
|
+
export {
|
|
115
|
+
Loader_default as Loader,
|
|
116
|
+
src_default as default
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Loader.tsx","../../src/styles.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport Container, { Text } from \"./styles\";\nimport type { TypeLoaderProps } from \"./LoaderTypes\";\n\nconst Loader = ({\n size = \"large\",\n text = \"\",\n delay = true,\n color = \"dark\",\n qa,\n ...rest\n}: TypeLoaderProps) => {\n return (\n <Container\n small={size === \"small\"}\n dark={color === \"dark\"}\n delay={delay}\n data-qa-loader=\"\"\n {...qa}\n {...rest}\n >\n <Text>{text || \"Loading\"}</Text>\n </Container>\n );\n};\n\nexport default Loader;\n","import styled, { css, keyframes } from \"styled-components\";\nimport { COMMON } from \"@sproutsocial/seeds-react-system-props\";\nimport { visuallyHidden } from \"@sproutsocial/seeds-react-mixins\";\nimport type { TypeLoaderProps } from \"./LoaderTypes\";\n\nconst getSize = (size: number) => {\n const spinnerSize = Math.round(size * 1);\n const borderWidth = Math.round(size * 0.1);\n\n return css`\n width: ${size}px;\n height: ${size}px;\n box-shadow: ${({ theme }) =>\n `0 0 0 2px ${theme.colors.neutral[600]}, \n inset 0 0 0 ${borderWidth + 2}px ${theme.colors.neutral[600]}`};\n\n &:after {\n width: ${spinnerSize}px;\n height: ${spinnerSize}px;\n box-sizing: border-box;\n border-width: ${borderWidth}px;\n }\n\n .no-cssanimations &::after {\n background-size: ${spinnerSize}px;\n }\n `;\n};\n\nconst spin = keyframes`\n from {\n transform: translate(-50%,-50%) rotate(0deg);\n }\n to {\n transform: translate(-50%,-50%) rotate(360deg);\n }\n`;\n\nconst delayAnimation = keyframes`\n 0% {\n opacity: 0;\n }\n 80% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n`;\n\ninterface TypeLoaderContainer extends Pick<TypeLoaderProps, \"delay\"> {\n small?: boolean;\n dark?: boolean;\n}\n\nconst Container = styled.div.attrs<{ className: string }>({\n className: \"Loader\",\n})<TypeLoaderContainer>`\n position: relative;\n margin: 0 auto;\n padding: 0;\n overflow: hidden;\n border-radius: 100%;\n\n animation: ${(props) =>\n props.delay\n ? css`\n ${delayAnimation} 2s 1;\n `\n : \"none\"};\n\n &:after {\n position: absolute;\n top: 50%;\n left: 50%;\n background: transparent;\n border-style: solid;\n border-radius: 100%;\n content: \"\";\n transition: opacity 250ms;\n border-color: ${({ theme }) =>\n `${theme.colors.neutral[0]} ${theme.colors.neutral[0]} ${theme.colors.neutral[600]} ${theme.colors.neutral[600]}`};\n\n animation: ${(props) =>\n props.delay\n ? css`\n ${spin} 2.25s infinite linear, ${delayAnimation} 2s 1\n `\n : css`\n ${spin} 2.25s infinite linear\n `};\n }\n\n ${(props) => (props.small ? getSize(20) : getSize(40))}\n ${COMMON}\n`;\n\nexport const Text = styled.div<Pick<TypeLoaderProps, \"text\">>`\n ${visuallyHidden}\n`;\n\nexport default Container;\n","import Loader from \"./Loader\";\n\nexport default Loader;\nexport { Loader };\nexport * from \"./LoaderTypes\";\n"],"mappings":";AAAA,OAAuB;;;ACAvB,OAAO,UAAU,KAAK,iBAAiB;AACvC,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAG/B,IAAM,UAAU,CAAC,SAAiB;AAChC,QAAM,cAAc,KAAK,MAAM,OAAO,CAAC;AACvC,QAAM,cAAc,KAAK,MAAM,OAAO,GAAG;AAEzC,SAAO;AAAA,aACI,IAAI;AAAA,cACH,IAAI;AAAA,kBACA,CAAC,EAAE,MAAM,MACrB,aAAa,MAAM,OAAO,QAAQ,GAAG,CAAC;AAAA,oBACxB,cAAc,CAAC,MAAM,MAAM,OAAO,QAAQ,GAAG,CAAC,EAAE;AAAA;AAAA;AAAA,eAGrD,WAAW;AAAA,gBACV,WAAW;AAAA;AAAA,sBAEL,WAAW;AAAA;AAAA;AAAA;AAAA,yBAIR,WAAW;AAAA;AAAA;AAGpC;AAEA,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASb,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBvB,IAAM,YAAY,OAAO,IAAI,MAA6B;AAAA,EACxD,WAAW;AACb,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAOc,CAAC,UACZ,MAAM,QACF;AAAA,YACI,cAAc;AAAA,YAElB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAWM,CAAC,EAAE,MAAM,MACvB,GAAG,MAAM,OAAO,QAAQ,CAAC,CAAC,IAAI,MAAM,OAAO,QAAQ,CAAC,CAAC,IAAI,MAAM,OAAO,QAAQ,GAAG,CAAC,IAAI,MAAM,OAAO,QAAQ,GAAG,CAAC,EAAE;AAAA;AAAA,iBAEtG,CAAC,UACZ,MAAM,QACF;AAAA,cACI,IAAI,2BAA2B,cAAc;AAAA,cAEjD;AAAA,cACI,IAAI;AAAA,WACP;AAAA;AAAA;AAAA,IAGP,CAAC,UAAW,MAAM,QAAQ,QAAQ,EAAE,IAAI,QAAQ,EAAE,CAAE;AAAA,IACpD,MAAM;AAAA;AAGH,IAAM,OAAO,OAAO;AAAA,IACvB,cAAc;AAAA;AAGlB,IAAO,iBAAQ;;;ADhFT;AAjBN,IAAM,SAAS,CAAC;AAAA,EACd,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR;AAAA,EACA,GAAG;AACL,MAAuB;AACrB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,SAAS;AAAA,MAChB,MAAM,UAAU;AAAA,MAChB;AAAA,MACA,kBAAe;AAAA,MACd,GAAG;AAAA,MACH,GAAG;AAAA,MAEJ,8BAAC,QAAM,kBAAQ,WAAU;AAAA;AAAA,EAC3B;AAEJ;AAEA,IAAO,iBAAQ;;;AExBf,IAAO,cAAQ;","names":[]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { TypeStyledComponentsCommonProps, TypeSystemCommonProps } from '@sproutsocial/seeds-react-system-props';
|
|
3
|
+
|
|
4
|
+
type TypeQaProps = object;
|
|
5
|
+
interface TypeLoaderProps extends TypeStyledComponentsCommonProps, TypeSystemCommonProps, Omit<React.ComponentPropsWithoutRef<"div">, keyof TypeSystemCommonProps> {
|
|
6
|
+
size?: "small" | "large";
|
|
7
|
+
/** Text for the loader. This text is not visible, but is used for accessibility purposed */
|
|
8
|
+
text?: string;
|
|
9
|
+
/** Whether the loader should wait 2 seconds before it displays */
|
|
10
|
+
delay?: boolean;
|
|
11
|
+
color?: "light" | "dark";
|
|
12
|
+
qa?: TypeQaProps;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const Loader: ({ size, text, delay, color, qa, ...rest }: TypeLoaderProps) => react_jsx_runtime.JSX.Element;
|
|
16
|
+
|
|
17
|
+
export { Loader, type TypeLoaderProps, Loader as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { TypeStyledComponentsCommonProps, TypeSystemCommonProps } from '@sproutsocial/seeds-react-system-props';
|
|
3
|
+
|
|
4
|
+
type TypeQaProps = object;
|
|
5
|
+
interface TypeLoaderProps extends TypeStyledComponentsCommonProps, TypeSystemCommonProps, Omit<React.ComponentPropsWithoutRef<"div">, keyof TypeSystemCommonProps> {
|
|
6
|
+
size?: "small" | "large";
|
|
7
|
+
/** Text for the loader. This text is not visible, but is used for accessibility purposed */
|
|
8
|
+
text?: string;
|
|
9
|
+
/** Whether the loader should wait 2 seconds before it displays */
|
|
10
|
+
delay?: boolean;
|
|
11
|
+
color?: "light" | "dark";
|
|
12
|
+
qa?: TypeQaProps;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const Loader: ({ size, text, delay, color, qa, ...rest }: TypeLoaderProps) => react_jsx_runtime.JSX.Element;
|
|
16
|
+
|
|
17
|
+
export { Loader, type TypeLoaderProps, Loader as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
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 src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Loader: () => Loader_default,
|
|
34
|
+
default: () => src_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/Loader.tsx
|
|
39
|
+
var React = require("react");
|
|
40
|
+
|
|
41
|
+
// src/styles.ts
|
|
42
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
43
|
+
var import_seeds_react_system_props = require("@sproutsocial/seeds-react-system-props");
|
|
44
|
+
var import_seeds_react_mixins = require("@sproutsocial/seeds-react-mixins");
|
|
45
|
+
var getSize = (size) => {
|
|
46
|
+
const spinnerSize = Math.round(size * 1);
|
|
47
|
+
const borderWidth = Math.round(size * 0.1);
|
|
48
|
+
return import_styled_components.css`
|
|
49
|
+
width: ${size}px;
|
|
50
|
+
height: ${size}px;
|
|
51
|
+
box-shadow: ${({ theme }) => `0 0 0 2px ${theme.colors.neutral[600]},
|
|
52
|
+
inset 0 0 0 ${borderWidth + 2}px ${theme.colors.neutral[600]}`};
|
|
53
|
+
|
|
54
|
+
&:after {
|
|
55
|
+
width: ${spinnerSize}px;
|
|
56
|
+
height: ${spinnerSize}px;
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
border-width: ${borderWidth}px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.no-cssanimations &::after {
|
|
62
|
+
background-size: ${spinnerSize}px;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
};
|
|
66
|
+
var spin = import_styled_components.keyframes`
|
|
67
|
+
from {
|
|
68
|
+
transform: translate(-50%,-50%) rotate(0deg);
|
|
69
|
+
}
|
|
70
|
+
to {
|
|
71
|
+
transform: translate(-50%,-50%) rotate(360deg);
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
var delayAnimation = import_styled_components.keyframes`
|
|
75
|
+
0% {
|
|
76
|
+
opacity: 0;
|
|
77
|
+
}
|
|
78
|
+
80% {
|
|
79
|
+
opacity: 0;
|
|
80
|
+
}
|
|
81
|
+
100% {
|
|
82
|
+
opacity: 1;
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
var Container = import_styled_components.default.div.attrs({
|
|
86
|
+
className: "Loader"
|
|
87
|
+
})`
|
|
88
|
+
position: relative;
|
|
89
|
+
margin: 0 auto;
|
|
90
|
+
padding: 0;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
border-radius: 100%;
|
|
93
|
+
|
|
94
|
+
animation: ${(props) => props.delay ? import_styled_components.css`
|
|
95
|
+
${delayAnimation} 2s 1;
|
|
96
|
+
` : "none"};
|
|
97
|
+
|
|
98
|
+
&:after {
|
|
99
|
+
position: absolute;
|
|
100
|
+
top: 50%;
|
|
101
|
+
left: 50%;
|
|
102
|
+
background: transparent;
|
|
103
|
+
border-style: solid;
|
|
104
|
+
border-radius: 100%;
|
|
105
|
+
content: "";
|
|
106
|
+
transition: opacity 250ms;
|
|
107
|
+
border-color: ${({ theme }) => `${theme.colors.neutral[0]} ${theme.colors.neutral[0]} ${theme.colors.neutral[600]} ${theme.colors.neutral[600]}`};
|
|
108
|
+
|
|
109
|
+
animation: ${(props) => props.delay ? import_styled_components.css`
|
|
110
|
+
${spin} 2.25s infinite linear, ${delayAnimation} 2s 1
|
|
111
|
+
` : import_styled_components.css`
|
|
112
|
+
${spin} 2.25s infinite linear
|
|
113
|
+
`};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
${(props) => props.small ? getSize(20) : getSize(40)}
|
|
117
|
+
${import_seeds_react_system_props.COMMON}
|
|
118
|
+
`;
|
|
119
|
+
var Text = import_styled_components.default.div`
|
|
120
|
+
${import_seeds_react_mixins.visuallyHidden}
|
|
121
|
+
`;
|
|
122
|
+
var styles_default = Container;
|
|
123
|
+
|
|
124
|
+
// src/Loader.tsx
|
|
125
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
126
|
+
var Loader = ({
|
|
127
|
+
size = "large",
|
|
128
|
+
text = "",
|
|
129
|
+
delay = true,
|
|
130
|
+
color = "dark",
|
|
131
|
+
qa,
|
|
132
|
+
...rest
|
|
133
|
+
}) => {
|
|
134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
135
|
+
styles_default,
|
|
136
|
+
{
|
|
137
|
+
small: size === "small",
|
|
138
|
+
dark: color === "dark",
|
|
139
|
+
delay,
|
|
140
|
+
"data-qa-loader": "",
|
|
141
|
+
...qa,
|
|
142
|
+
...rest,
|
|
143
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: text || "Loading" })
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
var Loader_default = Loader;
|
|
148
|
+
|
|
149
|
+
// src/index.ts
|
|
150
|
+
var src_default = Loader_default;
|
|
151
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
152
|
+
0 && (module.exports = {
|
|
153
|
+
Loader
|
|
154
|
+
});
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Loader.tsx","../src/styles.ts"],"sourcesContent":["import Loader from \"./Loader\";\n\nexport default Loader;\nexport { Loader };\nexport * from \"./LoaderTypes\";\n","import * as React from \"react\";\nimport Container, { Text } from \"./styles\";\nimport type { TypeLoaderProps } from \"./LoaderTypes\";\n\nconst Loader = ({\n size = \"large\",\n text = \"\",\n delay = true,\n color = \"dark\",\n qa,\n ...rest\n}: TypeLoaderProps) => {\n return (\n <Container\n small={size === \"small\"}\n dark={color === \"dark\"}\n delay={delay}\n data-qa-loader=\"\"\n {...qa}\n {...rest}\n >\n <Text>{text || \"Loading\"}</Text>\n </Container>\n );\n};\n\nexport default Loader;\n","import styled, { css, keyframes } from \"styled-components\";\nimport { COMMON } from \"@sproutsocial/seeds-react-system-props\";\nimport { visuallyHidden } from \"@sproutsocial/seeds-react-mixins\";\nimport type { TypeLoaderProps } from \"./LoaderTypes\";\n\nconst getSize = (size: number) => {\n const spinnerSize = Math.round(size * 1);\n const borderWidth = Math.round(size * 0.1);\n\n return css`\n width: ${size}px;\n height: ${size}px;\n box-shadow: ${({ theme }) =>\n `0 0 0 2px ${theme.colors.neutral[600]}, \n inset 0 0 0 ${borderWidth + 2}px ${theme.colors.neutral[600]}`};\n\n &:after {\n width: ${spinnerSize}px;\n height: ${spinnerSize}px;\n box-sizing: border-box;\n border-width: ${borderWidth}px;\n }\n\n .no-cssanimations &::after {\n background-size: ${spinnerSize}px;\n }\n `;\n};\n\nconst spin = keyframes`\n from {\n transform: translate(-50%,-50%) rotate(0deg);\n }\n to {\n transform: translate(-50%,-50%) rotate(360deg);\n }\n`;\n\nconst delayAnimation = keyframes`\n 0% {\n opacity: 0;\n }\n 80% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n`;\n\ninterface TypeLoaderContainer extends Pick<TypeLoaderProps, \"delay\"> {\n small?: boolean;\n dark?: boolean;\n}\n\nconst Container = styled.div.attrs<{ className: string }>({\n className: \"Loader\",\n})<TypeLoaderContainer>`\n position: relative;\n margin: 0 auto;\n padding: 0;\n overflow: hidden;\n border-radius: 100%;\n\n animation: ${(props) =>\n props.delay\n ? css`\n ${delayAnimation} 2s 1;\n `\n : \"none\"};\n\n &:after {\n position: absolute;\n top: 50%;\n left: 50%;\n background: transparent;\n border-style: solid;\n border-radius: 100%;\n content: \"\";\n transition: opacity 250ms;\n border-color: ${({ theme }) =>\n `${theme.colors.neutral[0]} ${theme.colors.neutral[0]} ${theme.colors.neutral[600]} ${theme.colors.neutral[600]}`};\n\n animation: ${(props) =>\n props.delay\n ? css`\n ${spin} 2.25s infinite linear, ${delayAnimation} 2s 1\n `\n : css`\n ${spin} 2.25s infinite linear\n `};\n }\n\n ${(props) => (props.small ? getSize(20) : getSize(40))}\n ${COMMON}\n`;\n\nexport const Text = styled.div<Pick<TypeLoaderProps, \"text\">>`\n ${visuallyHidden}\n`;\n\nexport default Container;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;;;ACAvB,+BAAuC;AACvC,sCAAuB;AACvB,gCAA+B;AAG/B,IAAM,UAAU,CAAC,SAAiB;AAChC,QAAM,cAAc,KAAK,MAAM,OAAO,CAAC;AACvC,QAAM,cAAc,KAAK,MAAM,OAAO,GAAG;AAEzC,SAAO;AAAA,aACI,IAAI;AAAA,cACH,IAAI;AAAA,kBACA,CAAC,EAAE,MAAM,MACrB,aAAa,MAAM,OAAO,QAAQ,GAAG,CAAC;AAAA,oBACxB,cAAc,CAAC,MAAM,MAAM,OAAO,QAAQ,GAAG,CAAC,EAAE;AAAA;AAAA;AAAA,eAGrD,WAAW;AAAA,gBACV,WAAW;AAAA;AAAA,sBAEL,WAAW;AAAA;AAAA;AAAA;AAAA,yBAIR,WAAW;AAAA;AAAA;AAGpC;AAEA,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASb,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBvB,IAAM,YAAY,yBAAAA,QAAO,IAAI,MAA6B;AAAA,EACxD,WAAW;AACb,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAOc,CAAC,UACZ,MAAM,QACF;AAAA,YACI,cAAc;AAAA,YAElB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAWM,CAAC,EAAE,MAAM,MACvB,GAAG,MAAM,OAAO,QAAQ,CAAC,CAAC,IAAI,MAAM,OAAO,QAAQ,CAAC,CAAC,IAAI,MAAM,OAAO,QAAQ,GAAG,CAAC,IAAI,MAAM,OAAO,QAAQ,GAAG,CAAC,EAAE;AAAA;AAAA,iBAEtG,CAAC,UACZ,MAAM,QACF;AAAA,cACI,IAAI,2BAA2B,cAAc;AAAA,cAEjD;AAAA,cACI,IAAI;AAAA,WACP;AAAA;AAAA;AAAA,IAGP,CAAC,UAAW,MAAM,QAAQ,QAAQ,EAAE,IAAI,QAAQ,EAAE,CAAE;AAAA,IACpD,sCAAM;AAAA;AAGH,IAAM,OAAO,yBAAAA,QAAO;AAAA,IACvB,wCAAc;AAAA;AAGlB,IAAO,iBAAQ;;;ADhFT;AAjBN,IAAM,SAAS,CAAC;AAAA,EACd,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR;AAAA,EACA,GAAG;AACL,MAAuB;AACrB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,SAAS;AAAA,MAChB,MAAM,UAAU;AAAA,MAChB;AAAA,MACA,kBAAe;AAAA,MACd,GAAG;AAAA,MACH,GAAG;AAAA,MAEJ,sDAAC,QAAM,kBAAQ,WAAU;AAAA;AAAA,EAC3B;AAEJ;AAEA,IAAO,iBAAQ;;;ADxBf,IAAO,cAAQ;","names":["styled"]}
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sproutsocial/seeds-react-loader",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Seeds React Loader",
|
|
5
|
+
"author": "Sprout Social, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup --dts",
|
|
12
|
+
"build:debug": "tsup --dts --metafile",
|
|
13
|
+
"dev": "tsup --watch --dts",
|
|
14
|
+
"clean": "rm -rf .turbo dist",
|
|
15
|
+
"clean:modules": "rm -rf node_modules",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"test:watch": "jest --watch --coverage=false"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@sproutsocial/seeds-react-theme": "^*",
|
|
22
|
+
"@sproutsocial/seeds-react-system-props": "^*",
|
|
23
|
+
"@sproutsocial/seeds-react-mixins": "^*"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^18.0.0",
|
|
27
|
+
"@types/styled-components": "^5.1.26",
|
|
28
|
+
"@sproutsocial/eslint-config-seeds": "*",
|
|
29
|
+
"react": "^18.0.0",
|
|
30
|
+
"styled-components": "^5.2.3",
|
|
31
|
+
"tsup": "^8.0.2",
|
|
32
|
+
"typescript": "^5.6.2",
|
|
33
|
+
"@sproutsocial/seeds-tsconfig": "*",
|
|
34
|
+
"@sproutsocial/seeds-testing": "*",
|
|
35
|
+
"@sproutsocial/seeds-react-testing-library": "*"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"styled-components": "^5.2.3"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Loader } from "./";
|
|
3
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Loader> = {
|
|
6
|
+
title: "Components/Loader",
|
|
7
|
+
component: Loader,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default meta;
|
|
11
|
+
|
|
12
|
+
type Story = StoryObj<typeof Loader>;
|
|
13
|
+
|
|
14
|
+
export const Default: Story = {
|
|
15
|
+
args: {
|
|
16
|
+
text: "Content loading",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const Small: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
text: "Content loading",
|
|
23
|
+
size: "small",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const NoDelay: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
text: "Content loading",
|
|
30
|
+
delay: false,
|
|
31
|
+
},
|
|
32
|
+
};
|
package/src/Loader.tsx
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Container, { Text } from "./styles";
|
|
3
|
+
import type { TypeLoaderProps } from "./LoaderTypes";
|
|
4
|
+
|
|
5
|
+
const Loader = ({
|
|
6
|
+
size = "large",
|
|
7
|
+
text = "",
|
|
8
|
+
delay = true,
|
|
9
|
+
color = "dark",
|
|
10
|
+
qa,
|
|
11
|
+
...rest
|
|
12
|
+
}: TypeLoaderProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<Container
|
|
15
|
+
small={size === "small"}
|
|
16
|
+
dark={color === "dark"}
|
|
17
|
+
delay={delay}
|
|
18
|
+
data-qa-loader=""
|
|
19
|
+
{...qa}
|
|
20
|
+
{...rest}
|
|
21
|
+
>
|
|
22
|
+
<Text>{text || "Loading"}</Text>
|
|
23
|
+
</Container>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default Loader;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TypeStyledComponentsCommonProps,
|
|
3
|
+
TypeSystemCommonProps,
|
|
4
|
+
} from "@sproutsocial/seeds-react-system-props";
|
|
5
|
+
|
|
6
|
+
type TypeQaProps = object;
|
|
7
|
+
|
|
8
|
+
export interface TypeLoaderProps
|
|
9
|
+
extends TypeStyledComponentsCommonProps,
|
|
10
|
+
TypeSystemCommonProps,
|
|
11
|
+
Omit<React.ComponentPropsWithoutRef<"div">, keyof TypeSystemCommonProps> {
|
|
12
|
+
size?: "small" | "large";
|
|
13
|
+
|
|
14
|
+
/** Text for the loader. This text is not visible, but is used for accessibility purposed */
|
|
15
|
+
text?: string;
|
|
16
|
+
|
|
17
|
+
/** Whether the loader should wait 2 seconds before it displays */
|
|
18
|
+
delay?: boolean;
|
|
19
|
+
color?: "light" | "dark";
|
|
20
|
+
qa?: TypeQaProps;
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Loader from "../Loader";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
function LoaderTypes() {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Loader text="Content loading" delay={false} />
|
|
9
|
+
{/* @ts-expect-error - test that invalid props are rejected */}
|
|
10
|
+
<Loader text={3} delay="invalid" />
|
|
11
|
+
</>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@sproutsocial/seeds-react-testing-library";
|
|
3
|
+
import Loader from "../Loader";
|
|
4
|
+
|
|
5
|
+
describe("Loader", () => {
|
|
6
|
+
it("should render properly", () => {
|
|
7
|
+
render(<Loader />);
|
|
8
|
+
expect(screen.getByText("Loading")).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should render with small size class", () => {
|
|
12
|
+
render(<Loader size="small" />);
|
|
13
|
+
expect(
|
|
14
|
+
screen.getByDataQaLabel({
|
|
15
|
+
loader: "",
|
|
16
|
+
})
|
|
17
|
+
).toHaveStyleRule("width", "20px");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should render with light theme", () => {
|
|
21
|
+
render(<Loader color="light" />);
|
|
22
|
+
expect(
|
|
23
|
+
screen.getByDataQaLabel({
|
|
24
|
+
loader: "",
|
|
25
|
+
})
|
|
26
|
+
).toHaveStyleRule("border-color", "#FFFFFF #FFFFFF #6e797a #6e797a", {
|
|
27
|
+
modifier: ":after",
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
package/src/index.ts
ADDED
package/src/styled.d.ts
ADDED
package/src/styles.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import styled, { css, keyframes } from "styled-components";
|
|
2
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
3
|
+
import { visuallyHidden } from "@sproutsocial/seeds-react-mixins";
|
|
4
|
+
import type { TypeLoaderProps } from "./LoaderTypes";
|
|
5
|
+
|
|
6
|
+
const getSize = (size: number) => {
|
|
7
|
+
const spinnerSize = Math.round(size * 1);
|
|
8
|
+
const borderWidth = Math.round(size * 0.1);
|
|
9
|
+
|
|
10
|
+
return css`
|
|
11
|
+
width: ${size}px;
|
|
12
|
+
height: ${size}px;
|
|
13
|
+
box-shadow: ${({ theme }) =>
|
|
14
|
+
`0 0 0 2px ${theme.colors.neutral[600]},
|
|
15
|
+
inset 0 0 0 ${borderWidth + 2}px ${theme.colors.neutral[600]}`};
|
|
16
|
+
|
|
17
|
+
&:after {
|
|
18
|
+
width: ${spinnerSize}px;
|
|
19
|
+
height: ${spinnerSize}px;
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
border-width: ${borderWidth}px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.no-cssanimations &::after {
|
|
25
|
+
background-size: ${spinnerSize}px;
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const spin = keyframes`
|
|
31
|
+
from {
|
|
32
|
+
transform: translate(-50%,-50%) rotate(0deg);
|
|
33
|
+
}
|
|
34
|
+
to {
|
|
35
|
+
transform: translate(-50%,-50%) rotate(360deg);
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const delayAnimation = keyframes`
|
|
40
|
+
0% {
|
|
41
|
+
opacity: 0;
|
|
42
|
+
}
|
|
43
|
+
80% {
|
|
44
|
+
opacity: 0;
|
|
45
|
+
}
|
|
46
|
+
100% {
|
|
47
|
+
opacity: 1;
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
interface TypeLoaderContainer extends Pick<TypeLoaderProps, "delay"> {
|
|
52
|
+
small?: boolean;
|
|
53
|
+
dark?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const Container = styled.div.attrs<{ className: string }>({
|
|
57
|
+
className: "Loader",
|
|
58
|
+
})<TypeLoaderContainer>`
|
|
59
|
+
position: relative;
|
|
60
|
+
margin: 0 auto;
|
|
61
|
+
padding: 0;
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
border-radius: 100%;
|
|
64
|
+
|
|
65
|
+
animation: ${(props) =>
|
|
66
|
+
props.delay
|
|
67
|
+
? css`
|
|
68
|
+
${delayAnimation} 2s 1;
|
|
69
|
+
`
|
|
70
|
+
: "none"};
|
|
71
|
+
|
|
72
|
+
&:after {
|
|
73
|
+
position: absolute;
|
|
74
|
+
top: 50%;
|
|
75
|
+
left: 50%;
|
|
76
|
+
background: transparent;
|
|
77
|
+
border-style: solid;
|
|
78
|
+
border-radius: 100%;
|
|
79
|
+
content: "";
|
|
80
|
+
transition: opacity 250ms;
|
|
81
|
+
border-color: ${({ theme }) =>
|
|
82
|
+
`${theme.colors.neutral[0]} ${theme.colors.neutral[0]} ${theme.colors.neutral[600]} ${theme.colors.neutral[600]}`};
|
|
83
|
+
|
|
84
|
+
animation: ${(props) =>
|
|
85
|
+
props.delay
|
|
86
|
+
? css`
|
|
87
|
+
${spin} 2.25s infinite linear, ${delayAnimation} 2s 1
|
|
88
|
+
`
|
|
89
|
+
: css`
|
|
90
|
+
${spin} 2.25s infinite linear
|
|
91
|
+
`};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
${(props) => (props.small ? getSize(20) : getSize(40))}
|
|
95
|
+
${COMMON}
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
export const Text = styled.div<Pick<TypeLoaderProps, "text">>`
|
|
99
|
+
${visuallyHidden}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
export default Container;
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
clean: true,
|
|
7
|
+
legacyOutput: true,
|
|
8
|
+
dts: options.dts,
|
|
9
|
+
external: ["react"],
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
metafile: options.metafile,
|
|
12
|
+
}));
|