@demokit-ai/react 0.2.0 → 0.4.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 DELETED
@@ -1,132 +0,0 @@
1
- # @demokit-ai/react
2
-
3
- ![Tests](https://img.shields.io/badge/tests-55%20passing-brightgreen)
4
- ![Coverage](https://img.shields.io/badge/coverage-8%25-red)
5
-
6
- React bindings for DemoKit - provider, hooks, and components for demo mode state management.
7
-
8
- ## Installation
9
-
10
- ```bash
11
- npm install @demokit-ai/react @demokit-ai/core
12
- ```
13
-
14
- ## Features
15
-
16
- - `DemoProvider` - React context provider for demo mode state
17
- - `DemoBanner` - Customizable banner component for demo mode indication
18
- - `useDemo` - Hook for accessing and controlling demo mode
19
- - `useDemoState` - Hook for managing demo-specific state
20
- - `withDemo` - HOC for conditionally rendering based on demo mode
21
- - Full TypeScript support
22
-
23
- ## Usage
24
-
25
- ### Provider Setup
26
-
27
- Wrap your app with the `DemoProvider`:
28
-
29
- ```tsx
30
- import { DemoProvider } from '@demokit-ai/react'
31
-
32
- function App() {
33
- return (
34
- <DemoProvider
35
- enabled={true}
36
- fixtures={{
37
- users: [{ id: '1', name: 'Demo User' }],
38
- }}
39
- >
40
- <YourApp />
41
- </DemoProvider>
42
- )
43
- }
44
- ```
45
-
46
- ### Using the Demo Hook
47
-
48
- Access demo mode state and controls:
49
-
50
- ```tsx
51
- import { useDemo } from '@demokit-ai/react'
52
-
53
- function MyComponent() {
54
- const { enabled, toggle, fixtures, setFixture } = useDemo()
55
-
56
- return (
57
- <div>
58
- <button onClick={toggle}>
59
- Demo Mode: {enabled ? 'ON' : 'OFF'}
60
- </button>
61
- {enabled && <pre>{JSON.stringify(fixtures, null, 2)}</pre>}
62
- </div>
63
- )
64
- }
65
- ```
66
-
67
- ### Demo Banner
68
-
69
- Show a banner when demo mode is active:
70
-
71
- ```tsx
72
- import { DemoBanner } from '@demokit-ai/react'
73
-
74
- function App() {
75
- return (
76
- <>
77
- <DemoBanner
78
- message="You're viewing demo data"
79
- position="top"
80
- dismissible
81
- />
82
- <YourApp />
83
- </>
84
- )
85
- }
86
- ```
87
-
88
- ### Conditional Rendering
89
-
90
- Use the HOC for conditional demo content:
91
-
92
- ```tsx
93
- import { withDemo } from '@demokit-ai/react'
94
-
95
- const DemoOnlyFeature = withDemo(({ fixtures }) => (
96
- <div>This only shows in demo mode</div>
97
- ))
98
- ```
99
-
100
- ## API Reference
101
-
102
- ### `DemoProvider`
103
-
104
- Props:
105
- - `enabled` - Whether demo mode is enabled
106
- - `fixtures` - Demo fixtures object
107
- - `onToggle` - Callback when demo mode is toggled
108
- - `storage` - Storage adapter for persistence
109
-
110
- ### `useDemo()`
111
-
112
- Returns:
113
- - `enabled` - Current demo mode state
114
- - `toggle()` - Toggle demo mode
115
- - `enable()` - Enable demo mode
116
- - `disable()` - Disable demo mode
117
- - `fixtures` - Current fixtures
118
- - `setFixture(key, value)` - Set a fixture
119
- - `clearFixtures()` - Clear all fixtures
120
-
121
- ### `DemoBanner`
122
-
123
- Props:
124
- - `message` - Banner message
125
- - `position` - 'top' | 'bottom'
126
- - `dismissible` - Whether the banner can be dismissed
127
- - `className` - Custom CSS class
128
- - `style` - Inline styles
129
-
130
- ## License
131
-
132
- MIT
package/dist/index.d.cts DELETED
@@ -1,235 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as _demokit_ai_core from '@demokit-ai/core';
3
- import { FixtureMap, SessionState } from '@demokit-ai/core';
4
- export { FixtureHandler, FixtureMap, RequestContext, SessionState } from '@demokit-ai/core';
5
- import * as react from 'react';
6
- import { ReactNode } from 'react';
7
-
8
- /**
9
- * Props for the DemoKitProvider component
10
- */
11
- interface DemoKitProviderProps {
12
- /**
13
- * Child components to render
14
- */
15
- children: ReactNode;
16
- /**
17
- * Map of URL patterns to fixture handlers
18
- */
19
- fixtures: FixtureMap;
20
- /**
21
- * localStorage key for persisting demo mode state
22
- * @default 'demokit-mode'
23
- */
24
- storageKey?: string;
25
- /**
26
- * Whether demo mode should be initially enabled
27
- * If not provided, will read from localStorage
28
- * @default false
29
- */
30
- initialEnabled?: boolean;
31
- /**
32
- * Callback invoked when demo mode state changes
33
- */
34
- onDemoModeChange?: (enabled: boolean) => void;
35
- /**
36
- * Base URL to use for relative URL parsing
37
- * @default 'http://localhost'
38
- */
39
- baseUrl?: string;
40
- }
41
- /**
42
- * Value provided by the DemoMode context
43
- */
44
- interface DemoModeContextValue {
45
- /**
46
- * Whether demo mode is currently enabled
47
- */
48
- isDemoMode: boolean;
49
- /**
50
- * Whether the component has hydrated (for SSR safety)
51
- * Always check this before rendering demo-dependent UI
52
- */
53
- isHydrated: boolean;
54
- /**
55
- * Enable demo mode
56
- */
57
- enable(): void;
58
- /**
59
- * Disable demo mode
60
- */
61
- disable(): void;
62
- /**
63
- * Toggle demo mode and return the new state
64
- */
65
- toggle(): void;
66
- /**
67
- * Set demo mode to a specific state
68
- */
69
- setDemoMode(enabled: boolean): void;
70
- /**
71
- * Reset the session state, clearing all stored data
72
- * Call this to manually reset the demo session without page refresh
73
- */
74
- resetSession(): void;
75
- /**
76
- * Get the current session state instance
77
- * Useful for inspecting or manipulating session state directly
78
- * Returns null if the interceptor hasn't been initialized yet
79
- */
80
- getSession(): SessionState | null;
81
- }
82
- /**
83
- * Props for the DemoModeBanner component
84
- */
85
- interface DemoModeBannerProps {
86
- /**
87
- * Additional CSS class name
88
- */
89
- className?: string;
90
- /**
91
- * Label for the exit button
92
- * @default 'Exit Demo Mode'
93
- */
94
- exitLabel?: string;
95
- /**
96
- * Label shown when demo mode is active
97
- * @default 'Demo Mode Active'
98
- */
99
- demoLabel?: string;
100
- /**
101
- * Description shown in the banner
102
- * @default 'Changes are simulated and not saved'
103
- */
104
- description?: string;
105
- /**
106
- * Whether to show the eye icon
107
- * @default true
108
- */
109
- showIcon?: boolean;
110
- /**
111
- * Custom styles for the banner container
112
- */
113
- style?: React.CSSProperties;
114
- /**
115
- * Callback when exit button is clicked
116
- * If not provided, will call disable() from context
117
- */
118
- onExit?: () => void;
119
- }
120
-
121
- /**
122
- * Provider component that enables demo mode functionality
123
- *
124
- * Wraps your app to provide demo mode state and controls.
125
- * Handles SSR hydration safely and persists state to localStorage.
126
- *
127
- * @example
128
- * const fixtures = {
129
- * 'GET /api/users': () => [{ id: '1', name: 'Demo User' }],
130
- * 'GET /api/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
131
- * }
132
- *
133
- * function App() {
134
- * return (
135
- * <DemoKitProvider
136
- * fixtures={fixtures}
137
- * onDemoModeChange={(enabled) => console.log('Demo mode:', enabled)}
138
- * >
139
- * <YourApp />
140
- * </DemoKitProvider>
141
- * )
142
- * }
143
- */
144
- declare function DemoKitProvider({ children, fixtures, storageKey, initialEnabled, onDemoModeChange, baseUrl, }: DemoKitProviderProps): react_jsx_runtime.JSX.Element;
145
-
146
- /**
147
- * Hook to access demo mode state and controls
148
- *
149
- * @returns Demo mode context value with state and control methods
150
- * @throws Error if used outside of DemoKitProvider
151
- *
152
- * @example
153
- * function MyComponent() {
154
- * const { isDemoMode, isHydrated, toggle } = useDemoMode()
155
- *
156
- * // Wait for hydration before rendering demo-dependent UI
157
- * if (!isHydrated) {
158
- * return <Loading />
159
- * }
160
- *
161
- * return (
162
- * <div>
163
- * <p>Demo mode: {isDemoMode ? 'ON' : 'OFF'}</p>
164
- * <button onClick={toggle}>Toggle</button>
165
- * </div>
166
- * )
167
- * }
168
- */
169
- declare function useDemoMode(): DemoModeContextValue;
170
- /**
171
- * Hook to check if demo mode is enabled
172
- * Shorthand for useDemoMode().isDemoMode
173
- *
174
- * @returns Whether demo mode is enabled
175
- */
176
- declare function useIsDemoMode(): boolean;
177
- /**
178
- * Hook to check if the component has hydrated
179
- * Shorthand for useDemoMode().isHydrated
180
- *
181
- * @returns Whether the component has hydrated
182
- */
183
- declare function useIsHydrated(): boolean;
184
- /**
185
- * Hook to access the session state
186
- * Shorthand for useDemoMode().getSession()
187
- *
188
- * @returns The session state, or null if not yet initialized
189
- *
190
- * @example
191
- * function MyComponent() {
192
- * const session = useDemoSession()
193
- *
194
- * const cart = session?.get<CartItem[]>('cart') || []
195
- * const addToCart = (item: CartItem) => {
196
- * session?.set('cart', [...cart, item])
197
- * }
198
- *
199
- * return <CartView items={cart} onAdd={addToCart} />
200
- * }
201
- */
202
- declare function useDemoSession(): _demokit_ai_core.SessionState | null;
203
-
204
- /**
205
- * A ready-to-use banner component that shows when demo mode is active
206
- *
207
- * Displays a prominent amber banner with a label, description, and exit button.
208
- * Automatically hides when demo mode is disabled or before hydration.
209
- *
210
- * @example
211
- * function App() {
212
- * return (
213
- * <DemoKitProvider fixtures={fixtures}>
214
- * <DemoModeBanner />
215
- * <YourApp />
216
- * </DemoKitProvider>
217
- * )
218
- * }
219
- *
220
- * @example Custom labels
221
- * <DemoModeBanner
222
- * demoLabel="Preview Mode"
223
- * description="You're viewing sample data"
224
- * exitLabel="Exit Preview"
225
- * />
226
- */
227
- declare function DemoModeBanner({ className, exitLabel, demoLabel, description, showIcon, style, onExit, }: DemoModeBannerProps): react_jsx_runtime.JSX.Element | null;
228
-
229
- /**
230
- * React context for demo mode state
231
- * @internal
232
- */
233
- declare const DemoModeContext: react.Context<DemoModeContextValue | undefined>;
234
-
235
- export { DemoKitProvider, type DemoKitProviderProps, DemoModeBanner, type DemoModeBannerProps, DemoModeContext, type DemoModeContextValue, useDemoMode, useDemoSession, useIsDemoMode, useIsHydrated };