Skip to content

Commit 16008a6

Browse files
committed
fix: made some changes to fix custom elements not being sized correctly
BREAKING CHANGE: Classnames and styles are now injected by default when using WebChatCustomElement.
1 parent 182d185 commit 16008a6

File tree

5 files changed

+4550
-19517
lines changed

5 files changed

+4550
-19517
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Set up Node and Build for Deploy
3030
uses: actions/setup-node@v3
3131
with:
32-
node-version: 16
32+
node-version: 20
3333
- name: Install Dependencies
3434
run: yarn install --immutable
3535
- name: Build

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ function renderUserDefinedResponse(event) {
131131

132132
## WebChatCustomElement
133133

134-
This library provides the component `WebChatCustomElement` which can be used to aid in render web chat inside a custom element. This is needed if you want to be able to change the location where web chat is rendered. This component will render an element in your React app and use that element as the custom element for rendering web chat. It will also the `WebChatContainer` component to manage the life cycle of web chat so you will use `WebChatCustomElement`.
134+
This library provides the component `WebChatCustomElement` which can be used to aid in rendering web chat inside a custom element. This is needed if you want to be able to change the location where web chat is rendered. This component will render an element in your React app and use that element as the custom element for rendering web chat.
135135

136-
If you use this component, you will need to provide some CSS styles to control how the transition occurs between web chat showing and hiding. By default, the component will simply add a `HideWebChat` class to the web chat main window when it is closed. All you need to do is provide a `#WACContainer.WACContainer .HideWebChat { display: none }` rule in your CSS. You can also override the view change code is you need more fine-grained control over the style changes that occur. This would be useful if you wanted to animate the transitions.
136+
The default behavior of this component will add and remove a classname from the web chat main window as well as your custom element to control the visibility of web chat when it is opened or closed. It will also inject a `style` tag into your application to define the rules for these classnames. When web chat is closed, a classname will be added to the web chat main window to hide the element and a classname will be added to your custom element to set its width and height to 0 so it doesn't take up space. Note that the custom element should remain visible if you want to use the built-in web chat launcher which is also contained in your custom element. If you don't want these behaviors, then provide your own `onViewChange` prop to `WebChatCustomElement` and provide your own logic for controlling the visibility of web chat. If you want custom animations when web chat is opened and closed, this would be the mechanism to do that.
137137

138138
The simplest example is this:
139139

@@ -158,10 +158,6 @@ function App() {
158158
width: 500px;
159159
height: 500px;
160160
}
161-
162-
#WACContainer.WACContainer .HideWebChat {
163-
display: none;
164-
}
165161
```
166162

167163
## API
@@ -190,7 +186,7 @@ Note that this component will call the [web chat render](https://web-chat.global
190186
|-----------|---------|-------------|
191187
| className | string | An optional classname that will be added to the custom element. |
192188
| id | string | An optional id that will be added to the custom element. |
193-
| onViewChange | function | An optional listener for "view:change" events. Such a listener is required when using a custom element in order to control the visibility of the web chat main window. If no callback is provided here, a default one will be used that just adds the classname "HideWebChat" when the main window is closed and removes it when the main window is opened. If you use the default, you will also need to add a "#WACContainer.WACContainer .HideWebChat { display: none }" rule to your CSS. You can provide a different callback here if you want custom behavior such as an animation when the main window is opened or closed. Note that this function can only be provided before web chat is loaded. After web chat is loaded, the event handler will not be updated. See the web chat [view:change documentation](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-events#view:change) for more information. Also see the [tutorial for using animiations with custom elements](https://github.com/watson-developer-cloud/assistant-toolkit/tree/master/integrations/webchat/examples/custom-element/client/javascript-animation) for an example of what can be done here. |
189+
| onViewChange | function | An optional listener for "view:change" events. Such a listener is required when using a custom element in order to control the visibility of the web chat main window. If no callback is provided here, a default one will be used that uses some classnames to control web chat and your custom element. You can provide a different callback here if you want custom behavior such as an animation when the main window is opened or closed. Note that this function can only be provided before web chat is loaded. After web chat is loaded, the event handler will not be updated. See the web chat [view:change documentation](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-events#view:change) for more information. Also see the [tutorial for using animiations with custom elements](https://github.com/watson-developer-cloud/assistant-toolkit/tree/master/integrations/webchat/examples/custom-element/client/javascript-animation) for an example of what can be done here. |
194190

195191
### Debugging
196192

0 commit comments

Comments
 (0)