Skip to content

Commit 8c1fc6a

Browse files
authored
Add monopackages for react-aria and react-stately (#1124)
* Add monopackages for react-aria and react-stately Also updates react-spectrum monopackage with new packages and exports and fixes the missing import linter for re-exports. * Add docs
1 parent d4bf06f commit 8c1fc6a

File tree

18 files changed

+413
-56
lines changed

18 files changed

+413
-56
lines changed

bin/imports.js

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,71 @@ const fs = require('fs');
1616
const Module = require('module');
1717

1818
module.exports = function (context) {
19-
return {
20-
ImportDeclaration(node) {
21-
let source = node.source.value.replace(/^[a-z]+:/, '');
22-
if (source.startsWith('.') || Module.builtinModules.includes(source)) {
23-
return;
24-
}
25-
26-
// Split the import specifier on slashes. If it starts with an @ then it's
27-
// a scoped package, otherwise just take the first part.
28-
let parts = source.split('/');
29-
let pkgName = source.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
30-
31-
// Search for a package.json starting from the current filename
32-
let pkgPath = findUp.sync('package.json', {cwd: path.dirname(context.getFilename())});
33-
if (!pkgPath) {
34-
return;
35-
}
36-
37-
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
38-
39-
// The only dev dependency should be spectrum-css.
40-
if (exists(pkg.devDependencies, pkgName) && pkgName === '@adobe/spectrum-css-temp') {
41-
return;
42-
}
43-
44-
if (!exists(pkg.dependencies, pkgName) && !exists(pkg.peerDependencies, pkgName)) {
45-
context.report({
46-
node,
47-
message: `Missing dependency on ${pkgName}.`,
48-
fix(fixer) {
49-
// Attempt to find a package in the monorepo. If the dep is for an external library,
50-
// then we cannot auto fix it because we don't know the version to add.
51-
let depPath = __dirname + '/../packages/' + pkgName + '/package.json';
52-
if (!fs.existsSync(depPath)) {
53-
return;
54-
}
55-
56-
let depPkg = JSON.parse(fs.readFileSync(depPath, 'utf8'));
57-
58-
if (pkgName === '@react-spectrum/provider') {
59-
pkg.peerDependencies = insertObject(pkg.peerDependencies, pkgName, depPkg.version);
60-
} else {
61-
pkg.dependencies = insertObject(pkg.dependencies, pkgName, depPkg.version);
62-
}
63-
64-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, false, 2) + '\n');
65-
66-
// Fake fix so eslint doesn't show the error.
67-
return {
68-
range: [0, 0],
69-
text: ''
70-
};
19+
let processNode = (node) => {
20+
if (!node.source) {
21+
return;
22+
}
23+
24+
let source = node.source.value.replace(/^[a-z]+:/, '');
25+
if (source.startsWith('.') || Module.builtinModules.includes(source)) {
26+
return;
27+
}
28+
29+
// Split the import specifier on slashes. If it starts with an @ then it's
30+
// a scoped package, otherwise just take the first part.
31+
let parts = source.split('/');
32+
let pkgName = source.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
33+
34+
// Search for a package.json starting from the current filename
35+
let pkgPath = findUp.sync('package.json', {cwd: path.dirname(context.getFilename())});
36+
if (!pkgPath) {
37+
return;
38+
}
39+
40+
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
41+
42+
// The only dev dependency should be spectrum-css.
43+
if (exists(pkg.devDependencies, pkgName) && pkgName === '@adobe/spectrum-css-temp') {
44+
return;
45+
}
46+
47+
if (!exists(pkg.dependencies, pkgName) && !exists(pkg.peerDependencies, pkgName)) {
48+
context.report({
49+
node,
50+
message: `Missing dependency on ${pkgName}.`,
51+
fix(fixer) {
52+
// Attempt to find a package in the monorepo. If the dep is for an external library,
53+
// then we cannot auto fix it because we don't know the version to add.
54+
let depPath = __dirname + '/../packages/' + pkgName + '/package.json';
55+
if (!fs.existsSync(depPath)) {
56+
return;
7157
}
72-
});
73-
}
58+
59+
let depPkg = JSON.parse(fs.readFileSync(depPath, 'utf8'));
60+
61+
if (pkgName === '@react-spectrum/provider') {
62+
pkg.peerDependencies = insertObject(pkg.peerDependencies, pkgName, depPkg.version);
63+
} else {
64+
pkg.dependencies = insertObject(pkg.dependencies, pkgName, depPkg.version);
65+
}
66+
67+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, false, 2) + '\n');
68+
69+
// Fake fix so eslint doesn't show the error.
70+
return {
71+
range: [0, 0],
72+
text: ''
73+
};
74+
}
75+
});
7476
}
7577
};
78+
79+
return {
80+
ImportDeclaration: processNode,
81+
ExportNamedDeclaration: processNode,
82+
ExportAllDeclaration: processNode
83+
};
7684
};
7785

7886
function exists(deps, name) {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"publish:nightly": "lerna publish -y --canary --preid nightly --dist-tag=nightly --exact --force-publish=* --no-push"
4040
},
4141
"workspaces": [
42+
"packages/react-stately",
43+
"packages/react-aria",
4244
"packages/*/*"
4345
],
4446
"devDependencies": {

packages/@adobe/react-spectrum/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"@react-spectrum/textfield": "^3.1.2",
5151
"@react-spectrum/theme-dark": "^3.1.0",
5252
"@react-spectrum/theme-default": "^3.1.0",
53+
"@react-spectrum/theme-light": "^3.1.0",
54+
"@react-spectrum/tooltip": "^3.0.0-alpha.0",
5355
"@react-spectrum/view": "^3.1.0",
5456
"@react-spectrum/well": "^3.1.0",
5557
"@react-stately/collections": "^3.2.0",

packages/@adobe/react-spectrum/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {Breadcrumbs} from '@react-spectrum/breadcrumbs';
1515
export {ActionButton, Button, LogicButton, ToggleButton} from '@react-spectrum/button';
1616
export {ButtonGroup} from '@react-spectrum/buttongroup';
1717
export {Checkbox, CheckboxGroup} from '@react-spectrum/checkbox';
18-
export {AlertDialog, Dialog, DialogTrigger} from '@react-spectrum/dialog';
18+
export {AlertDialog, Dialog, DialogTrigger, DialogContainer, useDialogContainer} from '@react-spectrum/dialog';
1919
export {Divider} from '@react-spectrum/divider';
2020
export {Form} from '@react-spectrum/form';
2121
export {Icon} from '@react-spectrum/icon';
@@ -38,6 +38,7 @@ export {TextArea, TextField} from '@react-spectrum/textfield';
3838
export {theme as darkTheme} from '@react-spectrum/theme-dark';
3939
export {theme as defaultTheme} from '@react-spectrum/theme-default';
4040
export {theme as lightTheme} from '@react-spectrum/theme-light';
41+
export {Tooltip, TooltipTrigger} from '@react-spectrum/tooltip';
4142
export {Content, Footer, Header, View} from '@react-spectrum/view';
4243
export {Well} from '@react-spectrum/well';
4344
export {Item, Section} from '@react-stately/collections';

packages/@react-aria/select/src/HiddenSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface HiddenSelectProps<T> extends AriaHiddenSelectProps<T> {
3939
* can be used in combination with `useSelect` to support browser form autofill, mobile form
4040
* navigation, and native HTML form submission.
4141
*/
42-
function useHiddenSelect<T>(props: AriaHiddenSelectProps<T>, state: SelectState<T>, triggerRef: RefObject<HTMLElement>) {
42+
export function useHiddenSelect<T>(props: AriaHiddenSelectProps<T>, state: SelectState<T>, triggerRef: RefObject<HTMLElement>) {
4343
let {name, isDisabled} = props;
4444
let modality = useInteractionModality();
4545
let {visuallyHiddenProps} = useVisuallyHidden();

packages/@react-spectrum/breadcrumbs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@react-spectrum/button": "^3.2.0",
4141
"@react-spectrum/menu": "^3.2.0",
4242
"@react-spectrum/utils": "^3.2.1",
43+
"@react-stately/collections": "^3.2.0",
4344
"@react-types/breadcrumbs": "^3.1.0",
4445
"@react-types/shared": "^3.2.0",
4546
"@spectrum-icons/ui": "^3.1.0"

packages/@react-spectrum/combobox/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@react-spectrum/overlays": "^3.1.0",
4545
"@react-spectrum/textfield": "^3.1.0",
4646
"@react-spectrum/utils": "^3.1.0",
47+
"@react-stately/collections": "^3.2.0",
4748
"@react-stately/combobox": "^3.0.0-alpha.1",
4849
"@react-types/combobox": "^3.0.0-alpha.1",
4950
"@react-types/overlays": "^3.1.0",

packages/@react-spectrum/picker/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@react-spectrum/provider": "^3.1.1",
4848
"@react-spectrum/text": "^3.1.0",
4949
"@react-spectrum/utils": "^3.2.1",
50+
"@react-stately/collections": "^3.2.0",
5051
"@react-stately/select": "^3.1.0",
5152
"@react-types/overlays": "^3.2.0",
5253
"@react-types/select": "^3.1.0",

packages/dev/docs/pages/react-aria/getting-started.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ You can install any React Aria package using a package manager like [npm](https:
3939
yarn add @react-aria/button
4040
```
4141

42+
We also offer a single package containing all React Aria hooks. See [below](#mono-package) for details.
43+
4244
## Building a component
4345

4446
React Aria provides behavior and accessibility through React Hooks. Since **it does not provide any rendering**,
@@ -121,6 +123,31 @@ function Checkbox(props) {
121123

122124
See the [useCheckbox](useCheckbox.html) docs for a full example of a custom styled checkbox.
123125

126+
## Mono-package
127+
128+
In addition to individual packages, we also offer a mono-package containing all of the React Aria hooks in a single
129+
package. This ensures that all packages use compatible versions and are upgraded together. If you release all components
130+
in your component library in a single package, or just want to get started easily without installing a lot of packages,
131+
the mono-package may be the way to go. It is available as the [react-aria](https://npmjs.com/package/react-aria) package
132+
on npm.
133+
134+
```
135+
yarn add react-aria
136+
```
137+
138+
Once installed, all hooks work the same way as the individual packages, but are imported from the `react-aria` package
139+
instead of individual packages.
140+
141+
```tsx
142+
// Individual packages
143+
import {useButton} from '@react-aria/button';
144+
```
145+
146+
```tsx
147+
// Monopackage
148+
import {useButton} from 'react-aria';
149+
```
150+
124151
## Next steps
125152

126153
Now that you understand how to use the hooks in React Aria to build your own components, you can read the documentation

packages/dev/docs/pages/react-stately/getting-started.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ You can install any React Stately package using a package manager like [npm](htt
4242
yarn add @react-stately/radio
4343
```
4444

45+
We also offer a single package containing all React Stately hooks. See [below](#mono-package) for details.
46+
4547
## Building a component
4648

4749
This example shows a very simple radio group component built with the [useRadioGroupState](useRadioGroupState.html) hook
@@ -86,6 +88,31 @@ If you're using React Stately on the web, see [useRadioGroup](../react-aria/useR
8688
handle more of this behavior and accessibility for you. To see an example of how React Stately manages more complex state,
8789
see [useSelectState](useSelectState.html).
8890
91+
## Mono-package
92+
93+
In addition to individual packages, we also offer a mono-package containing all of the React Stately hooks in a single
94+
package. This ensures that all packages use compatible versions and are upgraded together. If you release all components
95+
in your component library in a single package, or just want to get started easily without installing a lot of packages,
96+
the mono-package may be the way to go. It is available as the [react-stately](https://npmjs.com/package/react-stately) package
97+
on npm.
98+
99+
```
100+
yarn add react-stately
101+
```
102+
103+
Once installed, all hooks work the same way as the individual packages, but are imported from the `react-stately` package
104+
instead of individual packages.
105+
106+
```tsx
107+
// Individual packages
108+
import {useRadioGroupState} from '@react-stately/radio';
109+
```
110+
111+
```tsx
112+
// Monopackage
113+
import {useRadioGroupState} from 'react-stately';
114+
```
115+
89116
## Next steps
90117

91118
Now that you understand how to use the hooks in React Stately to build your own components, you can read the documentation

0 commit comments

Comments
 (0)