Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5] fix: various backwards-compatibility fixes #6141

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/common/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const INVALID_PROPS = [
"elementRef", // not used anymore in Blueprint v5.x, but kept for backcompat if consumers use this naming pattern
"fill",
"icon",
"iconSize",
"inputClassName",
"inputRef",
"intent",
Expand All @@ -135,6 +136,7 @@ const INVALID_PROPS = [
"rightElement",
"rightIcon",
"round",
"size",
"small",
"tagName",
"text",
Expand Down
26 changes: 17 additions & 9 deletions packages/core/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import * as React from "react";

import { IconComponent, IconName, Icons, IconSize, SVGIconProps } from "@blueprintjs/icons";

import { Classes, DISPLAYNAME_PREFIX, IntentProps, MaybeElement, Props } from "../../common";
import { Classes, DISPLAYNAME_PREFIX, IntentProps, MaybeElement, Props, removeNonHTMLProps } from "../../common";

// re-export for convenience, since some users won't be importing from or have a direct dependency on the icons package
export { IconName, IconSize };

export interface IconProps extends IntentProps, Props, SVGIconProps {
export type IconHTMLAttributes = Omit<React.HTMLAttributes<HTMLElement>, "children" | "title">;

export interface IconProps extends IntentProps, Props, SVGIconProps, IconHTMLAttributes {
/**
* Whether the component should automatically load icon contents using an async import.
*
Expand All @@ -49,6 +51,14 @@ export interface IconProps extends IntentProps, Props, SVGIconProps {
*/
icon: IconName | MaybeElement;

/**
* Alias for `size` prop. Kept around for backwards-compatibility with Blueprint v4.x,
* will be removed in v6.0.
*
* @deprecated use `size` prop instead
*/
iconSize?: number;

/** Props to apply to the `SVG` element */
svgProps?: React.HTMLAttributes<SVGElement>;
}
Expand All @@ -58,10 +68,7 @@ export interface IconProps extends IntentProps, Props, SVGIconProps {
*
* @see https://blueprintjs.com/docs/#core/components/icon
*/
export const Icon: React.FC<IconProps & Omit<React.HTMLAttributes<HTMLElement>, "title">> = React.forwardRef<
any,
IconProps
>((props, ref) => {
export const Icon: React.FC<IconProps> = React.forwardRef<any, IconProps>((props, ref) => {
const { icon } = props;
if (icon == null || typeof icon === "boolean") {
return null;
Expand All @@ -73,7 +80,6 @@ export const Icon: React.FC<IconProps & Omit<React.HTMLAttributes<HTMLElement>,
autoLoad,
className,
color,
size,
icon: _icon,
intent,
tagName,
Expand All @@ -83,6 +89,8 @@ export const Icon: React.FC<IconProps & Omit<React.HTMLAttributes<HTMLElement>,
...htmlProps
} = props;
const [Component, setIconComponent] = React.useState<IconComponent>();
// eslint-disable-next-line deprecation/deprecation
const size = props.size ?? props.iconSize;

React.useEffect(() => {
let shouldCancelIconLoading = false;
Expand Down Expand Up @@ -113,7 +121,7 @@ export const Icon: React.FC<IconProps & Omit<React.HTMLAttributes<HTMLElement>,
? Classes.ICON_LARGE
: undefined;
return React.createElement(tagName!, {
...htmlProps,
...removeNonHTMLProps(htmlProps),
"aria-hidden": title ? undefined : true,
className: classNames(
Classes.ICON,
Expand All @@ -138,7 +146,7 @@ export const Icon: React.FC<IconProps & Omit<React.HTMLAttributes<HTMLElement>,
htmlTitle={htmlTitle}
ref={ref}
svgProps={svgProps}
{...htmlProps}
{...removeNonHTMLProps(htmlProps)}
/>
);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export { Panel, PanelProps } from "./panel-stack2/panelTypes";
export { PopoverProps, Popover, PopoverInteractionKind } from "./popover/popover";
export {
DefaultPopoverTargetHTMLProps,
PopoverPosition,
PopoverSharedProps,
PopoverTargetProps,
PopoverClickTargetHandlers,
Expand All @@ -104,7 +105,8 @@ export { Tag, TagProps } from "./tag/tag";
export { TagInput, TagInputProps, TagInputAddMethod } from "./tag-input/tagInput";
export { OverlayToaster, OverlayToasterProps } from "./toast/overlayToaster";
export { Toast, ToastProps } from "./toast/toast";
export { Toaster, ToastOptions, ToasterPosition } from "./toast/toaster";
// eslint-disable-next-line deprecation/deprecation
export { Toaster, ToasterInstance, ToastOptions, ToasterPosition } from "./toast/toaster";
export { TooltipProps, Tooltip } from "./tooltip/tooltip";
export { Tree, TreeProps } from "./tree/tree";
export { TreeNodeInfo, TreeEventHandler } from "./tree/treeTypes";
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/components/toast/toaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ export interface Toaster {
/** Returns the props for all current toasts. */
getToasts(): ToastOptions[];
}

/** @deprecated use `Toaster` type instead */
export type ToasterInstance = Toaster;
9 changes: 7 additions & 2 deletions packages/popover2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ export {
PopoverTargetProps as Popover2TargetProps,
/** @deprecated import from @blueprintjs/core instead */
PopperBoundary,
/** @deprecated import from @blueprintjs/core instead */
PopperCustomModifier,
/**
* N.B. this misspelling was present in @blueprintjs/popover2 v4, we'll keep it around for now since it will
* be getting migrated to the correct spelling in @blueprintjs/core v5 anyway.
*
* @deprecated import from @blueprintjs/core instead (with corrected spelling)
*/
PopperCustomModifier as PopperCustomModifer,
/** @deprecated import from @blueprintjs/core instead */
PopperModifierOverrides,
/** @deprecated import from @blueprintjs/core instead */
Expand Down