tailwindcss-react-aria-components 1.0.0-beta.0 → 1.0.0-beta.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-react-aria-components",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "A Tailwind plugin that adds variants for data attributes in React Aria Components",
5
5
  "license": "Apache-2.0",
6
6
  "main": "src/index.js",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "1e98470a549563b15e7e449a8297fd2038ed34bc"
28
+ "gitHead": "4122e44d1991c90507d630d35ed297f89db435d3"
29
29
  }
package/src/index.js CHANGED
@@ -64,32 +64,40 @@ const nativeVariantSelectors = new Map([
64
64
  let getSelector = (prefix, attributeName, attributeValue) => {
65
65
  let baseSelector = attributeValue ? `[data-${attributeName}="${attributeValue}"]` : `[data-${attributeName}]`;
66
66
  if (prefix === '' && nativeVariantSelectors.has(attributeName)) {
67
- return `&:is([data-rac]${baseSelector}, :not([data-rac])${nativeVariantSelectors.get(attributeName)})`;
67
+ return [`&:where([data-rac])${baseSelector}`, `&:where(:not([data-rac]))${nativeVariantSelectors.get(attributeName)}`];
68
68
  } else {
69
69
  return `&${baseSelector}`;
70
70
  }
71
71
  };
72
72
 
73
+ let mapSelector = (selector, fn) => {
74
+ if (Array.isArray(selector)) {
75
+ return selector.map(fn);
76
+ } else {
77
+ return fn(selector);
78
+ }
79
+ };
80
+
73
81
  module.exports = plugin.withOptions((options) => (({addVariant}) => {
74
82
  let prefix = options?.prefix ? `${options.prefix}-` : '';
75
83
  attributes.boolean.forEach((attribute) => {
76
84
  let variantName = Array.isArray(attribute) ? attribute[0] : attribute;
77
85
  variantName = `${prefix}${variantName}`;
78
86
  let attributeName = Array.isArray(attribute) ? attribute[1] : attribute;
79
- let selector = getSelector(prefix, attributeName);
80
- addVariant(variantName, selector);
81
- addVariant(`group-${variantName}`, `:merge(.group)${selector.slice(1)} &`);
82
- addVariant(`peer-${variantName}`, `:merge(.peer)${selector.slice(1)} ~ &`);
87
+ let selectors = getSelector(prefix, attributeName);
88
+ addVariant(variantName, selectors);
89
+ addVariant(`group-${variantName}`, mapSelector(selectors, selector => `:merge(.group)${selector.slice(1)} &`));
90
+ addVariant(`peer-${variantName}`, mapSelector(selectors, selector => `:merge(.peer)${selector.slice(1)} ~ &`));
83
91
  });
84
92
  Object.keys(attributes.enum).forEach((attributeName) => {
85
93
  attributes.enum[attributeName].forEach(
86
94
  (attributeValue) => {
87
95
  let name = shortNames[attributeName] || attributeName;
88
96
  let variantName = `${prefix}${name}-${attributeValue}`;
89
- let selector = getSelector(prefix, attributeName, attributeValue);
90
- addVariant(variantName, selector);
91
- addVariant(`group-${variantName}`, `:merge(.group)${selector.slice(1)} &`);
92
- addVariant(`peer-${variantName}`, `:merge(.peer)${selector.slice(1)} ~ &`);
97
+ let selectors = getSelector(prefix, attributeName, attributeValue);
98
+ addVariant(variantName, selectors);
99
+ addVariant(`group-${variantName}`, mapSelector(selectors, selector => `:merge(.group)${selector.slice(1)} &`));
100
+ addVariant(`peer-${variantName}`, mapSelector(selectors, selector => `:merge(.peer)${selector.slice(1)} ~ &`));
93
101
  }
94
102
  );
95
103
  });
package/src/index.test.js CHANGED
@@ -23,22 +23,46 @@ function run({options, content}) {
23
23
  }
24
24
 
25
25
  test('variants', async () => {
26
- let content = html`<div data-rac className="hover:bg-red focus:bg-red focus-visible:bg-red focus-within:bg-red pressed:bg-red disabled:bg-red drop-target:bg-red dragging:bg-red empty:bg-red allows-dragging:bg-red allows-removing:bg-red allows-sorting:bg-red placeholder-shown:bg-red selected:bg-red indeterminate:bg-red read-only:bg-red required:bg-red entering:bg-red exiting:bg-red open:bg-red unavailable:bg-red outside-month:bg-red outside-visible-range:bg-red selection-start:bg-red selection-end:bg-red current:bg-red invalid:bg-red resizing:bg-red placement-left:bg-red placement-right:bg-red placement-top:bg-red placement-bottom:bg-red type-literal:bg-red type-year:bg-red type-month:bg-red type-day:bg-red layout-grid:bg-red layout-stack:bg-red orientation-horizontal:bg-red orientation-vertical:bg-red selection-single:bg-red selection-multiple:bg-red resizable-right:bg-red resizable-left:bg-red resizable-both:bg-red sort-ascending:bg-red sort-descending:bg-red group-pressed:bg-red peer-pressed:bg-red"></div>`;
26
+ let content = html`<div data-rac className="hover:bg-red focus:bg-red focus-visible:bg-red focus-within:bg-red pressed:bg-red disabled:bg-red drop-target:bg-red dragging:bg-red empty:bg-red allows-dragging:bg-red allows-removing:bg-red allows-sorting:bg-red placeholder-shown:bg-red selected:bg-red indeterminate:bg-red read-only:bg-red required:bg-red entering:bg-red exiting:bg-red open:bg-red unavailable:bg-red outside-month:bg-red outside-visible-range:bg-red selection-start:bg-red selection-end:bg-red current:bg-red invalid:bg-red resizing:bg-red placement-left:bg-red placement-right:bg-red placement-top:bg-red placement-bottom:bg-red type-literal:bg-red type-year:bg-red type-month:bg-red type-day:bg-red layout-grid:bg-red layout-stack:bg-red orientation-horizontal:bg-red orientation-vertical:bg-red selection-single:bg-red selection-multiple:bg-red resizable-right:bg-red resizable-left:bg-red resizable-both:bg-red sort-ascending:bg-red sort-descending:bg-red group-pressed:bg-red peer-pressed:bg-red group-hover:bg-red"></div>`;
27
27
  return run({content}).then((result) => {
28
28
  expect(result.css).toContain(css`
29
- .hover\:bg-red:is([data-rac][data-hovered], :not([data-rac]):hover) {
29
+ .hover\:bg-red:where([data-rac])[data-hovered] {
30
30
  --tw-bg-opacity: 1;
31
31
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
32
32
  }
33
- .focus\:bg-red:is([data-rac][data-focused], :not([data-rac]):focus) {
33
+ .hover\:bg-red:where(:not([data-rac])):hover {
34
34
  --tw-bg-opacity: 1;
35
35
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
36
36
  }
37
- .focus-visible\:bg-red:is([data-rac][data-focus-visible], :not([data-rac]):focus-visible) {
37
+ .group:where([data-rac])[data-hovered] .group-hover\:bg-red {
38
38
  --tw-bg-opacity: 1;
39
39
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
40
40
  }
41
- .focus-within\:bg-red:is([data-rac][data-focus-within], :not([data-rac]):focus-within) {
41
+ .group:where(:not([data-rac])):hover .group-hover\:bg-red {
42
+ --tw-bg-opacity: 1;
43
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
44
+ }
45
+ .focus\:bg-red:where([data-rac])[data-focused] {
46
+ --tw-bg-opacity: 1;
47
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
48
+ }
49
+ .focus\:bg-red:where(:not([data-rac])):focus {
50
+ --tw-bg-opacity: 1;
51
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
52
+ }
53
+ .focus-visible\:bg-red:where([data-rac])[data-focus-visible] {
54
+ --tw-bg-opacity: 1;
55
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
56
+ }
57
+ .focus-visible\:bg-red:where(:not([data-rac])):focus-visible {
58
+ --tw-bg-opacity: 1;
59
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
60
+ }
61
+ .focus-within\:bg-red:where([data-rac])[data-focus-within] {
62
+ --tw-bg-opacity: 1;
63
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
64
+ }
65
+ .focus-within\:bg-red:where(:not([data-rac])):focus-within {
42
66
  --tw-bg-opacity: 1;
43
67
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
44
68
  }
@@ -54,7 +78,11 @@ test('variants', async () => {
54
78
  --tw-bg-opacity: 1;
55
79
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
56
80
  }
57
- .disabled\:bg-red:is([data-rac][data-disabled], :not([data-rac]):disabled) {
81
+ .disabled\:bg-red:where([data-rac])[data-disabled] {
82
+ --tw-bg-opacity: 1;
83
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
84
+ }
85
+ .disabled\:bg-red:where(:not([data-rac])):disabled {
58
86
  --tw-bg-opacity: 1;
59
87
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
60
88
  }
@@ -66,7 +94,11 @@ test('variants', async () => {
66
94
  --tw-bg-opacity: 1;
67
95
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
68
96
  }
69
- .empty\:bg-red:is([data-rac][data-empty], :not([data-rac]):empty) {
97
+ .empty\:bg-red:where([data-rac])[data-empty] {
98
+ --tw-bg-opacity: 1;
99
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
100
+ }
101
+ .empty\:bg-red:where(:not([data-rac])):empty {
70
102
  --tw-bg-opacity: 1;
71
103
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
72
104
  }
@@ -82,7 +114,11 @@ test('variants', async () => {
82
114
  --tw-bg-opacity: 1;
83
115
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
84
116
  }
85
- .placeholder-shown\:bg-red:is([data-rac][data-placeholder], :not([data-rac]):placeholder-shown) {
117
+ .placeholder-shown\:bg-red:where([data-rac])[data-placeholder] {
118
+ --tw-bg-opacity: 1;
119
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
120
+ }
121
+ .placeholder-shown\:bg-red:where(:not([data-rac])):placeholder-shown {
86
122
  --tw-bg-opacity: 1;
87
123
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
88
124
  }
@@ -90,15 +126,27 @@ test('variants', async () => {
90
126
  --tw-bg-opacity: 1;
91
127
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
92
128
  }
93
- .indeterminate\:bg-red:is([data-rac][data-indeterminate], :not([data-rac]):indeterminate) {
129
+ .indeterminate\:bg-red:where([data-rac])[data-indeterminate] {
94
130
  --tw-bg-opacity: 1;
95
131
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
96
132
  }
97
- .read-only\:bg-red:is([data-rac][data-readonly], :not([data-rac]):read-only) {
133
+ .indeterminate\:bg-red:where(:not([data-rac])):indeterminate {
98
134
  --tw-bg-opacity: 1;
99
135
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
100
136
  }
101
- .required\:bg-red:is([data-rac][data-required], :not([data-rac]):required) {
137
+ .read-only\:bg-red:where([data-rac])[data-readonly] {
138
+ --tw-bg-opacity: 1;
139
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
140
+ }
141
+ .read-only\:bg-red:where(:not([data-rac])):read-only {
142
+ --tw-bg-opacity: 1;
143
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
144
+ }
145
+ .required\:bg-red:where([data-rac])[data-required] {
146
+ --tw-bg-opacity: 1;
147
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
148
+ }
149
+ .required\:bg-red:where(:not([data-rac])):required {
102
150
  --tw-bg-opacity: 1;
103
151
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
104
152
  }
@@ -110,7 +158,11 @@ test('variants', async () => {
110
158
  --tw-bg-opacity: 1;
111
159
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
112
160
  }
113
- .open\:bg-red:is([data-rac][data-open], :not([data-rac])[open]) {
161
+ .open\:bg-red:where([data-rac])[data-open] {
162
+ --tw-bg-opacity: 1;
163
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
164
+ }
165
+ .open\:bg-red:where(:not([data-rac]))[open] {
114
166
  --tw-bg-opacity: 1;
115
167
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
116
168
  }
@@ -138,7 +190,11 @@ test('variants', async () => {
138
190
  --tw-bg-opacity: 1;
139
191
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
140
192
  }
141
- .invalid\:bg-red:is([data-rac][data-invalid], :not([data-rac]):invalid) {
193
+ .invalid\:bg-red:where([data-rac])[data-invalid] {
194
+ --tw-bg-opacity: 1;
195
+ background-color: rgb(255 0 0 / var(--tw-bg-opacity))
196
+ }
197
+ .invalid\:bg-red:where(:not([data-rac])):invalid {
142
198
  --tw-bg-opacity: 1;
143
199
  background-color: rgb(255 0 0 / var(--tw-bg-opacity))
144
200
  }