Skip to content

Commit 2fe2a38

Browse files
authored
Merge pull request tailwindlabs#206 from tailwindcss/add-options-key-to-default-key
[0.2] Add options key to default config and document
2 parents a379d80 + caa00bb commit 2fe2a38

File tree

3 files changed

+123
-7
lines changed

3 files changed

+123
-7
lines changed

defaultConfig.stub.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,17 +759,17 @@ module.exports = {
759759

760760
/*
761761
|-----------------------------------------------------------------------------
762-
| Packages
762+
| Options https://tailwindcss.com/docs/configuration#options
763763
|-----------------------------------------------------------------------------
764764
|
765-
| Here is where you can define the configuration for any Tailwind packages
766-
| you're using. These can be utility packs, component bundles, or even
767-
| complete themes. You'll want to reference each package's
768-
| documentation for a list of settings available for it.
765+
| Here is where you can set your Tailwind configuration options. For more
766+
| details about these options, visit the configuration options documentation.
769767
|
770768
*/
771769

772-
packages: {
770+
options: {
771+
prefix: '',
772+
important: false,
773773
},
774774

775775
}

docs/source/docs/configuration.blade.md

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,121 @@ Please see the [installation](/docs/installation#4-process-your-css-with-tailwin
2828

2929
As you can see below, the default config file is heavily documented. Read through it to get a better understanding of how each section can be customized for your project.
3030

31+
<pre class="h-128 overflow-y-scroll language-javascript"><code>{!! str_replace('// var defaultConfig', 'var defaultConfig', file_get_contents(dirname(dirname(__DIR__)).'/defaultConfig.stub.js')) !!}</code></pre>
32+
33+
## Options
34+
35+
In addition to defining your project's design system, the configuration file can also be used for setting a variety of global options.
36+
37+
These options are available under the top-level `options` key, located at the bottom of the configuration file by default.
38+
39+
### Prefix
40+
41+
The `prefix` option allows you to add a custom prefix to all of Tailwind's generated utility classes.
42+
43+
This can be really useful when layering Tailwind on top of existing CSS where there might be naming conflicts.
44+
45+
For example, you could add a `tw-` prefix by setting the `prefix` option like so:
46+
3147
```js
32-
{!! str_replace('// var defaultConfig', 'var defaultConfig', file_get_contents(dirname(dirname(__DIR__)).'/defaultConfig.stub.js')) !!}
48+
{
49+
// ...
50+
options: {
51+
prefix: 'tw-',
52+
// ...
53+
}
54+
}
55+
```
56+
57+
It's important to understand that this prefix is added to the beginning of each *utility* name, not to the entire class name.
58+
59+
That means that classes with responsive or state prefixes like `sm:` or `hover:` will still have the responsive or state prefix *first*, with your custom prefix appearing after the colon:
60+
61+
```html
62+
<div class="tw-text-lg md:tw-text-xl tw-bg-red hover:tw-bg-blue">
63+
<!-- -->
64+
</div>
65+
```
66+
67+
Prefixes are only added to standard Tailwind utilities; **no prefix will be added to your own custom utilities.**
68+
69+
That means if you add your own responsive utility like this:
70+
71+
```css
72+
@responsive {
73+
.bg-brand-gradient { ... }
74+
}
75+
```
76+
77+
...the generated responsive classes will not have your configured prefix:
78+
79+
```css
80+
.bg-brand-gradient { ... }
81+
@media (min-width: 576px) {
82+
.sm\:bg-brand-gradient { ... }
83+
}
84+
@media (min-width: 768px) {
85+
.md\:bg-brand-gradient { ... }
86+
}
87+
@media (min-width: 992) {
88+
.lg\:bg-brand-gradient { ... }
89+
}
90+
@media (min-width: 1200px) {
91+
.xl\:bg-brand-gradient { ... }
92+
}
93+
```
94+
95+
If you'd like to prefix your own utilities as well, just add the prefix to the class definition:
96+
97+
```css
98+
@responsive {
99+
.tw-bg-brand-gradient { ... }
100+
}
101+
```
102+
103+
### Important
104+
105+
The `important` option lets you control whether or not Tailwind's utilities should be marked with `!important`.
106+
107+
This can be really useful when using Tailwind with existing CSS that has high specificity selectors.
108+
109+
To generate utilities as `!important`, set the `important` key in your configuration options to `true`:
110+
111+
```js
112+
{
113+
// ...
114+
options: {
115+
important: true,
116+
// ...
117+
}
118+
}
119+
```
120+
121+
Now all of Tailwind's utility classes will be generated as `!important`:
122+
123+
```css
124+
.leading-none {
125+
line-height: 1 !important;
126+
}
127+
.leading-tight {
128+
line-height: 1.25 !important;
129+
}
130+
.leading-normal {
131+
line-height: 1.5 !important;
132+
}
133+
.leading-loose {
134+
line-height: 2 !important;
135+
}
136+
```
137+
138+
Note that any of your own custom utilities **will not** be marked as `!important` just by enabling this option.
139+
140+
If you'd like to make your own utilities `!important`, just add `!important` to the end of each declaration yourself:
141+
142+
```css
143+
@responsive {
144+
.bg-brand-gradient {
145+
background-image: linear-gradient(#3490dc, #6574cd) !important;
146+
}
147+
}
33148
```

docs/tailwind.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ config.width = Object.assign(config.width, {
6868

6969
config.height = Object.assign(config.height, {
7070
'7': '1.75rem',
71+
'128': '32rem',
7172
})
7273

7374
config.padding = Object.assign(config.padding, {

0 commit comments

Comments
 (0)