Comments (1)
Hello @syn6UK 👋
Please use provided issue templates and do not skip the proposed structure. They are defined for the purpose to point what information we need in order to properly take care of your request. Link for reference: Feature request.
Answering your question. The documentation for @livechat/widget-react
package directly explains how the LiveChatWidget
should be used inside React
application.
The main goal of the Chat Widget Adapters project is to provide a framework-aware implementation for using our Chat Widget without the need to directly access our JS API. But the JS API is an option that is always available to you if you wish to integrate the widget that way.
Being a framework-aware implementation each adapter integrates the Chat Widget with a framework-specific reactivity model and best practices. In the case of React, we expose the component LiveChatWidget
which accepts a set of props described in the documentation: README.md#props. Props are split into two categories: Configuration and Event handlers.
Using React's definition/approach to how the UI should be rendered it's most commonly represented as: The UI is a result of component function being called with passed properties. That way we should always render Chat Widget in the same state while the same properties are provided. All of the props available on LiveChatWidget
component are properly reactive and you can steer the behavior of the widget by simply changing their values, the same way as you do with many other React components.
An example implementation of controlled widget visibility comes down to the concept of Controlled Component documented directly on official React docs. Properties of LiveChatComponent
being used are also described in the project's documentation: visibility
, onVisibilityChanged
.
import * as React from 'react'
import { LiveChatWidget } from '@livechat/widget-react'
import type { WidgetState, EventHandlerPayload } from '@livechat/widget-react'
function App() {
const [visibility, setVisibility] = React.useState<WidgetState['visibility']>('minimized')
function handleSelectChange(event: React.ChangeEvent<HTMLSelectElement>) {
setVisibility(event.target.value as WidgetState['visibility'])
}
function handleVisibilityChanged({ visibility }: EventHandlerPayload<'onVisibilityChanged'>) {
setVisibility(visibility)
}
return (
<main>
<div>
<label htmlFor="visibility">Widget visibility: </label>
<select id="visibility" value={visibility} onChange={handleSelectChange}>
<option>minimized</option>
<option>maximized</option>
<option>hidden</option>
</select>
</div>
<LiveChatWidget license="12332502" visibility={visibility} onVisibilityChanged={handleVisibilityChanged} />
</main>
)
}
Here is a video showcasing the example:
chat-widget-adapters-controlled-visibility.mov
from chat-widget-adapters.
Related Issues (20)
- Optimize external scripts HOT 2
- Color Change on react js HOT 1
- Question: How to use with Custom Identity Provider? HOT 2
- Set LiveChat Customer Avatar HOT 1
- Angular v15 update HOT 4
- Angular v15 update HOT 2
- Add SvelteKit Support HOT 1
- Intermittent white bar on bottom on mobile devices HOT 1
- Angular Adaptor Event Handlers
- uniapp require is not defined.
- hook to open the chat from a button or event
- Update window types
- Support Angular 16 HOT 1
- Programmatically start chat HOT 2
- asyncInit incorportation
- visibility="minimized" do hide chat icon in mobile view. HOT 1
- Cannot read properties of null (reading 'useRef')
- Hooks for interacting with the widget
- How to get baseAPI when use customIdentityProvider
- Minimised hides the vue chat widget, if the support is offline. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chat-widget-adapters.