@rakeyshgidwani/roger-ui-bank-theme-stan-design 0.1.3 → 0.1.5
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 +1 -1
- package/dist/index.d.ts +131 -131
- package/dist/index.esm.js +148 -148
- package/dist/index.js +148 -148
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/ui/accessibility-demo.tsx +271 -0
- package/src/components/ui/advanced-component-architecture-demo.tsx +916 -0
- package/src/components/ui/advanced-transition-system-demo.tsx +670 -0
- package/src/components/ui/advanced-transition-system.tsx +395 -0
- package/src/components/ui/animation/animated-container.tsx +166 -0
- package/src/components/ui/animation/index.ts +19 -0
- package/src/components/ui/animation/staggered-container.tsx +68 -0
- package/src/components/ui/animation-demo.tsx +250 -0
- package/src/components/ui/badge.tsx +33 -0
- package/src/components/ui/battery-conscious-animation-demo.tsx +568 -0
- package/src/components/ui/border-radius-shadow-demo.tsx +187 -0
- package/src/components/ui/button.tsx +36 -0
- package/src/components/ui/card.tsx +207 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/color-preview.tsx +411 -0
- package/src/components/ui/data-display/chart.tsx +653 -0
- package/src/components/ui/data-display/data-grid-simple.tsx +76 -0
- package/src/components/ui/data-display/data-grid.tsx +680 -0
- package/src/components/ui/data-display/list.tsx +456 -0
- package/src/components/ui/data-display/table.tsx +482 -0
- package/src/components/ui/data-display/timeline.tsx +441 -0
- package/src/components/ui/data-display/tree.tsx +602 -0
- package/src/components/ui/data-display/types.ts +536 -0
- package/src/components/ui/enterprise-mobile-experience-demo.tsx +749 -0
- package/src/components/ui/enterprise-mobile-experience.tsx +464 -0
- package/src/components/ui/feedback/alert.tsx +157 -0
- package/src/components/ui/feedback/progress.tsx +292 -0
- package/src/components/ui/feedback/skeleton.tsx +185 -0
- package/src/components/ui/feedback/toast.tsx +280 -0
- package/src/components/ui/feedback/types.ts +125 -0
- package/src/components/ui/font-preview.tsx +288 -0
- package/src/components/ui/form-demo.tsx +553 -0
- package/src/components/ui/hardware-acceleration-demo.tsx +547 -0
- package/src/components/ui/input.tsx +35 -0
- package/src/components/ui/label.tsx +16 -0
- package/src/components/ui/layout-demo.tsx +367 -0
- package/src/components/ui/layouts/adaptive-layout.tsx +139 -0
- package/src/components/ui/layouts/desktop-layout.tsx +224 -0
- package/src/components/ui/layouts/index.ts +10 -0
- package/src/components/ui/layouts/mobile-layout.tsx +162 -0
- package/src/components/ui/layouts/tablet-layout.tsx +197 -0
- package/src/components/ui/mobile-form-validation.tsx +451 -0
- package/src/components/ui/mobile-input-demo.tsx +201 -0
- package/src/components/ui/mobile-input.tsx +281 -0
- package/src/components/ui/mobile-skeleton-loading-demo.tsx +638 -0
- package/src/components/ui/navigation/breadcrumb.tsx +158 -0
- package/src/components/ui/navigation/index.ts +36 -0
- package/src/components/ui/navigation/menu.tsx +374 -0
- package/src/components/ui/navigation/navigation-demo.tsx +324 -0
- package/src/components/ui/navigation/pagination.tsx +272 -0
- package/src/components/ui/navigation/sidebar.tsx +383 -0
- package/src/components/ui/navigation/stepper.tsx +303 -0
- package/src/components/ui/navigation/tabs.tsx +205 -0
- package/src/components/ui/navigation/types.ts +299 -0
- package/src/components/ui/overlay/backdrop.tsx +81 -0
- package/src/components/ui/overlay/focus-manager.tsx +143 -0
- package/src/components/ui/overlay/index.ts +36 -0
- package/src/components/ui/overlay/modal.tsx +270 -0
- package/src/components/ui/overlay/overlay-manager.tsx +110 -0
- package/src/components/ui/overlay/popover.tsx +462 -0
- package/src/components/ui/overlay/portal.tsx +79 -0
- package/src/components/ui/overlay/tooltip.tsx +303 -0
- package/src/components/ui/overlay/types.ts +196 -0
- package/src/components/ui/performance-demo.tsx +596 -0
- package/src/components/ui/semantic-input-system-demo.tsx +502 -0
- package/src/components/ui/semantic-input-system-demo.tsx.disabled +873 -0
- package/src/components/ui/tablet-layout.tsx +192 -0
- package/src/components/ui/theme-customizer.tsx +386 -0
- package/src/components/ui/theme-preview.tsx +310 -0
- package/src/components/ui/theme-switcher.tsx +264 -0
- package/src/components/ui/theme-toggle.tsx +38 -0
- package/src/components/ui/token-demo.tsx +195 -0
- package/src/components/ui/touch-demo.tsx +462 -0
- package/src/components/ui/touch-friendly-interface-demo.tsx +519 -0
- package/src/components/ui/touch-friendly-interface.tsx +296 -0
- package/src/hooks/index.ts +190 -0
- package/src/hooks/use-accessibility-support.ts +518 -0
- package/src/hooks/use-adaptive-layout.ts +289 -0
- package/src/hooks/use-advanced-patterns.ts +294 -0
- package/src/hooks/use-advanced-transition-system.ts +393 -0
- package/src/hooks/use-animation-profile.ts +288 -0
- package/src/hooks/use-battery-animations.ts +384 -0
- package/src/hooks/use-battery-conscious-loading.ts +475 -0
- package/src/hooks/use-battery-optimization.ts +330 -0
- package/src/hooks/use-battery-status.ts +299 -0
- package/src/hooks/use-component-performance.ts +344 -0
- package/src/hooks/use-device-loading-states.ts +459 -0
- package/src/hooks/use-device.tsx +110 -0
- package/src/hooks/use-enterprise-mobile-experience.ts +488 -0
- package/src/hooks/use-form-feedback.ts +403 -0
- package/src/hooks/use-form-performance.ts +513 -0
- package/src/hooks/use-frame-rate.ts +251 -0
- package/src/hooks/use-gestures.ts +338 -0
- package/src/hooks/use-hardware-acceleration.ts +341 -0
- package/src/hooks/use-input-accessibility.ts +455 -0
- package/src/hooks/use-input-performance.ts +506 -0
- package/src/hooks/use-layout-performance.ts +319 -0
- package/src/hooks/use-loading-accessibility.ts +535 -0
- package/src/hooks/use-loading-performance.ts +473 -0
- package/src/hooks/use-memory-usage.ts +287 -0
- package/src/hooks/use-mobile-form-layout.ts +464 -0
- package/src/hooks/use-mobile-form-validation.ts +518 -0
- package/src/hooks/use-mobile-keyboard-optimization.ts +472 -0
- package/src/hooks/use-mobile-layout.ts +302 -0
- package/src/hooks/use-mobile-optimization.ts +406 -0
- package/src/hooks/use-mobile-skeleton.ts +402 -0
- package/src/hooks/use-mobile-touch.ts +414 -0
- package/src/hooks/use-performance-throttling.ts +348 -0
- package/src/hooks/use-performance.ts +316 -0
- package/src/hooks/use-reusable-architecture.ts +414 -0
- package/src/hooks/use-semantic-input-types.ts +357 -0
- package/src/hooks/use-semantic-input.ts +565 -0
- package/src/hooks/use-tablet-layout.ts +384 -0
- package/src/hooks/use-touch-friendly-input.ts +524 -0
- package/src/hooks/use-touch-friendly-interface.ts +331 -0
- package/src/hooks/use-touch-optimization.ts +375 -0
- package/src/index.ts +279 -279
- package/src/lib/utils.ts +6 -0
- package/src/themes/README.md +272 -0
- package/src/themes/ThemeContext.tsx +31 -0
- package/src/themes/ThemeProvider.tsx +232 -0
- package/src/themes/accessibility/index.ts +27 -0
- package/src/themes/accessibility.ts +259 -0
- package/src/themes/aria-patterns.ts +420 -0
- package/src/themes/base-themes.ts +55 -0
- package/src/themes/colorManager.ts +380 -0
- package/src/themes/examples/dark-theme.ts +154 -0
- package/src/themes/examples/minimal-theme.ts +108 -0
- package/src/themes/focus-management.ts +701 -0
- package/src/themes/fontLoader.ts +201 -0
- package/src/themes/high-contrast.ts +621 -0
- package/src/themes/index.ts +19 -0
- package/src/themes/inheritance.ts +227 -0
- package/src/themes/keyboard-navigation.ts +550 -0
- package/src/themes/motion-reduction.ts +662 -0
- package/src/themes/navigation.ts +238 -0
- package/src/themes/screen-reader.ts +645 -0
- package/src/themes/systemThemeDetector.ts +182 -0
- package/src/themes/themeCSSUpdater.ts +262 -0
- package/src/themes/themePersistence.ts +238 -0
- package/src/themes/themes/default.ts +586 -0
- package/src/themes/themes/harvey.ts +554 -0
- package/src/themes/themes/stan-design.ts +683 -0
- package/src/themes/types.ts +460 -0
- package/src/themes/useSystemTheme.ts +48 -0
- package/src/themes/useTheme.ts +87 -0
- package/src/themes/validation.ts +462 -0
- package/src/tokens/index.ts +34 -0
- package/src/tokens/tokenExporter.ts +397 -0
- package/src/tokens/tokenGenerator.ts +276 -0
- package/src/tokens/tokenManager.ts +248 -0
- package/src/tokens/tokenValidator.ts +543 -0
- package/src/tokens/types.ts +78 -0
- package/src/utils/bundle-analyzer.ts +260 -0
- package/src/utils/bundle-splitting.ts +483 -0
- package/src/utils/lazy-loading.ts +441 -0
- package/src/utils/performance-monitor.ts +513 -0
- package/src/utils/tree-shaking.ts +274 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
export type DeviceType = 'mobile' | 'tablet' | 'desktop'
|
|
4
|
+
export type Orientation = 'portrait' | 'landscape'
|
|
5
|
+
export type ScreenSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
|
6
|
+
|
|
7
|
+
export interface AdaptiveLayoutState {
|
|
8
|
+
deviceType: DeviceType
|
|
9
|
+
orientation: Orientation
|
|
10
|
+
screenSize: ScreenSize
|
|
11
|
+
width: number
|
|
12
|
+
height: number
|
|
13
|
+
isTouchDevice: boolean
|
|
14
|
+
isHighDensity: boolean
|
|
15
|
+
isLowPower: boolean
|
|
16
|
+
performanceScore: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AdaptiveLayoutConfig {
|
|
20
|
+
enablePerformanceOptimization?: boolean
|
|
21
|
+
enableTouchOptimization?: boolean
|
|
22
|
+
enableBatteryOptimization?: boolean
|
|
23
|
+
enableMemoryOptimization?: boolean
|
|
24
|
+
breakpoints?: {
|
|
25
|
+
xs: number
|
|
26
|
+
sm: number
|
|
27
|
+
md: number
|
|
28
|
+
lg: number
|
|
29
|
+
xl: number
|
|
30
|
+
'2xl': number
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AdaptiveLayoutCallbacks {
|
|
35
|
+
onDeviceChange?: (deviceType: DeviceType) => void
|
|
36
|
+
onOrientationChange?: (orientation: Orientation) => void
|
|
37
|
+
onScreenSizeChange?: (screenSize: ScreenSize) => void
|
|
38
|
+
onPerformanceChange?: (score: number) => void
|
|
39
|
+
onBatteryChange?: (isLow: boolean) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const useAdaptiveLayout = (
|
|
43
|
+
config: AdaptiveLayoutConfig = {},
|
|
44
|
+
callbacks: AdaptiveLayoutCallbacks = {}
|
|
45
|
+
) => {
|
|
46
|
+
const {
|
|
47
|
+
enablePerformanceOptimization = true,
|
|
48
|
+
enableTouchOptimization = true,
|
|
49
|
+
enableBatteryOptimization = true,
|
|
50
|
+
enableMemoryOptimization = true,
|
|
51
|
+
breakpoints = {
|
|
52
|
+
xs: 0,
|
|
53
|
+
sm: 640,
|
|
54
|
+
md: 768,
|
|
55
|
+
lg: 1024,
|
|
56
|
+
xl: 1280,
|
|
57
|
+
'2xl': 1536
|
|
58
|
+
}
|
|
59
|
+
} = config
|
|
60
|
+
|
|
61
|
+
const [state, setState] = useState<AdaptiveLayoutState>({
|
|
62
|
+
deviceType: 'desktop',
|
|
63
|
+
orientation: 'landscape',
|
|
64
|
+
screenSize: 'lg',
|
|
65
|
+
width: 0,
|
|
66
|
+
height: 0,
|
|
67
|
+
isTouchDevice: false,
|
|
68
|
+
isHighDensity: false,
|
|
69
|
+
isLowPower: false,
|
|
70
|
+
performanceScore: 100
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// Device detection
|
|
74
|
+
const detectDevice = useCallback((width: number, _height: number): DeviceType => {
|
|
75
|
+
if (width < breakpoints.md) return 'mobile'
|
|
76
|
+
if (width < breakpoints.lg) return 'tablet'
|
|
77
|
+
return 'desktop'
|
|
78
|
+
}, [breakpoints])
|
|
79
|
+
|
|
80
|
+
// Screen size detection
|
|
81
|
+
const detectScreenSize = useCallback((width: number): ScreenSize => {
|
|
82
|
+
if (width < breakpoints.sm) return 'xs'
|
|
83
|
+
if (width < breakpoints.md) return 'sm'
|
|
84
|
+
if (width < breakpoints.lg) return 'md'
|
|
85
|
+
if (width < breakpoints.xl) return 'lg'
|
|
86
|
+
if (width < breakpoints['2xl']) return 'xl'
|
|
87
|
+
return '2xl'
|
|
88
|
+
}, [breakpoints])
|
|
89
|
+
|
|
90
|
+
// Touch device detection
|
|
91
|
+
const detectTouchDevice = useCallback((): boolean => {
|
|
92
|
+
return 'ontouchstart' in window || navigator.maxTouchPoints > 0
|
|
93
|
+
}, [])
|
|
94
|
+
|
|
95
|
+
// High density display detection
|
|
96
|
+
const detectHighDensity = useCallback((): boolean => {
|
|
97
|
+
return window.devicePixelRatio > 1
|
|
98
|
+
}, [])
|
|
99
|
+
|
|
100
|
+
// Battery status detection
|
|
101
|
+
const detectBatteryStatus = useCallback(async (): Promise<boolean> => {
|
|
102
|
+
if ('getBattery' in navigator) {
|
|
103
|
+
try {
|
|
104
|
+
const battery = await (navigator as any).getBattery()
|
|
105
|
+
return battery.level < 0.2
|
|
106
|
+
} catch {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false
|
|
111
|
+
}, [])
|
|
112
|
+
|
|
113
|
+
// Performance monitoring
|
|
114
|
+
const measurePerformance = useCallback(async (): Promise<number> => {
|
|
115
|
+
if (!enablePerformanceOptimization) return 100
|
|
116
|
+
|
|
117
|
+
const startTime = performance.now()
|
|
118
|
+
|
|
119
|
+
// Simulate performance measurement
|
|
120
|
+
await new Promise(resolve => setTimeout(resolve, 10))
|
|
121
|
+
|
|
122
|
+
const endTime = performance.now()
|
|
123
|
+
const renderTime = endTime - startTime
|
|
124
|
+
|
|
125
|
+
// Calculate performance score (lower render time = higher score)
|
|
126
|
+
const baseScore = 100
|
|
127
|
+
const timePenalty = Math.min(renderTime * 10, 50)
|
|
128
|
+
const score = Math.max(baseScore - timePenalty, 0)
|
|
129
|
+
|
|
130
|
+
return Math.round(score)
|
|
131
|
+
}, [enablePerformanceOptimization])
|
|
132
|
+
|
|
133
|
+
// Memory usage monitoring
|
|
134
|
+
const measureMemoryUsage = useCallback((): number => {
|
|
135
|
+
if (!enableMemoryOptimization || !('memory' in performance)) return 0
|
|
136
|
+
|
|
137
|
+
const memory = (performance as any).memory
|
|
138
|
+
return (memory.usedJSHeapSize / memory.jsHeapSizeLimit) * 100
|
|
139
|
+
}, [enableMemoryOptimization])
|
|
140
|
+
|
|
141
|
+
// Update layout state
|
|
142
|
+
const updateLayout = useCallback(async () => {
|
|
143
|
+
const width = window.innerWidth
|
|
144
|
+
const height = window.innerHeight
|
|
145
|
+
const deviceType = detectDevice(width, height)
|
|
146
|
+
const screenSize = detectScreenSize(width)
|
|
147
|
+
const orientation = width > height ? 'landscape' : 'portrait'
|
|
148
|
+
const isTouchDevice = detectTouchDevice()
|
|
149
|
+
const isHighDensity = detectHighDensity()
|
|
150
|
+
const isLowPower = await detectBatteryStatus()
|
|
151
|
+
const performanceScore = await measurePerformance()
|
|
152
|
+
|
|
153
|
+
const newState: AdaptiveLayoutState = {
|
|
154
|
+
deviceType,
|
|
155
|
+
orientation,
|
|
156
|
+
screenSize,
|
|
157
|
+
width,
|
|
158
|
+
height,
|
|
159
|
+
isTouchDevice,
|
|
160
|
+
isHighDensity,
|
|
161
|
+
isLowPower,
|
|
162
|
+
performanceScore
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setState(newState)
|
|
166
|
+
|
|
167
|
+
// Trigger callbacks
|
|
168
|
+
if (callbacks.onDeviceChange && deviceType !== state.deviceType) {
|
|
169
|
+
callbacks.onDeviceChange(deviceType)
|
|
170
|
+
}
|
|
171
|
+
if (callbacks.onOrientationChange && orientation !== state.orientation) {
|
|
172
|
+
callbacks.onOrientationChange(orientation)
|
|
173
|
+
}
|
|
174
|
+
if (callbacks.onScreenSizeChange && screenSize !== state.screenSize) {
|
|
175
|
+
callbacks.onScreenSizeChange(screenSize)
|
|
176
|
+
}
|
|
177
|
+
if (callbacks.onPerformanceChange && performanceScore !== state.performanceScore) {
|
|
178
|
+
callbacks.onPerformanceChange(performanceScore)
|
|
179
|
+
}
|
|
180
|
+
if (callbacks.onBatteryChange && isLowPower !== state.isLowPower) {
|
|
181
|
+
callbacks.onBatteryChange(isLowPower)
|
|
182
|
+
}
|
|
183
|
+
}, [
|
|
184
|
+
detectDevice,
|
|
185
|
+
detectScreenSize,
|
|
186
|
+
detectTouchDevice,
|
|
187
|
+
detectHighDensity,
|
|
188
|
+
detectBatteryStatus,
|
|
189
|
+
measurePerformance,
|
|
190
|
+
callbacks,
|
|
191
|
+
state.deviceType,
|
|
192
|
+
state.orientation,
|
|
193
|
+
state.screenSize,
|
|
194
|
+
state.performanceScore,
|
|
195
|
+
state.isLowPower
|
|
196
|
+
])
|
|
197
|
+
|
|
198
|
+
// Initialize and set up event listeners
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
updateLayout()
|
|
201
|
+
|
|
202
|
+
const handleResize = () => updateLayout()
|
|
203
|
+
const handleOrientationChange = () => updateLayout()
|
|
204
|
+
|
|
205
|
+
window.addEventListener('resize', handleResize)
|
|
206
|
+
window.addEventListener('orientationchange', handleOrientationChange)
|
|
207
|
+
|
|
208
|
+
return () => {
|
|
209
|
+
window.removeEventListener('resize', handleResize)
|
|
210
|
+
window.removeEventListener('orientationchange', handleOrientationChange)
|
|
211
|
+
}
|
|
212
|
+
}, [updateLayout])
|
|
213
|
+
|
|
214
|
+
// Performance monitoring interval
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
if (!enablePerformanceOptimization) return
|
|
217
|
+
|
|
218
|
+
const interval = setInterval(updateLayout, 5000)
|
|
219
|
+
return () => clearInterval(interval)
|
|
220
|
+
}, [enablePerformanceOptimization, updateLayout])
|
|
221
|
+
|
|
222
|
+
// Battery monitoring
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
if (!enableBatteryOptimization) return
|
|
225
|
+
|
|
226
|
+
const interval = setInterval(updateLayout, 30000) // Check every 30 seconds
|
|
227
|
+
return () => clearInterval(interval)
|
|
228
|
+
}, [enableBatteryOptimization, updateLayout])
|
|
229
|
+
|
|
230
|
+
// Computed values
|
|
231
|
+
const isMobile = useMemo(() => state.deviceType === 'mobile', [state.deviceType])
|
|
232
|
+
const isTablet = useMemo(() => state.deviceType === 'tablet', [state.deviceType])
|
|
233
|
+
const isDesktop = useMemo(() => state.deviceType === 'desktop', [state.deviceType])
|
|
234
|
+
const isPortrait = useMemo(() => state.orientation === 'portrait', [state.orientation])
|
|
235
|
+
const isLandscape = useMemo(() => state.orientation === 'landscape', [state.orientation])
|
|
236
|
+
|
|
237
|
+
// Layout recommendations
|
|
238
|
+
const layoutRecommendations = useMemo(() => {
|
|
239
|
+
const recommendations = []
|
|
240
|
+
|
|
241
|
+
if (state.isLowPower && enableBatteryOptimization) {
|
|
242
|
+
recommendations.push('Reduce animations and effects for better battery life')
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (state.performanceScore < 70 && enablePerformanceOptimization) {
|
|
246
|
+
recommendations.push('Consider reducing layout complexity for better performance')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (state.isTouchDevice && enableTouchOptimization) {
|
|
250
|
+
recommendations.push('Touch-friendly interactions enabled')
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (state.isHighDensity) {
|
|
254
|
+
recommendations.push('High-density display detected - using optimized assets')
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return recommendations
|
|
258
|
+
}, [
|
|
259
|
+
state.isLowPower,
|
|
260
|
+
state.performanceScore,
|
|
261
|
+
state.isTouchDevice,
|
|
262
|
+
state.isHighDensity,
|
|
263
|
+
enableBatteryOptimization,
|
|
264
|
+
enablePerformanceOptimization,
|
|
265
|
+
enableTouchOptimization
|
|
266
|
+
])
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
// State
|
|
270
|
+
...state,
|
|
271
|
+
|
|
272
|
+
// Computed values
|
|
273
|
+
isMobile,
|
|
274
|
+
isTablet,
|
|
275
|
+
isDesktop,
|
|
276
|
+
isPortrait,
|
|
277
|
+
isLandscape,
|
|
278
|
+
|
|
279
|
+
// Layout recommendations
|
|
280
|
+
layoutRecommendations,
|
|
281
|
+
|
|
282
|
+
// Actions
|
|
283
|
+
updateLayout,
|
|
284
|
+
measurePerformance,
|
|
285
|
+
measureMemoryUsage
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export default useAdaptiveLayout
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { useState, useCallback, useRef, useEffect, ReactNode, ComponentType } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface AdvancedPatternsConfig {
|
|
4
|
+
enableCompoundComponents?: boolean
|
|
5
|
+
enableRenderProps?: boolean
|
|
6
|
+
enableHigherOrderComponents?: boolean
|
|
7
|
+
enableCustomHooks?: boolean
|
|
8
|
+
enablePerformanceOptimization?: boolean
|
|
9
|
+
enableAccessibilitySupport?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CompoundComponentContext {
|
|
13
|
+
registerComponent: (id: string, component: ReactNode) => void
|
|
14
|
+
unregisterComponent: (id: string) => void
|
|
15
|
+
getComponent: (id: string) => ReactNode | undefined
|
|
16
|
+
getAllComponents: () => ReactNode[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface RenderPropsConfig<T = any> {
|
|
20
|
+
data: T
|
|
21
|
+
loading: boolean
|
|
22
|
+
error: Error | null
|
|
23
|
+
render: (props: T) => ReactNode
|
|
24
|
+
fallback?: ReactNode
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface HigherOrderComponentConfig {
|
|
28
|
+
component: ComponentType<any>
|
|
29
|
+
props: Record<string, any>
|
|
30
|
+
enhancers: Array<(Component: ComponentType<any>) => ComponentType<any>>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AdvancedPatternsCallbacks {
|
|
34
|
+
onPatternApplied?: (pattern: string, component: string) => void
|
|
35
|
+
onPerformanceOptimized?: (optimization: string) => void
|
|
36
|
+
onAccessibilityEnhanced?: (feature: string) => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const useAdvancedPatterns = (
|
|
40
|
+
config: AdvancedPatternsConfig = {},
|
|
41
|
+
callbacks: AdvancedPatternsCallbacks = {}
|
|
42
|
+
) => {
|
|
43
|
+
const {
|
|
44
|
+
enableCompoundComponents = true,
|
|
45
|
+
enableRenderProps = true,
|
|
46
|
+
enableHigherOrderComponents = true,
|
|
47
|
+
enableCustomHooks = true,
|
|
48
|
+
enablePerformanceOptimization = true,
|
|
49
|
+
enableAccessibilitySupport = true
|
|
50
|
+
} = config
|
|
51
|
+
|
|
52
|
+
const [patterns, setPatterns] = useState<string[]>([])
|
|
53
|
+
const [isOptimizing, setIsOptimizing] = useState(false)
|
|
54
|
+
const componentsRef = useRef<Map<string, ReactNode>>(new Map())
|
|
55
|
+
const performanceMetricsRef = useRef<Map<string, number>>(new Map())
|
|
56
|
+
|
|
57
|
+
// Compound Components Pattern
|
|
58
|
+
const createCompoundComponent = useCallback((
|
|
59
|
+
baseComponent: ComponentType<any>,
|
|
60
|
+
subComponents: Record<string, ComponentType<any>>
|
|
61
|
+
) => {
|
|
62
|
+
if (!enableCompoundComponents) return baseComponent
|
|
63
|
+
|
|
64
|
+
const compoundComponent = Object.assign(baseComponent, subComponents)
|
|
65
|
+
|
|
66
|
+
setPatterns(prev => [...prev, 'Compound Components'])
|
|
67
|
+
callbacks.onPatternApplied?.('Compound Components', baseComponent.displayName || 'Unknown')
|
|
68
|
+
|
|
69
|
+
return compoundComponent
|
|
70
|
+
}, [enableCompoundComponents, callbacks])
|
|
71
|
+
|
|
72
|
+
// Render Props Pattern
|
|
73
|
+
const createRenderPropsComponent = useCallback(<T,>(
|
|
74
|
+
config: RenderPropsConfig<T>
|
|
75
|
+
) => {
|
|
76
|
+
if (!enableRenderProps) return null
|
|
77
|
+
|
|
78
|
+
const { data, loading, error, render, fallback } = config
|
|
79
|
+
|
|
80
|
+
if (loading) {
|
|
81
|
+
return { type: 'loading', fallback }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (error) {
|
|
85
|
+
return { type: 'error', message: error.message }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setPatterns(prev => [...prev, 'Render Props'])
|
|
89
|
+
callbacks.onPatternApplied?.('Render Props', 'RenderPropsComponent')
|
|
90
|
+
|
|
91
|
+
return { type: 'success', data, render }
|
|
92
|
+
}, [enableRenderProps, callbacks])
|
|
93
|
+
|
|
94
|
+
// Higher-Order Component Pattern
|
|
95
|
+
const createHigherOrderComponent = useCallback((
|
|
96
|
+
config: HigherOrderComponentConfig
|
|
97
|
+
) => {
|
|
98
|
+
if (!enableHigherOrderComponents) return config.component
|
|
99
|
+
|
|
100
|
+
const { component: Component, props, enhancers } = config
|
|
101
|
+
|
|
102
|
+
let EnhancedComponent = Component
|
|
103
|
+
|
|
104
|
+
enhancers.forEach(enhancer => {
|
|
105
|
+
EnhancedComponent = enhancer(EnhancedComponent)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
setPatterns(prev => [...prev, 'Higher-Order Components'])
|
|
109
|
+
callbacks.onPatternApplied?.('Higher-Order Components', Component.displayName || 'Unknown')
|
|
110
|
+
|
|
111
|
+
return { component: EnhancedComponent, props, enhanced: true }
|
|
112
|
+
}, [enableHigherOrderComponents, callbacks])
|
|
113
|
+
|
|
114
|
+
// Custom Hooks Pattern
|
|
115
|
+
const createCustomHook = useCallback(<T>(
|
|
116
|
+
hookName: string,
|
|
117
|
+
hookLogic: () => T
|
|
118
|
+
) => {
|
|
119
|
+
if (!enableCustomHooks) return hookLogic()
|
|
120
|
+
|
|
121
|
+
setPatterns(prev => [...prev, 'Custom Hooks'])
|
|
122
|
+
callbacks.onPatternApplied?.('Custom Hooks', hookName)
|
|
123
|
+
|
|
124
|
+
return hookLogic()
|
|
125
|
+
}, [enableCustomHooks, callbacks])
|
|
126
|
+
|
|
127
|
+
// Performance Optimization
|
|
128
|
+
const optimizeComponent = useCallback((
|
|
129
|
+
componentId: string,
|
|
130
|
+
optimizationType: 'memoization' | 'lazy-loading' | 'virtualization'
|
|
131
|
+
) => {
|
|
132
|
+
if (!enablePerformanceOptimization) return
|
|
133
|
+
|
|
134
|
+
setIsOptimizing(true)
|
|
135
|
+
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
const optimization = `${optimizationType} applied to ${componentId}`
|
|
138
|
+
setPatterns(prev => [...prev, optimization])
|
|
139
|
+
callbacks.onPerformanceOptimized?.(optimization)
|
|
140
|
+
setIsOptimizing(false)
|
|
141
|
+
}, 200)
|
|
142
|
+
}, [enablePerformanceOptimization, callbacks])
|
|
143
|
+
|
|
144
|
+
// Accessibility Enhancement
|
|
145
|
+
const enhanceAccessibility = useCallback((
|
|
146
|
+
componentId: string,
|
|
147
|
+
feature: 'aria' | 'keyboard' | 'screen-reader' | 'focus'
|
|
148
|
+
) => {
|
|
149
|
+
if (!enableAccessibilitySupport) return
|
|
150
|
+
|
|
151
|
+
const enhancement = `${feature} accessibility enhanced for ${componentId}`
|
|
152
|
+
setPatterns(prev => [...prev, enhancement])
|
|
153
|
+
callbacks.onAccessibilityEnhanced?.(enhancement)
|
|
154
|
+
}, [enableAccessibilitySupport, callbacks])
|
|
155
|
+
|
|
156
|
+
// Component Registry
|
|
157
|
+
const registerComponent = useCallback((id: string, component: ReactNode) => {
|
|
158
|
+
componentsRef.current.set(id, component)
|
|
159
|
+
}, [])
|
|
160
|
+
|
|
161
|
+
const unregisterComponent = useCallback((id: string) => {
|
|
162
|
+
componentsRef.current.delete(id)
|
|
163
|
+
}, [])
|
|
164
|
+
|
|
165
|
+
const getComponent = useCallback((id: string) => {
|
|
166
|
+
return componentsRef.current.get(id)
|
|
167
|
+
}, [])
|
|
168
|
+
|
|
169
|
+
const getAllComponents = useCallback(() => {
|
|
170
|
+
return Array.from(componentsRef.current.values())
|
|
171
|
+
}, [])
|
|
172
|
+
|
|
173
|
+
// Performance Monitoring
|
|
174
|
+
const measurePerformance = useCallback((componentId: string, operation: string) => {
|
|
175
|
+
const startTime = performance.now()
|
|
176
|
+
|
|
177
|
+
return () => {
|
|
178
|
+
const endTime = performance.now()
|
|
179
|
+
const duration = endTime - startTime
|
|
180
|
+
performanceMetricsRef.current.set(`${componentId}-${operation}`, duration)
|
|
181
|
+
}
|
|
182
|
+
}, [])
|
|
183
|
+
|
|
184
|
+
// Pattern Analysis
|
|
185
|
+
const analyzePatterns = useCallback(() => {
|
|
186
|
+
const patternCounts = patterns.reduce((acc, pattern) => {
|
|
187
|
+
acc[pattern] = (acc[pattern] || 0) + 1
|
|
188
|
+
return acc
|
|
189
|
+
}, {} as Record<string, number>)
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
totalPatterns: patterns.length,
|
|
193
|
+
patternCounts,
|
|
194
|
+
uniquePatterns: Object.keys(patternCounts).length,
|
|
195
|
+
performanceMetrics: Object.fromEntries(performanceMetricsRef.current)
|
|
196
|
+
}
|
|
197
|
+
}, [patterns])
|
|
198
|
+
|
|
199
|
+
// Pattern Recommendations
|
|
200
|
+
const getPatternRecommendations = useCallback(() => {
|
|
201
|
+
const recommendations = []
|
|
202
|
+
|
|
203
|
+
if (patterns.length === 0) {
|
|
204
|
+
recommendations.push('Consider implementing compound components for complex UI structures')
|
|
205
|
+
recommendations.push('Use render props for flexible component composition')
|
|
206
|
+
recommendations.push('Apply higher-order components for cross-cutting concerns')
|
|
207
|
+
recommendations.push('Create custom hooks for reusable logic')
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!patterns.includes('Performance Optimization')) {
|
|
211
|
+
recommendations.push('Implement memoization for expensive computations')
|
|
212
|
+
recommendations.push('Use lazy loading for large component trees')
|
|
213
|
+
recommendations.push('Consider virtualization for long lists')
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!patterns.includes('Accessibility Support')) {
|
|
217
|
+
recommendations.push('Add ARIA labels and roles to components')
|
|
218
|
+
recommendations.push('Implement keyboard navigation support')
|
|
219
|
+
recommendations.push('Ensure screen reader compatibility')
|
|
220
|
+
recommendations.push('Add focus management features')
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return recommendations
|
|
224
|
+
}, [patterns])
|
|
225
|
+
|
|
226
|
+
// Pattern Validation
|
|
227
|
+
const validatePatterns = useCallback(() => {
|
|
228
|
+
const validation = {
|
|
229
|
+
isValid: true,
|
|
230
|
+
errors: [] as string[],
|
|
231
|
+
warnings: [] as string[]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Check for pattern conflicts
|
|
235
|
+
if (patterns.includes('Compound Components') && patterns.includes('Higher-Order Components')) {
|
|
236
|
+
validation.warnings.push('Compound Components and Higher-Order Components can be used together but may increase complexity')
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Check for missing optimizations
|
|
240
|
+
if (patterns.length > 3 && !patterns.includes('Performance Optimization')) {
|
|
241
|
+
validation.warnings.push('Multiple patterns detected without performance optimization')
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Check for accessibility compliance
|
|
245
|
+
if (patterns.length > 2 && !patterns.includes('Accessibility Support')) {
|
|
246
|
+
validation.warnings.push('Multiple patterns detected without accessibility support')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return validation
|
|
250
|
+
}, [patterns])
|
|
251
|
+
|
|
252
|
+
// Cleanup on unmount
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
return () => {
|
|
255
|
+
componentsRef.current.clear()
|
|
256
|
+
performanceMetricsRef.current.clear()
|
|
257
|
+
}
|
|
258
|
+
}, [])
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
// State
|
|
262
|
+
patterns,
|
|
263
|
+
isOptimizing,
|
|
264
|
+
|
|
265
|
+
// Pattern Creators
|
|
266
|
+
createCompoundComponent,
|
|
267
|
+
createRenderPropsComponent,
|
|
268
|
+
createHigherOrderComponent,
|
|
269
|
+
createCustomHook,
|
|
270
|
+
|
|
271
|
+
// Optimization
|
|
272
|
+
optimizeComponent,
|
|
273
|
+
enhanceAccessibility,
|
|
274
|
+
measurePerformance,
|
|
275
|
+
|
|
276
|
+
// Component Registry
|
|
277
|
+
registerComponent,
|
|
278
|
+
unregisterComponent,
|
|
279
|
+
getComponent,
|
|
280
|
+
getAllComponents,
|
|
281
|
+
|
|
282
|
+
// Analysis
|
|
283
|
+
analyzePatterns,
|
|
284
|
+
getPatternRecommendations,
|
|
285
|
+
validatePatterns,
|
|
286
|
+
|
|
287
|
+
// Utility functions
|
|
288
|
+
hasPattern: (pattern: string) => patterns.includes(pattern),
|
|
289
|
+
getPatternCount: (pattern: string) => patterns.filter(p => p === pattern).length,
|
|
290
|
+
clearPatterns: () => setPatterns([])
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export default useAdvancedPatterns
|