Getting Started with SmarterElements
SmarterElements provides iframe-based UI components with automatic resizing, modal support, and secure isolation. Components can be mounted directly into the DOM or displayed as overlay modals.Installation
npm Installation
CDN / Script Tag Installation
For projects that don’t use npm or bundlers, you can include SmarterElements directly via script tags using unpkg.com:Version Options
Latest Version (Recommended for Development):Complete Example
Version Selection Guide
| Use Case | Recommended Version | Example |
|---|---|---|
| Development/Testing | @latest | @smarterservices/smarter-elements@latest |
| Production | Specific version | @smarterservices/smarter-elements@1.2.3 |
| Auto-updates (patch) | Minor range | @smarterservices/smarter-elements@~1.2.0 |
| Auto-updates (minor) | Major range | @smarterservices/smarter-elements@^1.0.0 |
Quick Start
React Integration
JavaScript Integration
Core Concepts
Elements
Elements are self-contained UI components that run in isolated iframes. Each element has:- Type: A unique identifier (e.g.,
blockkit/renderer) - Configuration: Parameters passed to the element
- Events: Messages the element can send/receive
- Lifecycle: Methods for mounting, destroying, etc.
Element Lifecycle
- Create - Initialize element with configuration
- Mount - Attach to DOM or open in modal
- Ready - Element is loaded and interactive
- Events - Ongoing communication with element
- Destroy - Clean up resources
Configuration
Elements accept configuration through theconfig parameter:
Size Constraints
Control element dimensions with width and height constraints:- Pixels:
300or'300px' - Percentages:
'80%'(of parent container) - Viewport units:
'50vw','30vh' - Relative units:
'20rem','15em'
Display Options
DOM Mounting
Mount elements directly into existing DOM elements:Modal Display
Display elements in overlay modals with comprehensive options:Event Handling
Elements can send events to the parent application:Error Handling
Handle element errors gracefully:Advanced Features
Auto-Resizing System
Elements use ResizeObserver for efficient content-based sizing:- Content-driven sizing - Height adjusts automatically to content
- Smooth transitions - CSS animations for resize changes
- Performance optimization - Debounced updates (60fps throttling)
- Constraint handling - Respects min/max width/height limits
- Container awareness - Never exceeds parent container bounds
Element Lifecycle Management
Multiple Elements
Best Practices
Performance
Error Handling
Accessibility
- Modal Focus Management: Automatic focus trapping and restoration
- Keyboard Navigation: ESC key closes modals, tab navigation works
- Screen Reader Support: Proper ARIA labels and semantic HTML
- Body Scroll Prevention: Background scrolling disabled in modals
Utility Functions
SmarterElements includes helpful utility functions for common tasks:Debounce and Throttle
Handle frequent events efficiently:CDN Usage
Next Steps
- API Reference - Complete method documentation
- Examples - Real-world usage patterns
- Troubleshooting - Common issues and solutions
Quick Reference
| Task | Method | Example |
|---|---|---|
| Create element | elements.create() | elements.create('type', { config }) |
| Mount to DOM | element.mount() | element.mount('#container') |
| Open modal | element.openModal() | await element.openModal({ width: '80%' }) |
| Update config | element.updateConfig() | element.updateConfig({ newParam: 'value' }) |
| Clean up | element.destroy() | element.destroy() |
Need help? Check our troubleshooting guide or contact support.
