mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-25 14:14:57 +00:00
- Introduced `menu.json` for menu component structure with bindings for trigger and content. - Created `password-input.json` for password input handling visibility and value changes. - Added `popover.json` for popover component with trigger and content bindings. feat: Implement custom hooks for UI interactions - Added `useAccordion` for managing accordion state with single/multiple item support. - Created `useBindingEditor` for managing bindings in a dynamic editor. - Implemented `useCopyState` for clipboard copy functionality with feedback. - Developed `useFileUpload` for handling file uploads with drag-and-drop support. - Introduced `useFocusState` for managing focus state in components. - Created `useImageState` for handling image loading and error states. - Added `useMenuState` for managing menu interactions and item clicks. - Implemented `usePasswordVisibility` for toggling password visibility. - Developed `usePopoverState` for managing popover visibility and interactions. feat: Add constants and interfaces for JSON UI components - Introduced constants for sizes, placements, styles, and object-fit handling. - Created interfaces for various components including Accordion, Binding Editor, Copy Button, Data Source Editor, File Upload, and more. - Added type definitions for menu items, popover props, and other UI elements to enhance type safety and maintainability.
2.9 KiB
2.9 KiB
JSON Constants Migration Guide
Overview
This document tracks the extraction of hardcoded constants from JSON component definitions into the centralized constants folder.
Status
✅ Constants Folder Created
Location: src/lib/json-ui/constants/
Files:
sizes.ts- Size-related constantsplacements.ts- Positioning constantsstyles.ts- CSS class constantsobject-fit.ts- Image object-fit constantsindex.ts- Centralized exports
📋 Constants Found in JSON Files
CopyButton (copy-button.json)
// Line 11: sizeStyles
const sizeStyles = { sm: 'p-1', md: 'p-2', lg: 'p-3' }
// → BUTTON_SIZES
// Lines 25, 39: iconSize (duplicated)
const iconSize = { sm: 12, md: 16, lg: 20 }
// → ICON_SIZES
Popover (popover.json)
// Line 39: placementStyles
const placementStyles = {
top: 'bottom-full mb-2 left-1/2 -translate-x-1/2',
bottom: 'top-full mt-2 left-1/2 -translate-x-1/2',
left: 'right-full mr-2 top-1/2 -translate-y-1/2',
right: 'left-full ml-2 top-1/2 -translate-y-1/2'
}
// → POPOVER_PLACEMENTS
Image (image.json)
// Line 51: Dynamic object-fit (uses template literal)
return `${base} ${opacity} object-${fit}`
// Could use OBJECT_FIT_CLASSES but requires transform refactor
Recommendations
Option 1: Keep Inline (Current Approach)
Pros:
- No changes to component-renderer needed
- Self-contained JSON definitions
- Easy to understand transforms
Cons:
- Duplication of constants
- Harder to maintain consistency
- Magic strings scattered across files
Option 2: Import Constants in Hooks
Pros:
- Hooks can use TypeScript constants
- No changes to JSON structure needed
- Immediate benefit for custom hooks
Cons:
- Only helps with hook-based logic
- Still have duplication in JSON transforms
Option 3: Add Constants to Transform Context (Future)
Pros:
- Eliminates duplication entirely
- Type-safe constants usage
- Easier to update global styles
Cons:
- Requires component-renderer changes
- More complex transform evaluation
- Migration effort for existing JSON files
Recommended Next Steps
-
Short term: Use constants in custom hooks (Option 2)
- Hooks can import from
@/lib/json-ui/constants - Reduce duplication in hook code
- Hooks can import from
-
Medium term: Document best practices
- Add examples of using constants
- Create migration guide for new components
-
Long term: Enhanced transform context (Option 3)
- Update component-renderer to expose constants
- Migrate existing JSON files to use constants
- Remove inline const statements
Files to Potentially Update
When migrating to Option 3:
copy-button.json- sizeStyles, iconSizepopover.json- placementStylesmenu.json- May have similar patternsfile-upload.json- May have size constants- Any future components using similar patterns