npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@statflo/textkit-widget-sdk-react

v1.3.2

Published

React Widget SDK for TextKit

Downloads

19

Readme

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

| Property | Type | Default | Description | |--|--|--|--| | header | string | undefined | Initial header value. Recommended for Standard Widgets. | | footer | string | undefined | Initial footer value. Recommended for Standard Widgets. | | label | string | undefined | Required for Action widgets that use the Conversation Scope. | | scrollOverride | boolean | false | Override 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

| Property | Type | Property | Description | |--|--|--|--| | state | object | | Current widget state please review below for all the available properties. | | setFooter | function | string | Update the widget footer. Used for Standard Widgets. | | setHeader | function | string | Update the widget header. Used for Standard Widgets. | | setLabel | function | string | Update the widget label. Used for Action Widgets using the Conversation Scope.| | setOpen | function | boolean | Open or close the widget. | | setSize | function | WidgetViewSize | Change the size of the widget. Used for Standard Widgets. Must be an instance of WidgetViewSize which can be imported. See below. | | appendMessage | function | string | The text/string you want to append to the message input. Used for Sendable Widets. | | replaceMessage | function | string | The text/string you want to replace to the message input with. Used for Sendable Widets. | | client | widgetClient | | Access 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.

| Property | Type | Description | |--|--|--| | context | object | Will return the current conversation context. | | defaultScroll | boolean | Whether 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. | | isOpen | boolean | Whether the widget is opened or not. Used in Standard widgets. | | isReady | boolean | The state of the widget. This will be true when TextKit is aware the widget has been registered. | | isShown | boolean | Whether the widget is shown or not. Used in Sendables and Action widgets. | | maxHeight | number | Will return the available maximum height based on the resolution. Great for when creating your own scrolling capabilities. | | size | WidgetViewSize | Will 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>
  )
}