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 CHANGED
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "name": "tailwindcss-react-aria-components",
3
- "version": "2.1.0",
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
- "main": "src/index.js",
7
- "types": "src/index.d.ts",
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
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/adobe/react-spectrum"
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
- "publishConfig": {
27
- "access": "public"
26
+ "peerDependencies": {
27
+ "tailwindcss": "^4.0.0"
28
28
  },
29
- "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
29
+ "gitHead": "1c84a49a1faf50b571c84e00bcf9c60b22ddd03e"
30
30
  }
package/src/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- declare function plugin(options?: Partial<{ prefix: string }>): {
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 = ['indeterminate', 'required', 'invalid', 'empty', 'focus-visible', 'focus-within', 'disabled'];
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((variant) => [variant, `:${variant}`]),
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 ? `[data-${attributeName}="${attributeValue}"]` : `[data-${attributeName}]`;
92
+ let baseSelector = attributeValue
93
+ ? `[data-${attributeName}="${attributeValue}"]`
94
+ : `[data-${attributeName}]`;
87
95
  let nativeSelector = nativeVariantSelectors.get(attributeName);
88
96
  if (prefix === '' && nativeSelector) {
89
- let wrappedNativeSelector = `&:where(:not([data-rac]))${nativeSelector}`;
90
- let nativeSelectorGenerator = wrappedNativeSelector;
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
- nativeSelectorGenerator = wrap => `@media (hover: hover) { ${wrap(wrappedNativeSelector)} }`;
106
+ return {
107
+ '@media (hover: hover)': {
108
+ [unifiedSelector]: '@slot'
109
+ }
110
+ };
93
111
  }
94
- return [`&:where([data-rac])${baseSelector}`, nativeSelectorGenerator];
112
+ return unifiedSelector;
95
113
  } else if (prefix === '' && nativeMergeSelectors.has(attributeName)) {
96
- return [`&${baseSelector}`, `&${nativeMergeSelectors.get(attributeName)}`];
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, mapSelector(selectors, selector => wrapSelector(selector, s => s)));
122
+ addVariant(variantName, selectors);
120
123
  };
121
124
 
122
- module.exports = plugin.withOptions((options) => (({addVariant}) => {
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((attributeName) => {
127
- attributes.enum[attributeName].forEach(
128
- (attributeValue, i) => {
129
- let name = shortNames[attributeName] || attributeName;
130
- let variantName = `${prefix}${name}-${attributeValue}`;
131
- let selectors = getSelector(prefix, attributeName, attributeValue);
132
- addVariants(variantName, selectors, addVariant, i);
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
+ });