Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom palettes #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mix.palette(options);
| `pretty` | `{Boolean}` | `false` | Use pretty formatting when writing the JSON file. |
| `tailwind` | `{Object}` | `{ ... }` | Set Tailwind options. (See below) |
| `tailwind.config` | `{String}` | `'./tailwind.config.js'` | Path to the Tailwind configuration file relative to the project root path. |
| `tailwind.shades` | `{Object\|Array\|Boolean}` | `false` | While set to `true`, every color shade (`100-900`) will be generated. When set to `false`, only `500` will be used. Optionally, you may define either an array of shades as strings `['50', '100', '500']` or an object containing shade labels `{50: 'Lightest', 100: 'Lighter', 500: ''}`. |
| `tailwind.shades` | `{Object\|Array\|Boolean}` | `false` | While set to `true`, every color shade (`100-900`) will be generated. When set to `false`, only `500` will be used. Optionally, you may define either an array of shades as strings `['50', '100', '500']` or an object containing shade labels `{50: 'Lightest', 100: 'Lighter', 500: ''}`. Enabling this option will also enable support for custom palettes. |
| `tailwind.path` | `{String}` | `'colors'` | Path to Tailwind config values for palette colors in dot notation. Uses Tailwind's color palette `theme('colors')` per default. |
| `sass` | `{Object}` | `{ ... }` | Set Sass options. (See below) |
| `sass.path` | `{String}` | `'resources/assets/styles/config'` | Path to Sass variable files relative to the project root path. |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"d3-color": "^2.0.0",
"d3-hsv": "^0.1.0",
"lodash": "^4.17.20",
"sass-export": "^1.0.6"
"sass-export": "^2.1.0"
},
"peerDependencies": {
"webpack": "^4.0.0 || ^5.0.0"
Expand Down
18 changes: 16 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,25 @@ class PaletteWebpackPlugin {
};
}

if (this.options.tailwind.shades) {
if ('default' == value.toLowerCase()) {
return {
name: this.title(key),
slug: key,
color: this.tailwind[key][value],
};
}

return {
name: this.title(key, value),
slug: `${key}-${value}`,
color: this.tailwind[key][value],
};
}

return {
name: isNaN(value)
? this.title(value)
: this.options.tailwind.shades
? this.title(key, value)
: this.title(key),
slug: `${key}-${value}`,
color: this.tailwind[key][value],
Expand Down
Loading