1.3.2 • Published 3 years ago

@statflo/textkit-widget-sdk-react v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

TextKit by Statflo

TextKit Widget React SDK

Installation

yarn add @statflo/textkit-widget-sdk-react

TextKit Provider

Begin by importing the provider into your App.tsx file

import { TextKitWidgetProvider } from "@statflo/textkit-widget-sdk-react";
import Widget from "./Widget";

export default function App() {
  return (
    <TextKitWidgetProvider header="My header" footer="My footer">
      <Widget />
    </TextKitWidgetProvider>
  )
}

Available properties

PropertyTypeDefaultDescription
headerstringundefinedInitial header value. Recommended for Standard Widgets.
footerstringundefinedInitial footer value. Recommended for Standard Widgets.
labelstringundefinedRequired for Action widgets that use the Conversation Scope.
scrollOverridebooleanfalseOverride the default scroll implmentation so you can create and manage your own.

TextKit hook

The following hook will give you access to the current widget state along with helpers for performing various functions. When importing this hook ensure it's within a child component of the above Provider.

import { useTextKitWidget } from "@statflo/textkit-widget-sdk-react";

export default function Widget() {
  const { state, setHeader, setFooter } = useTextKitWidget();

  const handleUpdateHeader = () => {
    setHeader("My new header");
  };

  const handleUpdateFooter = () => {
    setFooter("My new footer");
  };

  return (
    <div>
      <p>My Widget Content</p>
      <button onClick={handleUpdateHeader}>Update Header</button>
      <button onClick={handleUpdateFooter}>Update Footer</button>
    </div>
  );
}

Available Properties/Methods

PropertyTypePropertyDescription
stateobjectCurrent widget state please review below for all the available properties.
setFooterfunctionstringUpdate the widget footer. Used for Standard Widgets.
setHeaderfunctionstringUpdate the widget header. Used for Standard Widgets.
setLabelfunctionstringUpdate the widget label. Used for Action Widgets using the Conversation Scope.
setOpenfunctionbooleanOpen or close the widget.
setSizefunctionWidgetViewSizeChange the size of the widget. Used for Standard Widgets. Must be an instance of WidgetViewSize which can be imported. See below.
appendMessagefunctionstringThe text/string you want to append to the message input. Used for Sendable Widets.
replaceMessagefunctionstringThe text/string you want to replace to the message input with. Used for Sendable Widets.
clientwidgetClientAccess to the underlying widget class for low level implementations. Read the Widget SDK Readme for more details.

State Properties

When importing state from useTextKitWidget() these are the available properties.

PropertyTypeDescription
contextobjectWill return the current conversation context.
defaultScrollbooleanWhether you are using the default scrolling functionality or not. Default scrolling will be based on the length of the body and the state of the widget.
isOpenbooleanWhether the widget is opened or not. Used in Standard widgets.
isReadybooleanThe state of the widget. This will be true when TextKit is aware the widget has been registered.
isShownbooleanWhether the widget is shown or not. Used in Sendables and Action widgets.
maxHeightnumberWill return the available maximum height based on the resolution. Great for when creating your own scrolling capabilities.
sizeWidgetViewSizeWill contain one of the enum values from WidgetViewSize. This is for Standard Widgets only.

Widget View Size

import { WidgetViewSize } from "@statflo/textkit-widget-sdk-react";

/**
 * Example function
 * 
 * Available enums
 * 
 * WidgetViewSize.Small
 * WidgetViewSize.Medium
 * WidgetViewSize.Large
 */
setSize(WidgetViewSize.Medium);

Medium & Large Content Wrappers

These helper components listen for the size state changes and will display the correct content based on the current state value.

Example

import { MediumContent, LargeContent } from "@statflo/textkit-widget-sdk-react";

export default function Widget() {
  return (
    <div>
      <MediumContent>
        This content will be visible when Standard widgets are in their default view state. WidgetViewState.Medium.
      </MediumContent>
      <LargeContent>
        This content will be visible when Standard widgets are in their default view state. WidgetViewState.Large.
      </LargeContent>
    </div>
  )
}
1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago