Skip to contentSkip to navigationSkip to topbar
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.

We recommend using the following versions of Paste Core and Icons, to match the versions used in Flex UI:

1
"@twilio-paste/core": "^15.3.1",
2
"@twilio-paste/icons": "^9.2.0",

If you need a Paste component added after v15, you can use other versions of Paste up to twilio-paste/core version ^18.0.0 and twilio-paste/icons version ^10.0.0. Make sure to follow instructions described here.


Design tokens

design-tokens page anchor

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

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

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.

1
import { CustomizationProvider } from "@twilio-paste/core/customization";
2
import { Button as PasteButton } from "@twilio-paste/core/button";
3
4
Flex.setProviders({
5
PasteThemeProvider: CustomizationProvider
6
});
7
8
Flex.AgentDesktopView.Panel1.Content.add(
9
<div key="A">
10
<PasteButton key="A" variant="primary">
11
Paste Button
12
</PasteButton>
13
</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
1
import { CustomizationProvider } from "@twilio-paste/core/customization";
2
3
Flex.setProviders({
4
CustomProvider: (RootComponent) => (props) => {
5
const pasteProviderProps = {
6
baseTheme: props.theme?.isLight ? "default" : "dark",
7
theme: props.theme?.tokens,
8
style: { minWidth: "100%", height: "100%" },
9
elements: {
10
BUTTON: {
11
backgroundColor: "transparent"
12
}
13
}
14
};
15
16
return (
17
<CustomizationProvider {...pasteProviderProps}>
18
<RootComponent {...props} />
19
</CustomizationProvider>
20
);
21
}
22
});

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.