Skip to content

Commit 1bb07f9

Browse files
author
Chance Strickland
committed
break utils into entrypoints and update imports
1 parent 80f6ca5 commit 1bb07f9

File tree

91 files changed

+1237
-1087
lines changed

Some content is hidden

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

91 files changed

+1237
-1087
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pids
1818
/doc.json
1919

2020
# bundled files
21-
/packages/*/dist
21+
/packages/*/**/dist
2222
/packages/*/errors
2323

2424
# editor specific

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@babel/preset-react": "^7.12.10",
3030
"@babel/preset-typescript": "^7.12.7",
3131
"@manypkg/cli": "^0.17.0",
32-
"@preconstruct/cli": "^2.0.1",
32+
"@preconstruct/cli": "^2.0.6",
3333
"@reach/router": "^1.3.4",
3434
"@storybook/addon-actions": "^6.0.28",
3535
"@storybook/addon-docs": "^6.0.28",

packages/accordion/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@reach/descendants": "0.14.0",
1616
"@reach/utils": "0.14.0",
1717
"prop-types": "^15.7.2",
18+
"tiny-warning": "^1.0.3",
1819
"tslib": "^2.1.0"
1920
},
2021
"devDependencies": {

packages/accordion/src/index.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99
*/
1010

1111
import * as React from "react";
12-
import {
13-
createNamedContext,
14-
forwardRefWithAs,
15-
isBoolean,
16-
isNumber,
17-
makeId,
18-
noop,
19-
useCheckStyles,
20-
useForkedRef,
21-
warning,
22-
wrapEvent,
23-
} from "@reach/utils";
12+
import { createNamedContext } from "@reach/utils/context";
13+
import { forwardRefWithAs } from "@reach/utils/polymorphic";
14+
import { isBoolean, isNumber } from "@reach/utils/type-check";
15+
import { makeId } from "@reach/utils/make-id";
16+
import { noop } from "@reach/utils/noop";
17+
import { useCheckStyles } from "@reach/utils/dev-utils";
18+
import { useComposedRefs } from "@reach/utils/compose-refs";
19+
import { composeEventHandlers } from "@reach/utils/compose-event-handlers";
20+
import warning from "tiny-warning";
2421
import {
2522
createDescendantContext,
2623
DescendantProvider,
@@ -462,7 +459,7 @@ const AccordionButton = forwardRefWithAs<AccordionButtonProps, "button">(
462459
state,
463460
} = React.useContext(AccordionItemContext);
464461

465-
let ref = useForkedRef(forwardedRef, ownRef);
462+
let ref = useComposedRefs(forwardedRef, ownRef);
466463

467464
function handleClick(event: React.MouseEvent) {
468465
event.preventDefault();
@@ -530,8 +527,8 @@ const AccordionButton = forwardRefWithAs<AccordionButtonProps, "button">(
530527
// https://www.w3.org/TR/wai-aria-practices-1.2/#accordion
531528
disabled={disabled || undefined}
532529
id={buttonId}
533-
onClick={wrapEvent(onClick, handleClick)}
534-
onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}
530+
onClick={composeEventHandlers(onClick, handleClick)}
531+
onKeyDown={composeEventHandlers(onKeyDown, handleKeyDown)}
535532
>
536533
{children}
537534
</Comp>

packages/alert-dialog/src/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
import * as React from "react";
3434
import { DialogOverlay, DialogContent } from "@reach/dialog";
3535
import { useId } from "@reach/auto-id";
36-
import {
37-
createNamedContext,
38-
forwardRefWithAs,
39-
getOwnerDocument,
40-
makeId,
41-
useForkedRef,
42-
} from "@reach/utils";
36+
import { getOwnerDocument } from "@reach/utils/owner-document";
37+
import { createNamedContext } from "@reach/utils/context";
38+
import { forwardRefWithAs } from "@reach/utils/polymorphic";
39+
import { makeId } from "@reach/utils/make-id";
40+
import { useComposedRefs } from "@reach/utils/compose-refs";
4341
import invariant from "invariant";
4442
import PropTypes from "prop-types";
4543

@@ -66,7 +64,7 @@ let AlertDialogContext = createNamedContext<AlertDialogContextValue>(
6664
const AlertDialogOverlay = forwardRefWithAs<AlertDialogProps, "div">(
6765
function AlertDialogOverlay({ leastDestructiveRef, ...props }, forwardedRef) {
6866
let ownRef = React.useRef<HTMLDivElement | null>(null);
69-
let ref = useForkedRef(forwardedRef, ownRef);
67+
let ref = useComposedRefs(forwardedRef, ownRef);
7068
let id = useId(props.id);
7169
let labelId = id ? makeId("alert-dialog", id) : undefined;
7270
let descriptionId = id ? makeId("alert-dialog-description", id) : undefined;

packages/alert/src/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
import * as React from "react";
2626
import * as ReactDOM from "react-dom";
2727
import { VisuallyHidden } from "@reach/visually-hidden";
28-
import {
29-
forwardRefWithAs,
30-
getOwnerDocument,
31-
usePrevious,
32-
useForkedRef,
33-
} from "@reach/utils";
28+
import { usePrevious } from "@reach/utils/use-previous";
29+
import { getOwnerDocument } from "@reach/utils/owner-document";
30+
import { forwardRefWithAs } from "@reach/utils/polymorphic";
31+
import { useComposedRefs } from "@reach/utils/compose-refs";
3432
import PropTypes from "prop-types";
3533

3634
/*
@@ -70,7 +68,7 @@ const Alert = forwardRefWithAs<AlertProps, "div">(function Alert(
7068
forwardedRef
7169
) {
7270
const ownRef = React.useRef<HTMLDivElement>(null);
73-
const ref = useForkedRef(forwardedRef, ownRef);
71+
const ref = useComposedRefs(forwardedRef, ownRef);
7472
const child = React.useMemo(
7573
() => (
7674
<Comp {...props} ref={ref} data-reach-alert>

packages/auto-id/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*/
5656

5757
import * as React from "react";
58-
import { useIsomorphicLayoutEffect } from "@reach/utils";
58+
import { useIsomorphicLayoutEffect as useLayoutEffect } from "@reach/utils/use-isomorphic-layout-effect";
5959

6060
let serverHandoffComplete = false;
6161
let id = 0;
@@ -84,7 +84,7 @@ function useId(idFromProps?: string | null) {
8484

8585
const [id, setId] = React.useState(initialId);
8686

87-
useIsomorphicLayoutEffect(() => {
87+
useLayoutEffect(() => {
8888
if (id === null) {
8989
/*
9090
* Patch the ID after render. We do this in `useLayoutEffect` to avoid any

packages/checkbox/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@reach/machine": "0.14.0",
1717
"@reach/utils": "0.14.0",
1818
"prop-types": "^15.7.2",
19+
"tiny-warning": "^1.0.3",
1920
"tslib": "^2.1.0"
2021
},
2122
"devDependencies": {

packages/checkbox/src/custom.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
/* eslint-disable jsx-a11y/no-static-element-interactions */
3333

3434
import * as React from "react";
35-
import {
36-
createNamedContext,
37-
forwardRefWithAs,
38-
isFunction,
39-
useCheckStyles,
40-
useForkedRef,
41-
wrapEvent,
42-
} from "@reach/utils";
35+
import { createNamedContext } from "@reach/utils/context";
36+
import { forwardRefWithAs } from "@reach/utils/polymorphic";
37+
import { isFunction } from "@reach/utils/type-check";
38+
import { useCheckStyles } from "@reach/utils/dev-utils";
39+
import { useComposedRefs } from "@reach/utils/compose-refs";
40+
import { composeEventHandlers } from "@reach/utils/compose-event-handlers";
4341
import {
4442
internal_checkedPropToStateValue as checkedPropToStateValue,
4543
internal_useControlledSwitchWarning as useControlledSwitchWarning,
@@ -121,7 +119,7 @@ const CustomCheckboxContainer = forwardRefWithAs<
121119
data-reach-custom-checkbox-container=""
122120
data-focused={focused ? "" : undefined}
123121
data-state={checkedPropToStateValue(stateData.checked)}
124-
onClick={wrapEvent(onClick, handleClick)}
122+
onClick={composeEventHandlers(onClick, handleClick)}
125123
>
126124
{isFunction(children)
127125
? children({
@@ -229,7 +227,7 @@ const CustomCheckboxInput = forwardRefWithAs<CustomCheckboxInputProps, "input">(
229227
setFocused,
230228
} = useCustomCheckboxContext();
231229

232-
let ref = useForkedRef(forwardedRef, inputRef);
230+
let ref = useComposedRefs(forwardedRef, inputRef);
233231
let mounted = React.useRef(true);
234232

235233
function handleBlur() {
@@ -260,8 +258,8 @@ const CustomCheckboxInput = forwardRefWithAs<CustomCheckboxInputProps, "input">(
260258
type="checkbox"
261259
data-reach-custom-checkbox-input=""
262260
data-focused={focused ? "" : undefined}
263-
onBlur={wrapEvent(onBlur, handleBlur)}
264-
onFocus={wrapEvent(onFocus, handleFocus)}
261+
onBlur={composeEventHandlers(onBlur, handleBlur)}
262+
onFocus={composeEventHandlers(onFocus, handleFocus)}
265263
/>
266264
);
267265
}

packages/checkbox/src/mixed.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
*/
3333

3434
import * as React from "react";
35-
import {
36-
forwardRefWithAs,
37-
useForkedRef,
38-
useIsomorphicLayoutEffect,
39-
warning,
40-
wrapEvent,
41-
} from "@reach/utils";
35+
import { useIsomorphicLayoutEffect } from "@reach/utils/use-isomorphic-layout-effect";
36+
import { forwardRefWithAs } from "@reach/utils/polymorphic";
37+
import { useComposedRefs } from "@reach/utils/compose-refs";
38+
import { composeEventHandlers } from "@reach/utils/compose-event-handlers";
4239
import { assign, useCreateMachine, useMachine } from "@reach/machine";
40+
import warning from "tiny-warning";
4341
import PropTypes from "prop-types";
4442

4543
import type { MachineEventWithRefs, StateMachine } from "@reach/machine";
@@ -212,7 +210,7 @@ const MixedCheckbox = forwardRefWithAs<
212210
forwardedRef
213211
) {
214212
let ownRef: MixedCheckboxInputRef = React.useRef(null);
215-
let ref = useForkedRef(forwardedRef, ownRef);
213+
let ref = useComposedRefs(forwardedRef, ownRef);
216214
let [inputProps] = useMixedCheckbox(
217215
ownRef,
218216
{
@@ -312,8 +310,8 @@ function useMixedCheckbox(
312310
"aria-checked": stateValueToAriaChecked(current.value),
313311
checked: stateValueToChecked(current.value),
314312
disabled: !!disabled,
315-
onChange: wrapEvent(onChange, handleChange),
316-
onClick: wrapEvent(onClick, handleClick),
313+
onChange: composeEventHandlers(onChange, handleChange),
314+
onClick: composeEventHandlers(onClick, handleClick),
317315
type: "checkbox",
318316
};
319317

0 commit comments

Comments
 (0)