@lotics/ui 2.5.0 → 2.6.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/package.json +2 -1
- package/src/skeleton.tsx +47 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lotics/ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./tokens": "./src/tokens.ts",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"./counter": "./src/counter.tsx",
|
|
103
103
|
"./link_button": "./src/link_button.tsx",
|
|
104
104
|
"./sort_header": "./src/sort_header.tsx",
|
|
105
|
+
"./skeleton": "./src/skeleton.tsx",
|
|
105
106
|
"./table": "./src/table.tsx",
|
|
106
107
|
"./detail_row": "./src/detail_row.tsx",
|
|
107
108
|
"./scan_field": "./src/scan_field.tsx",
|
package/src/skeleton.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { Animated, type DimensionValue, type StyleProp, type ViewStyle } from "react-native";
|
|
3
|
+
import { colors } from "./colors";
|
|
4
|
+
|
|
5
|
+
export interface SkeletonProps {
|
|
6
|
+
/** Width — px or a percentage string ("100%", "60%"). Default "100%". */
|
|
7
|
+
width?: DimensionValue;
|
|
8
|
+
/** Height in px. Default 16. */
|
|
9
|
+
height?: number;
|
|
10
|
+
/** Corner radius. Default 6. */
|
|
11
|
+
radius?: number;
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A loading placeholder — a softly pulsing zinc tile that stands in for content
|
|
17
|
+
* not yet loaded. The point is **zero layout shift**: reserve the SAME footprint
|
|
18
|
+
* as the element it replaces, so nothing jumps when the data arrives. Compose
|
|
19
|
+
* several (with the loaded layout's widths/heights) to mirror a row or card, and
|
|
20
|
+
* render them in the load slot instead of a spinner that collapses the surface.
|
|
21
|
+
*
|
|
22
|
+
* Decorative — excluded from the accessibility tree (the surrounding region
|
|
23
|
+
* should carry a "loading" affordance if one is needed).
|
|
24
|
+
*/
|
|
25
|
+
export function Skeleton(props: SkeletonProps) {
|
|
26
|
+
const { width = "100%", height = 16, radius = 6, style } = props;
|
|
27
|
+
const pulse = useRef(new Animated.Value(0.6)).current;
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const loop = Animated.loop(
|
|
31
|
+
Animated.sequence([
|
|
32
|
+
Animated.timing(pulse, { toValue: 1, duration: 750, useNativeDriver: true }),
|
|
33
|
+
Animated.timing(pulse, { toValue: 0.6, duration: 750, useNativeDriver: true }),
|
|
34
|
+
]),
|
|
35
|
+
);
|
|
36
|
+
loop.start();
|
|
37
|
+
return () => loop.stop();
|
|
38
|
+
}, [pulse]);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Animated.View
|
|
42
|
+
accessible={false}
|
|
43
|
+
importantForAccessibility="no-hide-descendants"
|
|
44
|
+
style={[{ width, height, borderRadius: radius, backgroundColor: colors.zinc[100], opacity: pulse }, style]}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|