Development
Implementing themes
Use our Figma Plugin (recommended)
ShadcnUI Theme Pal generates CSS variables based on your Figma variables for your Shadcn UI projects. This plugin works exclusively with our UI kit and is tailored for projects using ShadcnUI.
- Open Shadcn UI Kit for Figma.
- Open the ShadcnUI Theme Pal plugin in the UI kit.
- Click "Generate CSS".
- Copy and paste into your Shadcn UI project's globals.css file.
Implement themes manually
Before implementing the theme, familiarize yourself with how theming works in shadcn/ui by reading their official documentation.
- In dev mode, navigate to the Plugins tab.
- Search for "Variables exporter for dev mode" in the search bar.
- Run the plugin and click the "Export Variables" button.
- Locate the '/ 2. Theme.Default.tokens.json /' section in your exported JSON.
- Update your project's CSS variables based on the exported data. Check for the color values in the TailwindCSS section if they are referenced. See the example below how ‘primary-light’ and ‘primary-light’ JSON variables were translated to the CSS variables. Make sure to convert the hex values into hsl values.
- For other theme settings like font family, update your CSS according to the JSON variables.
- To edit the styling of the components, check which components were marked as modified by designers.
- Adjust the styling of components in your code to match the designs in Figma.
JSON
/* 2. Theme.Default.tokens.json */
{
"colors": {
{ . . . }
"primary-light": {
"type": "color",
"value": "{tailwind colors.blue.600}"
},
"primary-dark": {
"type": "color",
"value": "{tailwind colors.blue.700}"
},
{ . . . }
},
CSS
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
--primary: 221 83% 53%;
--primary-foreground: 0 0% 98%;
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
--ring: 240 5.9% 10%;
--radius: 0.5rem;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
}
.dark {
--background: 240 10% 3.9%;
--foreground: 0 0% 98%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 224 76% 48%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
--ring: 240 4.9% 83.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}
Implementing components
Implementing shadcn/ui components based on your Figma designs can be an efficient way to bridge the gap between design and development. Here's a step-by-step guide on how you can do this:
- Analyze the Figma design: Start by thoroughly examining your Figma design. Take note of the components, layout, colors, typography, and any custom elements.
- Identify matching shadcn/ui components: shadcn/ui offers a wide range of pre-built components. Identify which ones closely match the elements in your Figma design. Common components include Button, Card, Input, Dropdown, etc.
- Set up your project: Ensure you have a Next.js project set up with shadcn/ui installed. More details here.
- Implement the components: Create React components that use shadcn/ui components as building blocks. Here's an example of how you might implement a card from your Figma design.
- Style your components: Use Tailwind CSS classes to style your components to match your Figma design. shadcn/ui is built with Tailwind, so you can easily customize the appearance.
- Customize theme: Adjust your Tailwind configuration to match your Figma design system. More details on theming here.
- Handle responsive design: Use Tailwind's responsive classes to make your components responsive, matching any breakpoints defined in your Figma design.
- Implement interactions: Use React hooks to add any interactions specified in your Figma prototype.
- Accessibility: Ensure your implementation maintains accessibility. shadcn/ui components are built with accessibility in mind, but double-check that your usage and any customizations preserve this.
- Iterate and refine: Compare your implemented components with the Figma design. Make adjustments as needed, possibly creating custom components or extending shadcn/ui components for perfect alignment with your design.
Remember, while shadcn/ui provides a great starting point, you may need to create custom components or extend existing ones to perfectly match your Figma designs. The goal is to use shadcn/ui as a foundation and customize as needed to achieve your specific design requirements.
By following these steps, you can efficiently implement shadcn/ui components based on your Figma designs, creating a cohesive and visually appealing user interface that closely matches your design specifications.
Using v0 by Vercel
v0 is an advanced AI coding assistant created by Vercel. It's designed to help developers and designers quickly turn ideas into functional code, particularly focusing on web development. v0 can be a powerful tool to help you implement your Figma designs quickly and efficiently.
Prompting
Here's how you can use v0 to turn your Figma designs into code with prompting:
- Describe your design: Start by describing the key elements and layout of your Figma design to v0. Be as specific as possible about the components, layout, colors, and interactions you want to implement.
- Generate components: v0 can generate React components based on your descriptions. You can ask for specific UI elements like headers, navigation bars, cards, or more complex layouts.
- Customize styles: v0 uses Tailwind CSS for styling, which aligns well with design systems. You can specify colors, spacing, and other design tokens from your Figma file, and v0 will incorporate them into the generated code.
- Iterate and refine: If the generated component doesn't match your Figma design perfectly, you can provide more details or ask for specific modifications. v0 can adjust the code based on your feedback.
- Implement interactions: Describe any interactions or state changes in your Figma prototype, and v0 can help implement them using React hooks and state management.
- Ensure accessibility: v0 implements accessibility best practices, but you can also ask for specific accessibility features to match your Figma design's requirements.
- Responsive design: Describe how your Figma design should behave on different screen sizes, and v0 can help implement responsive layouts using Tailwind CSS classes.
- Copy and integrate: Once you're satisfied with the generated components, you can copy the code and integrate it into your Next.js project.
Image and prompt
You can ask v0 to implement shadcn/ui code based on an image. This is one of v0's powerful features that can significantly speed up your development process. Here's how you can do it:
- Image Upload: v0 allows you to upload or attach images via the prompt form on the v0.dev interface.
- Image Analysis: Once you've uploaded an image, v0 can analyze and interpret the design elements in the image.
- Description and Request: After uploading the image, you can describe what you see in the image and ask v0 to implement it using shadcn/ui components. Be as specific as possible about the layout, components, and any interactions you want to implement.
- Code Generation: v0 will then generate React code using shadcn/ui components that closely matches the design in your image.
- shadcn/ui Integration: v0 is pre-configured to use shadcn/ui components, which it imports from "@/components/ui" . This means the generated code will automatically use these components where appropriate.
- Customization: If the generated code doesn't perfectly match your image, you can ask v0 to make specific adjustments or modifications.
Here's an example of how you might phrase your request to v0:
"I've uploaded an image of a login form. Can you implement this using shadcn/ui components? The form has input fields for email and password, a 'Remember me' checkbox, a 'Forgot password?' link, and a submit button. The layout is centered on the page with a card-like appearance."
Remember, while v0 is very capable, it may not perfectly replicate every detail of your design on the first try. You may need to provide additional details or request specific adjustments to get the exact result you're looking for.