API Reference
This document provides detailed information about the ruio API, including components, hooks, and configuration options.
Table of Contents
RuioContextProvider (RuioWrapper)
The main component that wraps your React application and provides ruio functionality.
Import
import RuioContextProvider from 'ruio'Alias: Also exported as RuioWrapper (same component, different name).
Usage
import RuioContextProvider from 'ruio'
function App() {
return (
<RuioContextProvider>
{/* Your application components */}
</RuioContextProvider>
)
}Props
children
ReactNode
Yes
-
Your application components
showInProduction
boolean
No
false
Override to show ruio UI in production environments. Useful for demo apps.
defaultRootSelector
string
No
Auto-detected
CSS selector for the root element to visualize. If not provided, ruio auto-detects common patterns (#root, #app, [data-reactroot], body > div:first-child). Examples: '#root', '#app', '.main-container', '[data-app-root]'
Behavior
Automatically detects development vs. production environment
Only renders the ruio UI toggle in development mode (
process.env.NODE_ENV !== 'production')Can be overridden with
showInProductionprop to enable in production (useful for demos)Auto-detects the root element using common patterns (
#root,#app, etc.) unlessdefaultRootSelectoris providedCreates a portal for the ruio UI controls to avoid CSS conflicts
Persists settings (enabled state, root element) in
localStorage
useRuioContext Hook
A React hook that provides access to ruio's internal state and controls. This is primarily for advanced use cases.
Import
Usage
Returns
The hook returns an object with the following properties:
ruioEnabled
boolean
Whether ruio visualization is currently enabled
setRuioEnabled
React.Dispatch<boolean>
Toggle ruio on/off
depth
number
Current UI depth for border visualization
setDepth
React.Dispatch<number>
Set the visualization depth
rootElement
HTMLElement | null
Currently selected root element
isElementSelectionModeActive
boolean
Whether element selection mode is active
setIsElementSelectionModeActive
React.Dispatch<boolean>
Control element selection mode
toggleElementSelectionMode
() => void
Toggle element selection mode
currentColorPalette
string
Current color palette/theme key
setCurrentColorPalette
React.Dispatch<string>
Change the color palette
Important Notes
This hook must be used within a component that is a child of
RuioContextProviderThrows an error if used outside of the provider context
Most users won't need this hook; it's primarily for advanced customization
Element Exclusion
You can exclude specific elements and their descendants from ruio's border visualization.
Usage
Add the ruio-exclude class to any element you want to exclude:
Behavior
Elements with
ruio-excludeclass are completely ignored by ruioAll descendant elements are also excluded (inclusive exclusion)
The ruio UI controls automatically have this class applied
Useful for:
Modal overlays
Fixed navigation bars
Third-party widgets
Any elements that shouldn't be visualized
Environment Detection
ruio automatically detects the environment and adjusts its behavior:
Development Mode
Toggle button is visible
Full ruio functionality enabled
Settings modal accessible
Element selection mode available
Production Mode
Toggle button is hidden
Minimal overhead
No UI controls rendered
Safe to include in production builds
How It Works
ruio checks process.env.NODE_ENV and only renders UI controls when the value is not 'production'.
LocalStorage Persistence
ruio automatically persists certain settings in localStorage:
ruio_enabled
boolean
Whether ruio is enabled
ruio_root_selector
string
CSS selector for the root element
These values are automatically restored on page refresh, providing a seamless developer experience.
TypeScript Support
ruio is written in TypeScript and includes full type definitions. No additional @types package is required.
Type Definitions
Examples
Basic Setup
Excluding Elements
Production Demo App
Custom Root Element
Advanced: Custom Controls
Questions or Issues?
If you have questions about the API or encounter issues, please:
Last updated
Was this helpful?
