Skip to content

Commit

Permalink
Use React.JSX instead of JSX (#2424)
Browse files Browse the repository at this point in the history
  • Loading branch information
r100-stack authored Feb 7, 2025
1 parent 43d2be0 commit e93c5a3
Show file tree
Hide file tree
Showing 38 changed files with 86 additions and 80 deletions.
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type AvatarProps = {
/**
* User image to be displayed. Can be `<img>` or `<svg>` or anything else.
*/
image?: JSX.Element;
image?: React.JSX.Element;
/**
* Color of the icon. You can use `getUserColor` function to generate color from user name or email. If not provided, default background color from CSS styling will be used (hsl(72, 51%, 56%) / olive green).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const AvatarGroup = React.forwardRef((props, ref) => {

const getAvatarList = (count: number) => {
return childrenArray.slice(0, count).map((child) =>
React.cloneElement(child as JSX.Element, {
React.cloneElement(child as React.JSX.Element, {
status: undefined,
size: iconSize,
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/itwinui-react/src/core/Buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export type ButtonProps = {
/**
* Icon shown before the main button content.
*/
startIcon?: JSX.Element;
startIcon?: React.JSX.Element;
/**
* Icon shown after the main button content.
*/
endIcon?: JSX.Element;
endIcon?: React.JSX.Element;
/**
* Passes props to the button label.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Buttons/DropdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type DropdownButtonProps = {
* Pass a function that takes the `close` argument (to close the menu),
* and returns a list of `MenuItem` components.
*/
menuItems: (close: () => void) => JSX.Element[];
menuItems: (close: () => void) => React.JSX.Element[];
/**
* Style of the dropdown button.
* Use 'borderless' to hide outline.
Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Buttons/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type SplitButtonProps = ButtonProps & {
* Pass a function that takes the `close` argument (to close the menu),
* and returns a list of `MenuItem` components.
*/
menuItems: (close: () => void) => JSX.Element[];
menuItems: (close: () => void) => React.JSX.Element[];
/**
* Placement of the dropdown menu.
* @default 'bottom-end'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CarouselSlider = React.forwardRef((props, ref) => {
() =>
React.Children.map(children, (child, index) =>
React.isValidElement(child)
? React.cloneElement(child as JSX.Element, {
? React.cloneElement(child as React.JSX.Element, {
id: `${idPrefix}--slide-${index}`,
'aria-labelledby': `${idPrefix}--dot-${index}`,
index,
Expand Down
8 changes: 4 additions & 4 deletions packages/itwinui-react/src/core/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export type ComboBoxProps<T> = {
endIconProps?: React.ComponentProps<typeof ComboBoxEndIcon>;
/**
* Message shown when no options are available.
* If `JSX.Element` is provided, it will be rendered as is and won't be wrapped with `MenuExtraContent`.
* If `React.JSX.Element` is provided, it will be rendered as is and won't be wrapped with `MenuExtraContent`.
* @default 'No options found'
*/
emptyStateMessage?: React.ReactNode;
Expand All @@ -155,7 +155,7 @@ export type ComboBoxProps<T> = {
id: string;
index: number;
},
) => JSX.Element;
) => React.JSX.Element;
/**
* If enabled, virtualization is used for the scrollable dropdown list.
* Use it if you expect a very long list of items.
Expand Down Expand Up @@ -652,7 +652,7 @@ export const ComboBox = React.forwardRef(
<SelectTag key={item.label} label={item.label} />
);
})
.filter(Boolean) as JSX.Element[])
.filter(Boolean) as React.JSX.Element[])
: undefined
}
/>
Expand All @@ -678,7 +678,7 @@ export const ComboBox = React.forwardRef(
},
) as <T>(
props: ComboBoxProps<T> & { ref?: React.ForwardedRef<HTMLElement> },
) => JSX.Element;
) => React.JSX.Element;
if (process.env.NODE_ENV === 'development') {
(ComboBox as any).displayName = 'ComboBox';
}
6 changes: 3 additions & 3 deletions packages/itwinui-react/src/core/ComboBox/ComboBoxInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import { ComboBoxMultipleContainer } from './ComboBoxMultipleContainer.js';
import { ComboBoxStateContext, ComboBoxRefsContext } from './helpers.js';

type ComboBoxInputProps = { selectTags?: JSX.Element[] } & React.ComponentProps<
typeof Input
>;
type ComboBoxInputProps = {
selectTags?: React.JSX.Element[];
} & React.ComponentProps<typeof Input>;

export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
const { selectTags, size, style, ...rest } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ComboBoxInputContainer = React.forwardRef(
<StatusMessage status={status}>{message}</StatusMessage>
) : (
React.isValidElement(message) &&
React.cloneElement(message as JSX.Element, { status })
React.cloneElement(message as React.JSX.Element, { status })
)
}
ref={forwardedRef}
Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/ComboBox/ComboBoxMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const VirtualizedComboBoxMenu = (props: React.ComponentProps<'div'>) => {
const menuItem =
filteredOptions.length > 0
? getMenuItem(filteredOptions[virtualItem.index], virtualItem.index)
: (children as JSX.Element); // Here is expected empty state content
: (children as React.JSX.Element); // Here is expected empty state content
return React.cloneElement(menuItem, {
key: virtualItem.key,
ref: virtualizer.measureElement,
Expand Down
5 changes: 4 additions & 1 deletion packages/itwinui-react/src/core/ComboBox/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ type ComboBoxStateContextProps<T = unknown> = {
enableVirtualization: boolean;
filteredOptions: SelectOption<T>[];
onClickHandler?: (prop: number) => void;
getMenuItem: (option: SelectOption<T>, filteredIndex?: number) => JSX.Element;
getMenuItem: (
option: SelectOption<T>,
filteredIndex?: number,
) => React.JSX.Element;
focusedIndex: number;
setFocusedIndex: React.Dispatch<React.SetStateAction<number>>;
multiple?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions packages/itwinui-react/src/core/DropdownMenu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export type DropdownMenuProps = {
* You can pass function that takes argument `close` that closes the dropdown menu, or a list of MenuItems.
*/
menuItems:
| ((close: () => void) => JSX.Element[])
| JSX.Element[]
| JSX.Element;
| ((close: () => void) => React.JSX.Element[])
| React.JSX.Element[]
| React.JSX.Element;
/**
* ARIA role. Role of menu. For menu use 'menu', for select use 'listbox'.
* @default 'menu'
Expand Down
4 changes: 3 additions & 1 deletion packages/itwinui-react/src/core/Fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const Fieldset = React.forwardRef((props, ref) => {
{disabled
? React.Children.map(children, (child) =>
React.isValidElement(child)
? React.cloneElement(child as JSX.Element, { disabled: true })
? React.cloneElement(child as React.JSX.Element, {
disabled: true,
})
: child,
)
: children}
Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type HeaderProps = {
* Pass a function that takes the `close` argument (to close the menu),
* and returns a list of `MenuItem` components.
*/
menuItems?: (close: () => void) => JSX.Element[];
menuItems?: (close: () => void) => React.JSX.Element[];
/**
* If true, the header height is reduced, typically used when viewing 3D content.
* @default false
Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Header/HeaderLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type HeaderLogoOwnProps = {
/**
* Logo shown before the main content.
*/
logo: JSX.Element;
logo: React.JSX.Element;
/**
* Click event handler.
* If passed, the component will be rendered as a `<button>` rather than `<div>`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type LabeledInputProps = {
/**
* Custom svg icon. Will override status icon if specified.
*/
svgIcon?: JSX.Element | null;
svgIcon?: React.JSX.Element | null;
/**
* Pass props to wrapper element.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type LabeledSelectProps<T> = {
*
* Custom svg icon. Will override status icon if specified.
*/
svgIcon?: JSX.Element;
svgIcon?: React.JSX.Element;
/**
* If true, shows a red asterisk.
*
Expand Down Expand Up @@ -177,7 +177,7 @@ export const LabeledSelect = React.forwardRef(
},
) as <T>(
props: LabeledSelectProps<T> & { ref?: React.ForwardedRef<HTMLElement> },
) => JSX.Element;
) => React.JSX.Element;
if (process.env.NODE_ENV === 'development') {
(LabeledSelect as any).displayName = 'LabeledSelect';
}
10 changes: 5 additions & 5 deletions packages/itwinui-react/src/core/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ export type MenuItemProps = {
/**
* SVG icon component shown on the left.
*/
startIcon?: JSX.Element;
startIcon?: React.JSX.Element;
/**
* @deprecated Use startIcon.
* SVG icon component shown on the left.
*/
icon?: JSX.Element;
icon?: React.JSX.Element;
/**
* SVG icon component shown on the right.
*/
endIcon?: JSX.Element;
endIcon?: React.JSX.Element;
/**
* @deprecated Use endIcon.
* SVG icon component shown on the right.
*/
badge?: JSX.Element;
badge?: React.JSX.Element;
/**
* ARIA role. For menu item use 'menuitem', for select item use 'option'.
* @default 'menuitem'
Expand All @@ -69,7 +69,7 @@ export type MenuItemProps = {
/**
* Items to be shown in the submenu when hovered over the item.
*/
subMenuItems?: JSX.Element[];
subMenuItems?: React.JSX.Element[];
/**
* Content of the menu item.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('ErrorPage', () => {
] as {
errorType: ErrorPageType;
errorName: string;
illustration: JSX.Element;
illustration: React.JSX.Element;
}[];

defaultTests.forEach((test) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/itwinui-react/src/core/NonIdealState/ErrorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const ErrorPage = React.forwardRef((props, forwardedRef) => {
...translatedErrorMessages,
} as ErrorTypeTranslations;

function getErrorIcon(): JSX.Element {
function getErrorIcon(): React.JSX.Element {
switch (errorType) {
case '300':
case '301':
Expand Down Expand Up @@ -232,7 +232,7 @@ export const ErrorPage = React.forwardRef((props, forwardedRef) => {
}
}

function getPrimaryButton(): JSX.Element | null {
function getPrimaryButton(): React.JSX.Element | null {
if (!primaryButtonHandle || !primaryButtonLabel) {
return null;
}
Expand All @@ -243,7 +243,7 @@ export const ErrorPage = React.forwardRef((props, forwardedRef) => {
);
}

function getSecondaryButton(): JSX.Element | null {
function getSecondaryButton(): React.JSX.Element | null {
if (!secondaryButtonHandle || !secondaryButtonLabel) {
return null;
}
Expand All @@ -254,7 +254,7 @@ export const ErrorPage = React.forwardRef((props, forwardedRef) => {
);
}

function getActions(): JSX.Element | null {
function getActions(): React.JSX.Element | null {
const primaryButton = getPrimaryButton();
const secondaryButton = getSecondaryButton();

Expand Down
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/RadioTiles/RadioTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type RadioTileProps = {
/**
* Icon to be used.
*/
icon?: JSX.Element;
icon?: React.JSX.Element;
/**
* Label of the Radio tile.
*/
Expand Down
Loading

0 comments on commit e93c5a3

Please sign in to comment.