200 Commits

Author SHA1 Message Date
Adam Wathan
007231fbfc Require plugin authors to manually escape variants
Not 100% convinced this is a net positive change, but I regret not having done things this way at the beginning.

In 0.x, we pass the `separator` and `className` values already escaped, so `:` comes through as `\:` for example, and `w-1/2` comes through as `w-1\/2`.

At first this sounds fine, less work for the plugin author right? But CSS escaping rules are kind of complicated and you have to escape characters differently depending on whether or not they are at the start of an identifier.

For example, it's totally fine for a class to contain a zero (`0` ), but it can't _start_ with a zero. For a class to start with a zero, it needs to be escaped like this: `\30 `

This means that as a general rule, trying to escape the individual segments of a class separately is a bad idea — you should escape the class as a whole so only the necessary escaping is applied. We break this rule when we pre-escape the separator and className for plugin authors who use the `modifySelectors` function.

We already require users to manually escape class names when they are using `addUtilities` or `addComponents`, so to me it feels more consistent for things to work this way and it's how they should have worked from day one.

Basically this code:

```js
function({ addVariant }) {
  addVariant('first-child', ({ modifySelectors, separator }) => {
    modifySelectors(({ className }) => {
      return `.first-child${separator}${className}:first-child`
    })
  })
},
```

...would need to be re-written like this if I merge this change:

```js
function({ addVariant, e }) {
  addVariant('first-child', ({ modifySelectors, separator }) => {
    modifySelectors(({ className }) => {
      return `.${e(`first-child${separator}${className}`)}:first-child`
    })
  })
},
```

Although I think this is the right way for this to work, I hesitate because it's a breaking change that makes any variant plugins authored for 0.x incompatible with 1.x. It's an easy fix on the plugin author's part, but it's still annoying.

I'm leaning towards merging so I don't regret this even more later when the plugin ecosystem is a lot bigger. Anyone have any thoughts?
2019-02-28 10:17:09 -05:00
Adam Wathan
4763840582 Merge branch 'master' into next 2019-02-15 14:31:17 -05:00
Adam Wathan
c0ec2c5fbe Allow users to customize default variant placement 2019-02-15 10:52:01 -05:00
Adam Wathan
690c7f2d52 Convert preflight to plugin 2019-02-07 15:19:54 -05:00
Adam Wathan
4a505be390 Load plugin base styles at @tailwind base 2019-02-07 15:09:18 -05:00
Adam Wathan
b8f965179c Finish merge of master 2019-02-07 13:58:47 -05:00
Adam Wathan
8aabccb8d4 Fix code style 2019-02-06 14:29:05 -05:00
Adam Wathan
b544febfcb Use root instead of array to unify code paths 2019-02-06 14:23:38 -05:00
Justin Anastos
40bb6c619d Add nested atRule support to substituteResponsiveAtRules 2019-02-05 10:15:59 -05:00
Adam Wathan
b036cac4b5 Fix code style 2019-02-01 12:32:50 -05:00
Adam Wathan
ec1bdd27ec Move screens into theme config 2019-02-01 12:32:50 -05:00
Adam Wathan
e8d16fcdb5 Move separator to top level config option 2019-02-01 12:32:50 -05:00
Adam Wathan
664f923312 Move prefix option to top-level in config 2019-02-01 12:32:16 -05:00
Adam Wathan
ffae87148d Revert "Allow plugins to register new config variables" 2019-02-01 12:32:04 -05:00
Adam Wathan
5ea8bbe798 Allow plugins to register new config variables 2019-02-01 12:32:04 -05:00
Adam Wathan
adc5d2597c Remove unnecessary parameter 2019-01-14 15:43:12 -05:00
Adam Wathan
1e8a70b68c Promote pluginVariants from experiment to feature 2018-10-31 15:52:32 -04:00
Jesse
55f8207d21 Fix apostrophe in error 2018-10-17 11:47:14 +02:00
Adam Wathan
750b62c5d2 Enable shadowLookup by default 2018-09-21 14:55:54 -04:00
Adam Wathan
8d5aee4a77 Refactor findClass 2018-09-15 08:24:42 -04:00
Adam Wathan
39ec3b14cc Use existing prefixSelector function 2018-09-14 16:22:49 -04:00
Rouven Hurling
d7d715a94e
fix code, test and style 2018-09-14 17:04:54 +02:00
Rouven Hurling
8042c268d4
Fix travis issue (missed an opening bracket) 2018-09-14 15:27:43 +02:00
Rouven Hurling
f629b647da
Implement optional prefix substitution in @apply 2018-09-14 15:10:17 +02:00
Adam Wathan
1a8383c08d
Merge branch 'master' into feature/focus-within 2018-09-13 21:41:16 +09:30
Adam Wathan
25744172d1 Extract duplication to function 2018-07-12 11:05:09 -04:00
Adam Wathan
80baf4aa17 Pass generated utilities around as array instead of root
When you do something like container.before(someRoot), PostCSS actually *mutates* someRoot, leaving it empty and moving its contents before the container. container.before(arrayOfNodes) on the other hand does no weird mutation.

This PR makes sure generatedUtilities is an array of nodes instead of a PostCSS container to avoid this unexpected mutation. It makes it a bit more work to walk those nodes if they need to be transformed, but I think it's worth the trade-off. Can always write a helper function around that if the boilerplate starts to feel repetitive.
2018-07-11 19:14:33 -04:00
Adam Wathan
597bad6ee5 Clone generatedUtilities before inserting 2018-07-11 15:54:11 -04:00
Adam Wathan
dd6fa7c4eb
Merge pull request #516 from tailwindcss/shadow-table
[Experiment] Allow `@apply`-ing utility classes that aren't explicitly defined but would be generated
2018-07-12 02:01:19 +09:30
Adam Wathan
7846d2a228 Move plugin variant features behind experiment 2018-07-11 12:13:50 -04:00
Adam Wathan
24e1385aca Only enable shadow lookup if shadowLookup experiment is enabled 2018-07-11 11:51:47 -04:00
Adam Wathan
cfe492220c Refactor duplication 2018-07-11 11:45:45 -04:00
Adam Wathan
cdbea36564 Fallback to shadow table 2018-07-11 09:56:11 -04:00
Adam Wathan
f974b8df03 Add support for writing variant plugins with raw PostCSS API 2018-06-26 13:44:47 -04:00
Adam Wathan
9b22ff3513 Only process plugins once 2018-06-26 13:44:47 -04:00
Adam Wathan
b21d258f63 Wrap Tailwind plugins in new plugin to only unwrap config once 2018-06-26 13:44:47 -04:00
Adam Wathan
64cda2f44b Refactor duplication to use generateVariantFunction 2018-06-26 13:44:47 -04:00
Adam Wathan
d77bc055ee Support for basic variant generator plugins
Allows you to write a plugin that registers a new variant but only
allows you to modify the selector (like what our built-in generators
do.)

Next steps are to support variants that wrap rules with at-rules
(like @supports for example), variants that can modify properties
(as opposed to just selectors), and to give variant plugin authors
control over how responsive variants interact with their own variants.
2018-06-26 13:44:47 -04:00
Adam Wathan
9eca69ad83 Refactor process plugins to return an object 2018-06-26 13:44:47 -04:00
Adam Wathan
9d05910507 Generate variants based on the order specified in the modules config 2018-06-26 13:44:47 -04:00
Adam Wathan
8333d46cae Add variant prefix to last class in a selector, not the first 2018-06-20 12:21:14 -04:00
Paulo
9e4e8a6d05 Add focus-within variant 2018-05-04 14:47:28 +02:00
Adam Wathan
2e34df923e Add sourcemaps for replaced preflight styles 2018-03-30 10:23:56 -04:00
Adam Wathan
cc968d1791 Fix conflics, refactor variant generator 2018-03-13 08:12:20 -04:00
Adam Wathan
6e7ae58910 Move container component to a built-in plugin 2018-03-12 15:34:34 -04:00
Adam Wathan
20461a3418 Generate container classes as components, not utilities 2018-03-12 15:34:34 -04:00
Adam Wathan
fa0e06c2dd Generate focus variants last and group-hover variants first 2018-03-12 15:34:14 -04:00
Adam Wathan
960275cc86 Add container classes as utilities not components
Just for now so that this feature can be introduced into the codebase
without forcing a BC break. The container classes will eventually be
moved to a built-in plugin that adds them as components.
2018-03-05 09:58:35 -05:00
Adam Wathan
dac591198f Provide a function for prefixing utilities in plugins 2018-03-05 09:58:35 -05:00
Adam Wathan
18d45b19cf Fix style 2018-03-05 09:58:35 -05:00