Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chempogonzalez/tailwind-semantic-setup
𧬠Tailwind preset to enable a good semantic setup for better Design Systems
https://github.com/chempogonzalez/tailwind-semantic-setup
classname colors css plugin preset semantic tailwind tailwindcss variants
Last synced: 3 months ago
JSON representation
𧬠Tailwind preset to enable a good semantic setup for better Design Systems
- Host: GitHub
- URL: https://github.com/chempogonzalez/tailwind-semantic-setup
- Owner: chempogonzalez
- License: mit
- Created: 2022-12-03T17:32:14.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-18T10:52:47.000Z (9 months ago)
- Last Synced: 2024-10-19T10:04:00.911Z (3 months ago)
- Topics: classname, colors, css, plugin, preset, semantic, tailwind, tailwindcss, variants
- Language: JavaScript
- Homepage:
- Size: 800 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 𧬠tailwind-semantic-setup
[![npm version](https://img.shields.io/npm/v/tailwind-semantic-setup?color=blue&style=flat-square)](https://www.npmjs.com/package/tailwind-semantic-setup)
Smart multi-theme tool for better semantic Design Systems
## π **Features**
- β Multiple themes support
- π₯ Auto-generate darker and contrast colors _(better readability)_
- π¦ All [official tailwind plugins](https://tailwindcss.com/docs/plugins#official-plugins) included by default
- π Custom addons to make your life easier:
- `theme name variants` to set classes only for a specific theme
- `wh` utility to set width and height at the same time
- `circle` to set same width and height with border-radius
- `hocus` to set hover and focus at the same time
- ...## π¦ **Installation**
```bash
# NPM
npm install -D tailwind-semantic-setup# PNPM
pnpm add -D tailwind-semantic-setup
```
## π» **Usage example**
### π£ 1. Wrap your tailwind config and set your themes
In your tailwind config file, wrap your tailwind config with the `withSemanticSetup` function.
With the `semanticSetup` property you can setup your themes to be handled automatically.```js
// tailwind.config.js
const { withSemanticSetup } = require('tailwind-semantic-setup')module.exports = withSemanticSetup({
/* ... your tailwind config */
semanticSetup: {
themes: [
{
name: 'my-brand',
colors: {
primary: '#e0a82e',
secondary: '#f9d72f',
accent: '#00ffff',
neutral: '#181830',
root: '#ffffff',
},
},
// ... other themes
],
},
})
```### π£ 2. Add the `data-theme` attribute to your html code
You can put it where you want, but it's recommended to put it in the html tag to make it global accessible for the entire application.
```html
```
### π£ 3. Use the theme classes
```html
```
---
## π **Documentation**
### π¨ **Themes**
You can define multiple themes in the `semanticSetup` property of your tailwind config.
Each theme must have a `name` and a `colors` object.```js
// tailwind.config.js
const { withSemanticSetup } = require('tailwind-semantic-setup')module.exports = withSemanticSetup({
// ... your tailwind config
semanticSetup: {
themes: [
{
name: 'my-brand',
preferredColorScheme: ['dark', 'light'],
colors: {
primary: '#e0a82e',
secondary: '#f9d72f',
accent: '#00ffff',
neutral: '#181830',
root: '#ffffff',
},
},
// ... other themes
],
},
})
```#### π **`name`** _(required)_
The name of the theme. It will be used to generate the classes and the _**data-theme**_ attribute value.#### π **`preferredColorScheme`** _(optional)_
You can set your preferences for the color scheme to be used in the user's browser. It will set _**color-scheme**_ css property#### π **`colors`** _(required)_
Semantic Setup provides you a semantic default setup but **you can add your custom colors**.Here you can see the default colors and the ones that are auto-generated for you:
##### **(Required - added by default)**
βͺοΈ `primary`: The main color of your brand
βͺοΈ `secondary`: The secondary color of your brand
βͺοΈ `accent`: Color to have high color contrasts and highlight.
βͺοΈ `neutral`: The neutral color of your brand
βͺοΈ `root`: The base color of your brand (background color)βͺοΈ `info`: The info color of your brand
βͺοΈ `warning`: The warning color of your brand
βͺοΈ `error`: The error color of your brand##### **(Optional - auto-generated for Required colors)**
- `(colorName)-dark`: The darker version of the (colorName) color _(i.e. `primary-dark`)_
- `(colorName)-content`: The readable color to use for text and icons on top of the (colorName) color _(i.e. `primary-content`)_
- `root-darkest` _(just for base color)_: The darkest version of the `root` color
![color-palette-image](https://github.com/chempogonzalez/tailwind-semantic-setup/blob/main/assets/palette.png)
This approach allows you to have a consistent color palette for your brand with different themes in a very simple way.
The default colors approach is mainly based on [daisyui colors palette](https://daisyui.com/docs/colors) but adding some other nice features to make it more customizable/extendable for your brand.
### π **Default Plugins activate / deactivate**
By default, all [official tailwind plugins](https://tailwindcss.com/docs/plugins#official-plugins) are activated.
You can deactivate them individually using the `plugins` property of the `semanticSetup` object in your tailwind config file.Here you can see the default plugins configuration:
```js
// tailwind.config.js
const { withSemanticSetup } = require('tailwind-semantic-setup')module.exports = withSemanticSetup({
// ... your tailwind config
semanticSetup: {
plugins: {
// @tailwindcss/typography
'typography': true,
// @tailwindcss/forms
'forms': true,
// @tailwindcss/line-clamp
// Deactivated by default because it's part of tailwindcss v3.3.0
'line-clamp': false,
// @tailwindcss/aspect-ratio
'aspect-ratio': true,
},
},
})
```### π **Custom Addons**
#### π **`theme name variants`**
You can set classes only for a specific theme using the theme name variants.
The variant has the following format: `theme-(your-theme-name):class````html
```#### π **`wh`**
You can set width and height at the same time.```html
```#### π **`circle`**
You can set a circle shape setting same width and height.```html
```#### π **`hocus`**
You can set a hover and focus state using the `hocus` utility.```html
```
> Created with JavaScript! β‘ and latin music πΊπ΅
### This README.md file has been written keeping in mind
- [GitHub Markdown](https://guides.github.com/features/mastering-markdown/)
- [Emoji Cheat Sheet](https://www.webfx.com/tools/emoji-cheat-sheet/)