Skip to content

Commit e0f6dab

Browse files
committed
refactor: move polymorphic types into a separate package
1 parent d415b96 commit e0f6dab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+159
-23
lines changed

.changeset/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@reach/listbox",
1818
"@reach/machine",
1919
"@reach/menu-button",
20+
"@reach/polymorphic",
2021
"@reach/popover",
2122
"@reach/portal",
2223
"@reach/rect",

.changeset/stupid-eels-stare.md

+6

packages/accordion/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@reach/auto-id": "workspace:*",
2020
"@reach/descendants": "workspace:*",
21+
"@reach/polymorphic": "workspace:*",
2122
"@reach/utils": "workspace:*"
2223
},
2324
"devDependencies": {

packages/accordion/src/reach-accordion.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
composeEventHandlers,
2020
useStatefulRefValue,
2121
} from "@reach/utils";
22-
import type { Polymorphic } from "@reach/utils";
22+
import type * as Polymorphic from "@reach/polymorphic";
2323
import {
2424
createDescendantContext,
2525
DescendantProvider,

packages/alert-dialog/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@reach/auto-id": "workspace:*",
1717
"@reach/dialog": "workspace:*",
18+
"@reach/polymorphic": "workspace:*",
1819
"@reach/utils": "workspace:*",
1920
"tiny-invariant": "^1.2.0"
2021
},

packages/alert-dialog/src/reach-alert-dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
makeId,
4040
useComposedRefs,
4141
} from "@reach/utils";
42-
import type { Polymorphic } from "@reach/utils";
42+
import type * as Polymorphic from "@reach/polymorphic";
4343
import invariant from "tiny-invariant";
4444

4545
import type { DialogProps, DialogContentProps } from "@reach/dialog";

packages/alert/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"build": "tsup"
1414
},
1515
"dependencies": {
16+
"@reach/polymorphic": "workspace:*",
1617
"@reach/utils": "workspace:*",
1718
"@reach/visually-hidden": "workspace:*"
1819
},

packages/alert/src/reach-alert.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as React from "react";
2626
import * as ReactDOM from "react-dom";
2727
import { VisuallyHidden } from "@reach/visually-hidden";
2828
import { getOwnerDocument, useComposedRefs } from "@reach/utils";
29-
import type { Polymorphic } from "@reach/utils";
29+
import type * as Polymorphic from "@reach/polymorphic";
3030

3131
/*
3232
* Singleton state is fine because you don't server render

packages/checkbox/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"@reach/auto-id": "workspace:*",
2121
"@reach/machine": "workspace:*",
22+
"@reach/polymorphic": "workspace:*",
2223
"@reach/utils": "workspace:*"
2324
},
2425
"devDependencies": {

packages/checkbox/src/custom.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
useComposedRefs,
4040
composeEventHandlers,
4141
} from "@reach/utils";
42-
import type { Polymorphic } from "@reach/utils";
42+
import type * as Polymorphic from "@reach/polymorphic";
4343
import {
4444
internal_checkedPropToStateValue as checkedPropToStateValue,
4545
useMixedCheckbox,

packages/checkbox/src/mixed.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
useIsomorphicLayoutEffect,
3838
useComposedRefs,
3939
} from "@reach/utils";
40-
import type { Polymorphic } from "@reach/utils";
40+
import type * as Polymorphic from "@reach/polymorphic";
4141
import { assign, useCreateMachine, useMachine } from "@reach/machine";
4242
import type { MachineEventWithRefs, StateMachine } from "@reach/machine";
4343

packages/combobox/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@reach/auto-id": "workspace:*",
2020
"@reach/descendants": "workspace:*",
21+
"@reach/polymorphic": "workspace:*",
2122
"@reach/popover": "workspace:*",
2223
"@reach/portal": "workspace:*",
2324
"@reach/utils": "workspace:*"

packages/combobox/src/reach-combobox.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
useStatefulRefValue,
3232
useUpdateEffect,
3333
} from "@reach/utils";
34-
import type { Polymorphic } from "@reach/utils";
34+
import type * as Polymorphic from "@reach/polymorphic";
3535
import {
3636
createDescendantContext,
3737
DescendantProvider,

packages/dialog/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"build": "tsup"
1717
},
1818
"dependencies": {
19+
"@reach/polymorphic": "workspace:*",
1920
"@reach/portal": "workspace:*",
2021
"@reach/utils": "workspace:*",
2122
"react-focus-lock": "2.5.2",

packages/dialog/src/reach-dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
useCheckStyles,
2222
useComposedRefs,
2323
} from "@reach/utils";
24-
import type { Polymorphic } from "@reach/utils";
24+
import type * as Polymorphic from "@reach/polymorphic";
2525
import FocusLock from "react-focus-lock";
2626
import { RemoveScroll } from "react-remove-scroll";
2727

packages/disclosure/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@reach/auto-id": "workspace:*",
17+
"@reach/polymorphic": "workspace:*",
1718
"@reach/utils": "workspace:*"
1819
},
1920
"devDependencies": {

packages/disclosure/src/reach-disclosure.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
composeEventHandlers,
2424
useControlledState,
2525
} from "@reach/utils";
26-
import type { Polymorphic } from "@reach/utils";
26+
import type * as Polymorphic from "@reach/polymorphic";
2727
import { useId } from "@reach/auto-id";
2828

2929
const [DisclosureProvider, useDisclosureCtx] =

packages/dropdown/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@reach/auto-id": "workspace:*",
2020
"@reach/descendants": "workspace:*",
21+
"@reach/polymorphic": "workspace:*",
2122
"@reach/popover": "workspace:*",
2223
"@reach/utils": "workspace:*"
2324
},

packages/dropdown/src/reach-dropdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
useStatefulRefValue,
2525
makeId,
2626
} from "@reach/utils";
27-
import type { Polymorphic } from "@reach/utils";
27+
import type * as Polymorphic from "@reach/polymorphic";
2828

2929
import type { Descendant } from "@reach/descendants";
3030
import type { Position } from "@reach/popover";

packages/listbox/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@reach/auto-id": "workspace:*",
2020
"@reach/descendants": "workspace:*",
2121
"@reach/machine": "workspace:*",
22+
"@reach/polymorphic": "workspace:*",
2223
"@reach/popover": "workspace:*",
2324
"@reach/utils": "workspace:*",
2425
"tiny-invariant": "^1.2.0"

packages/menu-button/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@reach/dropdown": "workspace:*",
20+
"@reach/polymorphic": "workspace:*",
2021
"@reach/popover": "workspace:*",
2122
"@reach/utils": "workspace:*"
2223
},

packages/menu-button/src/reach-menu-button.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
useDropdownContext,
2323
} from "@reach/dropdown";
2424
import { noop, useCheckStyles } from "@reach/utils";
25-
import type { Polymorphic } from "@reach/utils";
25+
import type * as Polymorphic from "@reach/polymorphic";
2626
import { isFragment } from "react-is";
2727

2828
import type { Position } from "@reach/popover";

packages/polymorphic/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/polymorphic/CHANGELOG.md

+1

packages/polymorphic/README.md

+5

packages/polymorphic/package.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@reach/polymorphic",
3+
"version": "0.18.0-pre.3",
4+
"description": "Internal utility types for polymorphism in Reach UI.",
5+
"author": "React Training <[email protected]>",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/reach/reach-ui.git",
10+
"directory": "packages/polymorphic"
11+
},
12+
"scripts": {
13+
"build": "tsup"
14+
},
15+
"dependencies": {},
16+
"devDependencies": {
17+
"@reach-internal/dev": "workspace:*",
18+
"@reach-internal/tsconfig": "workspace:*",
19+
"react": "^17.0.2",
20+
"tsup": "^6.1.3"
21+
},
22+
"peerDependencies": {
23+
"react": "^16.8.0 || 17.x"
24+
},
25+
"main": "./src/reach-polymorphic.ts",
26+
"types": "./src/reach-polymorphic.ts",
27+
"files": [
28+
"CHANGELOG.md",
29+
"LICENSE",
30+
"README.md",
31+
"dist"
32+
],
33+
"publishConfig": {
34+
"access": "public"
35+
}
36+
}

packages/utils/src/polymorphic.ts packages/polymorphic/src/reach-polymorphic.ts

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import type * as React from "react";
88

9+
declare const __DEV__: boolean;
10+
911
type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
1012

1113
/**
@@ -69,6 +71,15 @@ interface MemoComponent<IntrinsicElementString, OwnProps = {}>
6971
): React.ReactElement | null;
7072
}
7173

74+
/** @internal */
75+
export default () => {
76+
if (__DEV__) {
77+
throw new Error(
78+
"@reach/polymorphic is a package for internal utility types and should not be used directly."
79+
);
80+
}
81+
};
82+
7283
export type {
7384
ForwardRefComponent,
7485
IntrinsicElement,

packages/polymorphic/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@reach-internal/tsconfig/react-library.json",
3+
"include": ["."],
4+
"exclude": ["node_modules", "dist", "__tests__", "examples"],
5+
"compilerOptions": {
6+
"stripInternal": true
7+
}
8+
}

packages/polymorphic/tsup.config.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { defineConfig } from "tsup";
2+
import { getTsupConfig, getPackageInfo } from "@reach-internal/dev/tsup.js";
3+
4+
type TsupConfig = ReturnType<typeof defineConfig>;
5+
6+
let { name: packageName, version: packageVersion } = getPackageInfo(
7+
// @ts-expect-error
8+
__dirname
9+
);
10+
let cfg: TsupConfig = getTsupConfig(`src/reach-polymorphic.ts`, {
11+
packageName,
12+
packageVersion,
13+
});
14+
export default cfg;

packages/popover/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"directory": "packages/popover"
1414
},
1515
"dependencies": {
16+
"@reach/polymorphic": "workspace:*",
1617
"@reach/portal": "workspace:*",
1718
"@reach/rect": "workspace:*",
1819
"@reach/utils": "workspace:*",

packages/popover/src/reach-popover.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Portal } from "@reach/portal";
77
import type { PRect } from "@reach/rect";
88
import { useRect } from "@reach/rect";
99
import { getOwnerDocument, useComposedRefs } from "@reach/utils";
10-
import type { Polymorphic } from "@reach/utils";
10+
import type * as Polymorphic from "@reach/polymorphic";
1111
import { tabbable } from "tabbable";
1212

1313
// TODO: tabbable types incorrectly exclude `document` as a param. Open a PR to

packages/skip-nav/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"build": "tsup"
1717
},
1818
"dependencies": {
19+
"@reach/polymorphic": "workspace:*",
1920
"@reach/utils": "workspace:*"
2021
},
2122
"devDependencies": {

packages/skip-nav/src/reach-skip-nav.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22
import { useCheckStyles } from "@reach/utils";
3-
import type { Polymorphic } from "@reach/utils";
3+
import type * as Polymorphic from "@reach/polymorphic";
44

55
// The user may want to provide their own ID (maybe there are multiple nav
66
// menus on a page a use might want to skip at various points in tabbing?).

packages/slider/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@reach/auto-id": "workspace:*",
20+
"@reach/polymorphic": "workspace:*",
2021
"@reach/utils": "workspace:*"
2122
},
2223
"devDependencies": {

packages/slider/src/reach-slider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
useIsomorphicLayoutEffect as useLayoutEffect,
3939
useStableLayoutCallback,
4040
} from "@reach/utils";
41-
import type { Polymorphic } from "@reach/utils";
41+
import type * as Polymorphic from "@reach/polymorphic";
4242

4343
declare const __DEV__: boolean;
4444

packages/tabs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@reach/auto-id": "workspace:*",
2020
"@reach/descendants": "workspace:*",
21+
"@reach/polymorphic": "workspace:*",
2122
"@reach/utils": "workspace:*"
2223
},
2324
"devDependencies": {

packages/tabs/src/reach-tabs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
useComposedRefs,
4343
composeEventHandlers,
4444
} from "@reach/utils";
45-
import type { Polymorphic } from "@reach/utils";
45+
import type * as Polymorphic from "@reach/polymorphic";
4646
import { useId } from "@reach/auto-id";
4747

4848
const TabsDescendantsContext = createDescendantContext<TabDescendant>(

packages/tooltip/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@reach/auto-id": "workspace:*",
20+
"@reach/polymorphic": "workspace:*",
2021
"@reach/portal": "workspace:*",
2122
"@reach/rect": "workspace:*",
2223
"@reach/utils": "workspace:*",

packages/tooltip/src/reach-tooltip.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
useComposedRefs,
5151
composeEventHandlers,
5252
} from "@reach/utils";
53-
import type { Polymorphic } from "@reach/utils";
53+
import type * as Polymorphic from "@reach/polymorphic";
5454
import { Portal } from "@reach/portal";
5555
import { VisuallyHidden } from "@reach/visually-hidden";
5656
import { useRect } from "@reach/rect";

packages/utils/src/reach-utils.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type * as Polymorphic from "./polymorphic";
2-
31
export * from "./can-use-dom";
42
export * from "./clone-valid-element";
53
export * from "./compose-event-handlers";
@@ -27,5 +25,3 @@ export * from "./use-stable-callback";
2725
export * from "./use-stateful-ref-value";
2826
export * from "./use-update-effect";
2927
export * from "./types";
30-
31-
export type { Polymorphic };

packages/visually-hidden/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"build": "tsup"
1717
},
1818
"dependencies": {
19-
"@reach/utils": "workspace:*"
19+
"@reach/polymorphic": "workspace:*"
2020
},
2121
"devDependencies": {
2222
"@reach-internal/dev": "workspace:*",

packages/visually-hidden/src/reach-visually-hidden.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import * as React from "react";
14-
import type { Polymorphic } from "@reach/utils";
14+
import type * as Polymorphic from "@reach/polymorphic";
1515

1616
/**
1717
* VisuallyHidden

0 commit comments

Comments
 (0)