tailwindcss-react-aria-components 2.0.1 → 2.1.1
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 +27 -18
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-react-aria-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
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": "3577a20859b9585a000010c720f6ee39c1c588cc"
|
|
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,13 +85,13 @@ 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
97
|
let wrappedNativeSelector = `&:where(:not([data-rac]))${nativeSelector}`;
|
|
@@ -116,22 +124,23 @@ let wrapSelector = (selector, wrap) => {
|
|
|
116
124
|
};
|
|
117
125
|
|
|
118
126
|
let addVariants = (variantName, selectors, addVariant) => {
|
|
119
|
-
addVariant(
|
|
127
|
+
addVariant(
|
|
128
|
+
variantName,
|
|
129
|
+
mapSelector(selectors, selector => wrapSelector(selector, s => s))
|
|
130
|
+
);
|
|
120
131
|
};
|
|
121
132
|
|
|
122
|
-
module.exports = plugin.withOptions(
|
|
133
|
+
module.exports = plugin.withOptions(options => ({addVariant}) => {
|
|
123
134
|
let prefix = options?.prefix ? `${options.prefix}-` : '';
|
|
124
135
|
|
|
125
136
|
// 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
|
-
);
|
|
137
|
+
Object.keys(attributes.enum).forEach(attributeName => {
|
|
138
|
+
attributes.enum[attributeName].forEach((attributeValue, i) => {
|
|
139
|
+
let name = shortNames[attributeName] || attributeName;
|
|
140
|
+
let variantName = `${prefix}${name}-${attributeValue}`;
|
|
141
|
+
let selectors = getSelector(prefix, attributeName, attributeValue);
|
|
142
|
+
addVariants(variantName, selectors, addVariant, i);
|
|
143
|
+
});
|
|
135
144
|
});
|
|
136
145
|
|
|
137
146
|
attributes.boolean.forEach((attribute, i) => {
|
|
@@ -141,4 +150,4 @@ module.exports = plugin.withOptions((options) => (({addVariant}) => {
|
|
|
141
150
|
let selectors = getSelector(prefix, attributeName, null);
|
|
142
151
|
addVariants(variantName, selectors, addVariant, i);
|
|
143
152
|
});
|
|
144
|
-
})
|
|
153
|
+
});
|