Skip to content

Commit

Permalink
refactor: move polymorphic types into a separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed Oct 12, 2022
1 parent d415b96 commit e0f6dab
Show file tree
Hide file tree
Showing 43 changed files with 159 additions and 23 deletions.
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@reach/listbox",
"@reach/machine",
"@reach/menu-button",
"@reach/polymorphic",
"@reach/popover",
"@reach/portal",
"@reach/rect",
Expand Down
6 changes: 6 additions & 0 deletions .changeset/stupid-eels-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@reach/utils": minor
"@reach/polymorphic": minor
---

All `Polymorphic` types that were previously exported from `@reach/utils` have been moved to a separate package `@reach/polymorphic`. As `@reach/utils` is an internal package, this [breaking] change should not affect you [if you listened to us and did not use the package directly].
1 change: 1 addition & 0 deletions packages/accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/descendants": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/accordion/src/reach-accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
composeEventHandlers,
useStatefulRefValue,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import {
createDescendantContext,
DescendantProvider,
Expand Down
1 change: 1 addition & 0 deletions packages/alert-dialog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/dialog": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*",
"tiny-invariant": "^1.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/alert-dialog/src/reach-alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
makeId,
useComposedRefs,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import invariant from "tiny-invariant";

import type { DialogProps, DialogContentProps } from "@reach/dialog";
Expand Down
1 change: 1 addition & 0 deletions packages/alert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build": "tsup"
},
"dependencies": {
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*",
"@reach/visually-hidden": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/alert/src/reach-alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as React from "react";
import * as ReactDOM from "react-dom";
import { VisuallyHidden } from "@reach/visually-hidden";
import { getOwnerDocument, useComposedRefs } from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";

/*
* Singleton state is fine because you don't server render
Expand Down
1 change: 1 addition & 0 deletions packages/checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/machine": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/src/custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
useComposedRefs,
composeEventHandlers,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import {
internal_checkedPropToStateValue as checkedPropToStateValue,
useMixedCheckbox,
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/src/mixed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
useIsomorphicLayoutEffect,
useComposedRefs,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import { assign, useCreateMachine, useMachine } from "@reach/machine";
import type { MachineEventWithRefs, StateMachine } from "@reach/machine";

Expand Down
1 change: 1 addition & 0 deletions packages/combobox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/descendants": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/popover": "workspace:*",
"@reach/portal": "workspace:*",
"@reach/utils": "workspace:*"
Expand Down
2 changes: 1 addition & 1 deletion packages/combobox/src/reach-combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
useStatefulRefValue,
useUpdateEffect,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import {
createDescendantContext,
DescendantProvider,
Expand Down
1 change: 1 addition & 0 deletions packages/dialog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "tsup"
},
"dependencies": {
"@reach/polymorphic": "workspace:*",
"@reach/portal": "workspace:*",
"@reach/utils": "workspace:*",
"react-focus-lock": "2.5.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/dialog/src/reach-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
useCheckStyles,
useComposedRefs,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import FocusLock from "react-focus-lock";
import { RemoveScroll } from "react-remove-scroll";

Expand Down
1 change: 1 addition & 0 deletions packages/disclosure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/disclosure/src/reach-disclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
composeEventHandlers,
useControlledState,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import { useId } from "@reach/auto-id";

const [DisclosureProvider, useDisclosureCtx] =
Expand Down
1 change: 1 addition & 0 deletions packages/dropdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/descendants": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/popover": "workspace:*",
"@reach/utils": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dropdown/src/reach-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
useStatefulRefValue,
makeId,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";

import type { Descendant } from "@reach/descendants";
import type { Position } from "@reach/popover";
Expand Down
1 change: 1 addition & 0 deletions packages/listbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@reach/auto-id": "workspace:*",
"@reach/descendants": "workspace:*",
"@reach/machine": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/popover": "workspace:*",
"@reach/utils": "workspace:*",
"tiny-invariant": "^1.2.0"
Expand Down
1 change: 1 addition & 0 deletions packages/menu-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@reach/dropdown": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/popover": "workspace:*",
"@reach/utils": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/menu-button/src/reach-menu-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
useDropdownContext,
} from "@reach/dropdown";
import { noop, useCheckStyles } from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import { isFragment } from "react-is";

import type { Position } from "@reach/popover";
Expand Down
1 change: 1 addition & 0 deletions packages/polymorphic/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
1 change: 1 addition & 0 deletions packages/polymorphic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @reach/polymorphic
5 changes: 5 additions & 0 deletions packages/polymorphic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @reach/polymorphic

[![Stable release](https://img.shields.io/npm/v/@reach/polymorphic.svg)](https://npm.im/@reach/polymorphic) ![MIT license](https://badgen.now.sh/badge/license/MIT)

**Important:** This package is primarily intended for internal use by the Reach UI library. You should not use it directly in your production projects, as the APIs can change at any time without regard to semver.
36 changes: 36 additions & 0 deletions packages/polymorphic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@reach/polymorphic",
"version": "0.18.0-pre.3",
"description": "Internal utility types for polymorphism in Reach UI.",
"author": "React Training <hello@reacttraining.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/reach/reach-ui.git",
"directory": "packages/polymorphic"
},
"scripts": {
"build": "tsup"
},
"dependencies": {},
"devDependencies": {
"@reach-internal/dev": "workspace:*",
"@reach-internal/tsconfig": "workspace:*",
"react": "^17.0.2",
"tsup": "^6.1.3"
},
"peerDependencies": {
"react": "^16.8.0 || 17.x"
},
"main": "./src/reach-polymorphic.ts",
"types": "./src/reach-polymorphic.ts",
"files": [
"CHANGELOG.md",
"LICENSE",
"README.md",
"dist"
],
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import type * as React from "react";

declare const __DEV__: boolean;

type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;

/**
Expand Down Expand Up @@ -69,6 +71,15 @@ interface MemoComponent<IntrinsicElementString, OwnProps = {}>
): React.ReactElement | null;
}

/** @internal */
export default () => {
if (__DEV__) {
throw new Error(
"@reach/polymorphic is a package for internal utility types and should not be used directly."
);
}
};

export type {
ForwardRefComponent,
IntrinsicElement,
Expand Down
8 changes: 8 additions & 0 deletions packages/polymorphic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@reach-internal/tsconfig/react-library.json",
"include": ["."],
"exclude": ["node_modules", "dist", "__tests__", "examples"],
"compilerOptions": {
"stripInternal": true
}
}
14 changes: 14 additions & 0 deletions packages/polymorphic/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { defineConfig } from "tsup";
import { getTsupConfig, getPackageInfo } from "@reach-internal/dev/tsup.js";

type TsupConfig = ReturnType<typeof defineConfig>;

let { name: packageName, version: packageVersion } = getPackageInfo(
// @ts-expect-error
__dirname
);
let cfg: TsupConfig = getTsupConfig(`src/reach-polymorphic.ts`, {
packageName,
packageVersion,
});
export default cfg;
1 change: 1 addition & 0 deletions packages/popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"directory": "packages/popover"
},
"dependencies": {
"@reach/polymorphic": "workspace:*",
"@reach/portal": "workspace:*",
"@reach/rect": "workspace:*",
"@reach/utils": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/popover/src/reach-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Portal } from "@reach/portal";
import type { PRect } from "@reach/rect";
import { useRect } from "@reach/rect";
import { getOwnerDocument, useComposedRefs } from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import { tabbable } from "tabbable";

// TODO: tabbable types incorrectly exclude `document` as a param. Open a PR to
Expand Down
1 change: 1 addition & 0 deletions packages/skip-nav/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "tsup"
},
"dependencies": {
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/skip-nav/src/reach-skip-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { useCheckStyles } from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";

// The user may want to provide their own ID (maybe there are multiple nav
// menus on a page a use might want to skip at various points in tabbing?).
Expand Down
1 change: 1 addition & 0 deletions packages/slider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/slider/src/reach-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
useIsomorphicLayoutEffect as useLayoutEffect,
useStableLayoutCallback,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";

declare const __DEV__: boolean;

Expand Down
1 change: 1 addition & 0 deletions packages/tabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/descendants": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/utils": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/tabs/src/reach-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
useComposedRefs,
composeEventHandlers,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import { useId } from "@reach/auto-id";

const TabsDescendantsContext = createDescendantContext<TabDescendant>(
Expand Down
1 change: 1 addition & 0 deletions packages/tooltip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@reach/auto-id": "workspace:*",
"@reach/polymorphic": "workspace:*",
"@reach/portal": "workspace:*",
"@reach/rect": "workspace:*",
"@reach/utils": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/tooltip/src/reach-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
useComposedRefs,
composeEventHandlers,
} from "@reach/utils";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";
import { Portal } from "@reach/portal";
import { VisuallyHidden } from "@reach/visually-hidden";
import { useRect } from "@reach/rect";
Expand Down
4 changes: 0 additions & 4 deletions packages/utils/src/reach-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type * as Polymorphic from "./polymorphic";

export * from "./can-use-dom";
export * from "./clone-valid-element";
export * from "./compose-event-handlers";
Expand Down Expand Up @@ -27,5 +25,3 @@ export * from "./use-stable-callback";
export * from "./use-stateful-ref-value";
export * from "./use-update-effect";
export * from "./types";

export type { Polymorphic };
2 changes: 1 addition & 1 deletion packages/visually-hidden/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "tsup"
},
"dependencies": {
"@reach/utils": "workspace:*"
"@reach/polymorphic": "workspace:*"
},
"devDependencies": {
"@reach-internal/dev": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/visually-hidden/src/reach-visually-hidden.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import * as React from "react";
import type { Polymorphic } from "@reach/utils";
import type * as Polymorphic from "@reach/polymorphic";

/**
* VisuallyHidden
Expand Down
Loading

0 comments on commit e0f6dab

Please sign in to comment.