### Implement User Actions with Tuya Button Component Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Demonstrates various styles, sizes, and states of the Tuya Button component for user interactions. Includes examples for primary, default, warn, plain, loading, mini, and special-purpose buttons like share and get user info. ```xml ``` -------------------------------- ### Capture Single-Line Text with Tuya Input Component Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Provides examples of the Tuya Input component for single-line text entry. Covers different input types (text, password, digit), placeholders, character limits, and event handling for input and confirmation. ```xml Device Name: Password: Temperature: Email: ``` -------------------------------- ### Embedded Web Page - JavaScript for Communication Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt This snippet illustrates a JavaScript example for a web page embedded within a miniapp using the WebView component. It shows how to send messages to the miniapp, navigate back, and navigate to other miniapp pages using the `wx.miniProgram` API. ```javascript // Send message to miniapp wx.miniProgram.postMessage({ data: { action: 'control', data: { deviceId: '123', command: 'turnOn' } } }) // Navigate back wx.miniProgram.navigateBack() // Navigate to miniapp page wx.miniProgram.navigateTo({ url: '/pages/device/detail?id=123' }) ``` -------------------------------- ### Camera Component for Photo and Video Capture Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt The system camera component allows for capturing photos and recording videos. It offers control over flash mode, camera facing direction, and provides event callbacks for initialization, stopping, errors, and scan codes. Includes example JavaScript for controlling camera actions. ```xml Page({ data: { cameraPosition: 'back', flashMode: 'off' }, onReady() { this.cameraContext = wx.createCameraContext() }, takePhoto() { this.cameraContext.takePhoto({ quality: 'high', success: (res) => { console.log('Photo path:', res.tempImagePath) this.setData({ photoPath: res.tempImagePath }) }, fail: (err) => { console.error('Take photo failed:', err) } }) }, startRecord() { this.cameraContext.startRecord({ success: () => { console.log('Recording started') } }) }, stopRecord() { this.cameraContext.stopRecord({ success: (res) => { console.log('Video path:', res.tempVideoPath) this.setData({ videoPath: res.tempVideoPath }) } }) }, switchCamera() { this.setData({ cameraPosition: this.data.cameraPosition === 'back' ? 'front' : 'back' }) } }) ``` -------------------------------- ### CoverView for Overlays on Native Components - Tuya XML Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt The CoverView component is designed for overlaying content on native components like video, map, and camera. It allows for custom controls and text positioned directly above these native elements, as shown in this video control example. ```xml ``` -------------------------------- ### IPC Player Component for Smart Camera Feeds Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt This component is designed for streaming and controlling IP camera feeds. It supports features like PTZ control, different stream types (HD/SD), and provides event handlers for playback and specific camera actions like snapshots. Includes example JavaScript for basic control. ```xml Page({ data: { ipcDeviceId: 'device_123456', streamType: 'hd' }, onIpcPlay() { console.log('IPC playback started') }, switchHD() { this.setData({ streamType: 'hd' }) }, switchSD() { this.setData({ streamType: 'sd' }) } }) ``` -------------------------------- ### Display System Icons with Tuya Icon Component Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Demonstrates how to display standard system icons using the Tuya Icon component. It shows various icon types and how to set their size and color. ```xml ``` -------------------------------- ### WebView Component - XML and JavaScript for Miniapp Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt This snippet shows the XML structure for the WebView component and the corresponding JavaScript logic in a miniapp's page.js file. It demonstrates how to initialize the web URL, handle messages received from the embedded web page, and manage load and error events. ```xml ``` ```javascript Page({ data: { webUrl: 'https://example.com/device-dashboard' }, onLoad(options) { if (options.url) { this.setData({ webUrl: decodeURIComponent(options.url) }) } }, onWebMessage(e) { console.log('Message from web:', e.detail.data) // Handle messages from web page const messages = e.detail.data messages.forEach(msg => { if (msg.action === 'control') { this.handleDeviceControl(msg.data) } }) }, onWebLoad(e) { console.log('Web page loaded') }, onWebError(e) { console.error('Web page error:', e.detail) } }) ``` -------------------------------- ### Visualize Task Progress with Tuya Progress Component Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Illustrates the usage of the Tuya Progress component to visualize task completion and loading states. It supports dynamic updates of progress percentage and visual customization. ```xml Download Progress Upload Progress (Active) ``` -------------------------------- ### Image Display with Options (XML & JS) Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt An image component for displaying images with various resize modes, lazy loading, and error handling. It includes attributes for controlling image display behavior, handling load/error events, and enabling context menus. Requires XML for image structure and JavaScript for event handling and data binding. ```xml ``` ```javascript Page({ data: { deviceImage: '/images/device.jpg', qrCode: 'https://example.com/qr.png', thumbnail: '/images/thumb.webp' }, onImageLoad(e) { console.log('Image loaded:', e.detail) }, onImageError(e) { console.error('Image error:', e.detail.errMsg) this.setData({ deviceImage: '/images/default.png' }) } }) ``` -------------------------------- ### Native Video Component for Optimized Playback Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt This component provides a native video player optimized for platform-specific performance, ensuring high-quality video playback. It supports standard video attributes and event bindings for playback control. ```xml ``` -------------------------------- ### Render Formatted Content with Tuya RichText Component Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Shows how to use the Tuya RichText component to render HTML content. This allows for displaying formatted text, including headings, paragraphs, lists, and inline styles. ```xml Page({ data: { htmlContent: "

Device Setup Instructions

Follow these steps to configure your device:

  1. Power on the device
  2. Open the Tuya Smart app
  3. Tap Add Device

Complete setup within 2 minutes

" } }) ``` -------------------------------- ### Switch for Binary States (XML) Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt A toggle switch component for managing binary on/off states. It allows for customization of colors and can be disabled based on other conditions. Ideal for controlling features like WiFi, Bluetooth, or automatic modes. ```xml WiFi Bluetooth Auto Mode ``` -------------------------------- ### Text Component for Displaying Text - Tuya XML Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt The Text component is used for rendering text content in Tuya miniapps. It supports features like selectable text, rich formatting, decode for HTML entities, and dynamic styling based on component state. ```xml Smart Home Control Control your devices from anywhere. Long press to select and copy this text. Temperature: 24°C   Humidity: 65% {{deviceOnline ? '● Online' : '● Offline'}} ``` -------------------------------- ### Basic View Component for Layout - Tuya XML Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt The View component serves as a fundamental layout container for structuring content and organizing UI elements hierarchically in Tuya miniapps. It accepts class names for styling and can contain other components. ```xml Device Control Panel Smart Light ``` -------------------------------- ### Map Component: Displaying Locations and Routes with Tuya Map Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Renders an interactive map using the Tuya Map component. It supports displaying markers, polylines for routes, and circles for defined areas. The component is configurable with various properties like longitude, latitude, scale, and event handlers for user interactions such as marker taps and region changes. Dependencies include a valid Tuya environment and image assets for markers and controls. ```xml ``` ```javascript Page({ data: { longitude: 120.131441, latitude: 30.279383, mapScale: 16, markers: [ { id: 1, longitude: 120.131441, latitude: 30.279383, iconPath: '/images/marker.png', width: 30, height: 30, title: 'Device Location', callout: { content: 'Smart Gateway\nOnline', fontSize: 14, borderRadius: 5, padding: 10, display: 'ALWAYS' } }, { id: 2, longitude: 120.135, latitude: 30.280, iconPath: '/images/marker-offline.png', width: 30, height: 30 } ], polylines: [ { points: [ { longitude: 120.131441, latitude: 30.279383 }, { longitude: 120.135, latitude: 30.280 } ], color: '#1890ff', width: 4, dottedLine: false } ], circles: [ { longitude: 120.131441, latitude: 30.279383, radius: 500, color: '#1890ff33', fillColor: '#1890ff11', strokeWidth: 2 } ], controls: [ { id: 1, position: { left: 10, top: 10, width: 50, height: 50 }, iconPath: '/images/location.png', clickable: true } ] }, onMarkerTap(e) { console.log('Marker tapped:', e.detail.markerId) }, onControlTap(e) { console.log('Control tapped:', e.detail.controlId) if (e.detail.controlId === 1) { this.moveToMyLocation() } }, moveToMyLocation() { this.mapContext = wx.createMapContext('deviceMap', this) this.mapContext.moveToLocation() } }) ``` -------------------------------- ### Handle Multi-Line Text with Tuya Textarea Component Source: https://context7.com/context7/v0-tuya-component-documentation_vercel_app/llms.txt Showcases the Tuya Textarea component for multi-line text input. It supports character counting, auto-height adjustment, cursor spacing, and various input event handlers. ```xml