@impulse-ui-native/data-state 2.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/dist/index.d.mts +48 -0
- package/dist/index.js +283 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType, PropsWithChildren } from 'react';
|
|
3
|
+
import { PressableProps, ViewStyle } from 'react-native';
|
|
4
|
+
import { IconProps } from '@impulse-ui-native/icon';
|
|
5
|
+
import { ViewProps } from '@impulse-ui-native/primitives';
|
|
6
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
interface StateActionsFooterProps extends ViewProps {
|
|
9
|
+
onPressPrimaryAction: PressableProps["onPress"];
|
|
10
|
+
primaryActionLabel: string;
|
|
11
|
+
onPressSecondaryAction?: PressableProps["onPress"];
|
|
12
|
+
secondaryActionLabel?: string;
|
|
13
|
+
}
|
|
14
|
+
interface StateViewProps extends StateActionsFooterProps, ViewProps {
|
|
15
|
+
text: string;
|
|
16
|
+
variant?: IconProps["variant"];
|
|
17
|
+
contentContainerStyle?: ViewStyle;
|
|
18
|
+
}
|
|
19
|
+
interface EmptyViewProps extends StateViewProps {
|
|
20
|
+
isEmpty: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ErrorViewProps extends StateViewProps {
|
|
23
|
+
error: Error | null;
|
|
24
|
+
}
|
|
25
|
+
interface LoadingViewProps extends ViewProps {
|
|
26
|
+
loading: boolean;
|
|
27
|
+
LoadingComponent: ComponentType;
|
|
28
|
+
contentContainerStyle?: ViewStyle;
|
|
29
|
+
}
|
|
30
|
+
interface DataViewProps extends ViewProps {
|
|
31
|
+
error: ErrorViewProps["error"];
|
|
32
|
+
isEmpty: EmptyViewProps["isEmpty"];
|
|
33
|
+
LoadingComponent: ComponentType;
|
|
34
|
+
loading: LoadingViewProps["loading"];
|
|
35
|
+
contentContainerStyle?: ViewStyle;
|
|
36
|
+
errorViewProps: StateViewProps;
|
|
37
|
+
emptyViewProps: StateViewProps;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare const ErrorView: react.NamedExoticComponent<ErrorViewProps>;
|
|
41
|
+
|
|
42
|
+
declare const EmptyView: react.NamedExoticComponent<EmptyViewProps>;
|
|
43
|
+
|
|
44
|
+
declare const LoadingView: react.NamedExoticComponent<LoadingViewProps>;
|
|
45
|
+
|
|
46
|
+
declare const DataView: react.MemoExoticComponent<(props: PropsWithChildren<DataViewProps>) => react_jsx_runtime.JSX.Element>;
|
|
47
|
+
|
|
48
|
+
export { DataView, type DataViewProps, EmptyView, type EmptyViewProps, ErrorView, type ErrorViewProps, LoadingView, type LoadingViewProps, type StateActionsFooterProps, type StateViewProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
// src/components/error-view.tsx
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { View } from "@impulse-ui-native/primitives";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var ErrorView = memo(function ErrorView2(props) {
|
|
6
|
+
const {
|
|
7
|
+
variant,
|
|
8
|
+
text,
|
|
9
|
+
error,
|
|
10
|
+
onPressPrimaryAction,
|
|
11
|
+
onPressSecondaryAction,
|
|
12
|
+
primaryActionLabel,
|
|
13
|
+
secondaryActionLabel,
|
|
14
|
+
contentContainerStyle,
|
|
15
|
+
children,
|
|
16
|
+
...rest
|
|
17
|
+
} = props;
|
|
18
|
+
return /* @__PURE__ */ jsx(View, { ...rest, children: /* @__PURE__ */ jsx(View, { style: contentContainerStyle, children }) });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// src/components/empty-view.tsx
|
|
22
|
+
import { memo as memo2 } from "react";
|
|
23
|
+
import { View as View2 } from "@impulse-ui-native/primitives";
|
|
24
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
25
|
+
var EmptyView = memo2(function EmptyView2(props) {
|
|
26
|
+
const {
|
|
27
|
+
variant,
|
|
28
|
+
text,
|
|
29
|
+
isEmpty,
|
|
30
|
+
onPressPrimaryAction,
|
|
31
|
+
primaryActionLabel,
|
|
32
|
+
onPressSecondaryAction,
|
|
33
|
+
secondaryActionLabel,
|
|
34
|
+
contentContainerStyle,
|
|
35
|
+
children,
|
|
36
|
+
...rest
|
|
37
|
+
} = props;
|
|
38
|
+
return /* @__PURE__ */ jsx2(View2, { ...rest, children: /* @__PURE__ */ jsx2(View2, { style: contentContainerStyle, children }) });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// src/components/loading-view.tsx
|
|
42
|
+
import { memo as memo3, useCallback, useEffect, useMemo, useState } from "react";
|
|
43
|
+
import Animated, {
|
|
44
|
+
Easing,
|
|
45
|
+
useAnimatedStyle,
|
|
46
|
+
useSharedValue,
|
|
47
|
+
withTiming
|
|
48
|
+
} from "react-native-reanimated";
|
|
49
|
+
import { scheduleOnRN } from "react-native-worklets";
|
|
50
|
+
import { View as View3 } from "@impulse-ui-native/primitives";
|
|
51
|
+
import { useComponentsTokens } from "@impulse-ui-native/theme";
|
|
52
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
53
|
+
var LoadingView = memo3(function LoadingView2(props) {
|
|
54
|
+
const {
|
|
55
|
+
loading,
|
|
56
|
+
children,
|
|
57
|
+
LoadingComponent,
|
|
58
|
+
contentContainerStyle,
|
|
59
|
+
style,
|
|
60
|
+
...rest
|
|
61
|
+
} = props;
|
|
62
|
+
const tokens = useComponentsTokens().dataState.loading;
|
|
63
|
+
const [shouldMountLoader, setShouldMountLoader] = useState(loading);
|
|
64
|
+
const [loaderHeight, setLoaderHeight] = useState(0);
|
|
65
|
+
const loaderOpacity = useSharedValue(loading ? 1 : 0);
|
|
66
|
+
const childrenOpacity = useSharedValue(loading ? 0 : 1);
|
|
67
|
+
const onLoaderLayout = useCallback((event) => {
|
|
68
|
+
const height = event.nativeEvent.layout.height;
|
|
69
|
+
setLoaderHeight((prev) => {
|
|
70
|
+
if (prev === height) {
|
|
71
|
+
return prev;
|
|
72
|
+
}
|
|
73
|
+
return height;
|
|
74
|
+
});
|
|
75
|
+
}, []);
|
|
76
|
+
const containerStyle = useMemo(
|
|
77
|
+
() => [
|
|
78
|
+
{
|
|
79
|
+
position: "relative",
|
|
80
|
+
minHeight: shouldMountLoader ? loaderHeight : void 0
|
|
81
|
+
},
|
|
82
|
+
style
|
|
83
|
+
],
|
|
84
|
+
[loaderHeight, shouldMountLoader, style]
|
|
85
|
+
);
|
|
86
|
+
const loaderStyles = useAnimatedStyle(() => ({
|
|
87
|
+
position: "absolute",
|
|
88
|
+
bottom: 0,
|
|
89
|
+
left: 0,
|
|
90
|
+
right: 0,
|
|
91
|
+
top: 0,
|
|
92
|
+
zIndex: tokens.loaderZIndex,
|
|
93
|
+
opacity: loaderOpacity.value
|
|
94
|
+
}));
|
|
95
|
+
const childrenStyles = useAnimatedStyle(() => ({
|
|
96
|
+
opacity: childrenOpacity.value
|
|
97
|
+
}));
|
|
98
|
+
const childrenContainerStyles = useMemo(
|
|
99
|
+
() => [contentContainerStyle, childrenStyles],
|
|
100
|
+
[contentContainerStyle, childrenStyles]
|
|
101
|
+
);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (loading) {
|
|
104
|
+
setShouldMountLoader(true);
|
|
105
|
+
loaderOpacity.value = 1;
|
|
106
|
+
childrenOpacity.value = 0;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
loaderOpacity.value = withTiming(
|
|
110
|
+
0,
|
|
111
|
+
{
|
|
112
|
+
duration: tokens.transitionDuration,
|
|
113
|
+
easing: Easing.linear
|
|
114
|
+
},
|
|
115
|
+
(finished) => {
|
|
116
|
+
if (finished) {
|
|
117
|
+
scheduleOnRN(setShouldMountLoader, false);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
childrenOpacity.value = withTiming(1, {
|
|
122
|
+
duration: tokens.transitionDuration,
|
|
123
|
+
easing: Easing.linear
|
|
124
|
+
});
|
|
125
|
+
}, [loading, loaderOpacity, childrenOpacity, tokens.transitionDuration]);
|
|
126
|
+
return /* @__PURE__ */ jsxs(View3, { ...rest, style: containerStyle, children: [
|
|
127
|
+
/* @__PURE__ */ jsx3(Animated.View, { style: childrenContainerStyles, children }),
|
|
128
|
+
shouldMountLoader ? /* @__PURE__ */ jsx3(Animated.View, { style: loaderStyles, pointerEvents: "auto", children: /* @__PURE__ */ jsx3(View3, { onLayout: onLoaderLayout, children: /* @__PURE__ */ jsx3(LoadingComponent, {}) }) }) : null
|
|
129
|
+
] });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// src/components/data-view.tsx
|
|
133
|
+
import { memo as memo7, useMemo as useMemo2 } from "react";
|
|
134
|
+
import { View as View7 } from "@impulse-ui-native/primitives";
|
|
135
|
+
import { useComponentsTokens as useComponentsTokens5 } from "@impulse-ui-native/theme";
|
|
136
|
+
|
|
137
|
+
// src/components/empty-details.tsx
|
|
138
|
+
import { memo as memo5 } from "react";
|
|
139
|
+
import { EmptyIcon } from "@impulse-ui-native/icon";
|
|
140
|
+
import { Typography, View as View5 } from "@impulse-ui-native/primitives";
|
|
141
|
+
import { useComponentsTokens as useComponentsTokens3 } from "@impulse-ui-native/theme";
|
|
142
|
+
|
|
143
|
+
// src/components/state-actions-footer.tsx
|
|
144
|
+
import { memo as memo4 } from "react";
|
|
145
|
+
import { Button, View as View4 } from "@impulse-ui-native/primitives";
|
|
146
|
+
import { useComponentsTokens as useComponentsTokens2 } from "@impulse-ui-native/theme";
|
|
147
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
148
|
+
var StateActionsFooter = memo4(function StateActionsFooter2(props) {
|
|
149
|
+
const tokens = useComponentsTokens2().dataState.actionsFooter;
|
|
150
|
+
const {
|
|
151
|
+
onPressPrimaryAction,
|
|
152
|
+
onPressSecondaryAction,
|
|
153
|
+
primaryActionLabel,
|
|
154
|
+
secondaryActionLabel,
|
|
155
|
+
...rest
|
|
156
|
+
} = props;
|
|
157
|
+
return /* @__PURE__ */ jsxs2(
|
|
158
|
+
View4,
|
|
159
|
+
{
|
|
160
|
+
flexDirection: "row",
|
|
161
|
+
gap: tokens.gap,
|
|
162
|
+
justifyContent: "center",
|
|
163
|
+
alignItems: "center",
|
|
164
|
+
...rest,
|
|
165
|
+
children: [
|
|
166
|
+
/* @__PURE__ */ jsx4(Button, { onPress: props.onPressPrimaryAction, children: props.primaryActionLabel }),
|
|
167
|
+
props.onPressSecondaryAction ? /* @__PURE__ */ jsx4(Button, { variant: "outlined", onPress: props.onPressSecondaryAction, children: props.secondaryActionLabel }) : null
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// src/components/empty-details.tsx
|
|
174
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
175
|
+
var EmptyDetails = memo5(function EmptyDetails2(props) {
|
|
176
|
+
const tokens = useComponentsTokens3().dataState.details;
|
|
177
|
+
return /* @__PURE__ */ jsxs3(View5, { alignItems: "center", justifyContent: "center", gap: tokens.gap, children: [
|
|
178
|
+
/* @__PURE__ */ jsx5(
|
|
179
|
+
EmptyIcon,
|
|
180
|
+
{
|
|
181
|
+
width: tokens.iconSize,
|
|
182
|
+
height: tokens.iconSize,
|
|
183
|
+
variant: props.variant,
|
|
184
|
+
color: tokens.iconColor
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
/* @__PURE__ */ jsx5(Typography.Body, { children: props.text }),
|
|
188
|
+
/* @__PURE__ */ jsx5(
|
|
189
|
+
StateActionsFooter,
|
|
190
|
+
{
|
|
191
|
+
onPressPrimaryAction: props.onPressPrimaryAction,
|
|
192
|
+
primaryActionLabel: props.primaryActionLabel,
|
|
193
|
+
onPressSecondaryAction: props.onPressSecondaryAction,
|
|
194
|
+
secondaryActionLabel: props.secondaryActionLabel
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
] });
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// src/components/error-details.tsx
|
|
201
|
+
import { memo as memo6 } from "react";
|
|
202
|
+
import { CloudXIcon } from "@impulse-ui-native/icon";
|
|
203
|
+
import { Typography as Typography2, View as View6 } from "@impulse-ui-native/primitives";
|
|
204
|
+
import { useComponentsTokens as useComponentsTokens4 } from "@impulse-ui-native/theme";
|
|
205
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
206
|
+
var ErrorDetails = memo6(function ErrorDetails2(props) {
|
|
207
|
+
const tokens = useComponentsTokens4().dataState.details;
|
|
208
|
+
return /* @__PURE__ */ jsxs4(View6, { alignItems: "center", justifyContent: "center", gap: tokens.gap, children: [
|
|
209
|
+
/* @__PURE__ */ jsx6(
|
|
210
|
+
CloudXIcon,
|
|
211
|
+
{
|
|
212
|
+
width: tokens.iconSize,
|
|
213
|
+
height: tokens.iconSize,
|
|
214
|
+
variant: props.variant,
|
|
215
|
+
color: tokens.iconColor
|
|
216
|
+
}
|
|
217
|
+
),
|
|
218
|
+
/* @__PURE__ */ jsx6(Typography2.Body, { children: props.text }),
|
|
219
|
+
/* @__PURE__ */ jsx6(
|
|
220
|
+
StateActionsFooter,
|
|
221
|
+
{
|
|
222
|
+
onPressPrimaryAction: props.onPressPrimaryAction,
|
|
223
|
+
primaryActionLabel: props.primaryActionLabel,
|
|
224
|
+
onPressSecondaryAction: props.onPressSecondaryAction,
|
|
225
|
+
secondaryActionLabel: props.secondaryActionLabel
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
] });
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// src/components/data-view.tsx
|
|
232
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
233
|
+
var DataView = memo7((props) => {
|
|
234
|
+
const tokens = useComponentsTokens5().dataState;
|
|
235
|
+
const {
|
|
236
|
+
error,
|
|
237
|
+
isEmpty,
|
|
238
|
+
loading,
|
|
239
|
+
errorViewProps,
|
|
240
|
+
emptyViewProps,
|
|
241
|
+
LoadingComponent,
|
|
242
|
+
contentContainerStyle,
|
|
243
|
+
children,
|
|
244
|
+
...rest
|
|
245
|
+
} = props;
|
|
246
|
+
const content = useMemo2(() => {
|
|
247
|
+
if (!error && !isEmpty) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return /* @__PURE__ */ jsxs5(
|
|
251
|
+
View7,
|
|
252
|
+
{
|
|
253
|
+
alignItems: "center",
|
|
254
|
+
justifyContent: "center",
|
|
255
|
+
zIndex: tokens.content.zIndex,
|
|
256
|
+
children: [
|
|
257
|
+
error ? /* @__PURE__ */ jsx7(ErrorDetails, { ...errorViewProps }) : null,
|
|
258
|
+
isEmpty ? /* @__PURE__ */ jsx7(EmptyDetails, { ...emptyViewProps }) : null
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
}, [error, isEmpty, errorViewProps, emptyViewProps, tokens.content.zIndex]);
|
|
263
|
+
return /* @__PURE__ */ jsxs5(
|
|
264
|
+
LoadingView,
|
|
265
|
+
{
|
|
266
|
+
...rest,
|
|
267
|
+
LoadingComponent,
|
|
268
|
+
contentContainerStyle,
|
|
269
|
+
loading,
|
|
270
|
+
children: [
|
|
271
|
+
!error && !isEmpty && !loading ? children : null,
|
|
272
|
+
content
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
export {
|
|
278
|
+
DataView,
|
|
279
|
+
EmptyView,
|
|
280
|
+
ErrorView,
|
|
281
|
+
LoadingView
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/error-view.tsx","../src/components/empty-view.tsx","../src/components/loading-view.tsx","../src/components/data-view.tsx","../src/components/empty-details.tsx","../src/components/state-actions-footer.tsx","../src/components/error-details.tsx"],"sourcesContent":["import { memo } from \"react\";\r\n\r\nimport { View } from \"@impulse-ui-native/primitives\";\r\n\r\nimport { ErrorViewProps } from \"../types\";\r\n\r\nexport const ErrorView = memo(function ErrorView(props: ErrorViewProps) {\r\n const {\r\n variant,\r\n text,\r\n error,\r\n onPressPrimaryAction,\r\n onPressSecondaryAction,\r\n primaryActionLabel,\r\n secondaryActionLabel,\r\n contentContainerStyle,\r\n children,\r\n ...rest\r\n } = props;\r\n\r\n return (\r\n <View {...rest}>\r\n <View style={contentContainerStyle}>{children}</View>\r\n </View>\r\n );\r\n});\r\n","import { memo } from \"react\";\r\n\r\nimport { View } from \"@impulse-ui-native/primitives\";\r\n\r\nimport { EmptyViewProps } from \"../types\";\r\n\r\nexport const EmptyView = memo(function EmptyView(props: EmptyViewProps) {\r\n const {\r\n variant,\r\n text,\r\n isEmpty,\r\n onPressPrimaryAction,\r\n primaryActionLabel,\r\n onPressSecondaryAction,\r\n secondaryActionLabel,\r\n contentContainerStyle,\r\n children,\r\n ...rest\r\n } = props;\r\n\r\n return (\r\n <View {...rest}>\r\n <View style={contentContainerStyle}>{children}</View>\r\n </View>\r\n );\r\n});\r\n","import { memo, useCallback, useEffect, useMemo, useState } from \"react\";\r\nimport { LayoutChangeEvent, StyleProp, ViewStyle } from \"react-native\";\r\nimport Animated, {\r\n Easing,\r\n useAnimatedStyle,\r\n useSharedValue,\r\n withTiming,\r\n} from \"react-native-reanimated\";\r\nimport { scheduleOnRN } from \"react-native-worklets\";\r\n\r\nimport { View } from \"@impulse-ui-native/primitives\";\r\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\r\n\r\nimport { LoadingViewProps } from \"../types\";\r\n\r\nexport const LoadingView = memo(function LoadingView(props: LoadingViewProps) {\r\n const {\r\n loading,\r\n children,\r\n LoadingComponent,\r\n contentContainerStyle,\r\n style,\r\n ...rest\r\n } = props;\r\n\r\n const tokens = useComponentsTokens().dataState.loading;\r\n\r\n const [shouldMountLoader, setShouldMountLoader] = useState(loading);\r\n const [loaderHeight, setLoaderHeight] = useState(0);\r\n\r\n const loaderOpacity = useSharedValue(loading ? 1 : 0);\r\n const childrenOpacity = useSharedValue(loading ? 0 : 1);\r\n\r\n const onLoaderLayout = useCallback((event: LayoutChangeEvent) => {\r\n const height = event.nativeEvent.layout.height;\r\n\r\n setLoaderHeight((prev) => {\r\n if (prev === height) {\r\n return prev;\r\n }\r\n\r\n return height;\r\n });\r\n }, []);\r\n\r\n const containerStyle = useMemo<StyleProp<ViewStyle>>(\r\n () => [\r\n {\r\n position: \"relative\",\r\n minHeight: shouldMountLoader ? loaderHeight : undefined,\r\n },\r\n style,\r\n ],\r\n [loaderHeight, shouldMountLoader, style],\r\n );\r\n\r\n const loaderStyles = useAnimatedStyle(() => ({\r\n position: \"absolute\",\r\n bottom: 0,\r\n left: 0,\r\n right: 0,\r\n top: 0,\r\n zIndex: tokens.loaderZIndex,\r\n opacity: loaderOpacity.value,\r\n }));\r\n\r\n const childrenStyles = useAnimatedStyle(() => ({\r\n opacity: childrenOpacity.value,\r\n }));\r\n\r\n const childrenContainerStyles = useMemo(\r\n () => [contentContainerStyle, childrenStyles],\r\n [contentContainerStyle, childrenStyles],\r\n );\r\n\r\n useEffect(() => {\r\n if (loading) {\r\n setShouldMountLoader(true);\r\n\r\n loaderOpacity.value = 1;\r\n childrenOpacity.value = 0;\r\n\r\n return;\r\n }\r\n\r\n loaderOpacity.value = withTiming(\r\n 0,\r\n {\r\n duration: tokens.transitionDuration,\r\n easing: Easing.linear,\r\n },\r\n (finished) => {\r\n if (finished) {\r\n scheduleOnRN(setShouldMountLoader, false);\r\n }\r\n },\r\n );\r\n\r\n childrenOpacity.value = withTiming(1, {\r\n duration: tokens.transitionDuration,\r\n easing: Easing.linear,\r\n });\r\n }, [loading, loaderOpacity, childrenOpacity, tokens.transitionDuration]);\r\n\r\n return (\r\n <View {...rest} style={containerStyle}>\r\n <Animated.View style={childrenContainerStyles}>{children}</Animated.View>\r\n\r\n {shouldMountLoader ? (\r\n <Animated.View style={loaderStyles} pointerEvents=\"auto\">\r\n <View onLayout={onLoaderLayout}>\r\n <LoadingComponent />\r\n </View>\r\n </Animated.View>\r\n ) : null}\r\n </View>\r\n );\r\n});\r\n","import { memo, PropsWithChildren, useMemo } from \"react\";\r\n\r\nimport { View } from \"@impulse-ui-native/primitives\";\r\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\r\n\r\nimport { DataViewProps } from \"../types\";\r\nimport { EmptyDetails } from \"./empty-details\";\r\nimport { ErrorDetails } from \"./error-details\";\r\nimport { LoadingView } from \"./loading-view\";\r\n\r\nexport const DataView = memo((props: PropsWithChildren<DataViewProps>) => {\r\n const tokens = useComponentsTokens().dataState;\r\n const {\r\n error,\r\n isEmpty,\r\n loading,\r\n errorViewProps,\r\n emptyViewProps,\r\n LoadingComponent,\r\n contentContainerStyle,\r\n children,\r\n ...rest\r\n } = props;\r\n\r\n const content = useMemo(() => {\r\n if (!error && !isEmpty) {\r\n return null;\r\n }\r\n\r\n return (\r\n <View\r\n alignItems=\"center\"\r\n justifyContent=\"center\"\r\n zIndex={tokens.content.zIndex}\r\n >\r\n {error ? <ErrorDetails {...errorViewProps} /> : null}\r\n {isEmpty ? <EmptyDetails {...emptyViewProps} /> : null}\r\n </View>\r\n );\r\n }, [error, isEmpty, errorViewProps, emptyViewProps, tokens.content.zIndex]);\r\n\r\n return (\r\n <LoadingView\r\n {...rest}\r\n LoadingComponent={LoadingComponent}\r\n contentContainerStyle={contentContainerStyle}\r\n loading={loading}\r\n >\r\n {!error && !isEmpty && !loading ? children : null}\r\n {content}\r\n </LoadingView>\r\n );\r\n});\r\n","import { memo } from \"react\";\r\n\r\nimport { EmptyIcon } from \"@impulse-ui-native/icon\";\r\nimport { Typography, View } from \"@impulse-ui-native/primitives\";\r\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\r\n\r\nimport { StateViewProps } from \"../types\";\r\nimport { StateActionsFooter } from \"./state-actions-footer\";\r\n\r\nexport const EmptyDetails = memo(function EmptyDetails(props: StateViewProps) {\r\n const tokens = useComponentsTokens().dataState.details;\r\n\r\n return (\r\n <View alignItems=\"center\" justifyContent=\"center\" gap={tokens.gap}>\r\n <EmptyIcon\r\n width={tokens.iconSize}\r\n height={tokens.iconSize}\r\n variant={props.variant}\r\n color={tokens.iconColor}\r\n />\r\n <Typography.Body>{props.text}</Typography.Body>\r\n <StateActionsFooter\r\n onPressPrimaryAction={props.onPressPrimaryAction}\r\n primaryActionLabel={props.primaryActionLabel}\r\n onPressSecondaryAction={props.onPressSecondaryAction}\r\n secondaryActionLabel={props.secondaryActionLabel}\r\n />\r\n </View>\r\n );\r\n});\r\n","import { memo } from \"react\";\r\n\r\nimport { Button, View } from \"@impulse-ui-native/primitives\";\r\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\r\n\r\nimport { StateActionsFooterProps } from \"../types\";\r\n\r\nexport const StateActionsFooter = memo(function StateActionsFooter(\r\n props: StateActionsFooterProps,\r\n) {\r\n const tokens = useComponentsTokens().dataState.actionsFooter;\r\n const {\r\n onPressPrimaryAction,\r\n onPressSecondaryAction,\r\n primaryActionLabel,\r\n secondaryActionLabel,\r\n ...rest\r\n } = props;\r\n\r\n return (\r\n <View\r\n flexDirection=\"row\"\r\n gap={tokens.gap}\r\n justifyContent=\"center\"\r\n alignItems=\"center\"\r\n {...rest}\r\n >\r\n <Button onPress={props.onPressPrimaryAction}>\r\n {props.primaryActionLabel}\r\n </Button>\r\n {props.onPressSecondaryAction ? (\r\n <Button variant=\"outlined\" onPress={props.onPressSecondaryAction}>\r\n {props.secondaryActionLabel}\r\n </Button>\r\n ) : null}\r\n </View>\r\n );\r\n});\r\n","import { memo } from \"react\";\r\n\r\nimport { CloudXIcon } from \"@impulse-ui-native/icon\";\r\nimport { Typography, View } from \"@impulse-ui-native/primitives\";\r\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\r\n\r\nimport { StateViewProps } from \"../types\";\r\nimport { StateActionsFooter } from \"./state-actions-footer\";\r\n\r\nexport const ErrorDetails = memo(function ErrorDetails(props: StateViewProps) {\r\n const tokens = useComponentsTokens().dataState.details;\r\n\r\n return (\r\n <View alignItems=\"center\" justifyContent=\"center\" gap={tokens.gap}>\r\n <CloudXIcon\r\n width={tokens.iconSize}\r\n height={tokens.iconSize}\r\n variant={props.variant}\r\n color={tokens.iconColor}\r\n />\r\n <Typography.Body>{props.text}</Typography.Body>\r\n <StateActionsFooter\r\n onPressPrimaryAction={props.onPressPrimaryAction}\r\n primaryActionLabel={props.primaryActionLabel}\r\n onPressSecondaryAction={props.onPressSecondaryAction}\r\n secondaryActionLabel={props.secondaryActionLabel}\r\n />\r\n </View>\r\n );\r\n});\r\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,SAAS,YAAY;AAoBf;AAhBC,IAAM,YAAY,KAAK,SAASA,WAAU,OAAuB;AACtE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AAEJ,SACE,oBAAC,QAAM,GAAG,MACR,8BAAC,QAAK,OAAO,uBAAwB,UAAS,GAChD;AAEJ,CAAC;;;ACzBD,SAAS,QAAAC,aAAY;AAErB,SAAS,QAAAC,aAAY;AAoBf,gBAAAC,YAAA;AAhBC,IAAM,YAAYF,MAAK,SAASG,WAAU,OAAuB;AACtE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AAEJ,SACE,gBAAAD,KAACD,OAAA,EAAM,GAAG,MACR,0BAAAC,KAACD,OAAA,EAAK,OAAO,uBAAwB,UAAS,GAChD;AAEJ,CAAC;;;ACzBD,SAAS,QAAAG,OAAM,aAAa,WAAW,SAAS,gBAA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AM,CAAC;AAE1E,SACE,gBAAAC;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MAEC;AAAA,SAAC,SAAS,CAAC,WAAW,CAAC,UAAU,WAAW;AAAA,QAC5C;AAAA;AAAA;AAAA,EACH;AAEJ,CAAC;","names":["ErrorView","memo","View","jsx","EmptyView","memo","View","jsx","LoadingView","memo","useMemo","View","useComponentsTokens","memo","View","useComponentsTokens","memo","View","useComponentsTokens","jsx","jsxs","StateActionsFooter","jsx","jsxs","memo","EmptyDetails","useComponentsTokens","View","memo","Typography","View","useComponentsTokens","jsx","jsxs","memo","ErrorDetails","useComponentsTokens","View","Typography","jsx","jsxs","memo","useComponentsTokens","useMemo","View"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@impulse-ui-native/data-state",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.mts",
|
|
7
|
+
"react-native": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"react-native": "./src/index.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@impulse-ui-native/theme": "2.0.0",
|
|
22
|
+
"@impulse-ui-native/core": "2.0.0",
|
|
23
|
+
"@impulse-ui-native/primitives": "2.0.0",
|
|
24
|
+
"@impulse-ui-native/skeleton": "2.0.0",
|
|
25
|
+
"@impulse-ui-native/icon": "2.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/react": "~19.2.14",
|
|
29
|
+
"eslint": "^9.38.0",
|
|
30
|
+
"prettier": "^3.6.2",
|
|
31
|
+
"react": "19.2.0",
|
|
32
|
+
"react-native": "0.83.6",
|
|
33
|
+
"react-native-reanimated": "4.2.1",
|
|
34
|
+
"react-native-worklets": "0.7.4",
|
|
35
|
+
"typescript": "~5.9.2",
|
|
36
|
+
"@impulse-ui-native/eslint-config": "1.0.0",
|
|
37
|
+
"@impulse-ui-native/prettier-config": "1.0.0",
|
|
38
|
+
"@impulse-ui-native/tsconfig": "1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": ">=18",
|
|
42
|
+
"react-native": ">=0.73",
|
|
43
|
+
"react-native-reanimated": ">=3.6.0",
|
|
44
|
+
"react-native-worklets": ">=0.5"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"prettier": "@impulse-ui-native/prettier-config",
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup --config tsup.config.ts",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
53
|
+
"lint": "pnpm exec eslint . --fix",
|
|
54
|
+
"format": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md}\" --ignore-path ../../.prettierignore"
|
|
55
|
+
}
|
|
56
|
+
}
|