A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://liveblocks.io/docs/api-reference/liveblocks-react-ui below:

@liveblocks/react-ui | API Reference

@liveblocks/react-ui provides you with React components to build collaborative experiences. Read our Comments and Notifications get started guides to learn more.

AI Copilots Default components AiChat

Displays an interactive AI chat. AI can use knowledge and run actions or display content via tools.

Each chat is stored permanently, and is identified by its unique chatId. Chats are only visible to the authenticated user who created the chat.

Assigning a copilot

Use a custom copilot in your chat. You can define copilots with custom prompts & settings in the Liveblocks dashboard, passing your API key from OpenAI, Anthropic, or Google. Copy the copilot's ID and pass it to the copilotId prop.

Dynamically switching copilots is possible, and messages will use whichever copilotId is set when a message is sent.

Show placeholder content in new chats

In chats without messages, you can display placeholder content to welcome and guide the user. To set this content, use the Empty property under components.

Additionally, you can add suggestion buttons which will automatically submit new messages to the chat when clicked. Create them with useSendAiMessage.

List the user’s chats and switch between them

You can display a list of all chats created by the current user with useAiChats. For example, you can render a list of buttons that allow you to switch between chats. In each button, you can display the chat’s automatically generated title, as seen below. Chats can be deleted with useDeleteAiChat.

Display the chat’s title

Each chat has a title property, automatically generated by AI. The title of a new chat starts empty, and is updated after AI receives the first message and writes a response. You can render this alongside your chat with useAiChat.

Add front-end knowledge

You can add front-end knowledge to chats, meaning the AI will understand the information you pass, and will answer questions or call tools based on it. This is particularly helpful for passing user info, app state, and small contextual knowledge.

It’s generally recommended to use RegisterAiKnowledge for adding knowledge, as this will add knowledge to all AI features on the page. However, if you’d like knowledge that is specific to one chat, you can add it with the knowledge prop on AiChat. No other chats will have access to this knowledge.

Add back-end knowledge

You can add back-end knowledge to chats, meaning the AI will understand the information you pass, and can answer questions or call tools based on it. This is a way to pass large amounts of project-wide information, for example complex documentation.

When creating or editing a copilot in the Liveblocks dashboard navigate to the Knowledge tab. Within here you can upload any relevant files, or submit websites for indexing. Your copilot will internalize this knowledge using retrieval-augmented generation (RAG).

Adjusting the chat’s width

When using the default inset layout, it’s possible to adjust the chat’s width by setting the --lb-ai-chat-container-width CSS variable. This allows the chat’s scroll window to stay full width, whilst keeping the composer and messages centered in the middle.

Compact layout mode

An alternate compact layout mode is available, ideal for smaller UI components such as pop-up windows. Compact layout mode removes the shadow and padding on the composer, makes it full-width, and displays a border above it.

Change background color

You can change the background color of the chat by setting the --lb-background CSS variable on .lb-ai-chat.

Customize CSS variables and classes

You can customize the default styles of the chat by modifying CSS variables and classes prefixed with lb. Here are some examples.

Customize how Markdown is rendered

You can customize how Markdown is rendered in messages by passing components to the components prop. A full list is available here.

Props components

Override specific parts of AiChat with custom components.

AiTool

Displays AI tool calls and their progress. Can be customized for many different UIs.

By default, AiTool will display the name of the current tool, and a loading spinner as it runs.

Optionally, you can provide a title and icon to render the UI differently.

Props

All other HTML div props are also supported and will be passed through to the underlying container element.

AiTool.Confirmation

Displays an AI tool with a confirmation UI. This allows you to create actions that users must confirm or cancel before they’re run.

Use the confirm and cancel props to define which actions should be taken when the users clicks the buttons. You can return information that helps the AI understand what has taken place, and data which you can use in render after the tool is called.

AiTool.Confirmation will display different content depending on the stage of the tool. For example, the confirm and cancel buttons will disappear when clicked.

Props

All other HTML div props are also supported and will be passed through to the underlying element.

AiTool.Inspector

Displays formatted view of the JSON arguments sent to and results returned by the AI during the current tool invocation. This is useful for debugging or for providing developers with insight into the data exchanged within your app.

To use, simply include <AiTool.Inspector /> inside an <AiTool /> component to display the tool’s input arguments and resulting output.

Props

All HTML div props are supported and will be passed through to the underlying element.

Comments Default components Thread

Displays a thread of comments. Each thread has a composer for creating replies.

Map through threads to render a list of the room’s threads and comments. Threads can be retrieved with useThreads.

Resolved and unresolved threads

A thread can be marked as resolved or unresolved via its resolved property. The Thread component automatically handles this through its resolved toggle button displayed by default.

You can additionally use thread.resolved to filter the displayed threads for example. Or if you want to create your own Thread component using the primitives, you can use useMarkThreadAsResolved and useMarkThreadAsUnresolved to update the property.

Collapsed threads

You can collapse threads by setting the maxVisibleComments prop. If a thread contains more comments than the limit set, some of the comments will be hidden and a "Show more replies" button will be displayed instead. Clicking on it will expand the thread to show all comments.

The first and last comments are always visible, and by default the oldest comments are more likely to be hidden. You can customize this behavior by setting maxVisibleComments to an object.

Props Composer

Displays a composer for creating threads or comments.

By default, submitting the composer will create a new thread.

Adding thread metadata

If you’d like to attach custom metadata to the newly created thread, you can add a metadata prop.

Typed metadata

You can use TypeScript to type your custom metadata by editing your config file. Metadata properties can be string, number, or boolean.

Replying to a thread

If you provide a threadId, then submitting the composer will add a new reply to the thread.

Modifying a comment

If you provide both a threadId and a commentId, then submitting the composer will edit the comment.

Custom behavior

If you’d like to customize submission behavior, you can use event.preventDefault() in onComposerSubmit to disable the default behavior and call comment and thread mutation methods manually.

Learn more about mutation hooks under @liveblocks/react.

Props Comment

Displays a single comment.

Map through thread.comments to render each comment in a thread. Threads can be retrieved with useThreads.

Custom thread components

Comment can be used in combination with Composer to create a custom thread component. The composer in this example is used to reply to the existing thread.

Props Primitives

Primitives are unstyled, headless components that can be used to create fully custom commenting experiences. We have a primitives example highlighting how to use them.

Using primitives with TypeScript

If you run into the Cannot find module '@liveblocks/react-ui/primitives' or its corresponding type declarations error, you should update your tsconfig.json’s moduleResolution property to "node16" or "nodenext" (or "bundler" if you’re on TS >=5).

Composition

All primitives are composable; they forward their props and refs, merge their classes and styles, and chain their event handlers.

Inspired by Radix (and powered by its Slot utility), most of the primitives also support an asChild prop to replace the rendered element by any provided child, and both set of props will be merged.

Learn more about this concept on Radix’s composition guide.

Composer

Used to render a composer for creating, or editing, threads and comments.

Combine with useCreateThread to render a composer that creates threads.

Composer.Form

Surrounds the composer’s content and handles submissions. By default, no action occurs when the composer is submitted. You must create your own mutations within onComposerSubmit for creating threads, creating comments, editing comments, etc.

Composer.Editor

Displays the composer’s editor.

Attribute Value data-focused Present when the component is focused. data-disabled Present when the component is disabled. components

The components displayed within the editor.

Mention

The component used to display mentions.

MentionSuggestions

The component used to display mention suggestions.

Link

The component used to display links.

FloatingToolbar

Displays a floating toolbar attached to the selection within Composer.Editor.

Composer.Mention

Displays mentions within Composer.Editor.

Attribute Value data-selected Present when the mention is selected. Composer.Suggestions

Contains suggestions within Composer.Editor.

Composer.SuggestionsList

Displays a list of suggestions within Composer.Editor.

Composer.SuggestionsListItem

Displays a suggestion within Composer.SuggestionsList.

Attribute Value data-selected Present when the item is selected. Composer.Link

Displays links within Composer.Editor.

Composer.Submit

A button to submit the composer.

Composer.FloatingToolbar

Displays a floating toolbar attached to the selection within Composer.Editor.

Composer.MarkToggle

A toggle button which toggles a specific text mark.

Composer.AttachFiles

A button which opens a file picker to create attachments.

Composer.AttachmentsDropArea

A drop area which accepts files to create attachments.

Comment

Used to render a single comment.

Map through thread.comments to render each comment in a thread. Threads can be retrieved with useThreads.

Comment.Body

Displays a comment body.

components

The components displayed within the comment body.

Mention

The component used to display mentions.

Link

The component used to display links.

Comment.Mention

Displays mentions within Comment.Body.

Comment.Link

Displays links within Comment.Body.

Timestamp

Displays a formatted date, and automatically re-renders to support relative formatting. Defaults to relative formatting for recent dates (e.g. “5 minutes ago”) and a short absolute formatting for older ones (e.g. “25 Aug”).

Use with comment.createdAt, comment.editedAt, or comment.deletedAt to display a human-readable time.

FileSize

Displays a formatted file size.

Use with attachment.size to display a human-readable file size.

Emoji picker

Using Frimousse alongside useAddReaction, a package originally designed for Comments, you can easily add an emoji picker to your primitive Comments components.

Find a full code snippet of this in our Comments primitives example.

Emoji reactions

A list of clickable emoji reactions can be created using the useAddReaction, useRemoveReaction, and useSelf hooks.

Hooks useComposer

Returns states and methods related to the composer. Can only be used within the Composer.Form primitive. All values listed below.

Custom composer behavior

useComposer can be used in combination with Composer primitives to create a custom composer, and control its behavior. For example, createMention allows you to create a button which focuses the editor, adds @, and opens the mention suggestions dropdown.

Handle attachments

When using primitives, Composer.AttachFiles and Composer.AttachmentsDropArea add attachments to the composer, but they’re not rendered without useComposer. The attachments array can be used to render the current attachments, and removeAttachment allows you to remove them.

Values Other hooks

Other Comments hooks are part of @liveblocks/react, you can find them on the React API reference page.

Notifications Default components InboxNotification

Displays a single inbox notification.

Map through inboxNotifications with useInboxNotifications to render a list of the room’s notifications.

Rendering notification kinds differently

Different kinds of notifications are available, for example thread which is triggered when using Comments, or $myCustomNotification which would be a custom notification you’ve triggered manually. You can choose to render each notification differently.

Adding these two properties to kinds will overwrite the default component that’s displayed for those two notification types. Using InboxNotification.Thread and InboxNotification.Custom in this way allow you to easily create components that fit into the existing design system, whilst still adding lots of customization. However, it’s also valid to render any custom JSX.

Typing custom notifications

To type custom notifications, edit the ActivitiesData type in your config file.

Your activities data is now correctly typed in inline functions.

If you’d like to create a typed function elsewhere, you can use InboxNotificationCustomProps with a generic. In the example below we’re using the $alert notification kind as a generic, InboxNotificationCustomKindProps<"$alert">.

Props kinds

Override specific kinds of inbox notifications.

InboxNotification.Thread

Displays a thread inbox notification kind.

InboxNotification.TextMention

Displays a text mention inbox notification kind.

InboxNotification.Custom

Displays a custom notification kind.

InboxNotification.Inspector

Displays the inbox notification’s data in a JSON code snippet. Useful when debugging notifications in your app.

InboxNotificationList

Displays inbox notifications as a list. Each InboxNotification component will be wrapped in a li element.

Props Hooks

All hooks for Notifications are in @liveblocks/react.

Version History

Private beta

Version history is currently in private beta. If you would like access to the beta, please contact us. We’d love to hear from you.

When enabled, version history will automatically create versions of your Lexical or Yjs document and allow you to restore to specific versions. These components aid in displaying a list of those versions.

Default components HistoryVersionSummary

Displays a version summary which includes the author and date.

Props HistoryVersionSummaryList

Displays a list of version summaries for a document’s history including authors and dates.

Props Utilities Components Icon

Most icons used in the default components can be exported via <Icon.* />. They’re stroke-based and designed for use at 20×20 pixels.

Find a full list of available icons in our GitHub repo.

LiveblocksUiConfig

Set configuration options for all @liveblocks/react-ui components, such as overrides.

Props Hooks

All hooks for Version History are in @liveblocks/react.

Styling and customization Default styles

The default components come with default styles. These styles can be imported into the root of your app or directly into a CSS file with @import.

Dark mode

You can also import default dark mode styling. There are two versions to choose from, the first uses the system theme.

The second uses the dark class name, and two commonly used data attributes.

CSS variables

The default components are built around a set of customizable CSS variables. Set these variables within .lb-root to globally style your components.

Class names

Each default component has a set of predefined class names, which can be helpful for custom styling, for example.

Additionally, some elements also have data attributes to provide contextual information, for example:

Internal classes

Classes containing colons : are internal and may change over time.

Portaled elements

Floating elements within the default components (e.g. tooltips, dropdowns, etc) are portaled to the end of the document to avoid z-index conflicts and overflow issues.

When portaled, those elements are also wrapped in a container to handle their positioning. These containers don’t have any specific class names or data attributes so they shouldn’t be targeted or styled directly, but they will mirror whichever z-index value is set on their inner element (which would be auto by default). So if you need to set a specific z-index value on floating elements, you should set it on the floating elements themselves directly, ignoring their containers. You can either target specific floating elements (e.g. .lb-tooltip, .lb-dropdown, etc) or all of them at once via the .lb-portal class name.

Overrides

Overrides can be used to customize components’ strings and localization-related properties, such as locale and reading direction.

They can be set globally for all components using LiveblocksUiConfig:

Overrides can also be set per-component, and these settings will take precedence over global settings. This is particularly useful in certain contexts, for example when you’re using a <Composer /> component for creating replies to threads:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4