Modifying the countdown block to have configurable styles
Introduction
Now that we have implemented the countdown, how about adding a little customization? In this step, you will learn basic concepts about CSS handles and Tachyons to customize the style of your app.
CSS Handles
CSS handles are used to customize your store's components through CSS classes in the theme code. All settings are defined through the appvtex.css-handles, responsible for declaring all the customization points of your block.
By defining the names of your handles and adding them to their respective HTML elements, it is possible to give the theme's user customization points that allow them to create flexible layouts.
Tachyons
Tachyons is a framework for functional CSS. Unlike other known frameworks, like Bootstrap, it does not have "pre-built" UI components. In fact, its purpose is, precisely, separate the CSS rules into small, reusable parts. This type of strategy is commonly known as Subatomic Design System and, if you are interested, you can find a reference in this link. This strategy makes frameworks like Tachyons very flexible, scalable and fast.
A lot of the Tachyons' definitions can be changed, so that your store will have a more customized style. To do this, just define a JSON file in the styles / configs folder; this information can be found in more detail at: Build a store using VTEX IO - Customizing styles.
Activity
Import the useCssHandleshook. To do so, return to Countdown.tsx and do the import:
// react/Countdown.tsx
import { useCssHandles } from "vtex.css-handles"
Besides, define in a Array all necessary handles (in this case, only 'countdown' will be used):
At last, it is needed to use the handle in the component to see the customization. For this, use the prop className with the classes to be used and the Tachyons classes, for global styles.
Modifying the countdown block to have configurable styles
Introduction
Now that we have implemented the
countdown
, how about adding a little customization? In this step, you will learn basic concepts about CSS handles and Tachyons to customize the style of your app.CSS Handles
CSS handles are used to customize your store's components through CSS classes in the theme code. All settings are defined through the app
vtex.css-handles
, responsible for declaring all the customization points of your block.By defining the names of your handles and adding them to their respective HTML elements, it is possible to give the theme's user customization points that allow them to create flexible layouts.
Tachyons
Tachyons is a framework for functional CSS. Unlike other known frameworks, like Bootstrap, it does not have "pre-built" UI components. In fact, its purpose is, precisely, separate the CSS rules into small, reusable parts. This type of strategy is commonly known as Subatomic Design System and, if you are interested, you can find a reference in this link. This strategy makes frameworks like Tachyons very flexible, scalable and fast.
A lot of the Tachyons' definitions can be changed, so that your store will have a more customized style. To do this, just define a JSON file in the
styles / configs
folder; this information can be found in more detail at: Build a store using VTEX IO - Customizing styles.Activity
Import the
useCssHandles
hook. To do so, return toCountdown.tsx
and do the import:Besides, define in a Array all necessary handles (in this case, only
'countdown'
will be used):Use the
useCssHandles
in the componentCountdown
to define thecountdown
handle:At last, it is needed to use the handle in the component to see the customization. For this, use the prop
className
with the classes to be used and the Tachyons classes, for global styles.Let's see the result?