Customization Provider
The Customization Provider provides functionality to change token values and the style of Paste components.
The CustomizationProvider
provides a central place for customizations to be applied to an application that is using Paste.
Say you want to build a web application or website using Paste, but want to have your own look and feel—the CustomizationProvider
exists to do just that.
If you’re a Flex customer, and want to build a Flex plugin that follows your brand guidelines, the CustomizationProvider
can be used for that as well.
Similar to the Paste ThemeProvider, the CustomizationProvider
uses React Context to provide a theme object to any descendant components in the tree.
The CustomizationProvider
currently differs in two ways:
- Firstly, you set a
baseTheme
. The base theme tells the provider which Paste theme you would like to base your custom theme on. You can choose from the 'default' or 'dark' Theme. - Secondly, you set a
theme
, but unlike with the<Theme.Provider />
you pass it an object.
Selecting a base theme allows you to choose which Paste theme you would like to build on top of. By default we select the default theme for you, but if you would like to create a custom application using a dark theme, you can choose the dark baseTheme as your starting point.
import {CustomizationProvider} from '@twilio-paste/core/customization';
const MyApp = () => (
<CustomizationProvider baseTheme="dark">
rest of app
</CustomizationProvider>
)
For the theme
prop you can pass a complete theme object or a partial theme object for smaller customizations. If a partial theme object is passed, the CustomizationProvider
merges the custom theme object with the base Paste theme you chose. For example, if you want to customize certain background color tokens of the Dark theme you would only need to pass the following:
import {CustomizationProvider} from '@twilio-paste/core/customization';
const MyApp = () => (
<CustomizationProvider baseTheme="dark" theme={{
"backgroundColors": {
"colorBackgroundPrimary": "rgb(80, 123, 30)",
"colorBackgroundPrimaryStronger": "rgb(56, 86, 21)",
"colorBackgroundPrimaryWeaker": "rgb(154,199,232)",
"colorBackgroundPrimaryWeakest": "rgb(197, 223, 242)",
}
}}>
rest of app
</CustomizationProvider>
)
This will output the Paste theme of your choice with the custom background color tokens above. So any component using colorBackgroundPrimary
, colorBackgroundPrimaryStronger
, etc will use the custom background color token values instead of the background color token values provided by the base theme.
The theme object should follow the following format, where each theme key can take any valid design token for that grouping:
Object {
"backgroundColors": Object {},
"borderColors": Object {},
"borderWidths": Object {},
"breakpoints": Object {},
"colorSchemes": Object {},
"dataVisualization": Object {},
"fontSizes": Object {},
"fontWeights": Object {},
"fonts": Object {},
"heights": Object {},
"iconSizes": Object {},
"lineHeights": Object {},
"maxHeights": Object {},
"maxWidths": Object {},
"minHeights": Object {},
"minWidths": Object {},
"radii": Object {},
"shadows": Object {},
"sizes": Object {},
"space": Object {},
"textColors": Object {},
"widths": Object {},
"zIndices": Object {},
}
Custom themes can also be stored in their own files and imported as a json object. As long as the imported custom theme follows the format of the Paste theme object, you can pass it directly to the theme prop.
The CustomizationProvider
should wrap the root of your application, or a part of the application you would like to theme.
import {CustomizationProvider} from '@twilio-paste/core/customization';
import CustomTheme from './themes/theme.json';
const MyApp = () => (
<CustomizationProvider baseTheme="default" theme={CustomTheme}>
rest of app
</CustomizationProvider>
);
You can set a collection of Component Elements that you want to customize at the Customization Provider level. A Component Element is a DOM node within a component that you can target by name and provide custom CSS for. There maybe one or more exposed Component Elements for any given component within Paste. Component Elements can also be created for your own custom components for your customers to customize.
To read about how to customize components, head to the Customizating Components page.
import {CustomizationProvider} from '@twilio-paste/core/customization';
const MyApp = () => (
<CustomizationProvider baseTheme="dark" elements={{
CARD: {
backgroundColor: 'colorBackground',
borderRadius: 'borderRadius30',
borderWidth: 'borderWidth20'
}
}}>
rest of app
</CustomizationProvider>
)
yarn add @twilio-paste/customization - or - yarn add @twilio-paste/core
import {CustomizationProvider} from '@twilio-paste/core/customization';
import CustomTheme from ''./themes/theme.json';
const MyApp = () => (
<CustomizationProvider baseTheme="default" theme={CustomTheme}>
rest of app
</CustomizationProvider>
)
baseTheme?: 'default' (default) | 'dark'
Choose the base theme you would like your application to extend from
customBreakpoints?: string[]
Provide an array of breakpoint sizes that you would like to be able to use in responsive layouts, using the responsive style props
disableAnimation?: boolean
Manually disable all animations in the components using the animation library useful for testing components such as performing visual regression testing
elements?: {[key: string]: PasteCustomCSS}
Supply the Customization Provider an object of Elements that you would like to customize the CSS of. Use the element name provided by Paste as a key and provide any Valid CSS in the Emotion CSS Object format
theme?: Partial<GenericThemeShape>
Provide a full or partial Paste theme to be merged into the base theme that you provide
Changelog
d9f96d7d8
#3739 Thanks @TheSisb! - [ThemeProvider, CustomizationProvider] Now accepts an optionalstyle
prop to override element styles.This is helpful in scenarios where ThemeProvider isn't wrapping your app root, but instead is nested in your DOM tree and needs some styling overrides.
949df9e5e
#3612 Thanks @nkrantz! - [Customization] Minor change to customization tests to reflect updated prop change from 'variant' to 'variants' on CustomizationProvider.
b8d79200b
#3442 Thanks @TheSisb! - Removed all run-time prop-type checkingfrom Paste components. Paste now ships with only TypeScript types.ACTION NEEDED: None. This should be 100% backwards compatible.
733709127
#3395 Thanks @SiTaggart! - Modified the compile target of our JavaScript bundles fromnode
tobrowser
to minimize the risk of clashing with RequireJS. This is marked as a major out of an abundance of caution. You shouldn't need to do anything but we wanted you to be aware of the change on the off chance it has unintended consequences
- Updated dependencies [
733709127
]:- @twilio-paste/color-contrast-utils@5.0.0
- @twilio-paste/design-tokens@10.0.0
- @twilio-paste/animation-library@2.0.0
- @twilio-paste/styling-library@3.0.0
- @twilio-paste/style-props@9.0.0
- @twilio-paste/theme@11.0.0
- @twilio-paste/types@6.0.0
3ab2bb6f4
#3114 Thanks @SiTaggart! - ### Breaking changeWe have moved
@types/react
and@types/react-dom
to peer dependencies of the library. This should allow for greater control and backwards compatibility with older versions of React as Paste is no longer bundling the type libraries.Your application likely has both of these as dependencies anyway, but it is now up to you to manage that version number.
Action needed
Ensure
@types/react
and@types/react-dom
are installed as dependencies of your application.
- Updated dependencies [
bce889344
,3ab2bb6f4
]:- @twilio-paste/theme@10.0.0
- @twilio-paste/style-props@8.0.0
- @twilio-paste/types@5.0.0
d97098846
#3020 Thanks @SiTaggart! - This major version included listing all the missing peer dependencies for each Paste package.If you are using a package from Paste in isolation from Core, when upgrading to this latest version, be sure to correctly install all the missing peer dependencies.
- Updated dependencies [
dbd9bf992
,3c89fd83d
,d97098846
,0acdf3486
,ef094db4a
,0acdf3486
]:- @twilio-paste/design-tokens@9.0.0
- @twilio-paste/animation-library@1.0.0
- @twilio-paste/styling-library@2.0.0
- @twilio-paste/style-props@7.0.0
- @twilio-paste/theme@9.0.0
- @twilio-paste/types@4.0.0
- @twilio-paste/color-contrast-utils@4.0.0
a4c9e70b0
#2763 Thanks @shleewhite! - Update ESLint rules, which changed some formatting.
- Updated dependencies [
12c4ba22a
,364083627
,364083627
,364083627
,364083627
]:- @twilio-paste/style-props@6.0.0
- @twilio-paste/design-tokens@8.0.0
- @twilio-paste/theme@8.0.0
ae9dd50f
#2466 Thanks @TheSisb! - [All packages] Update our ESBuild version and remove minification of identifiers in our production builds.
9983b52e9
#2419 Thanks @gloriliale! - [Combobox, Data grid, Color contrast utils, Customization, Design tokens, Icons, Style props, Token contrast checker, Types, Utils, Website] Consolidate and update lodash dependencies and the way lodash is imported in our files, per lodash's guidance. Details: https://lodash.com/per-method-packages
- Updated dependencies [
09762f0f1
,09762f0f1
]:- @twilio-paste/styling-library@1.0.0
- @twilio-paste/theme@7.0.0
- @twilio-paste/style-props@5.0.0
91d20b99
#2328 Thanks @TheSisb! - [Theme & Customization] Fix an issue where animations would run once regardless of if animations should be disabled.
73c596919
#2269 Thanks @SiTaggart! - Fixed a regression with the compilation script that caused incompatible ESM module importing of JSON files.
c867e3f48
#2237 Thanks @SiTaggart! - Updated a build dependency (esbuild) which changes the output of our builds slightly, without materially changing anything about the code.
- Updated dependencies [
0a52eeee
,0a52eeee
,04de0d1d
,04de0d1d
,04de0d1d
]:- @twilio-paste/design-tokens@7.0.0
- @twilio-paste/theme@6.0.0
- @twilio-paste/style-props@4.0.0
8bedb9fd
#2021 Thanks @TheSisb! - [Theme and Customization] Slight tweak to prevent animations from running once on app load when they should be disabled from the beginning.
b7675915
#1985 Thanks @TheSisb! - For debugging purposes we now ship afilename.debug.js
unminified version of each component or library in Paste.
ed5c0a49c
#1965 Thanks @shleewhite! - Upgrade Paste to use React 17 by default, but maintain React 16 support for consumers.
66285238
#1599 Thanks @SiTaggart! - Switch lodash.merge with deepmerge for significant bundle size savings
f2594fca
#1599 Thanks @SiTaggart! - [Customization] minor change to the elements prop type to change thevariant
to thevariants
key to more closely match styled system. Also correct the elements type to use a string key for the element names
72cdd336
#1599 Thanks @SiTaggart! - Ensure that the elements object cannot have duplicate element names, even across different casings of the names
5b26f9bf
#1509 Thanks @SiTaggart! - [customization]: add ability for customization provider to accept an elements prop which it then merges into the styled theme context.Also add the ability to choose which base theme is used when customizing a theme, for use in programmable apps. You can choose from Default or Dark theme as your starting point.
0eded1fd
#1319 Thanks @SiTaggart! - Change internal dependencies to have minor range matching on version numbers
- Updated dependencies [
514bd5aa
]:- @twilio-paste/theme@5.0.1
- Updated dependencies [
4c9ed5ca
,26c828d8
]:- @twilio-paste/design-tokens@6.6.0
- @twilio-paste/theme@5.0.0
- Updated dependencies [
944c3407
]:- @twilio-paste/design-tokens@6.5.2
- @twilio-paste/theme@4.3.1
- Updated dependencies [
f1675586
]:- @twilio-paste/theme@4.3.0
a12acb61
#1158 Thanks @richbachman! - Pinned all twilio-paste package versions in order to keep them in sync with core when they are updated by changesets.Updated dependencies [
a12acb61
]:- @twilio-paste/theme@4.2.2
All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
0.2.1 (2021-01-25)
Note: Version bump only for package @twilio-paste/customization
0.1.4 (2021-01-15)
Note: Version bump only for package @twilio-paste/customization
0.1.3 (2021-01-07)
Note: Version bump only for package @twilio-paste/customization
0.1.2 (2020-12-17)
Note: Version bump only for package @twilio-paste/customization
0.1.1 (2020-12-11)
- customization: add public access for npm publish (dc8912a)
- customization: switch typings for generic theme to theme package (3a91b24)
- customization: add customization provider (2b1e6da)