@dloizides/ui-feedback 1.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ Initial release. Extracted the proven duplicated feedback components from erevna-web ↔
6
+ katalogos-web (Capability Wave C1, batch 1).
7
+
8
+ - `FeedbackUiProvider` + `useFeedbackUi` — injectable theme/translate/navigate context.
9
+ - `ErrorState`, `EmptyListState`, `LoadingFallback`, `PageSkeleton`, `ConfirmDialog`.
10
+ - `FEEDBACK_TEST_IDS`, `MODAL_OVERLAY_COLOR`, `DISABLED_OPACITY` constants.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 dloizides
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,85 @@
1
+ # @dloizides/ui-feedback
2
+
3
+ Themable, brand-agnostic React Native (RN-web) **feedback** components for the
4
+ dloizides.com portfolio. The components read theme colours and translated copy from
5
+ a small injectable provider, so each app supplies its own theme + i18n without the
6
+ package depending on any app's internals.
7
+
8
+ ## Components
9
+
10
+ | Component | Purpose |
11
+ |-----------|---------|
12
+ | `ErrorState` | Generic error message with an optional retry button. |
13
+ | `EmptyListState` | Empty-collection message with an optional navigating call-to-action. |
14
+ | `LoadingFallback` | Lightweight spinner for `React.lazy` / `Suspense` boundaries. |
15
+ | `PageSkeleton` | Shimmer skeleton for full-page loads (list or card variant). |
16
+ | `ConfirmDialog` | Modal confirm/cancel dialog with destructive + loading states. |
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @dloizides/ui-feedback
22
+ ```
23
+
24
+ Peer dependencies: `react >= 18`, `react-native >= 0.74` (use `react-native-web` on web).
25
+
26
+ ## Setup
27
+
28
+ Mount `FeedbackUiProvider` once, high in your tree, **below** your app's own theme
29
+ provider. Adapt your local `useTheme()` + translate helper to the provider:
30
+
31
+ ```tsx
32
+ import { FeedbackUiProvider } from '@dloizides/ui-feedback';
33
+ import { useRouter } from 'expo-router';
34
+ import { FM } from './localization/helpers';
35
+ import { useTheme } from './theme/hooks/useTheme';
36
+
37
+ const FeedbackUiAdapter = ({ children }: { children: React.ReactNode }) => {
38
+ const { theme } = useTheme();
39
+ const router = useRouter();
40
+ return (
41
+ <FeedbackUiProvider theme={theme} t={FM} navigate={(route) => router.push(route)}>
42
+ {children}
43
+ </FeedbackUiProvider>
44
+ );
45
+ };
46
+ ```
47
+
48
+ The injected `theme` only needs `colors.{background,surfaceElevated,text,textSecondary,border}`,
49
+ `palette.primary['500']` and `semantic.error['500']` — any resolved theme with those
50
+ fields is structurally compatible.
51
+
52
+ ## Usage
53
+
54
+ ```tsx
55
+ import { ErrorState, ConfirmDialog, LoadingFallback } from '@dloizides/ui-feedback';
56
+
57
+ <ErrorState message="Could not load data" onRetry={refetch} />
58
+ <LoadingFallback fullScreen />
59
+ <ConfirmDialog
60
+ visible={open}
61
+ title="Delete item?"
62
+ message="This cannot be undone."
63
+ destructive
64
+ onConfirm={onDelete}
65
+ onCancel={() => setOpen(false)}
66
+ />
67
+ ```
68
+
69
+ ## i18n keys
70
+
71
+ The components call the injected `t(key)` with these keys (provide them in each app's
72
+ locale files): `common.retry`, `common.retryHint`, `common.confirm`, `common.cancel`,
73
+ `common.confirmHint`, `common.cancelHint`, `loadingFallback.label`, `loadingFallback.hint`,
74
+ `pageSkeleton.loadingLabel`, `pageSkeleton.loadingHint`. `EmptyListState` takes its keys as props.
75
+
76
+ ## testIDs
77
+
78
+ Default testIDs (`FEEDBACK_TEST_IDS`) match the strings the consuming apps already used,
79
+ so existing Playwright selectors keep working: `error-state`, `error-state-retry`,
80
+ `empty-list-cta`, `loading-fallback`, `page-skeleton`, `confirm-dialog`, `confirm-button`,
81
+ `cancel-confirm-button`.
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,145 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * The minimal theme surface the feedback components read. Each consuming app's
5
+ * resolved theme object is structurally compatible with this shape, so apps pass
6
+ * their existing `useTheme().theme` straight through the provider.
7
+ */
8
+ interface FeedbackThemeColors {
9
+ background: string;
10
+ surfaceElevated: string;
11
+ text: string;
12
+ textSecondary: string;
13
+ border: string;
14
+ }
15
+ /** A colour scale where the `500` step is the one the feedback components use. */
16
+ interface FeedbackColorScale {
17
+ '500': string;
18
+ }
19
+ interface FeedbackTheme {
20
+ colors: FeedbackThemeColors;
21
+ palette: {
22
+ primary: FeedbackColorScale;
23
+ };
24
+ semantic: {
25
+ error: FeedbackColorScale;
26
+ };
27
+ }
28
+ /** Translate function — mirrors the apps' `FM(key, p1?, p2?, p3?)` helper. */
29
+ type FeedbackTranslate = (key: string, p1?: string, p2?: string, p3?: string) => string;
30
+ /** Navigation callback used by EmptyListState's optional call-to-action. */
31
+ type FeedbackNavigate = (route: string) => void;
32
+ interface FeedbackUiValue {
33
+ theme: FeedbackTheme;
34
+ t: FeedbackTranslate;
35
+ navigate?: FeedbackNavigate;
36
+ }
37
+ interface FeedbackUiProviderProps extends FeedbackUiValue {
38
+ children: React.ReactNode;
39
+ }
40
+ /**
41
+ * Supplies the host app's theme + translate (+ optional navigate) to the
42
+ * `@dloizides/ui-feedback` components. Mount once, high in the app tree, below
43
+ * the app's own ThemeProvider.
44
+ */
45
+ declare const FeedbackUiProvider: ({ theme, t, navigate, children, }: FeedbackUiProviderProps) => React.ReactElement;
46
+ /** Reads the feedback UI context; throws if used outside a FeedbackUiProvider. */
47
+ declare function useFeedbackUi(): FeedbackUiValue;
48
+
49
+ /** Semi-transparent scrim behind modal dialogs. */
50
+ declare const MODAL_OVERLAY_COLOR = "rgba(0, 0, 0, 0.5)";
51
+ /** Opacity applied to disabled interactive controls. */
52
+ declare const DISABLED_OPACITY = 0.5;
53
+ /**
54
+ * Default testID strings. These match the values the consuming apps already used
55
+ * so existing Playwright selectors keep working after migration.
56
+ */
57
+ declare const FEEDBACK_TEST_IDS: {
58
+ readonly errorState: "error-state";
59
+ readonly errorStateRetry: "error-state-retry";
60
+ readonly emptyListCta: "empty-list-cta";
61
+ readonly loadingFallback: "loading-fallback";
62
+ readonly pageSkeleton: "page-skeleton";
63
+ readonly confirmDialog: "confirm-dialog";
64
+ readonly confirmButton: "confirm-button";
65
+ readonly cancelConfirmButton: "cancel-confirm-button";
66
+ };
67
+
68
+ /**
69
+ * ErrorState - generic error display with optional retry button.
70
+ */
71
+
72
+ interface ErrorStateProps {
73
+ message: string;
74
+ onRetry?: () => void;
75
+ testID?: string;
76
+ }
77
+ declare const ErrorState: ({ message, onRetry, testID, }: ErrorStateProps) => React.ReactElement;
78
+
79
+ /**
80
+ * EmptyListState - empty-collection message with an optional call-to-action.
81
+ *
82
+ * The CTA navigates via the `navigate` callback supplied through FeedbackUiProvider
83
+ * (the host app adapts its router, e.g. expo-router's `router.push`).
84
+ */
85
+
86
+ interface EmptyListStateProps {
87
+ messageKey: string;
88
+ ctaTextKey?: string;
89
+ ctaHintKey?: string;
90
+ ctaRoute?: string;
91
+ testID: string;
92
+ }
93
+ declare const EmptyListState: ({ messageKey, ctaTextKey, ctaHintKey, ctaRoute, testID, }: EmptyListStateProps) => React.ReactElement;
94
+
95
+ /**
96
+ * LoadingFallback - lightweight loading indicator for lazy-loaded components.
97
+ *
98
+ * Used with React.lazy() and Suspense to show a loading state while heavy
99
+ * components are loading. Optimized for minimal bundle impact.
100
+ */
101
+
102
+ interface LoadingFallbackProps {
103
+ /** Show as full-screen loader (default: false) */
104
+ fullScreen?: boolean;
105
+ /** Custom size for the spinner */
106
+ size?: 'small' | 'large';
107
+ }
108
+ declare const LoadingFallback: React.FC<LoadingFallbackProps>;
109
+
110
+ /**
111
+ * PageSkeleton - shimmer skeleton loader for full pages.
112
+ *
113
+ * Improves perceived performance (Speed Index) by showing immediate visual
114
+ * feedback while page content loads.
115
+ */
116
+
117
+ interface PageSkeletonProps {
118
+ /** Number of skeleton rows to show */
119
+ rows?: number;
120
+ /** Show header skeleton */
121
+ showHeader?: boolean;
122
+ /** Show card skeletons instead of rows */
123
+ variant?: 'list' | 'cards';
124
+ }
125
+ declare const PageSkeleton: React.FC<PageSkeletonProps>;
126
+
127
+ /**
128
+ * ConfirmDialog - modal confirm/cancel dialog with optional destructive + loading states.
129
+ */
130
+
131
+ interface ConfirmDialogProps {
132
+ visible: boolean;
133
+ title: string;
134
+ message: string;
135
+ onConfirm: () => void;
136
+ onCancel: () => void;
137
+ confirmLabel?: string;
138
+ cancelLabel?: string;
139
+ confirmDisabled?: boolean;
140
+ loading?: boolean;
141
+ destructive?: boolean;
142
+ }
143
+ declare const ConfirmDialog: ({ visible, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, confirmDisabled, loading, destructive, }: ConfirmDialogProps) => React.ReactElement | null;
144
+
145
+ export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, useFeedbackUi };
@@ -0,0 +1,145 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * The minimal theme surface the feedback components read. Each consuming app's
5
+ * resolved theme object is structurally compatible with this shape, so apps pass
6
+ * their existing `useTheme().theme` straight through the provider.
7
+ */
8
+ interface FeedbackThemeColors {
9
+ background: string;
10
+ surfaceElevated: string;
11
+ text: string;
12
+ textSecondary: string;
13
+ border: string;
14
+ }
15
+ /** A colour scale where the `500` step is the one the feedback components use. */
16
+ interface FeedbackColorScale {
17
+ '500': string;
18
+ }
19
+ interface FeedbackTheme {
20
+ colors: FeedbackThemeColors;
21
+ palette: {
22
+ primary: FeedbackColorScale;
23
+ };
24
+ semantic: {
25
+ error: FeedbackColorScale;
26
+ };
27
+ }
28
+ /** Translate function — mirrors the apps' `FM(key, p1?, p2?, p3?)` helper. */
29
+ type FeedbackTranslate = (key: string, p1?: string, p2?: string, p3?: string) => string;
30
+ /** Navigation callback used by EmptyListState's optional call-to-action. */
31
+ type FeedbackNavigate = (route: string) => void;
32
+ interface FeedbackUiValue {
33
+ theme: FeedbackTheme;
34
+ t: FeedbackTranslate;
35
+ navigate?: FeedbackNavigate;
36
+ }
37
+ interface FeedbackUiProviderProps extends FeedbackUiValue {
38
+ children: React.ReactNode;
39
+ }
40
+ /**
41
+ * Supplies the host app's theme + translate (+ optional navigate) to the
42
+ * `@dloizides/ui-feedback` components. Mount once, high in the app tree, below
43
+ * the app's own ThemeProvider.
44
+ */
45
+ declare const FeedbackUiProvider: ({ theme, t, navigate, children, }: FeedbackUiProviderProps) => React.ReactElement;
46
+ /** Reads the feedback UI context; throws if used outside a FeedbackUiProvider. */
47
+ declare function useFeedbackUi(): FeedbackUiValue;
48
+
49
+ /** Semi-transparent scrim behind modal dialogs. */
50
+ declare const MODAL_OVERLAY_COLOR = "rgba(0, 0, 0, 0.5)";
51
+ /** Opacity applied to disabled interactive controls. */
52
+ declare const DISABLED_OPACITY = 0.5;
53
+ /**
54
+ * Default testID strings. These match the values the consuming apps already used
55
+ * so existing Playwright selectors keep working after migration.
56
+ */
57
+ declare const FEEDBACK_TEST_IDS: {
58
+ readonly errorState: "error-state";
59
+ readonly errorStateRetry: "error-state-retry";
60
+ readonly emptyListCta: "empty-list-cta";
61
+ readonly loadingFallback: "loading-fallback";
62
+ readonly pageSkeleton: "page-skeleton";
63
+ readonly confirmDialog: "confirm-dialog";
64
+ readonly confirmButton: "confirm-button";
65
+ readonly cancelConfirmButton: "cancel-confirm-button";
66
+ };
67
+
68
+ /**
69
+ * ErrorState - generic error display with optional retry button.
70
+ */
71
+
72
+ interface ErrorStateProps {
73
+ message: string;
74
+ onRetry?: () => void;
75
+ testID?: string;
76
+ }
77
+ declare const ErrorState: ({ message, onRetry, testID, }: ErrorStateProps) => React.ReactElement;
78
+
79
+ /**
80
+ * EmptyListState - empty-collection message with an optional call-to-action.
81
+ *
82
+ * The CTA navigates via the `navigate` callback supplied through FeedbackUiProvider
83
+ * (the host app adapts its router, e.g. expo-router's `router.push`).
84
+ */
85
+
86
+ interface EmptyListStateProps {
87
+ messageKey: string;
88
+ ctaTextKey?: string;
89
+ ctaHintKey?: string;
90
+ ctaRoute?: string;
91
+ testID: string;
92
+ }
93
+ declare const EmptyListState: ({ messageKey, ctaTextKey, ctaHintKey, ctaRoute, testID, }: EmptyListStateProps) => React.ReactElement;
94
+
95
+ /**
96
+ * LoadingFallback - lightweight loading indicator for lazy-loaded components.
97
+ *
98
+ * Used with React.lazy() and Suspense to show a loading state while heavy
99
+ * components are loading. Optimized for minimal bundle impact.
100
+ */
101
+
102
+ interface LoadingFallbackProps {
103
+ /** Show as full-screen loader (default: false) */
104
+ fullScreen?: boolean;
105
+ /** Custom size for the spinner */
106
+ size?: 'small' | 'large';
107
+ }
108
+ declare const LoadingFallback: React.FC<LoadingFallbackProps>;
109
+
110
+ /**
111
+ * PageSkeleton - shimmer skeleton loader for full pages.
112
+ *
113
+ * Improves perceived performance (Speed Index) by showing immediate visual
114
+ * feedback while page content loads.
115
+ */
116
+
117
+ interface PageSkeletonProps {
118
+ /** Number of skeleton rows to show */
119
+ rows?: number;
120
+ /** Show header skeleton */
121
+ showHeader?: boolean;
122
+ /** Show card skeletons instead of rows */
123
+ variant?: 'list' | 'cards';
124
+ }
125
+ declare const PageSkeleton: React.FC<PageSkeletonProps>;
126
+
127
+ /**
128
+ * ConfirmDialog - modal confirm/cancel dialog with optional destructive + loading states.
129
+ */
130
+
131
+ interface ConfirmDialogProps {
132
+ visible: boolean;
133
+ title: string;
134
+ message: string;
135
+ onConfirm: () => void;
136
+ onCancel: () => void;
137
+ confirmLabel?: string;
138
+ cancelLabel?: string;
139
+ confirmDisabled?: boolean;
140
+ loading?: boolean;
141
+ destructive?: boolean;
142
+ }
143
+ declare const ConfirmDialog: ({ visible, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, confirmDisabled, loading, destructive, }: ConfirmDialogProps) => React.ReactElement | null;
144
+
145
+ export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, useFeedbackUi };