Skip to content

Commit 9009dea

Browse files
authored
[chore] Update component React imports following New JSX Transform (#7500)
1 parent 3457fa9 commit 9009dea

419 files changed

Lines changed: 1766 additions & 1907 deletions

File tree

Some content is hidden

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

packages/core/src/accessibility/useInteractiveAttributes.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
33
*/
44

5-
import * as React from "react";
5+
import { useCallback, useRef, useState } from "react";
66

77
import { mergeRefs, Utils } from "../common";
88

@@ -35,13 +35,13 @@ export function useInteractiveAttributes<E extends HTMLElement>(
3535
const { defaultTabIndex, disabledTabIndex } = options;
3636
const { active, onClick, onFocus, onKeyDown, onKeyUp, onBlur, tabIndex = defaultTabIndex } = props;
3737
// the current key being pressed
38-
const [currentKeyPressed, setCurrentKeyPressed] = React.useState<string | undefined>();
38+
const [currentKeyPressed, setCurrentKeyPressed] = useState<string | undefined>();
3939
// whether the button is in "active" state
40-
const [isActive, setIsActive] = React.useState(false);
40+
const [isActive, setIsActive] = useState(false);
4141
// our local ref for the interactive element, merged with the consumer's own ref in this hook's return value
42-
const elementRef = React.useRef<E | null>(null);
42+
const elementRef = useRef<E | null>(null);
4343

44-
const handleBlur = React.useCallback(
44+
const handleBlur = useCallback(
4545
(e: React.FocusEvent<E>) => {
4646
if (isActive) {
4747
setIsActive(false);
@@ -52,7 +52,7 @@ export function useInteractiveAttributes<E extends HTMLElement>(
5252
[isActive, onBlur],
5353
);
5454

55-
const handleKeyDown = React.useCallback(
55+
const handleKeyDown = useCallback(
5656
(e: React.KeyboardEvent<E>) => {
5757
if (Utils.isKeyboardClick(e)) {
5858
e.preventDefault();
@@ -67,7 +67,7 @@ export function useInteractiveAttributes<E extends HTMLElement>(
6767
[currentKeyPressed, onKeyDown],
6868
);
6969

70-
const handleKeyUp = React.useCallback(
70+
const handleKeyUp = useCallback(
7171
(e: React.KeyboardEvent<E>) => {
7272
if (Utils.isKeyboardClick(e)) {
7373
setIsActive(false);

packages/core/src/common/abstractComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as React from "react";
17+
import { Component } from "react";
1818

1919
import { isNodeEnv } from "./utils";
2020

@@ -23,7 +23,7 @@ import { isNodeEnv } from "./utils";
2323
* in order to add some common functionality like runtime props validation.
2424
*/
2525
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
26-
export abstract class AbstractComponent<P, S = {}, SS = {}> extends React.Component<P, S, SS> {
26+
export abstract class AbstractComponent<P, S = {}, SS = {}> extends Component<P, S, SS> {
2727
// unsafe lifecycle methods
2828
public componentWillUpdate!: never;
2929

packages/core/src/common/abstractPureComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as React from "react";
17+
import { PureComponent } from "react";
1818

1919
import { isNodeEnv } from "./utils";
2020

@@ -23,7 +23,7 @@ import { isNodeEnv } from "./utils";
2323
* in order to add some common functionality like runtime props validation.
2424
*/
2525
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
26-
export abstract class AbstractPureComponent<P, S = {}, SS = {}> extends React.PureComponent<P, S, SS> {
26+
export abstract class AbstractPureComponent<P, S = {}, SS = {}> extends PureComponent<P, S, SS> {
2727
// unsafe lifecycle method
2828
public componentWillUpdate!: never;
2929

packages/core/src/common/props.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type * as React from "react";
18-
1917
import type { IconName } from "@blueprintjs/icons";
2018

2119
import type { Intent } from "./intent";

packages/core/src/common/refs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type * as React from "react";
18-
1917
export function isRefObject<T>(value: React.Ref<T> | undefined): value is React.RefObject<T> {
2018
return value != null && typeof value !== "function";
2119
}

packages/core/src/common/utils/reactUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as React from "react";
17+
import { cloneElement, createElement } from "react";
1818

1919
import { isEmptyString } from "./jsUtils";
2020

@@ -69,11 +69,11 @@ export function ensureElement(
6969
isReactNodeArray(child)
7070
) {
7171
// wrap the child element
72-
return React.createElement(tagName, props, child);
72+
return createElement(tagName, props, child);
7373
} else if (isReactElement(child)) {
7474
if (Object.keys(props).length > 0) {
7575
// clone the element and merge props
76-
return React.cloneElement(child, props);
76+
return cloneElement(child, props);
7777
} else {
7878
// nothing to do, it's a valid ReactElement
7979
return child;

packages/core/src/components/alert/alert.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import classNames from "classnames";
18-
import * as React from "react";
18+
import { useCallback } from "react";
1919

2020
import { Classes, DISPLAYNAME_PREFIX, type Intent, type MaybeElement, type Props } from "../../common";
2121
import {
@@ -170,20 +170,20 @@ export const Alert: React.FC<AlertProps> = props => {
170170
}
171171
}, [canEscapeKeyCancel, canOutsideClickCancel, cancelButtonText, onCancel, onClose]);
172172

173-
const internalHandleCallbacks = React.useCallback(
173+
const internalHandleCallbacks = useCallback(
174174
(confirmed: boolean, event?: React.SyntheticEvent<HTMLElement>) => {
175175
(confirmed ? onConfirm : onCancel)?.(event);
176176
onClose?.(confirmed, event);
177177
},
178178
[onCancel, onClose, onConfirm],
179179
);
180180

181-
const handleCancel = React.useCallback(
181+
const handleCancel = useCallback(
182182
(event?: React.SyntheticEvent<HTMLElement>) => internalHandleCallbacks(false, event),
183183
[internalHandleCallbacks],
184184
);
185185

186-
const handleConfirm = React.useCallback(
186+
const handleConfirm = useCallback(
187187
(event: React.SyntheticEvent<HTMLElement>) => internalHandleCallbacks(true, event),
188188
[internalHandleCallbacks],
189189
);

packages/core/src/components/breadcrumbs/breadcrumb.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import classNames from "classnames";
18-
import * as React from "react";
1918

2019
import { type ActionProps, Classes, type LinkProps } from "../../common";
2120
import { Icon } from "../icon/icon";

packages/core/src/components/breadcrumbs/breadcrumbs.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import classNames from "classnames";
18-
import * as React from "react";
1918

2019
import { AbstractPureComponent, Boundary, Classes, type Props, removeNonHTMLProps } from "../../common";
2120
import { Menu } from "../menu/menu";

packages/core/src/components/button/buttonGroup.tsx

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import classNames from "classnames";
18-
import * as React from "react";
18+
import { forwardRef } from "react";
1919

2020
import { type Alignment, type ButtonVariant, Classes, type Size } from "../../common";
2121
import { DISPLAYNAME_PREFIX, type HTMLDivProps, type Props } from "../../common/props";
@@ -92,40 +92,38 @@ export interface ButtonGroupProps extends Props, HTMLDivProps, React.RefAttribut
9292
*
9393
* @see https://blueprintjs.com/docs/#core/components/button-group
9494
*/
95-
export const ButtonGroup: React.FC<ButtonGroupProps> = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
96-
(props, ref) => {
97-
const {
98-
alignText,
99-
className,
100-
fill,
101-
// eslint-disable-next-line @typescript-eslint/no-deprecated
102-
minimal,
103-
// eslint-disable-next-line @typescript-eslint/no-deprecated
104-
outlined,
105-
// eslint-disable-next-line @typescript-eslint/no-deprecated
106-
large,
107-
size = "medium",
108-
variant = "solid",
109-
vertical,
110-
...htmlProps
111-
} = props;
95+
export const ButtonGroup: React.FC<ButtonGroupProps> = forwardRef<HTMLDivElement, ButtonGroupProps>((props, ref) => {
96+
const {
97+
alignText,
98+
className,
99+
fill,
100+
// eslint-disable-next-line @typescript-eslint/no-deprecated
101+
minimal,
102+
// eslint-disable-next-line @typescript-eslint/no-deprecated
103+
outlined,
104+
// eslint-disable-next-line @typescript-eslint/no-deprecated
105+
large,
106+
size = "medium",
107+
variant = "solid",
108+
vertical,
109+
...htmlProps
110+
} = props;
112111

113-
const buttonGroupClasses = classNames(
114-
Classes.BUTTON_GROUP,
115-
{
116-
[Classes.FILL]: fill,
117-
[Classes.VERTICAL]: vertical,
118-
},
119-
Classes.alignmentClass(alignText),
120-
Classes.sizeClass(size, { large }),
121-
Classes.variantClass(variant, { minimal, outlined }),
122-
className,
123-
);
124-
return (
125-
<div {...htmlProps} ref={ref} className={buttonGroupClasses}>
126-
{props.children}
127-
</div>
128-
);
129-
},
130-
);
112+
const buttonGroupClasses = classNames(
113+
Classes.BUTTON_GROUP,
114+
{
115+
[Classes.FILL]: fill,
116+
[Classes.VERTICAL]: vertical,
117+
},
118+
Classes.alignmentClass(alignText),
119+
Classes.sizeClass(size, { large }),
120+
Classes.variantClass(variant, { minimal, outlined }),
121+
className,
122+
);
123+
return (
124+
<div {...htmlProps} ref={ref} className={buttonGroupClasses}>
125+
{props.children}
126+
</div>
127+
);
128+
});
131129
ButtonGroup.displayName = `${DISPLAYNAME_PREFIX}.ButtonGroup`;

0 commit comments

Comments
 (0)