react-skeletonify 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/README.md +14 -0
- package/dist/index.css +32 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +137 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +100 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# React Skeletonify
|
|
2
|
+
|
|
3
|
+
A lightweight and flexible skeleton loading component for React ⚡.
|
|
4
|
+
Easily add animated skeleton loaders to any UI element.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🚀 Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install react-skeletonify
|
|
12
|
+
# or
|
|
13
|
+
yarn add react-skeletonify
|
|
14
|
+
```
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* src/styles/skeleton.css */
|
|
2
|
+
.Rss-skeleton {
|
|
3
|
+
animation: Rss-skeleton-loading 1s linear infinite alternate;
|
|
4
|
+
background-color: hsl(200, 20%, 90%);
|
|
5
|
+
color: transparent !important;
|
|
6
|
+
border: none !important;
|
|
7
|
+
outline: none !important;
|
|
8
|
+
pointer-events: none !important;
|
|
9
|
+
border-radius: 8px !important;
|
|
10
|
+
}
|
|
11
|
+
.Rss-skeleton img {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
}
|
|
14
|
+
.Rss-skeleton a {
|
|
15
|
+
text-decoration: none !important;
|
|
16
|
+
color: transparent !important;
|
|
17
|
+
}
|
|
18
|
+
.Rss-skeleton-text {
|
|
19
|
+
margin-top: 5px !important;
|
|
20
|
+
}
|
|
21
|
+
.Rss-skeleton::placeholder {
|
|
22
|
+
color: transparent !important;
|
|
23
|
+
}
|
|
24
|
+
@keyframes Rss-skeleton-loading {
|
|
25
|
+
0% {
|
|
26
|
+
background-color: hsl(200, 20%, 80%);
|
|
27
|
+
}
|
|
28
|
+
100% {
|
|
29
|
+
background-color: hsl(200, 20%, 95%);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/styles/skeleton.css"],"sourcesContent":[".Rss-skeleton {\n animation: Rss-skeleton-loading 1s linear infinite alternate;\n background-color: hsl(200, 20%, 90%);\n color: transparent !important;\n border: none !important;\n outline: none !important;\n pointer-events: none !important;\n border-radius: 8px !important;\n}\n\n.Rss-skeleton img {\n opacity: 0;\n}\n\n.Rss-skeleton a {\n text-decoration: none !important;\n color: transparent !important;\n}\n\n.Rss-skeleton-text {\n margin-top: 5px !important;\n}\n\n.Rss-skeleton::placeholder {\n color: transparent !important;\n}\n\n@keyframes Rss-skeleton-loading {\n 0% {\n background-color: hsl(200, 20%, 80%);\n }\n 100% {\n background-color: hsl(200, 20%, 95%);\n }\n}\n"],"mappings":";AAAA,CAAC;AACC,aAAW,qBAAqB,GAAG,OAAO,SAAS;AACnD,oBAAkB,IAAI,GAAG,EAAE,GAAG,EAAE;AAChC,SAAO;AACP,UAAQ;AACR,WAAS;AACT,kBAAgB;AAChB,iBAAe;AACjB;AAEA,CAVC,aAUa;AACZ,WAAS;AACX;AAEA,CAdC,aAca;AACZ,mBAAiB;AACjB,SAAO;AACT;AAEA,CAAC;AACC,cAAY;AACd;AAEA,CAvBC,YAuBY;AACX,SAAO;AACT;AAEA,WA1Ba;AA2BX;AACE,sBAAkB,IAAI,GAAG,EAAE,GAAG,EAAE;AAClC;AACA;AACE,sBAAkB,IAAI,GAAG,EAAE,GAAG,EAAE;AAClC;AACF;","names":[]}
|
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
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.tsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SkeletonWrapper: () => SkeletonWrapper_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/components/SkeletonElement.tsx
|
|
38
|
+
var import_react4 = __toESM(require("react"));
|
|
39
|
+
|
|
40
|
+
// src/hooks/useAddSkelton.ts
|
|
41
|
+
var import_react3 = __toESM(require("react"));
|
|
42
|
+
|
|
43
|
+
// src/utils/create-node-wrapper.ts
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
function createNodeWrapper(node) {
|
|
46
|
+
var _a;
|
|
47
|
+
if (!node) return null;
|
|
48
|
+
return (0, import_react.createElement)(
|
|
49
|
+
"div",
|
|
50
|
+
{
|
|
51
|
+
className: (((_a = node == null ? void 0 : node.props) == null ? void 0 : _a.className) || "") + " Rss-skeleton"
|
|
52
|
+
},
|
|
53
|
+
node
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/constants/tags.ts
|
|
58
|
+
var TEXT_TAGS = [
|
|
59
|
+
"p",
|
|
60
|
+
"span",
|
|
61
|
+
"h1",
|
|
62
|
+
"h2",
|
|
63
|
+
"h3",
|
|
64
|
+
"h4",
|
|
65
|
+
"h5",
|
|
66
|
+
"h6",
|
|
67
|
+
"li"
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
// src/utils/create-leaf-node.ts
|
|
71
|
+
var import_react2 = __toESM(require("react"));
|
|
72
|
+
function createLeafNode(node, className = "") {
|
|
73
|
+
return import_react2.default.cloneElement(node, {
|
|
74
|
+
...node.props,
|
|
75
|
+
className: (node.props.className || "") + " Rss-skeleton " + className
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/hooks/useAddSkelton.ts
|
|
80
|
+
function useAddSkelton() {
|
|
81
|
+
const addSkeleton = (node) => {
|
|
82
|
+
if (!import_react3.default.isValidElement(node)) return createNodeWrapper(node);
|
|
83
|
+
const element = node;
|
|
84
|
+
const { children } = element.props;
|
|
85
|
+
const elementType = element.type;
|
|
86
|
+
const hasChildren = import_react3.default.Children.count(children) > 0;
|
|
87
|
+
const isValidChildren = typeof children !== "string";
|
|
88
|
+
if (typeof elementType === "function") {
|
|
89
|
+
const rendered = elementType(element.props);
|
|
90
|
+
return addSkeleton(rendered);
|
|
91
|
+
}
|
|
92
|
+
if (TEXT_TAGS.includes(elementType)) {
|
|
93
|
+
return createLeafNode(node, "Rss-skeleton-text");
|
|
94
|
+
}
|
|
95
|
+
if (elementType === "img") {
|
|
96
|
+
return createNodeWrapper(element);
|
|
97
|
+
}
|
|
98
|
+
if (hasChildren && isValidChildren) {
|
|
99
|
+
const childWithSkeletons = import_react3.default.Children.map(children, addSkeleton);
|
|
100
|
+
return import_react3.default.cloneElement(element, {
|
|
101
|
+
...element.props,
|
|
102
|
+
children: childWithSkeletons
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return createLeafNode(element);
|
|
106
|
+
};
|
|
107
|
+
return addSkeleton;
|
|
108
|
+
}
|
|
109
|
+
var useAddSkelton_default = useAddSkelton;
|
|
110
|
+
|
|
111
|
+
// src/components/SkeletonElement.tsx
|
|
112
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
113
|
+
var SkeletonElement = ({
|
|
114
|
+
children
|
|
115
|
+
}) => {
|
|
116
|
+
const addSkeleton = useAddSkelton_default();
|
|
117
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "skeleton-container", children: import_react4.default.Children.map(children, (child) => addSkeleton(child)) });
|
|
118
|
+
};
|
|
119
|
+
var SkeletonElement_default = SkeletonElement;
|
|
120
|
+
|
|
121
|
+
// src/components/SkeletonWrapper.tsx
|
|
122
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
123
|
+
var SkeletonWrapper = ({
|
|
124
|
+
loading,
|
|
125
|
+
children
|
|
126
|
+
}) => {
|
|
127
|
+
if (loading) {
|
|
128
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SkeletonElement_default, { children });
|
|
129
|
+
}
|
|
130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
|
|
131
|
+
};
|
|
132
|
+
var SkeletonWrapper_default = SkeletonWrapper;
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
SkeletonWrapper
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx","../src/components/SkeletonElement.tsx","../src/hooks/useAddSkelton.ts","../src/utils/create-node-wrapper.ts","../src/constants/tags.ts","../src/utils/create-leaf-node.ts","../src/components/SkeletonWrapper.tsx"],"sourcesContent":["import \"./styles/skeleton.css\";\n\nexport { default as SkeletonWrapper } from \"./components/SkeletonWrapper\";\n","import React from \"react\";\nimport useAddSkelton from \"../hooks/useAddSkelton\";\n\nconst SkeletonElement: React.FC<{ children: React.ReactNode }> = ({\n children,\n}) => {\n const addSkeleton = useAddSkelton();\n return (\n <div className=\"skeleton-container\">\n {React.Children.map(children, (child) => addSkeleton(child))}\n </div>\n );\n};\n\nexport default SkeletonElement;\n","import React from \"react\";\nimport createNodeWrapper from \"../utils/create-node-wrapper\";\nimport { TEXT_TAGS } from \"../constants/tags\";\nimport createLeafNode from \"../utils/create-leaf-node\";\n\nfunction useAddSkelton() {\n const addSkeleton = (node: React.ReactNode): React.ReactNode => {\n if (!React.isValidElement(node)) return createNodeWrapper(node as any);\n\n const element = node as React.ReactElement<any>;\n const { children } = element.props;\n const elementType = element.type;\n\n const hasChildren = React.Children.count(children) > 0;\n const isValidChildren = typeof children !== \"string\";\n\n if (typeof elementType === \"function\") {\n const rendered = (elementType as any)(element.props);\n return addSkeleton(rendered);\n }\n\n if (TEXT_TAGS.includes(elementType)) {\n return createLeafNode(node, \"Rss-skeleton-text\");\n }\n\n if (elementType === \"img\") {\n return createNodeWrapper(element);\n }\n\n if (hasChildren && isValidChildren) {\n const childWithSkeletons = React.Children.map(children, addSkeleton);\n\n return React.cloneElement(element, {\n ...element.props,\n children: childWithSkeletons,\n } as typeof element.props);\n }\n\n return createLeafNode(element);\n };\n\n return addSkeleton;\n}\n\nexport default useAddSkelton;\n","import React, { createElement } from \"react\";\n\nexport default function createNodeWrapper(node: React.ReactElement<any>) {\n if (!node) return null;\n\n return createElement(\n \"div\",\n {\n className: (node?.props?.className || \"\") + \" Rss-skeleton\",\n },\n node\n );\n}\n","export const TEXT_TAGS = [\n \"p\",\n \"span\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"li\",\n];\n","import React from \"react\";\n\nexport default function createLeafNode(\n node: React.ReactElement<any>,\n className: string = \"\"\n): React.ReactElement {\n return React.cloneElement(node, {\n ...node.props,\n className: (node.props.className || \"\") + \" Rss-skeleton \" + className,\n } as typeof node.props);\n}\n","import React from \"react\";\nimport SkeletonElement from \"./SkeletonElement\";\n\ninterface SkeletonWrapperProps {\n loading: boolean;\n children: React.ReactNode;\n}\n\nconst SkeletonWrapper: React.FC<SkeletonWrapperProps> = ({\n loading,\n children,\n}) => {\n if (loading) {\n return <SkeletonElement>{children}</SkeletonElement>;\n }\n return <>{children}</>;\n};\n\nexport default SkeletonWrapper;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAkB;;;ACAlB,IAAAC,gBAAkB;;;ACAlB,mBAAqC;AAEtB,SAAR,kBAAmC,MAA+B;AAFzE;AAGE,MAAI,CAAC,KAAM,QAAO;AAElB,aAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,cAAY,kCAAM,UAAN,mBAAa,cAAa,MAAM;AAAA,IAC9C;AAAA,IACA;AAAA,EACF;AACF;;;ACZO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACVA,IAAAC,gBAAkB;AAEH,SAAR,eACL,MACA,YAAoB,IACA;AACpB,SAAO,cAAAC,QAAM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ACF,MAAM;AACJ,MAAI,SAAS;AACX,WAAO,6CAAC,2BAAiB,UAAS;AAAA,EACpC;AACA,SAAO,6EAAG,UAAS;AACrB;AAEA,IAAO,0BAAQ;","names":["import_react","import_react","import_react","React","React","React","import_jsx_runtime"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/components/SkeletonElement.tsx
|
|
2
|
+
import React4 from "react";
|
|
3
|
+
|
|
4
|
+
// src/hooks/useAddSkelton.ts
|
|
5
|
+
import React3 from "react";
|
|
6
|
+
|
|
7
|
+
// src/utils/create-node-wrapper.ts
|
|
8
|
+
import { createElement } from "react";
|
|
9
|
+
function createNodeWrapper(node) {
|
|
10
|
+
var _a;
|
|
11
|
+
if (!node) return null;
|
|
12
|
+
return createElement(
|
|
13
|
+
"div",
|
|
14
|
+
{
|
|
15
|
+
className: (((_a = node == null ? void 0 : node.props) == null ? void 0 : _a.className) || "") + " Rss-skeleton"
|
|
16
|
+
},
|
|
17
|
+
node
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/constants/tags.ts
|
|
22
|
+
var TEXT_TAGS = [
|
|
23
|
+
"p",
|
|
24
|
+
"span",
|
|
25
|
+
"h1",
|
|
26
|
+
"h2",
|
|
27
|
+
"h3",
|
|
28
|
+
"h4",
|
|
29
|
+
"h5",
|
|
30
|
+
"h6",
|
|
31
|
+
"li"
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// src/utils/create-leaf-node.ts
|
|
35
|
+
import React2 from "react";
|
|
36
|
+
function createLeafNode(node, className = "") {
|
|
37
|
+
return React2.cloneElement(node, {
|
|
38
|
+
...node.props,
|
|
39
|
+
className: (node.props.className || "") + " Rss-skeleton " + className
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/hooks/useAddSkelton.ts
|
|
44
|
+
function useAddSkelton() {
|
|
45
|
+
const addSkeleton = (node) => {
|
|
46
|
+
if (!React3.isValidElement(node)) return createNodeWrapper(node);
|
|
47
|
+
const element = node;
|
|
48
|
+
const { children } = element.props;
|
|
49
|
+
const elementType = element.type;
|
|
50
|
+
const hasChildren = React3.Children.count(children) > 0;
|
|
51
|
+
const isValidChildren = typeof children !== "string";
|
|
52
|
+
if (typeof elementType === "function") {
|
|
53
|
+
const rendered = elementType(element.props);
|
|
54
|
+
return addSkeleton(rendered);
|
|
55
|
+
}
|
|
56
|
+
if (TEXT_TAGS.includes(elementType)) {
|
|
57
|
+
return createLeafNode(node, "Rss-skeleton-text");
|
|
58
|
+
}
|
|
59
|
+
if (elementType === "img") {
|
|
60
|
+
return createNodeWrapper(element);
|
|
61
|
+
}
|
|
62
|
+
if (hasChildren && isValidChildren) {
|
|
63
|
+
const childWithSkeletons = React3.Children.map(children, addSkeleton);
|
|
64
|
+
return React3.cloneElement(element, {
|
|
65
|
+
...element.props,
|
|
66
|
+
children: childWithSkeletons
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return createLeafNode(element);
|
|
70
|
+
};
|
|
71
|
+
return addSkeleton;
|
|
72
|
+
}
|
|
73
|
+
var useAddSkelton_default = useAddSkelton;
|
|
74
|
+
|
|
75
|
+
// src/components/SkeletonElement.tsx
|
|
76
|
+
import { jsx } from "react/jsx-runtime";
|
|
77
|
+
var SkeletonElement = ({
|
|
78
|
+
children
|
|
79
|
+
}) => {
|
|
80
|
+
const addSkeleton = useAddSkelton_default();
|
|
81
|
+
return /* @__PURE__ */ jsx("div", { className: "skeleton-container", children: React4.Children.map(children, (child) => addSkeleton(child)) });
|
|
82
|
+
};
|
|
83
|
+
var SkeletonElement_default = SkeletonElement;
|
|
84
|
+
|
|
85
|
+
// src/components/SkeletonWrapper.tsx
|
|
86
|
+
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
87
|
+
var SkeletonWrapper = ({
|
|
88
|
+
loading,
|
|
89
|
+
children
|
|
90
|
+
}) => {
|
|
91
|
+
if (loading) {
|
|
92
|
+
return /* @__PURE__ */ jsx2(SkeletonElement_default, { children });
|
|
93
|
+
}
|
|
94
|
+
return /* @__PURE__ */ jsx2(Fragment, { children });
|
|
95
|
+
};
|
|
96
|
+
var SkeletonWrapper_default = SkeletonWrapper;
|
|
97
|
+
export {
|
|
98
|
+
SkeletonWrapper_default as SkeletonWrapper
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/SkeletonElement.tsx","../src/hooks/useAddSkelton.ts","../src/utils/create-node-wrapper.ts","../src/constants/tags.ts","../src/utils/create-leaf-node.ts","../src/components/SkeletonWrapper.tsx"],"sourcesContent":["import React from \"react\";\nimport useAddSkelton from \"../hooks/useAddSkelton\";\n\nconst SkeletonElement: React.FC<{ children: React.ReactNode }> = ({\n children,\n}) => {\n const addSkeleton = useAddSkelton();\n return (\n <div className=\"skeleton-container\">\n {React.Children.map(children, (child) => addSkeleton(child))}\n </div>\n );\n};\n\nexport default SkeletonElement;\n","import React from \"react\";\nimport createNodeWrapper from \"../utils/create-node-wrapper\";\nimport { TEXT_TAGS } from \"../constants/tags\";\nimport createLeafNode from \"../utils/create-leaf-node\";\n\nfunction useAddSkelton() {\n const addSkeleton = (node: React.ReactNode): React.ReactNode => {\n if (!React.isValidElement(node)) return createNodeWrapper(node as any);\n\n const element = node as React.ReactElement<any>;\n const { children } = element.props;\n const elementType = element.type;\n\n const hasChildren = React.Children.count(children) > 0;\n const isValidChildren = typeof children !== \"string\";\n\n if (typeof elementType === \"function\") {\n const rendered = (elementType as any)(element.props);\n return addSkeleton(rendered);\n }\n\n if (TEXT_TAGS.includes(elementType)) {\n return createLeafNode(node, \"Rss-skeleton-text\");\n }\n\n if (elementType === \"img\") {\n return createNodeWrapper(element);\n }\n\n if (hasChildren && isValidChildren) {\n const childWithSkeletons = React.Children.map(children, addSkeleton);\n\n return React.cloneElement(element, {\n ...element.props,\n children: childWithSkeletons,\n } as typeof element.props);\n }\n\n return createLeafNode(element);\n };\n\n return addSkeleton;\n}\n\nexport default useAddSkelton;\n","import React, { createElement } from \"react\";\n\nexport default function createNodeWrapper(node: React.ReactElement<any>) {\n if (!node) return null;\n\n return createElement(\n \"div\",\n {\n className: (node?.props?.className || \"\") + \" Rss-skeleton\",\n },\n node\n );\n}\n","export const TEXT_TAGS = [\n \"p\",\n \"span\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"li\",\n];\n","import React from \"react\";\n\nexport default function createLeafNode(\n node: React.ReactElement<any>,\n className: string = \"\"\n): React.ReactElement {\n return React.cloneElement(node, {\n ...node.props,\n className: (node.props.className || \"\") + \" Rss-skeleton \" + className,\n } as typeof node.props);\n}\n","import React from \"react\";\nimport SkeletonElement from \"./SkeletonElement\";\n\ninterface SkeletonWrapperProps {\n loading: boolean;\n children: React.ReactNode;\n}\n\nconst SkeletonWrapper: React.FC<SkeletonWrapperProps> = ({\n loading,\n children,\n}) => {\n if (loading) {\n return <SkeletonElement>{children}</SkeletonElement>;\n }\n return <>{children}</>;\n};\n\nexport default SkeletonWrapper;\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACAlB,OAAOC,YAAW;;;ACAlB,SAAgB,qBAAqB;AAEtB,SAAR,kBAAmC,MAA+B;AAFzE;AAGE,MAAI,CAAC,KAAM,QAAO;AAElB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,cAAY,kCAAM,UAAN,mBAAa,cAAa,MAAM;AAAA,IAC9C;AAAA,IACA;AAAA,EACF;AACF;;;ACZO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACVA,OAAOC,YAAW;AAEH,SAAR,eACL,MACA,YAAoB,IACA;AACpB,SAAOA,OAAM,aAAa,MAAM;AAAA,IAC9B,GAAG,KAAK;AAAA,IACR,YAAY,KAAK,MAA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ACA,SAAO,gBAAAA,KAAA,YAAG,UAAS;AACrB;AAEA,IAAO,0BAAQ;","names":["React","React","React","React","React","jsx"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-skeletonify",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "rm -rf dist",
|
|
12
|
+
"build": "tsup",
|
|
13
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"react",
|
|
17
|
+
"skeleton",
|
|
18
|
+
"loader",
|
|
19
|
+
"skeleton-ui",
|
|
20
|
+
"react-component",
|
|
21
|
+
"loading-ui"
|
|
22
|
+
],
|
|
23
|
+
"author": "Sinan sinan.m.p333@gmail.com",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"description": "A lightweight React package to add smart skeleton loaders to any component",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/Sinan0333/react-skeletonify"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/Sinan0333/react-skeletonify#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Sinan0333/react-skeletonify/issues"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=18.0.0",
|
|
36
|
+
"react-dom": ">=18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^19.1.12",
|
|
40
|
+
"@types/react-dom": "^19.1.8",
|
|
41
|
+
"tsup": "^8.5.0",
|
|
42
|
+
"typescript": "^5.9.2",
|
|
43
|
+
"vite": "^7.1.3",
|
|
44
|
+
"react": "^19.1.1",
|
|
45
|
+
"react-dom": "^19.1.1"
|
|
46
|
+
}
|
|
47
|
+
}
|