tailwindcss-react-aria-components 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -12
- package/src/index.d.ts +4 -4
- package/src/index.js +40 -39
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-react-aria-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A Tailwind plugin that adds variants for data attributes in React Aria Components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
9
|
+
},
|
|
8
10
|
"source": "src/index.js",
|
|
9
11
|
"files": [
|
|
10
12
|
"dist",
|
|
11
13
|
"src"
|
|
12
14
|
],
|
|
13
15
|
"sideEffects": false,
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"tailwindcss": "^4.0.0"
|
|
16
|
+
"main": "src/index.js",
|
|
17
|
+
"types": "src/index.d.ts",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@tailwindcss/postcss": "^4.0.0",
|
|
23
23
|
"postcss": "^8.0.0",
|
|
24
24
|
"tailwindcss": "^4.0.0"
|
|
25
25
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"tailwindcss": "^4.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1c84a49a1faf50b571c84e00bcf9c60b22ddd03e"
|
|
30
30
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
declare function plugin(options?: Partial<{
|
|
2
|
-
handler: () => void
|
|
3
|
-
}
|
|
1
|
+
declare function plugin(options?: Partial<{prefix: string}>): {
|
|
2
|
+
handler: () => void;
|
|
3
|
+
};
|
|
4
4
|
|
|
5
5
|
declare namespace plugin {
|
|
6
6
|
const __isOptionsFunction: true;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export = plugin
|
|
9
|
+
export = plugin;
|
package/src/index.js
CHANGED
|
@@ -65,9 +65,17 @@ const shortNames = {
|
|
|
65
65
|
|
|
66
66
|
// Variants we use that are already defined by Tailwind:
|
|
67
67
|
// https://github.com/tailwindlabs/tailwindcss/blob/a2fa6932767ab328515f743d6188c2164ad2a5de/src/corePlugins.js#L84
|
|
68
|
-
const nativeVariants = [
|
|
68
|
+
const nativeVariants = [
|
|
69
|
+
'indeterminate',
|
|
70
|
+
'required',
|
|
71
|
+
'invalid',
|
|
72
|
+
'empty',
|
|
73
|
+
'focus-visible',
|
|
74
|
+
'focus-within',
|
|
75
|
+
'disabled'
|
|
76
|
+
];
|
|
69
77
|
const nativeVariantSelectors = new Map([
|
|
70
|
-
...nativeVariants.map(
|
|
78
|
+
...nativeVariants.map(variant => [variant, `:${variant}`]),
|
|
71
79
|
['hovered', ':hover'],
|
|
72
80
|
['focused', ':focus'],
|
|
73
81
|
['active', ':active'],
|
|
@@ -77,61 +85,54 @@ const nativeVariantSelectors = new Map([
|
|
|
77
85
|
]);
|
|
78
86
|
|
|
79
87
|
// Variants where both native and RAC attributes should apply. We don't override these.
|
|
80
|
-
const nativeMergeSelectors = new Map([
|
|
81
|
-
['placeholder', ':placeholder-shown']
|
|
82
|
-
]);
|
|
88
|
+
const nativeMergeSelectors = new Map([['placeholder', ':placeholder-shown']]);
|
|
83
89
|
|
|
84
90
|
// If no prefix is specified, we want to avoid overriding native variants on non-RAC components, so we only target elements with the data-rac attribute for those variants.
|
|
85
91
|
let getSelector = (prefix, attributeName, attributeValue) => {
|
|
86
|
-
let baseSelector = attributeValue
|
|
92
|
+
let baseSelector = attributeValue
|
|
93
|
+
? `[data-${attributeName}="${attributeValue}"]`
|
|
94
|
+
: `[data-${attributeName}]`;
|
|
87
95
|
let nativeSelector = nativeVariantSelectors.get(attributeName);
|
|
88
96
|
if (prefix === '' && nativeSelector) {
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
// Collapse the RAC and native branches into a single `:is()` so `not-*`
|
|
98
|
+
// works — Tailwind's `not` walker bails on a dual-selector (array) shape.
|
|
99
|
+
// `:where()` keeps specificity at (0,1,0).
|
|
100
|
+
let unifiedSelector = `&:is(:where([data-rac])${baseSelector}, :where(:not([data-rac]))${nativeSelector})`;
|
|
101
|
+
// Hover needs `@media (hover: hover)` to avoid sticky styles on touch.
|
|
102
|
+
// Emitted as CSS-in-JS (not `@media ... { & }`) so Tailwind reports
|
|
103
|
+
// compounds as `StyleRules | AtRules`, keeping `group-hover:`/`peer-hover:`
|
|
104
|
+
// composable while still letting `not-hover:` invert cleanly.
|
|
91
105
|
if (nativeSelector === ':hover') {
|
|
92
|
-
|
|
106
|
+
return {
|
|
107
|
+
'@media (hover: hover)': {
|
|
108
|
+
[unifiedSelector]: '@slot'
|
|
109
|
+
}
|
|
110
|
+
};
|
|
93
111
|
}
|
|
94
|
-
return
|
|
112
|
+
return unifiedSelector;
|
|
95
113
|
} else if (prefix === '' && nativeMergeSelectors.has(attributeName)) {
|
|
96
|
-
|
|
114
|
+
// Same `:is()` collapse for merge selectors (e.g. placeholder).
|
|
115
|
+
return `&:is(${baseSelector}, ${nativeMergeSelectors.get(attributeName)})`;
|
|
97
116
|
} else {
|
|
98
117
|
return `&${baseSelector}`;
|
|
99
118
|
}
|
|
100
119
|
};
|
|
101
120
|
|
|
102
|
-
let mapSelector = (selector, fn) => {
|
|
103
|
-
if (Array.isArray(selector)) {
|
|
104
|
-
return selector.map(fn);
|
|
105
|
-
} else {
|
|
106
|
-
return fn(selector);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
let wrapSelector = (selector, wrap) => {
|
|
111
|
-
if (typeof selector === 'function') {
|
|
112
|
-
return selector(wrap);
|
|
113
|
-
} else {
|
|
114
|
-
return wrap(selector);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
121
|
let addVariants = (variantName, selectors, addVariant) => {
|
|
119
|
-
addVariant(variantName,
|
|
122
|
+
addVariant(variantName, selectors);
|
|
120
123
|
};
|
|
121
124
|
|
|
122
|
-
module.exports = plugin.withOptions(
|
|
125
|
+
module.exports = plugin.withOptions(options => ({addVariant}) => {
|
|
123
126
|
let prefix = options?.prefix ? `${options.prefix}-` : '';
|
|
124
127
|
|
|
125
128
|
// Enum attributes go first because currently they are all non-interactive states.
|
|
126
|
-
Object.keys(attributes.enum).forEach(
|
|
127
|
-
attributes.enum[attributeName].forEach(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
);
|
|
129
|
+
Object.keys(attributes.enum).forEach(attributeName => {
|
|
130
|
+
attributes.enum[attributeName].forEach((attributeValue, i) => {
|
|
131
|
+
let name = shortNames[attributeName] || attributeName;
|
|
132
|
+
let variantName = `${prefix}${name}-${attributeValue}`;
|
|
133
|
+
let selectors = getSelector(prefix, attributeName, attributeValue);
|
|
134
|
+
addVariants(variantName, selectors, addVariant, i);
|
|
135
|
+
});
|
|
135
136
|
});
|
|
136
137
|
|
|
137
138
|
attributes.boolean.forEach((attribute, i) => {
|
|
@@ -141,4 +142,4 @@ module.exports = plugin.withOptions((options) => (({addVariant}) => {
|
|
|
141
142
|
let selectors = getSelector(prefix, attributeName, null);
|
|
142
143
|
addVariants(variantName, selectors, addVariant, i);
|
|
143
144
|
});
|
|
144
|
-
})
|
|
145
|
+
});
|