Section 1
Getting started
We will create another frontend repository with Next.js and Chakra UI in today's story. I read a post a few days ago about Chakra UI being the best UI library and I do have written an article for the Perfect UI library in React. So it seems to me that there’s a clash, and to decide which one is better I deep dive into both.
Section 2
Installing
The installation process is not very heavy. You have to install the packages or modules, import them to the root of the application, wrap the provider with the root of the application and we are done.
yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4Tailwind CSS’ theming style inspires Chakra UI. It supports all the basic colours with their grades.
The next step is to wrap the provider to the application's root.
import * as React from "react";
import { ChakraProvider } from "@chakra-ui/react";
function App({ Component, pageProps }) {
return (
<ChakraProvider>
<Component {...pageProps} />
</ChakraProvider>
);
};In the _app.js file inside pages, the directory adds the above code. We are simply wrapping the Chakra provider with our App component to pass down the theme and CSS to our application.
Once this is done, we are ready to use the component of Chakra UI.
Section 3
Takeaway
I have used Material-UI, Ant Design, React Bootstrap, Tailwind CSS etc.
To develop this simple blog page, I don't have to spend so much time on the pre-built components which makes development pretty easy.
But a few things I always look at on the website are —
How easy is it to extend and how responsive is the website?
For me, Tailwind CSS provides an easy-to-develop responsive interface but inline CSS is still not highly appreciated in the professional domain.
Colours and Shades
In addition, Chakra UI has one good thing — it supports all the basic colours and shades within every component. This is something I loved the most. The second thing is their features section like RTL, sx props, layout styles, and so on. Also, Chakra UI provides export breakpoints from theme-tools which helps to define your breakpoints.
<Text fontSize={{ base: "24px", md: "40px", lg: "56px" }}>
This is responsive text
</Text>
In this case, we provide the same inline CSS to handle responsiveness. This is also a good and easy way, just like Tailwind CSS.
Hooks
They provide multiple hooks like useBoolean, useClipboard, useMediaQuery, useTheme, and so on. These hooks help to handle specific cases like responsive hamburger, scroll to the view property, although much of the UI libraries do provide these kinds of hooks.
https://chakra-ui.com/docs/hooks/use-boolean
CSS Variables
https://chakra-ui.com/docs/features/css-variables
This is something new for me. You can declare the variables in inline CSS in any component and use them within the component.
<Box sx={{ "--my-color": "#53c8c4" }}>
<Heading color="var(--my-color)" size="lg">
This uses CSS Custom Properties!
</Heading>
</Box>That's it for today
See you in the next one
Shrey
