Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Use Twilio Paste with a Flex Plugin


Not every component you build needs to start from scratch. Existing React component libraries can help you use components that have already been built with browser compatibility, responsive screen sizes, and accessibility in mind. Internally, the Flex UI leverages Twilio Paste(link takes you to an external page) for many of its components. You can similarly use Paste to create components that start with a similar style to Flex UI's existing layout.

Paste is already a dependency of flex-ui but if you choose to include it explicitly, ensure the plugin doesn't have multiple versions of Paste in its dependency tree.


Design tokens

design-tokens page anchor

Paste design tokens can be referenced as is from within the props of any Paste components.


_10
import { Text } from "@twilio-paste/core/text";
_10
_10
_10
Flex.MainHeader.Content.add(<Text as="p" color="colorTextBrandHighlight" key="some-text">Hello</Text>, {
_10
sortOrder: -1,
_10
align: "end"
_10
});

For more information, please refer to Twilio Paste Tokens(link takes you to an external page).

(information)

Info

Creating a custom theme following the official Paste docs may not work. To override default design tokens when using Paste, please see Theming Flex UI - Paste tokens.


Set up your plugin to use Paste

set-up-your-plugin-to-use-paste page anchor

In order to use Twilio Paste inside your plugin, please use Flex.setProviders()(link takes you to an external page) as follows which will wrap the Flex UI with the passed Paste theme provider. This will allow you to use Paste elements and design tokens within your plugin. Ensure this is done before declaring any components.


_14
import { CustomizationProvider } from "@twilio-paste/core/customization";
_14
import { Button as PasteButton } from "@twilio-paste/core/button";
_14
_14
Flex.setProviders({
_14
PasteThemeProvider: CustomizationProvider
_14
});
_14
_14
Flex.AgentDesktopView.Panel1.Content.add(
_14
<div key="A">
_14
<PasteButton key="A" variant="primary">
_14
Paste Button
_14
</PasteButton>
_14
</div>
_14
);


Customize Paste components using elements

customize-paste-components-using-elements page anchor

To override Paste components styling using Paste's elements, you can use Flex.setProviders()(link takes you to an external page) to wrap a custom Paste theme provider. In this, you can pass it an elements prop to customize specific components. Refer to Providing Component elements(link takes you to an external page) for more details.

(warning)

Warning

You can only replace the elements property in the following code examples. baseTheme, theme, and style need to be included as provided.

JavaScript exampleTypeScript example

_22
import { CustomizationProvider } from "@twilio-paste/core/customization";
_22
_22
Flex.setProviders({
_22
CustomProvider: (RootComponent) => (props) => {
_22
const pasteProviderProps = {
_22
baseTheme: props.theme?.isLight ? "default" : "dark",
_22
theme: props.theme?.tokens,
_22
style: { minWidth: "100%", height: "100%" },
_22
elements: {
_22
BUTTON: {
_22
backgroundColor: "transparent"
_22
}
_22
}
_22
};
_22
_22
return (
_22
<CustomizationProvider {...pasteProviderProps}>
_22
<RootComponent {...props} />
_22
</CustomizationProvider>
_22
);
_22
}
_22
});


Rate this page: