Ant Design look
An Ant Design-style admin page, built from nxds parts with your own colors.
The first page is built with nxds parts. The second is the same page built with Ant Design, to compare.
Set your own colors
Create the colors file:
Replace its values with Ant Design's palette:
The nav-* colors belong to the Sidebar alone, so the sider is navy while the
page is light.
The
full palette
has every color for light and dark. It sets them on a wrapper, so they reach
only the preview on this page. Your app sets them on :root and .dark.
Your own colors covers the colors file.
Set Ant's corners
Ant rounds a control by 6px and a container by 8px. No corners value gives
6px, so redefine subtle in the colors file:
These corners apply at the Default UI scale.
Set Ant's line height
Ant sets 14px text on a 22px line, and 12px text on a 20px line. Set the two line heights in the colors file:
The text size setting then stops changing these two line heights.
Add the parts
Each part needs a different amount of work:
| Part | Change |
|---|---|
| Sidebar, Button, Badge, Label | Ant's sizes, as classes where you use them |
| DescriptionList | A bordered grid, two pairs to a row, and filled label cells |
| Accordion | One bordered box, tinted headers, the arrow before the label |
| Slider | A new class recipe: a thin rail and a round handle |
Use the stock parts
Four Ant parts are the stock nxds parts in Ant's colors. Pass Ant's sizes as classes where you use them:
| Ant Design part | nxds part | Classes |
|---|---|---|
| Dark Menu in a Sider | Sidebar, which reads the nav-* colors | nx:h-10 nx:rounded-lg nx:px-6 on each SidebarMenuButton |
| Primary Button, 32px | <Button size="sm"> | nx:px-[15px] nx:font-normal |
| Tag | <Badge fill="outline"> | nx:min-h-[22px] nx:rounded-sm nx:px-[7px] nx:typography-body-small nx:normal-case |
| Form label | Label | nx:font-normal |
Edit the DescriptionList
Ant's bordered Descriptions is a grid with filled label cells, two pairs to a row. Change the DescriptionList's classes, and add a wrapper:
| Ant Design needs | Change |
|---|---|
| A bordered grid | A wrapper with the border and corners, and two lines on each cell |
| Two pairs to a row | A four-column grid on the list, once the wrapper is 28rem wide |
| Filled label cells | nx:bg-muted on the term |
| Padded cells | nx:px-6 nx:py-4 on the term and the description |
A narrow list stacks each label over its value, as the stock part does.
Edit the Accordion
Ant's Collapse is one bordered box, with the arrow before each label. Change the Accordion's classes, and move its icon:
| Ant Design needs | Change |
|---|---|
| One bordered box | A border and corners on the root |
| Tinted headers | nx:bg-muted on each item |
| The arrow before the label | IconChevronRight ahead of the label, turning by 90° |
| Plain content under a divider | nx:bg-container and a top border on the content |
Rewrite the Slider
Ant's Slider is a thin rail with a round handle. Replace the Slider's class recipes, and remove the code that rounds the range at each end of the rail. The props and behavior stay as they are:
| Ant Design needs | Change in the recipe |
|---|---|
| A thin rail | A 4px rail with 2px corners and no border |
| A light track that darkens on hover | nx:bg-primary-border, then nx:bg-primary-border-active |
| A round handle with a ring | A 10px dot with nx:ring-2, and nx:ring-4 on hover and focus |
| The same handle in both directions | sliderThumbVariants as one string, with no orientation |
| Ringed marks | 8px dots with a border |
Use the parts
What nxds provides
| From nxds | In this example |
|---|---|
| Light and dark mode | The provider switches .dark, and the colors file has a value for each |
| Density | Every part sizes itself from nxds spacing tokens |
| Color names | Every class reads an nxds color, so one file recolors every part |
| Behavior | Accordion and Slider keep their keyboard and screen reader support |
The nxds page in the preview follows the page's mode and density. Its colors and corners come from the palette file, so the theme picker doesn't change them. The Ant Design page follows the page's mode only.
Next steps
- Material look: a settings screen with a rewritten Switch and a new TextField.
- Your own colors: the colors file, and what keeps working.
- Sidebar: the stock Sidebar and its parts.