Skip to content

Commit 1524259

Browse files
committed
chore(react-experiments): resolve issues with React 18 migration
1 parent 6320dfd commit 1524259

File tree

12 files changed

+37
-33
lines changed

12 files changed

+37
-33
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Jest test setup file. */
2+
import '@testing-library/jest-dom';

packages/react-experiments/src/components/Accordion/Accordion.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const AccordionStatics = {
4242
defaultProps: {},
4343
};
4444

45-
export const Accordion: React.FunctionComponent<IAccordionProps> & {
46-
Item: React.FunctionComponent<ICollapsibleSectionProps>;
45+
export const Accordion: React.FunctionComponent<React.PropsWithChildren<IAccordionProps>> & {
46+
Item: React.FunctionComponent<React.PropsWithChildren<ICollapsibleSectionProps>>;
4747
} = createComponent(AccordionView, {
4848
displayName: 'Accordion',
4949
styles,

packages/react-experiments/src/components/CollapsibleSection/CollapsibleSection.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ import { collapsibleSectionStyles } from './CollapsibleSection.styles';
55
import { createComponent } from '@fluentui/foundation-legacy';
66
import type { ICollapsibleSectionProps } from './CollapsibleSection.types';
77

8-
export const CollapsibleSection: React.FunctionComponent<ICollapsibleSectionProps> = createComponent(
9-
CollapsibleSectionView,
10-
{
8+
export const CollapsibleSection: React.FunctionComponent<React.PropsWithChildren<ICollapsibleSectionProps>> =
9+
createComponent(CollapsibleSectionView, {
1110
displayName: 'CollapsibleSection',
1211
state: useCollapsibleSectionState,
1312
styles: collapsibleSectionStyles,
14-
},
15-
);
13+
});
1614

1715
// TODO: This is only here for testing createComponent and should be removed before promoting to production
18-
export const CollapsibleSectionStateless: React.FunctionComponent<ICollapsibleSectionProps> = createComponent(
19-
CollapsibleSectionView,
20-
{
16+
export const CollapsibleSectionStateless: React.FunctionComponent<React.PropsWithChildren<ICollapsibleSectionProps>> =
17+
createComponent(CollapsibleSectionView, {
2118
displayName: 'CollapsibleSection',
2219
styles: collapsibleSectionStyles,
23-
},
24-
);
20+
});

packages/react-experiments/src/components/FolderCover/FolderCover.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface IFolderCoverChildrenProps {
99
contentSize: ISize;
1010
}
1111

12-
export interface IFolderCoverProps extends IBaseProps, React.HTMLAttributes<HTMLDivElement> {
12+
export interface IFolderCoverProps extends IBaseProps, Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
1313
/**
1414
* The breakpoint size of the folder cover.
1515
*/
@@ -39,5 +39,5 @@ export interface IFolderCoverProps extends IBaseProps, React.HTMLAttributes<HTML
3939
* The children to pass into the content area of the folder cover.
4040
*/
4141
// eslint-disable-next-line @typescript-eslint/no-deprecated
42-
children?: React.Props<{}>['children'] | ((childrenProps: IFolderCoverChildrenProps) => JSX.Element | null);
42+
children?: React.ReactNode | ((childrenProps: IFolderCoverChildrenProps) => JSX.Element | null);
4343
}

packages/react-experiments/src/components/SelectedItemsList/Items/CopyableItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const CopyableItem = <T extends any>(
1717
): CopyableItemWrappedComponent<T> => {
1818
return React.memo((selectedItemProps: ISelectedItemProps<T>) => {
1919
const onCopy = React.useCallback(
20-
item => {
20+
(item: T) => {
2121
const copyText = copyableItemProps.getCopyItemText([item]);
2222
const copyInput = document.createElement('input') as HTMLInputElement;
2323
document.body.appendChild(copyInput);
@@ -44,7 +44,7 @@ export const CopyableItem = <T extends any>(
4444
// doesn't re-render the component."
4545
// eslint-disable-next-line react-hooks/exhaustive-deps
4646
[copyableItemProps.getCopyItemText],
47-
);
47+
) as React.ClipboardEventHandler<HTMLElement>;
4848

4949
const ItemComponent = copyableItemProps.itemComponent;
5050
return <ItemComponent {...selectedItemProps} onCopy={onCopy} />;

packages/react-experiments/src/components/SelectedItemsList/Items/ItemTrigger.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import type { ISelectedItemProps } from '../SelectedItemsList.types';
33

44
export type TriggerProps<T> = ISelectedItemProps<T> & {
5+
item: T;
56
onTrigger?: () => void;
67
};
78

packages/react-experiments/src/components/SelectedItemsList/Items/ItemWithContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const ItemWithContextMenu = <T extends any>(
2121
setIsContextMenuOpen(true);
2222
}, [setIsContextMenuOpen]);
2323
const closeContextMenu = React.useCallback(
24-
e => {
24+
(e: React.MouseEvent) => {
2525
e.preventDefault();
2626
setIsContextMenuOpen(false);
2727
},

packages/react-experiments/src/components/SelectedItemsList/Items/TriggerOnContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const TriggerOnContextMenu = <T extends any>(ItemComponent: React.Compone
88
const { onTrigger } = props;
99
// eslint-disable-next-line react-hooks/rules-of-hooks -- this is a component
1010
const trigger = React.useCallback(
11-
e => {
11+
(e: React.MouseEvent<HTMLElement>) => {
1212
e.preventDefault();
1313
e.stopPropagation();
1414
onTrigger?.();

packages/react-experiments/src/components/SelectedItemsList/SelectedPeopleList/Items/SelectedPersona.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const SelectedPersonaInner = React.memo(
8181
const dragDropOptions: IDragDropOptions = {
8282
eventMap: eventsToRegister,
8383
selectionIndex: index,
84-
context: { data: item, index: index },
84+
context: { data: item, index },
8585
...dragDropEvents,
8686
updateDropState: _updateDroppingState,
8787
};
@@ -110,7 +110,7 @@ const SelectedPersonaInner = React.memo(
110110
);
111111

112112
const onExpandClicked = React.useCallback(
113-
ev => {
113+
(ev: React.MouseEvent<HTMLElement>) => {
114114
ev.stopPropagation();
115115
ev.preventDefault();
116116
if (onItemChange && getExpandedItems) {
@@ -127,7 +127,7 @@ const SelectedPersonaInner = React.memo(
127127
);
128128

129129
const onRemoveClicked = React.useCallback(
130-
ev => {
130+
(ev: React.MouseEvent<HTMLElement>) => {
131131
ev.stopPropagation();
132132
ev.preventDefault();
133133
onRemoveItem && onRemoveItem();

packages/react-experiments/src/components/Tile/Tile.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export class Tile extends React.Component<ITileProps, ITileState> {
9494
const isModal = !!selection && !!selection.isModal && selection.isModal();
9595

9696
this.state = {
97-
isSelected: isSelected,
98-
isModal: isModal,
97+
isSelected,
98+
isModal,
9999
};
100100

101101
this._events = new EventGroup(this);
@@ -112,8 +112,8 @@ export class Tile extends React.Component<ITileProps, ITileState> {
112112
const isModal = !!nextSelection && nextSelection.isModal && nextSelection.isModal();
113113

114114
this.setState({
115-
isSelected: isSelected,
116-
isModal: isModal,
115+
isSelected,
116+
isModal,
117117
});
118118
}
119119
}
@@ -191,8 +191,13 @@ export class Tile extends React.Component<ITileProps, ITileState> {
191191

192192
const tileLayout = getTileLayoutFromProps(this.props);
193193

194-
const background = typeof propsBackground === 'function' ? propsBackground(tileLayout) : propsBackground;
195-
const foreground = typeof propsForeground === 'function' ? propsForeground(tileLayout) : propsForeground;
194+
const background = (
195+
typeof propsBackground === 'function' ? propsBackground(tileLayout) : propsBackground
196+
) as React.JSX.Element;
197+
198+
const foreground = (
199+
typeof propsForeground === 'function' ? propsForeground(tileLayout) : propsForeground
200+
) as React.JSX.Element;
196201

197202
const onRenderBackground = propsOnRenderBackground
198203
? composeRenderFunction(propsOnRenderBackground, this._onRenderBackground)
@@ -290,7 +295,7 @@ export class Tile extends React.Component<ITileProps, ITileState> {
290295
) : null}
291296
{isSelectable
292297
? this._onRenderCheck({
293-
isSelected: isSelected,
298+
isSelected,
294299
})
295300
: null}
296301
</div>
@@ -406,8 +411,8 @@ export class Tile extends React.Component<ITileProps, ITileState> {
406411
const isModal = !!selection && !!selection.isModal && selection.isModal();
407412

408413
this.setState({
409-
isSelected: isSelected,
410-
isModal: isModal,
414+
isSelected,
415+
isModal,
411416
});
412417
};
413418
}

0 commit comments

Comments
 (0)