Read if:
I would say please read part one if you haven't, it's a continuation.
Introduction
In last part we learned how to What is design system, tailwindcss, sveltekit. We also created a project where we added tailwind css in sveltekit. That what we have done in last part. In this part we gonna make changes in our tailwind.config.cjs
file to define are colors, screen sizes, spacing and many more things.
Get to know tailwind configurations
Here we gonna edit tailwind config file. Tailwind provides out of the box design system level configuration.
content : It is an array type object, where we pass which file to be processed by tailwind compiler to add tailwind css in your project.
theme : It is a dictionary type object, where you define your color palette, fonts, type scale, border sizes, breakpoints — anything related to the visual design of your site.
plugins : It is an array type object, this allows you to register plugins with Tailwind that can be used to generate extra utilities, components, base styles, or custom variants.
corePlugins : It is a dictionary type object, where you completely disable classes that Tailwind would normally generate by default if you don’t need them for your project.
According to me, these are the main parameters that you need to play with mostly in config file. If you wanna learn more about configuration click here.
Setting up tailwind config
In our project, I'm going to focus on theme
section which is the most important for a design system.
theme
section you have two options. theme: {
extend: {
colors: {
'additional-color-name':'value',
}
}
theme: {
colors: {
'color':'value',
}
}
This will replace the default colors.
If you wanna learn more about tailwind theme configuration click here
- We need our design system, so we gonna replace default with our values. Here, I'm going with my own colors.
So, I'll add this configuration in my tailwind config of theme:
const colors = require('tailwindcss/colors.js');
theme: {
colors: {
gray: colors.gray,
black: colors.black,
white: colors.white,
danger: colors.rose,
info: colors.sky,
warning: colors.amber,
success: colors.teal,
primary: colors.orange,
secondary: colors.violet,
tertiary: colors.rose
}
}
Here, I decide to use tailwind colors with my own defined names or you can use tailwind shade generators and can provide color config.
That's all we have to add our design system's colors. Same we can do with screens, spacings too.
How to use it?
In last part, In the end we had this code :
<h1 class="text-3xl font-bold underline">
Hello world!
</h1>
If you notice we didn’t gave it a color property last time but we can do that in default or custom without any issues.
Now when we are using are design system we can do this :
<h1 class="text-3xl font-bold underline text-primary">
Hello world!
</h1>
This is the end of the this series with two parts.
Thank You for reading till the end.
This is me writing for you. If you wanna ask or suggest anything please put it in comment.
Our service will help you design and develop your product.