|
1 | 1 | import plugin from 'tailwindcss/plugin';
|
2 | 2 |
|
| 3 | +// Order of these is important because it determines which states win in a conflict. |
| 4 | +// We mostly follow Tailwind's defaults, adding our additional states following the categories they define. |
| 5 | +// https://github.com/tailwindlabs/tailwindcss/blob/304c2bad6cb5fcb62754a4580b1c8f4c16b946ea/src/corePlugins.js#L83 |
3 | 6 | const attributes = {
|
4 | 7 | boolean: [
|
5 |
| - ['hover', 'hovered'], |
6 |
| - ['focus', 'focused'], |
7 |
| - 'focus-visible', |
8 |
| - 'focus-within', |
9 |
| - 'pressed', |
10 |
| - 'disabled', |
11 |
| - 'drop-target', |
12 |
| - 'dragging', |
13 |
| - 'empty', |
14 |
| - 'allows-dragging', |
| 8 | + // Conditions |
15 | 9 | 'allows-removing',
|
16 | 10 | 'allows-sorting',
|
17 |
| - ['placeholder-shown', 'placeholder'], |
18 |
| - 'selected', |
19 |
| - 'indeterminate', |
20 |
| - ['read-only', 'readonly'], |
21 |
| - 'required', |
| 11 | + 'allows-dragging', |
| 12 | + |
| 13 | + // States |
| 14 | + 'open', |
22 | 15 | 'entering',
|
23 | 16 | 'exiting',
|
24 |
| - 'open', |
| 17 | + 'indeterminate', |
| 18 | + ['placeholder-shown', 'placeholder'], |
| 19 | + 'current', |
| 20 | + 'required', |
25 | 21 | 'unavailable',
|
| 22 | + 'invalid', |
| 23 | + ['read-only', 'readonly'], |
26 | 24 | 'outside-month',
|
27 | 25 | 'outside-visible-range',
|
| 26 | + |
| 27 | + // Content |
| 28 | + 'empty', |
| 29 | + |
| 30 | + // Interactive states |
| 31 | + 'focus-within', |
| 32 | + ['hover', 'hovered'], |
| 33 | + ['focus', 'focused'], |
| 34 | + 'focus-visible', |
| 35 | + 'pressed', |
| 36 | + 'selected', |
28 | 37 | 'selection-start',
|
29 | 38 | 'selection-end',
|
30 |
| - 'current', |
31 |
| - 'invalid', |
32 |
| - 'resizing' |
| 39 | + 'dragging', |
| 40 | + 'drop-target', |
| 41 | + 'resizing', |
| 42 | + 'disabled' |
33 | 43 | ],
|
34 | 44 | enum: {
|
35 | 45 | placement: ['left', 'right', 'top', 'bottom'],
|
@@ -100,21 +110,24 @@ let addVariants = (variantName, selectors, addVariant, matchVariant) => {
|
100 | 110 |
|
101 | 111 | module.exports = plugin.withOptions((options) => (({addVariant, matchVariant}) => {
|
102 | 112 | let prefix = options?.prefix ? `${options.prefix}-` : '';
|
| 113 | + |
| 114 | + // Enum attributes go first because currently they are all non-interactive states. |
| 115 | + Object.keys(attributes.enum).forEach((attributeName) => { |
| 116 | + attributes.enum[attributeName].forEach( |
| 117 | + (attributeValue) => { |
| 118 | + let name = shortNames[attributeName] || attributeName; |
| 119 | + let variantName = `${prefix}${name}-${attributeValue}`; |
| 120 | + let selectors = getSelector(prefix, attributeName, attributeValue); |
| 121 | + addVariants(variantName, selectors, addVariant, matchVariant); |
| 122 | + } |
| 123 | + ); |
| 124 | + }); |
| 125 | + |
103 | 126 | attributes.boolean.forEach((attribute) => {
|
104 | 127 | let variantName = Array.isArray(attribute) ? attribute[0] : attribute;
|
105 | 128 | variantName = `${prefix}${variantName}`;
|
106 | 129 | let attributeName = Array.isArray(attribute) ? attribute[1] : attribute;
|
107 | 130 | let selectors = getSelector(prefix, attributeName);
|
108 | 131 | addVariants(variantName, selectors, addVariant, matchVariant);
|
109 | 132 | });
|
110 |
| - Object.keys(attributes.enum).forEach((attributeName) => { |
111 |
| - attributes.enum[attributeName].forEach( |
112 |
| - (attributeValue) => { |
113 |
| - let name = shortNames[attributeName] || attributeName; |
114 |
| - let variantName = `${prefix}${name}-${attributeValue}`; |
115 |
| - let selectors = getSelector(prefix, attributeName, attributeValue); |
116 |
| - addVariants(variantName, selectors, addVariant, matchVariant); |
117 |
| - } |
118 |
| - ); |
119 |
| - }); |
120 | 133 | }));
|
0 commit comments