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 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.
Paste design tokens can be referenced as is from within the props of any Paste components.
1import { Text } from "@twilio-paste/core/text";234Flex.MainHeader.Content.add(<Text as="p" color="colorTextBrandHighlight" key="some-text">Hello</Text>, {5sortOrder: -1,6align: "end"7});8
For more information, please refer to Twilio Paste Tokens.
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.
In order to use Twilio Paste inside your plugin, please use Flex.setProviders() 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.
1import { CustomizationProvider } from "@twilio-paste/core/customization";2import { Button as PasteButton } from "@twilio-paste/core/button";34Flex.setProviders({5PasteThemeProvider: CustomizationProvider6});78Flex.AgentDesktopView.Panel1.Content.add(9<div key="A">10<PasteButton key="A" variant="primary">11Paste Button12</PasteButton>13</div>14);
To override Paste components styling using Paste's elements
, you can use Flex.setProviders() 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 for more details.
You can only replace the elements
property in the following code examples. baseTheme
, theme
, and style
need to be included as provided.
1import { CustomizationProvider } from "@twilio-paste/core/customization";23Flex.setProviders({4CustomProvider: (RootComponent) => (props) => {5const pasteProviderProps = {6baseTheme: props.theme?.isLight ? "default" : "dark",7theme: props.theme?.tokens,8style: { minWidth: "100%", height: "100%" },9elements: {10BUTTON: {11backgroundColor: "transparent"12}13}14};1516return (17<CustomizationProvider {...pasteProviderProps}>18<RootComponent {...props} />19</CustomizationProvider>20);21}22});