Skip to content

Commit

Permalink
feat: add enableWidgetExpandButton option (#334)
Browse files Browse the repository at this point in the history
## Changes
- Add `enableWidgetExpandButton` option
  • Loading branch information
bang9 authored Aug 13, 2024
1 parent 4e1b8d3 commit 2203b5e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default App;
| `messageInputControls.blockWhileBotResponding` | `boolean \| number` | No | N/A | Allows to control enabled/disabled state of the message input for waiting for the bot's reply mesage. If number value is given, a timer will be set to force unblock the message input. |
| `dateLocale` | `Locale` | No | `enUS` | Locale value to be applied to string values of message timestamp and date separator. Locale values must be imported from `date-fns`. |
| `enableHideWidgetForDeactivatedUser` | `boolean` | No | `false` | Determines whether the chatbot widget is hidden when the user is deactivated. |
| `enableWidgetExpandButton` | `boolean` | No | `false` | Determines whether the expand button is displayed in the chatbot widget. |

## For internal contributors
- [Release guide](./release-guide.md)
5 changes: 3 additions & 2 deletions src/components/CustomChannelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ interface Props {
channelName?: string;
}
export default function CustomChannelHeader({ botProfileUrl, botNickname, channelName, onRenewButtonClick }: Props) {
const { betaMark, customBetaMarkText, customRefreshComponent, isMobileView, callbacks } = useConstantState();
const { betaMark, customBetaMarkText, customRefreshComponent, isMobileView, enableWidgetExpandButton } =
useConstantState();
const { setIsOpen } = useWidgetState();

async function handleRenewButtonClick() {
Expand Down Expand Up @@ -110,7 +111,7 @@ export default function CustomChannelHeader({ botProfileUrl, botNickname, channe
right: isMobileView
? 0
: // to make the refresh icon appear next to the close icon in the widget window
callbacks?.onWidgetExpandStateChange
enableWidgetExpandButton
? RIGHT_WITH_EXPAND_BUTTON
: RIGHT_WITHOUT_EXPAND_BUTTON,
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/widget/WidgetWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import styled, { css } from 'styled-components';

import { WIDGET_WINDOW_Z_INDEX, elementIds } from '../../const';
import { elementIds, WIDGET_WINDOW_Z_INDEX } from '../../const';
import { useConstantState } from '../../context/ConstantContext';
import { useWidgetState } from '../../context/WidgetStateContext';
import CloseIcon from '../../icons/ic-widget-close.svg';
Expand Down Expand Up @@ -105,7 +105,7 @@ const StyledCloseButton = styled.button`
const WidgetWindow = ({ children }: { children: React.ReactNode }) => {
const { isVisible, isOpen, setIsOpen } = useWidgetState();
const [isExpanded, setIsExpanded] = useState(false);
const { callbacks } = useConstantState();
const { callbacks, enableWidgetExpandButton } = useConstantState();

const onExpandButtonToggle = () => {
setIsExpanded((prev) => {
Expand All @@ -117,7 +117,7 @@ const WidgetWindow = ({ children }: { children: React.ReactNode }) => {

return (
<StyledWidgetWindowWrapper isOpen={isOpen && isVisible} isExpanded={isExpanded} id={elementIds.widgetWindow}>
{callbacks?.onWidgetExpandStateChange && (
{enableWidgetExpandButton && (
<StyledExpandButton onClick={onExpandButtonToggle}>
{isExpanded ? <CollapseIcon id={elementIds.collapseIcon} /> : <ExpandIcon id={elementIds.expandIcon} />}
</StyledExpandButton>
Expand Down
6 changes: 6 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const DEFAULT_CONSTANT = {
enableEmojiFeedback: true,
enableMention: true,
enableResetHistoryOnConnect: false,
enableWidgetExpandButton: false,
dateLocale: enUS,
enableHideWidgetForDeactivatedUser: false,
messageInputControls: {
Expand Down Expand Up @@ -303,6 +304,11 @@ interface ConstantFeatureFlags {
* @description Hide widget for deactivated user.
* */
enableHideWidgetForDeactivatedUser: boolean;
/**
* @public
* @description Enable widget expand button.
* */
enableWidgetExpandButton: boolean;
}

export interface SuggestedReply {
Expand Down
1 change: 1 addition & 0 deletions src/context/ConstantContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const ConstantStateProvider = (props: PropsWithChildren<ConstantContextPr
enableResetHistoryOnConnect: props.enableResetHistoryOnConnect ?? initialState.enableResetHistoryOnConnect,
enableHideWidgetForDeactivatedUser:
props.enableHideWidgetForDeactivatedUser ?? initialState.enableHideWidgetForDeactivatedUser,
enableWidgetExpandButton: props.enableWidgetExpandButton ?? initialState.enableWidgetExpandButton,
// ----- Legacy props ----- //
betaMark: props.betaMark ?? initialState.betaMark,
customBetaMarkText: props.customBetaMarkText ?? initialState.customBetaMarkText,
Expand Down

0 comments on commit 2203b5e

Please sign in to comment.