Components
This document provides detailed documentation for the React components and helpers available in the xbees-connect-react package.
CopyInfoButton
The CopyInfoButton component provides a clickable button that copies specified text to the clipboard using the x-bees platform's clipboard functionality.
import { CopyInfoButton } from '@wildix/xbees-connect-react';
function MyComponent() {
return (
<CopyInfoButton
value="Text to copy"
// Additional Material-UI icon props can be passed here
/>
);
}
Props
value(string, required): The text that will be copied to the clipboard when the button is clicked- Additional Material-UI icon props can be passed to customize the button's appearance
Features
- Uses the x-bees platform's
toClipboardfunctionality throughClient.getInstance().toClipboard() - Automatically handles the copy operation when clicked
- Styled with a pointer cursor for better UX
- Extends Material-UI icon props for customization
ThemeProvider
The ThemeProvider component sets up the theme context for your application, integrating with both Material-UI and styled-components. It uses the useThemeEffect hook to synchronize with the x-bees platform's theme.
import { ThemeProvider } from '@wildix/xbees-connect-react';
function App() {
return (
<ThemeProvider>
{/* Your application components */}
</ThemeProvider>
);
}
Features
- Integrates Material-UI and styled-components theme providers
- Automatically syncs with x-bees platform theme
- Includes
CssBaselinefor consistent styling - Uses
StyledEngineProviderwithinjectFirstto ensure proper style injection - Enables color scheme support through
enableColorScheme
Implementation Details
The component:
- Uses
useThemeEffecthook to get the current theme - Wraps the application in both Material-UI and styled-components theme providers
- Applies the theme consistently across both styling solutions
- Includes
CssBaselinefor consistent baseline styles - Ensures proper style injection order with
injectFirst
Integration with Client
The ThemeProvider component works in conjunction with the Client class's theme-related functionality:
- Uses
getTheme()to fetch the current theme - Listens for theme changes through
onThemeChangeevents - Supports both light and dark modes
- Maintains theme consistency across the application
For more detailed information about theme management, refer to the useThemeEffect hook documentation and Client documentation.
Helpers
This section provides documentation for helper functions available in the xbees-connect-react package.
setViewport
The setViewport helper function manages the communication of viewport dimensions to the x-bees platform. It efficiently updates the parent window about the current iframe dimensions while implementing caching to prevent unnecessary updates.
import { setViewport } from '@wildix/xbees-connect-react';
// Basic usage
setViewport();
// With offset
setViewport(20); // Adds 20px to the height
Parameters
offset(number, optional): Additional height to add to the viewport height. Defaults to 0.
Features
- Automatically calculates the current viewport dimensions
- Implements caching to prevent redundant updates
- Uses
Client.getInstance().setViewport()to communicate with the x-bees platform - Returns a Promise when the viewport is updated, or null if no update was needed
Implementation Details
The function:
- Calculates the current height of the document body plus any provided offset
- Checks if the height has changed since the last update (using internal caching)
- If changed, calculates the current width of the document
- Updates the cache with the new height
- Sends the new dimensions to the x-bees platform via
setViewport
Usage Example
import { setViewport } from '@wildix/xbees-connect-react';
// Update viewport with additional padding
function updateViewportWithPadding() {
setViewport(20); // Adds 20px padding to the height
}
// Update viewport when content changes
function onContentChange() {
setViewport(); // Updates with current dimensions
}
Integration with Client
The setViewport helper works in conjunction with the Client class's viewport-related functionality:
- Uses
Client.getInstance().setViewport()to send dimension updates - Integrates with the
useViewPortEffecthook for automatic viewport management - Supports dynamic resizing of the iframe content