@skel-ui/react-native 1.0.0-alpha.01475df
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/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/Animation.d.ts +27 -0
- package/dist/cjs/Animation.js +118 -0
- package/dist/cjs/funcs.js +87 -0
- package/dist/cjs/index.js +96 -0
- package/dist/cjs/utils.js +24 -0
- package/dist/esm/Animation.js +95 -0
- package/dist/esm/funcs.js +67 -0
- package/dist/esm/index.js +66 -0
- package/dist/esm/utils.js +4 -0
- package/dist/funcs.d.ts +7 -0
- package/dist/index.d.ts +24 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Augustin Joseph
|
|
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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Skel UI resolves the challenges of implementing skeletons by eliminating the need to create dedicated loading screens and providing an easier way to manage skeleton states using React Context.
|
|
2
|
+
|
|
3
|
+
See the comparision [here](https://skel-ui.augustin.zip/#comparision).
|
|
4
|
+
|
|
5
|
+
## Get Started
|
|
6
|
+
|
|
7
|
+
### Add Skel Provider
|
|
8
|
+
|
|
9
|
+
Wrap your application with Skel UI provider.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import * as Skel from "@skel-ui/react-native";
|
|
14
|
+
|
|
15
|
+
export default function App() {
|
|
16
|
+
return <Skel.Provider> ... </Skel.Provider>;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Implement Skel UI
|
|
21
|
+
|
|
22
|
+
Now it's time for you to craft your user interface to life!
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import * as Skel from "@skel-ui/react-native";
|
|
26
|
+
import RN from "react-native";
|
|
27
|
+
|
|
28
|
+
export default function PostCard() {
|
|
29
|
+
const { post, isLoading } = usePost();
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Skel.Root isLoading={isLoading}>
|
|
33
|
+
<RN.View style={styles.card}>
|
|
34
|
+
<Skel.Image src={post?.image} style={styles.cardImage} />
|
|
35
|
+
<Skel.Text sw="65%" style={styles.cardTitle}>
|
|
36
|
+
{post?.title}
|
|
37
|
+
</Skel.Text>
|
|
38
|
+
<Skel.Text numberOfLines={3} style={styles.cardDescription}>
|
|
39
|
+
{post?.description}
|
|
40
|
+
</Skel.Text>
|
|
41
|
+
</RN.View>
|
|
42
|
+
</Skel.Root>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const styles = RN.StyleSheet.create({
|
|
47
|
+
card: {
|
|
48
|
+
width: 320,
|
|
49
|
+
padding: 10,
|
|
50
|
+
marginHorizontal: "auto",
|
|
51
|
+
borderWidth: 1,
|
|
52
|
+
borderColor: "#e2e8f0",
|
|
53
|
+
borderRadius: 8,
|
|
54
|
+
},
|
|
55
|
+
cardImage: {
|
|
56
|
+
borderRadius: 4,
|
|
57
|
+
aspectRatio: 800 / 530,
|
|
58
|
+
},
|
|
59
|
+
cardTitle: {
|
|
60
|
+
marginTop: 16,
|
|
61
|
+
marginBottom: 8,
|
|
62
|
+
fontSize: 24,
|
|
63
|
+
lineHeight: 28,
|
|
64
|
+
fontWeight: 800,
|
|
65
|
+
},
|
|
66
|
+
cardDescription: {
|
|
67
|
+
fontSize: 14,
|
|
68
|
+
lineHeight: 20,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Now, not only have you designed the skeleton, but you have also done the actual UI. Additionally, the skeleton state for the entire UI is handled in a single place at the `<Skel.Root>` .
|
|
74
|
+
|
|
75
|
+
For full documentation, visit [skel-ui.augustin.zip](https://skel-ui.augustin.zip/)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SkelComponentProps } from "@skel-ui/core";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import { EasingFunction, EasingFunctionFactory } from "react-native-reanimated";
|
|
5
|
+
import { TStyle } from "./funcs";
|
|
6
|
+
type AnimationProps = Pick<SkelComponentProps<typeof View>, "sw" | "sh" | "sr"> & {
|
|
7
|
+
style?: TStyle;
|
|
8
|
+
numberOfLines?: number;
|
|
9
|
+
};
|
|
10
|
+
export type UIOptions = {
|
|
11
|
+
color?: string;
|
|
12
|
+
radius?: number;
|
|
13
|
+
shimmer?: {
|
|
14
|
+
color?: string;
|
|
15
|
+
};
|
|
16
|
+
animation?: {
|
|
17
|
+
component: ReactNode;
|
|
18
|
+
} | {
|
|
19
|
+
delay?: number;
|
|
20
|
+
easing?: EasingFunction | EasingFunctionFactory;
|
|
21
|
+
duration?: number;
|
|
22
|
+
};
|
|
23
|
+
skelUIPulse?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const UIOptionsContext: import("react").Context<UIOptions>;
|
|
26
|
+
export declare function Animation({ sw, sh, sr, style, numberOfLines }: AnimationProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
var Animation_exports = {};
|
|
30
|
+
__export(Animation_exports, {
|
|
31
|
+
Animation: () => Animation,
|
|
32
|
+
UIOptionsContext: () => UIOptionsContext
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Animation_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var import_expo_linear_gradient = require("expo-linear-gradient");
|
|
37
|
+
var import_react = require("react");
|
|
38
|
+
var import_react_native = require("react-native");
|
|
39
|
+
var import_react_native_reanimated = __toESM(require("react-native-reanimated"));
|
|
40
|
+
var import_funcs = require("./funcs");
|
|
41
|
+
const UIOptionsContext = (0, import_react.createContext)({});
|
|
42
|
+
function Pluse({ color, animation }) {
|
|
43
|
+
const opacity = (0, import_react_native_reanimated.useSharedValue)(0.5);
|
|
44
|
+
(0, import_react_native_reanimated.useFrameCallback)(() => {
|
|
45
|
+
if (opacity.value === 1 || opacity.value === 0.5) {
|
|
46
|
+
const { delay, ...options } = animation;
|
|
47
|
+
opacity.value = (0, import_react_native_reanimated.withDelay)(delay, (0, import_react_native_reanimated.withTiming)(opacity.value === 1 ? 0.5 : 1, options));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_reanimated.default.View, { style: { width: "100%", height: "100%", opacity, backgroundColor: color }, "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { children: " \u200C " }) });
|
|
51
|
+
}
|
|
52
|
+
function Shimmer({ color, shimmer, animation }) {
|
|
53
|
+
const translate = (0, import_react_native_reanimated.useSharedValue)("-100%");
|
|
54
|
+
const cords = {
|
|
55
|
+
x: { start: { x: 0, y: 0 }, end: { x: 1, y: 0 } },
|
|
56
|
+
y: { start: { x: 0, y: 0 }, end: { x: 0, y: 1 } }
|
|
57
|
+
};
|
|
58
|
+
const style = { width: "100%", height: "100%" };
|
|
59
|
+
(0, import_react.useEffect)(() => {
|
|
60
|
+
const { delay, ...options } = animation;
|
|
61
|
+
translate.value = (0, import_react_native_reanimated.withDelay)(delay, (0, import_react_native_reanimated.withRepeat)((0, import_react_native_reanimated.withTiming)("100%", options), -1, false));
|
|
62
|
+
}, []);
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { backgroundColor: color }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
64
|
+
import_react_native_reanimated.default.View,
|
|
65
|
+
{
|
|
66
|
+
style: {
|
|
67
|
+
...style,
|
|
68
|
+
transform: [{ translateX: translate }]
|
|
69
|
+
// transform: [{ [isVertical ? "translateY" : ("translateX" as never)]: translate as unknown as number }],
|
|
70
|
+
},
|
|
71
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
+
import_expo_linear_gradient.LinearGradient,
|
|
73
|
+
{
|
|
74
|
+
...cords.x,
|
|
75
|
+
style,
|
|
76
|
+
colors: [color, shimmer.color, color]
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
) });
|
|
81
|
+
}
|
|
82
|
+
function Animation({ sw, sh, sr, style = {}, numberOfLines = 1 }) {
|
|
83
|
+
const text = (0, import_react.useMemo)(() => new Array(numberOfLines).fill(" \u200C ").join("\n"), [numberOfLines]);
|
|
84
|
+
const { viewStyle, textStyle } = (0, import_funcs.filterStyle)(style);
|
|
85
|
+
const { color = "#cbd5e1", radius = 4, shimmer = {}, animation = {}, skelUIPulse } = (0, import_react.useContext)(UIOptionsContext);
|
|
86
|
+
const $props = {
|
|
87
|
+
color,
|
|
88
|
+
radius,
|
|
89
|
+
shimmer: {
|
|
90
|
+
color: "#f1f0f0",
|
|
91
|
+
...shimmer
|
|
92
|
+
},
|
|
93
|
+
animation: {
|
|
94
|
+
delay: 0,
|
|
95
|
+
easing: import_react_native_reanimated.Easing.bezier(0.4, 0, 0.6, 1),
|
|
96
|
+
duration: skelUIPulse ? 1e3 : 2e3,
|
|
97
|
+
...animation
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
101
|
+
import_react_native.View,
|
|
102
|
+
{
|
|
103
|
+
style: {
|
|
104
|
+
...style,
|
|
105
|
+
width: sw || viewStyle.width,
|
|
106
|
+
height: sh || viewStyle.height,
|
|
107
|
+
borderRadius: sr || viewStyle.borderRadius || radius,
|
|
108
|
+
overflow: "hidden",
|
|
109
|
+
position: "relative",
|
|
110
|
+
backgroundColor: void 0
|
|
111
|
+
},
|
|
112
|
+
children: [
|
|
113
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: textStyle, children: text }),
|
|
114
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { inset: 0, position: "absolute" }, children: "component" in animation ? animation.component : skelUIPulse ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pluse, { ...$props }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Shimmer, { ...$props }) })
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var funcs_exports = {};
|
|
20
|
+
__export(funcs_exports, {
|
|
21
|
+
filterStyle: () => filterStyle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(funcs_exports);
|
|
24
|
+
const viewWhitelistStyles = [
|
|
25
|
+
"aspectRatio",
|
|
26
|
+
"bottom",
|
|
27
|
+
"display",
|
|
28
|
+
"flex",
|
|
29
|
+
"flexBasis",
|
|
30
|
+
"flexGrow",
|
|
31
|
+
"flexShrink",
|
|
32
|
+
"left",
|
|
33
|
+
"margin",
|
|
34
|
+
"marginBottom",
|
|
35
|
+
"marginEnd",
|
|
36
|
+
"marginHorizontal",
|
|
37
|
+
"marginLeft",
|
|
38
|
+
"marginRight",
|
|
39
|
+
"marginStart",
|
|
40
|
+
"marginTop",
|
|
41
|
+
"marginVertical",
|
|
42
|
+
"maxHeight",
|
|
43
|
+
"maxWidth",
|
|
44
|
+
"minHeight",
|
|
45
|
+
"minWidth",
|
|
46
|
+
"padding",
|
|
47
|
+
"paddingBottom",
|
|
48
|
+
"paddingEnd",
|
|
49
|
+
"paddingHorizontal",
|
|
50
|
+
"paddingLeft",
|
|
51
|
+
"paddingRight",
|
|
52
|
+
"paddingStart",
|
|
53
|
+
"paddingTop",
|
|
54
|
+
"paddingVertical",
|
|
55
|
+
"position",
|
|
56
|
+
"right",
|
|
57
|
+
"top",
|
|
58
|
+
"zIndex",
|
|
59
|
+
"width",
|
|
60
|
+
"height",
|
|
61
|
+
"borderRadius",
|
|
62
|
+
"borderBottomEndRadius",
|
|
63
|
+
"borderBottomLeftRadius",
|
|
64
|
+
"borderBottomRightRadius",
|
|
65
|
+
"borderBottomStartRadius",
|
|
66
|
+
"borderStartEndRadius",
|
|
67
|
+
"borderStartStartRadius",
|
|
68
|
+
"borderEndEndRadius",
|
|
69
|
+
"borderEndStartRadius",
|
|
70
|
+
"borderTopEndRadius",
|
|
71
|
+
"borderTopLeftRadius",
|
|
72
|
+
"borderTopRightRadius",
|
|
73
|
+
"borderTopStartRadius"
|
|
74
|
+
];
|
|
75
|
+
const textWhitelistStyles = ["fontFamily", "fontSize", "fontStyle", "fontWeight", "lineHeight"];
|
|
76
|
+
const filterStyle = (style) => {
|
|
77
|
+
const viewStyle = {};
|
|
78
|
+
const textStyle = {};
|
|
79
|
+
Object.entries(style).forEach(([name, value]) => {
|
|
80
|
+
if (viewWhitelistStyles.includes(name)) {
|
|
81
|
+
viewStyle[name] = value;
|
|
82
|
+
} else if (textWhitelistStyles.includes(name)) {
|
|
83
|
+
textStyle[name] = value;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return { viewStyle, textStyle };
|
|
87
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
var index_exports = {};
|
|
30
|
+
__export(index_exports, {
|
|
31
|
+
Button: () => Button,
|
|
32
|
+
Image: () => Image,
|
|
33
|
+
Item: () => Item,
|
|
34
|
+
Pressable: () => Pressable,
|
|
35
|
+
Provider: () => Provider,
|
|
36
|
+
Root: () => Root,
|
|
37
|
+
Text: () => Text,
|
|
38
|
+
TextInput: () => TextInput,
|
|
39
|
+
TouchableHighlight: () => TouchableHighlight,
|
|
40
|
+
TouchableOpacity: () => TouchableOpacity,
|
|
41
|
+
TouchableWithoutFeedback: () => TouchableWithoutFeedback,
|
|
42
|
+
View: () => View
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
var import_core = require("@skel-ui/core");
|
|
47
|
+
var import_react = __toESM(require("react"));
|
|
48
|
+
var ReactNative = __toESM(require("react-native"));
|
|
49
|
+
var import_Animation = require("./Animation");
|
|
50
|
+
function createSkelComponent(type) {
|
|
51
|
+
return ({ sw, sh, sr, children, ...props }) => {
|
|
52
|
+
const isLoading = import_react.default.useContext(import_core.IsLoadingContext);
|
|
53
|
+
return isLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
54
|
+
import_Animation.Animation,
|
|
55
|
+
{
|
|
56
|
+
sw,
|
|
57
|
+
sh,
|
|
58
|
+
sr,
|
|
59
|
+
style: { width: props.width, height: props.height, ...props.style },
|
|
60
|
+
numberOfLines: props.numberOfLines
|
|
61
|
+
}
|
|
62
|
+
) : import_react.default.createElement(type, props, children);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function SkelProvider({
|
|
66
|
+
color,
|
|
67
|
+
radius,
|
|
68
|
+
shimmer,
|
|
69
|
+
children,
|
|
70
|
+
animation,
|
|
71
|
+
skelUIPulse
|
|
72
|
+
}) {
|
|
73
|
+
const value = import_react.default.useMemo(
|
|
74
|
+
() => ({ color, radius, shimmer, animation, skelUIPulse }),
|
|
75
|
+
[color, radius, shimmer, animation, skelUIPulse]
|
|
76
|
+
);
|
|
77
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Animation.UIOptionsContext.Provider, { value, children });
|
|
78
|
+
}
|
|
79
|
+
function SkelItem({
|
|
80
|
+
component,
|
|
81
|
+
...rest
|
|
82
|
+
}) {
|
|
83
|
+
return createSkelComponent(component)(rest);
|
|
84
|
+
}
|
|
85
|
+
const Root = import_core.SkelRoot;
|
|
86
|
+
const Item = SkelItem;
|
|
87
|
+
const Provider = SkelProvider;
|
|
88
|
+
const View = createSkelComponent(ReactNative.View);
|
|
89
|
+
const Text = createSkelComponent(ReactNative.Text);
|
|
90
|
+
const Image = createSkelComponent(ReactNative.Image);
|
|
91
|
+
const Button = createSkelComponent(ReactNative.Button);
|
|
92
|
+
const Pressable = createSkelComponent(ReactNative.Pressable);
|
|
93
|
+
const TextInput = createSkelComponent(ReactNative.TextInput);
|
|
94
|
+
const TouchableOpacity = createSkelComponent(ReactNative.TouchableOpacity);
|
|
95
|
+
const TouchableHighlight = createSkelComponent(ReactNative.TouchableHighlight);
|
|
96
|
+
const TouchableWithoutFeedback = createSkelComponent(ReactNative.TouchableWithoutFeedback);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
generatePlaceholder: () => import_core.generatePlaceholder
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(utils_exports);
|
|
24
|
+
var import_core = require("@skel-ui/core");
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LinearGradient } from "expo-linear-gradient";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
4
|
+
import { Text, View } from "react-native";
|
|
5
|
+
import Animated, {
|
|
6
|
+
Easing,
|
|
7
|
+
useFrameCallback,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
withDelay,
|
|
10
|
+
withRepeat,
|
|
11
|
+
withTiming
|
|
12
|
+
} from "react-native-reanimated";
|
|
13
|
+
import { filterStyle } from "./funcs";
|
|
14
|
+
const UIOptionsContext = createContext({});
|
|
15
|
+
function Pluse({ color, animation }) {
|
|
16
|
+
const opacity = useSharedValue(0.5);
|
|
17
|
+
useFrameCallback(() => {
|
|
18
|
+
if (opacity.value === 1 || opacity.value === 0.5) {
|
|
19
|
+
const { delay, ...options } = animation;
|
|
20
|
+
opacity.value = withDelay(delay, withTiming(opacity.value === 1 ? 0.5 : 1, options));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ jsx(Animated.View, { style: { width: "100%", height: "100%", opacity, backgroundColor: color }, "aria-hidden": true, children: /* @__PURE__ */ jsx(Text, { children: " \u200C " }) });
|
|
24
|
+
}
|
|
25
|
+
function Shimmer({ color, shimmer, animation }) {
|
|
26
|
+
const translate = useSharedValue("-100%");
|
|
27
|
+
const cords = {
|
|
28
|
+
x: { start: { x: 0, y: 0 }, end: { x: 1, y: 0 } },
|
|
29
|
+
y: { start: { x: 0, y: 0 }, end: { x: 0, y: 1 } }
|
|
30
|
+
};
|
|
31
|
+
const style = { width: "100%", height: "100%" };
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const { delay, ...options } = animation;
|
|
34
|
+
translate.value = withDelay(delay, withRepeat(withTiming("100%", options), -1, false));
|
|
35
|
+
}, []);
|
|
36
|
+
return /* @__PURE__ */ jsx(View, { style: { backgroundColor: color }, children: /* @__PURE__ */ jsx(
|
|
37
|
+
Animated.View,
|
|
38
|
+
{
|
|
39
|
+
style: {
|
|
40
|
+
...style,
|
|
41
|
+
transform: [{ translateX: translate }]
|
|
42
|
+
// transform: [{ [isVertical ? "translateY" : ("translateX" as never)]: translate as unknown as number }],
|
|
43
|
+
},
|
|
44
|
+
children: /* @__PURE__ */ jsx(
|
|
45
|
+
LinearGradient,
|
|
46
|
+
{
|
|
47
|
+
...cords.x,
|
|
48
|
+
style,
|
|
49
|
+
colors: [color, shimmer.color, color]
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
) });
|
|
54
|
+
}
|
|
55
|
+
function Animation({ sw, sh, sr, style = {}, numberOfLines = 1 }) {
|
|
56
|
+
const text = useMemo(() => new Array(numberOfLines).fill(" \u200C ").join("\n"), [numberOfLines]);
|
|
57
|
+
const { viewStyle, textStyle } = filterStyle(style);
|
|
58
|
+
const { color = "#cbd5e1", radius = 4, shimmer = {}, animation = {}, skelUIPulse } = useContext(UIOptionsContext);
|
|
59
|
+
const $props = {
|
|
60
|
+
color,
|
|
61
|
+
radius,
|
|
62
|
+
shimmer: {
|
|
63
|
+
color: "#f1f0f0",
|
|
64
|
+
...shimmer
|
|
65
|
+
},
|
|
66
|
+
animation: {
|
|
67
|
+
delay: 0,
|
|
68
|
+
easing: Easing.bezier(0.4, 0, 0.6, 1),
|
|
69
|
+
duration: skelUIPulse ? 1e3 : 2e3,
|
|
70
|
+
...animation
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return /* @__PURE__ */ jsxs(
|
|
74
|
+
View,
|
|
75
|
+
{
|
|
76
|
+
style: {
|
|
77
|
+
...style,
|
|
78
|
+
width: sw || viewStyle.width,
|
|
79
|
+
height: sh || viewStyle.height,
|
|
80
|
+
borderRadius: sr || viewStyle.borderRadius || radius,
|
|
81
|
+
overflow: "hidden",
|
|
82
|
+
position: "relative",
|
|
83
|
+
backgroundColor: void 0
|
|
84
|
+
},
|
|
85
|
+
children: [
|
|
86
|
+
/* @__PURE__ */ jsx(Text, { style: textStyle, children: text }),
|
|
87
|
+
/* @__PURE__ */ jsx(View, { style: { inset: 0, position: "absolute" }, children: "component" in animation ? animation.component : skelUIPulse ? /* @__PURE__ */ jsx(Pluse, { ...$props }) : /* @__PURE__ */ jsx(Shimmer, { ...$props }) })
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
Animation,
|
|
94
|
+
UIOptionsContext
|
|
95
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const viewWhitelistStyles = [
|
|
2
|
+
"aspectRatio",
|
|
3
|
+
"bottom",
|
|
4
|
+
"display",
|
|
5
|
+
"flex",
|
|
6
|
+
"flexBasis",
|
|
7
|
+
"flexGrow",
|
|
8
|
+
"flexShrink",
|
|
9
|
+
"left",
|
|
10
|
+
"margin",
|
|
11
|
+
"marginBottom",
|
|
12
|
+
"marginEnd",
|
|
13
|
+
"marginHorizontal",
|
|
14
|
+
"marginLeft",
|
|
15
|
+
"marginRight",
|
|
16
|
+
"marginStart",
|
|
17
|
+
"marginTop",
|
|
18
|
+
"marginVertical",
|
|
19
|
+
"maxHeight",
|
|
20
|
+
"maxWidth",
|
|
21
|
+
"minHeight",
|
|
22
|
+
"minWidth",
|
|
23
|
+
"padding",
|
|
24
|
+
"paddingBottom",
|
|
25
|
+
"paddingEnd",
|
|
26
|
+
"paddingHorizontal",
|
|
27
|
+
"paddingLeft",
|
|
28
|
+
"paddingRight",
|
|
29
|
+
"paddingStart",
|
|
30
|
+
"paddingTop",
|
|
31
|
+
"paddingVertical",
|
|
32
|
+
"position",
|
|
33
|
+
"right",
|
|
34
|
+
"top",
|
|
35
|
+
"zIndex",
|
|
36
|
+
"width",
|
|
37
|
+
"height",
|
|
38
|
+
"borderRadius",
|
|
39
|
+
"borderBottomEndRadius",
|
|
40
|
+
"borderBottomLeftRadius",
|
|
41
|
+
"borderBottomRightRadius",
|
|
42
|
+
"borderBottomStartRadius",
|
|
43
|
+
"borderStartEndRadius",
|
|
44
|
+
"borderStartStartRadius",
|
|
45
|
+
"borderEndEndRadius",
|
|
46
|
+
"borderEndStartRadius",
|
|
47
|
+
"borderTopEndRadius",
|
|
48
|
+
"borderTopLeftRadius",
|
|
49
|
+
"borderTopRightRadius",
|
|
50
|
+
"borderTopStartRadius"
|
|
51
|
+
];
|
|
52
|
+
const textWhitelistStyles = ["fontFamily", "fontSize", "fontStyle", "fontWeight", "lineHeight"];
|
|
53
|
+
const filterStyle = (style) => {
|
|
54
|
+
const viewStyle = {};
|
|
55
|
+
const textStyle = {};
|
|
56
|
+
Object.entries(style).forEach(([name, value]) => {
|
|
57
|
+
if (viewWhitelistStyles.includes(name)) {
|
|
58
|
+
viewStyle[name] = value;
|
|
59
|
+
} else if (textWhitelistStyles.includes(name)) {
|
|
60
|
+
textStyle[name] = value;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return { viewStyle, textStyle };
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
filterStyle
|
|
67
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { IsLoadingContext, SkelRoot } from "@skel-ui/core";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import * as ReactNative from "react-native";
|
|
5
|
+
import { Animation, UIOptionsContext } from "./Animation";
|
|
6
|
+
function createSkelComponent(type) {
|
|
7
|
+
return ({ sw, sh, sr, children, ...props }) => {
|
|
8
|
+
const isLoading = React.useContext(IsLoadingContext);
|
|
9
|
+
return isLoading ? /* @__PURE__ */ jsx(
|
|
10
|
+
Animation,
|
|
11
|
+
{
|
|
12
|
+
sw,
|
|
13
|
+
sh,
|
|
14
|
+
sr,
|
|
15
|
+
style: { width: props.width, height: props.height, ...props.style },
|
|
16
|
+
numberOfLines: props.numberOfLines
|
|
17
|
+
}
|
|
18
|
+
) : React.createElement(type, props, children);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function SkelProvider({
|
|
22
|
+
color,
|
|
23
|
+
radius,
|
|
24
|
+
shimmer,
|
|
25
|
+
children,
|
|
26
|
+
animation,
|
|
27
|
+
skelUIPulse
|
|
28
|
+
}) {
|
|
29
|
+
const value = React.useMemo(
|
|
30
|
+
() => ({ color, radius, shimmer, animation, skelUIPulse }),
|
|
31
|
+
[color, radius, shimmer, animation, skelUIPulse]
|
|
32
|
+
);
|
|
33
|
+
return /* @__PURE__ */ jsx(UIOptionsContext.Provider, { value, children });
|
|
34
|
+
}
|
|
35
|
+
function SkelItem({
|
|
36
|
+
component,
|
|
37
|
+
...rest
|
|
38
|
+
}) {
|
|
39
|
+
return createSkelComponent(component)(rest);
|
|
40
|
+
}
|
|
41
|
+
const Root = SkelRoot;
|
|
42
|
+
const Item = SkelItem;
|
|
43
|
+
const Provider = SkelProvider;
|
|
44
|
+
const View = createSkelComponent(ReactNative.View);
|
|
45
|
+
const Text = createSkelComponent(ReactNative.Text);
|
|
46
|
+
const Image = createSkelComponent(ReactNative.Image);
|
|
47
|
+
const Button = createSkelComponent(ReactNative.Button);
|
|
48
|
+
const Pressable = createSkelComponent(ReactNative.Pressable);
|
|
49
|
+
const TextInput = createSkelComponent(ReactNative.TextInput);
|
|
50
|
+
const TouchableOpacity = createSkelComponent(ReactNative.TouchableOpacity);
|
|
51
|
+
const TouchableHighlight = createSkelComponent(ReactNative.TouchableHighlight);
|
|
52
|
+
const TouchableWithoutFeedback = createSkelComponent(ReactNative.TouchableWithoutFeedback);
|
|
53
|
+
export {
|
|
54
|
+
Button,
|
|
55
|
+
Image,
|
|
56
|
+
Item,
|
|
57
|
+
Pressable,
|
|
58
|
+
Provider,
|
|
59
|
+
Root,
|
|
60
|
+
Text,
|
|
61
|
+
TextInput,
|
|
62
|
+
TouchableHighlight,
|
|
63
|
+
TouchableOpacity,
|
|
64
|
+
TouchableWithoutFeedback,
|
|
65
|
+
View
|
|
66
|
+
};
|
package/dist/funcs.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SkelComponentProps, SkelRoot } from "@skel-ui/core";
|
|
2
|
+
import type { ComponentProps, ComponentType, ReactNode } from "react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import * as ReactNative from "react-native";
|
|
5
|
+
import { UIOptions } from "./Animation";
|
|
6
|
+
declare function SkelProvider({ color, radius, shimmer, children, animation, skelUIPulse, }: UIOptions & {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare function SkelItem<T extends ComponentType<ComponentProps<T>>>({ component, ...rest }: {
|
|
10
|
+
component: T;
|
|
11
|
+
} & ComponentProps<T> & Pick<SkelComponentProps<T>, "sw" | "sh" | "sr">): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare const Root: typeof SkelRoot;
|
|
13
|
+
export declare const Item: typeof SkelItem;
|
|
14
|
+
export declare const Provider: typeof SkelProvider;
|
|
15
|
+
export declare const View: ({ sw, sh, sr, children, ...props }: SkelComponentProps<typeof ReactNative.View>) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare const Text: ({ sw, sh, sr, children, ...props }: SkelComponentProps<typeof ReactNative.Text>) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare const Image: ({ sw, sh, sr, children, ...props }: SkelComponentProps<typeof ReactNative.Image>) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export declare const Button: ({ sw, sh, sr, children, ...props }: SkelComponentProps<typeof ReactNative.Button>) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare const Pressable: ({ sw, sh, sr, children, ...props }: SkelComponentProps<React.ForwardRefExoticComponent<ReactNative.PressableProps & React.RefAttributes<ReactNative.View>>>) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare const TextInput: ({ sw, sh, sr, children, ...props }: SkelComponentProps<typeof ReactNative.TextInput>) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare const TouchableOpacity: ({ sw, sh, sr, children, ...props }: SkelComponentProps<React.ForwardRefExoticComponent<ReactNative.TouchableOpacityProps & React.RefAttributes<ReactNative.View>>>) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare const TouchableHighlight: ({ sw, sh, sr, children, ...props }: SkelComponentProps<React.ForwardRefExoticComponent<ReactNative.TouchableHighlightProps & React.RefAttributes<ReactNative.View>>>) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare const TouchableWithoutFeedback: ({ sw, sh, sr, children, ...props }: SkelComponentProps<typeof ReactNative.TouchableWithoutFeedback>) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export {};
|
package/dist/utils.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skel-ui/react-native",
|
|
3
|
+
"author": "https://github.com/sudoaugustin",
|
|
4
|
+
"version": "1.0.0-alpha.01475df",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Lightweight and powerful skeleton loading library for React.",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"main": "dist/cjs/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"module": "dist/esm/index.js",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react",
|
|
15
|
+
"native",
|
|
16
|
+
"skeleton",
|
|
17
|
+
"loading",
|
|
18
|
+
"placeholder"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/esm/index.js",
|
|
24
|
+
"require": "./dist/cjs/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./utils": {
|
|
27
|
+
"types": "./dist/utils.d.ts",
|
|
28
|
+
"import": "./dist/esm/utils.js",
|
|
29
|
+
"require": "./dist/cjs/utils.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
"*": {
|
|
34
|
+
"utils": [
|
|
35
|
+
"./dist/utils.d.ts"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/sudoaugustin/skel-ui/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://skel-ui.augustin.zip",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/sudoaugustin/skel-ui"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@skel-ui/core": "1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/react": "18.3.12",
|
|
52
|
+
"esbuild": "^0.24.0",
|
|
53
|
+
"expo-linear-gradient": "^14.0",
|
|
54
|
+
"react": "^18.3.1",
|
|
55
|
+
"react-native": "0.76.3",
|
|
56
|
+
"typescript": "^5.7.2",
|
|
57
|
+
"react-native-reanimated": "^3.0",
|
|
58
|
+
"commons-tsconfig": "0.0.1",
|
|
59
|
+
"@skel-ui/core": "1.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"expo-linear-gradient": "^14.0",
|
|
63
|
+
"react": "^17.0 || ^18.0",
|
|
64
|
+
"react-native": "*",
|
|
65
|
+
"react-native-reanimated": "^3.0"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "rm -rf dist && pnpm build:dts && pnpm build:esm && pnpm build:cjs",
|
|
69
|
+
"build:dts": "tsc -p tsconfig.json --outDir dist --emitDeclarationOnly",
|
|
70
|
+
"build:css": "esbuild src/styles.css --outdir=dist",
|
|
71
|
+
"build:esm": "esbuild src/*.ts* --format=esm --outdir=dist/esm",
|
|
72
|
+
"build:cjs": "esbuild src/*.ts* --format=cjs --outdir=dist/cjs"
|
|
73
|
+
}
|
|
74
|
+
}
|