Home / Articles / Blog

Next JS with Ant Design
Next.jsReact.jsAnt DesignUI libraryFrontend

Next JS with Ant Design

Creating another boilerplate for the UI library

FrontendShrey Vijayvargiya

Under the Hood

We have covered in-depth stories for integrating the stories with Next JS and so on.

In today’s story, we will cover another UI library with Next JS or let say React called Ant Design.

Ant Design is still the most popular UI library with React. Many developers prefer them over Material UI React Bootstrap or Chakra UI.

I’ve already covered getting started with Material UI Chakra UI and Bootstrap whose link you can find at the end of the articles.

Getting Started

As usual, I will define the steps we will be doing to get started with Ant Design in Next JS.

  • Add ant design package yarn add antd
  • Add other ant design dependencies for next js like zeit/css, ziet/less and so on.
  • Add and design global less style files
  • Import and pass global styles to the root of the application to render CSS on the server-side.

That’s it, really in 4 steps, we are ready to use ant design in our next js project.

Adding antd and dependencies

If you using ant design with next js like in this article, then it's always good to add dependencies first and foremost to avoid making any development or compatibility or plugins error.

text
yarn add antd// Dependencies yarn add @zeit/next-css @zeit/next-less @zeit/next-sass babel-plugin-import less

Adding antd global CSS styling files

Remember, ant design works with less for styling its components and we need plugins to work with less in the Next JS. Also, we do need to import and pass the styles to the root of the application inside _app.js.

text
// antdstyles.less file
@import "~antd/dist/antd.less";
@primary-color: #000; // primary color for all components
@link-color: #1890ff; // link color
@success-color: #52c41a; // success state color
@warning-color: #faad14; // warning state color
@error-color: #f5222d; // error state color
@font-size-base: 14px; // major text font size
@heading-color: rgba(0, 0, 0, 0.85); // heading text color
@text-color: rgba(0, 0, 0, 0.65); // major text color
@text-color-secondary: rgba(0, 0, 0, 0.45); // secondary text color
@disabled-color: rgba(0, 0, 0, 0.25); // disable state color
@border-radius-base: 4px; // major border radius
@border-color-base: #d9d9d9; // major border color
@box-shadow-base: 0 2px 8px rgba(0, 0, 0, 0.15); // major shadow for layers

And now inside _app.js in the Next JS pages directory, add the following line at the top.

text
import '../utils/antDesignStyles.less';

Hence, our installation and getting started is completed with Ant Design and Next JS. In almost 4 steps we are again ready to use an entirely new different UI library with Next JS.

text
Click to Reach Code Repository

Conclusion

That’s it for today's people, I hope you like the story, don’t forget to follow me

Until next time, have a good day

Shrey

Explore topics

More in

Weekly letter

Subscribe to iHateReading

Our once-a-week newsletter on programming, jobs, AI, and building products online.

Our once a week newsletter on Programming, Jobs, AI, and Business