Component Customization
Understand how to customize a component as per your requirements
Each Cashfree.js
component is initialized with a configuration object that allows you to customize both its behavior and appearance. The configuration object helps you seamlessly integrate the component with your application’s design system.
Basic Usage
Configuration Options
Notes:
- All configuration options are optional. Components will use default styles if not specified.
- The style object supports most CSS properties in camelCase format.
- Custom fonts specified in the fonts array are loaded automatically before the component renders.
- Use the disabled option to temporarily prevent user interaction (e.g., during form submission).
- The loader option can be used to show/hide loading states while the component initializes
classes
Type: object
You can use classes
which is an object that will have names of classes. The classes you specify will be applied to DOM container where the component is mounted. You have to make sure that these are present in your application css .
Please note that you do not have to add the classes to your DOM container. The sdk will do it when required.
Default values
base
The string
you provide as a value of base will be applied to the container. This is the base class. If you do not provide a value of base, default value of cf-base-private
will be applied.
Your css file
Your HTML
In this case a padding of 5px
will be added to your container once a component is mounted
complete
A complete class will be applied to the container when the component you have mounted has been completed by the customer. This is relevant for example in card number input box when the user has entered a valid card number you would want to make the border of your container green. Default is cf-complete-private
.
Please note that not all components will have apply a complete class to your container.
Example
Your js file
Your css file
Combining example of base
and complete
you can figure out that when the component is complete it will have two classes so css of both of the classes wil be applied which are
empty
An empty class will be applied to the container when the component being mounted is empty. Example would be card number not yet entered by the user means that the card number component will be empty and the empty class that you have specified will be applied. Default is cf-empty-private
Example
Your js file
Your css file
When empty a box-shadow
will appear in your container
focus
This will be applied to your container when the element inside is focussed. Example would be user has focussed on the card number input area. Default is cf-focus-private
Example
Your js file
Your css file
When focussed the container will move up by 5px
invalid
This will be applied when the component inside is invalid. For example the user has entered a wrong card number. Default is cf-invalid-private
Example
Your js file
Your css file
When invalid the container will have a red
border
disabled
This will be applied when you want the component inside the container to be disabled. Default is cf-disabled-private
Example
Your js file
Your css file
When disabled your container will be dimmer
fonts
Type: array
Using fonts you can make sure that the text inside component has the same font as your web application.
Default value
There are two ways to specify fonts
- Using a absolute URL to a css file with @font-face definitions.F or example:
https://fonts.googleapis.com/css?family=Open+Sans
Example
- Using a absolute URL for a font file along with other parameters
Example
Required: src
and fontFamily
You can specify multiple fonts and choose which to use in the component
style
Type: object
The style
object is used to apply css properties to the contents of the component. It is different from classes
in the fact that classes
are used to apply css to the container that contains the component. There are 4 variants base
, complete
, empty
and invalid
.
You are free to add any css property by converting the propery type to camelCase and having the proerty value as string. Example being fontSize: '16px'
for font-size: 16px
Default values
The following pseudo-classes and pseudo-elements can also be styled using a nested object inside of a variant:
:hover
:focus
:dsiabled
::placeholder
Example
values
Type: object
The values property is used to initialize a component with a particular starting state. The keys of the values object changes according to the component type.
Default value
Examples
Component Name: cardHolder
Component Name: upiCollect
Visit sections under different components to get all the available keys
disabled
Type: bool
You can use this to specify if the component should be loaded in a disabled state. Please note that the classes.disabled
and style.base[":disabled"]
or style.empty[":disabled"]
will be applied to the container and compoent respectively
Default value
loader
Type: bool
Display skeleton loader UI while waiting for Elements to be fully loaded, after they are mounted. Not all components might support loader
Default value
Was this page helpful?