Developer Docs

Custom Components

Carousel

Carousel Rendered Example

About

The Carousel component provides a horizontally scrollable container for displaying multiple cards or items. It's designed to work seamlessly with CustomCard components to create interactive, scrollable content galleries.

Properties

The Carousel component accepts these properties:

PropertyTypeRequiredDescription
childrenReactNodeYesContent to be rendered inside the carousel

Import and Basic Usage

You can import the Carousel component from touchpoint once the package has been installed or made available in your project.

Define onClick

When using Carousel with CustomCard components, define click handlers on the individual cards to handle user interactions. The Carousel itself is a container component.

Access the ConversationHandler method

sendChoice via conversationHandler.sendChoice to send the user's choice back to NLX.

Read more details about building Custom Components with Touchpoint in the Getting started with Touchpoint components documentation page.

Example

The Carousel component is best used with multiple CustomCard components to create a scrollable interface.

Example Modality Schema

1[ 2 { 3 "id": "uuid", 4 "thumbnail": "imageUrl", 5 "label": "Label text", 6 "value": "Value text" 7 } 8]
1<script type="module"> 2 import { create, React, html } from "https://unpkg.com/@nlxai/touchpoint-ui@1.0.5-alpha.12/lib/index.js?module"; 3 4 const ItemsCarousel = ({ data, conversationHandler }) => { 5 const [selectedItemId, setSelectedItemId] = React.useState(null); 6 7 return html` 8 <Carousel> 9 ${data.map( 10 (item) => html` 11 <CustomCard 12 key=${item.id} 13 selected=${item.id === selectedItemId} 14 onClick=${() => { 15 setSelectedItemId(item.id); 16 conversationHandler.sendChoice(item.id); 17 }} 18 > 19 <CustomCardImageRow src=${item.thumbnail} alt="Image" /> 20 <CustomCardRow 21 left=${html`<BaseText faded>Label</BaseText>`} 22 right=${html`<BaseText>Value</BaseText>`} 23 /> 24 <CustomCardRow 25 left=${html`<BaseText faded>Label</BaseText>`} 26 right=${html`<BaseText>Value</BaseText>`} 27 /> 28 </CustomCard> 29 `, 30 )} 31 </Carousel> 32 `; 33 }; 34 35 // Register component when creating touchpoint 36 const touchpoint = await create({ 37 config: { 38 applicationUrl: "YOUR_APPLICATION_URL", 39 headers: { "nlx-api-key": "YOUR_API_KEY" }, 40 languageCode: "en-US", 41 }, 42 customModalities: { 43 ItemsCarouselModality: ItemsCarousel, 44 }, 45 }); 46 47</script>