Skip to content

Commit

Permalink
chore: use consistent react imports (microsoft#33252)
Browse files Browse the repository at this point in the history
Co-authored-by: Makoto Morimoto <[email protected]>
  • Loading branch information
mainframev and khmakoto authored Nov 19, 2024
1 parent ce34749 commit e1b642f
Show file tree
Hide file tree
Showing 89 changed files with 334 additions and 254 deletions.
3 changes: 1 addition & 2 deletions apps/public-docsite-v9/src/DocsComponents/Toc.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import { addons } from '@storybook/preview-api';
import { NAVIGATE_URL } from '@storybook/core-events';
import { makeStyles, shorthands } from '@fluentui/react-components';
import { useRef } from 'react';

const useTocStyles = makeStyles({
root: {
Expand Down Expand Up @@ -76,7 +75,7 @@ export const nameToHash = (id: string): string => id.toLowerCase().replace(/[^a-

export const Toc = ({ stories }: { stories: TocItem[] }) => {
const [selected, setSelected] = React.useState('');
const isNavigating = useRef<boolean>(false);
const isNavigating = React.useRef<boolean>(false);

React.useEffect(() => {
const observer = new IntersectionObserver(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: add no-restricted-syntax to react-config",
"packageName": "@fluentui/eslint-plugin",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-carousel",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-combobox",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-dialog",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-docsite-components",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: update api.md",
"packageName": "@fluentui/react-drawer",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-experiments",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-hooks",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-tabster",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-teaching-popover",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-text",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-utilities",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: use consistent react imports",
"packageName": "@fluentui/react-virtualizer",
"email": "[email protected]",
"dependentChangeType": "none"
}
7 changes: 3 additions & 4 deletions packages/charts/react-charting/etc/react-charting.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { SankeyLink } from 'd3-sankey';
import { SankeyNode } from 'd3-sankey';
import { ScaleBand } from 'd3-scale';
import { ScaleLinear } from 'd3-scale';
import { SVGProps } from 'react';
import { TimeLocaleDefinition } from 'd3-time-format';

// @public
Expand Down Expand Up @@ -400,8 +399,8 @@ export interface IChartProps {
chartTitle?: string;
chartTitleAccessibilityData?: IAccessibilityProps;
lineChartData?: ILineChartPoints[];
pointLineOptions?: SVGProps<SVGLineElement>;
pointOptions?: SVGProps<SVGCircleElement>;
pointLineOptions?: React_2.SVGProps<SVGLineElement>;
pointOptions?: React_2.SVGProps<SVGCircleElement>;
SankeyChartData?: ISankeyChartData;
}

Expand Down Expand Up @@ -933,7 +932,7 @@ export interface ILineChartGap {
}

// @public (undocumented)
export interface ILineChartLineOptions extends SVGProps<SVGPathElement> {
export interface ILineChartLineOptions extends React_2.SVGProps<SVGPathElement> {
lineBorderColor?: string;
lineBorderWidth?: string | number;
strokeDasharray?: string | number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { lazy } from 'react';
import { IProcessedStyleSet } from '@fluentui/react/lib/Styling';
import { classNamesFunction, getId, getRTL } from '@fluentui/react/lib/Utilities';
import { Callout } from '@fluentui/react/lib/Callout';
Expand Down Expand Up @@ -34,7 +33,7 @@ import { LegendShape, Shape } from '../Legends/index';
import { SVGTooltipText } from '../../utilities/SVGTooltipText';

const getClassNames = classNamesFunction<ICartesianChartStyleProps, ICartesianChartStyles>();
const ChartHoverCard = lazy(() =>
const ChartHoverCard = React.lazy(() =>
import('../../utilities/ChartHoverCard/ChartHoverCard').then(module => ({ default: module.ChartHoverCard })),
);

Expand Down
8 changes: 4 additions & 4 deletions packages/charts/react-charting/src/types/IDataPoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { SankeyLink, SankeyNode } from 'd3-sankey';
import { SVGProps } from 'react';
import { LegendShape } from '../components/Legends/Legends.types';

export interface IBasestate {
Expand Down Expand Up @@ -361,7 +361,7 @@ export interface ILineChartGap {
/**
* {@docCategory IChartProps}
*/
export interface ILineChartLineOptions extends SVGProps<SVGPathElement> {
export interface ILineChartLineOptions extends React.SVGProps<SVGPathElement> {
/**
* Width of the line/stroke.
* Overrides the strokeWidth set on ICartesianChartProps level.
Expand Down Expand Up @@ -491,12 +491,12 @@ export interface IChartProps {
/**
* data for the points in the line chart
*/
pointOptions?: SVGProps<SVGCircleElement>;
pointOptions?: React.SVGProps<SVGCircleElement>;

/**
* data for the dotted line on hovering the point
*/
pointLineOptions?: SVGProps<SVGLineElement>;
pointLineOptions?: React.SVGProps<SVGLineElement>;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/eslint-plugin/src/configs/react-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ module.exports = {
],
},
rules: {
/**
* Enforce consistent importing from React by resticting named imports.
*/
'no-restricted-syntax': [
'error',
{
selector: "ImportDeclaration[source.value='react'] ImportSpecifier",
message: "Avoid named imports from 'react'. Use 'import * as React from \"react\"' instead.",
},
],
/**
* griffel eslint rules
* @see https://github.com/microsoft/griffel/tree/main/packages/eslint-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useCarouselContext_unstable as useCarouselContext } from '../CarouselCo
import type { CarouselButtonProps, CarouselButtonState } from './CarouselButton.types';
import type { CarouselUpdateData } from '../Carousel/Carousel.types';
import { carouselButtonClassNames } from './useCarouselButtonStyles.styles';
import { useRef } from 'react';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';

/**
Expand All @@ -36,7 +35,7 @@ export const useCarouselButton_unstable = (
const [totalSlides, setTotalSlides] = React.useState(0);

const { dir } = useFluent();
const buttonRef = useRef<HTMLButtonElement>();
const buttonRef = React.useRef<HTMLButtonElement>();
const circular = useCarouselContext(ctx => ctx.circular);
const containerRef = useCarouselContext(ctx => ctx.containerRef);
const selectPageByDirection = useCarouselContext(ctx => ctx.selectPageByDirection);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'react';
import * as React from 'react';
import { useControllableState } from '@fluentui/react-utilities';
import { OptionValue } from './OptionCollection.types';
import { SelectionEvents, SelectionProps, SelectionState } from './Selection.types';
Expand All @@ -12,7 +12,7 @@ export const useSelection = (props: SelectionProps): SelectionState => {
initialState: [],
});

const selectOption = useCallback(
const selectOption = React.useCallback(
(event: SelectionEvents, option: OptionValue) => {
// if the option is disabled, do nothing
if (option.disabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { ForwardRefComponent } from '@fluentui/react-utilities';
import { JSXElementConstructor } from 'react';
import type { PortalProps } from '@fluentui/react-portal';
import type { PresenceMotionSlotProps } from '@fluentui/react-motion';
import { Provider } from 'react';
import * as React_2 from 'react';
import { ReactElement } from 'react';
import type { Slot } from '@fluentui/react-utilities';
Expand Down Expand Up @@ -169,7 +168,7 @@ export type DialogSurfaceElement = HTMLElement;
export type DialogSurfaceProps = ComponentProps<Partial<DialogSurfaceSlots>> & Pick<PortalProps, 'mountNode'>;

// @public (undocumented)
export const DialogSurfaceProvider: Provider<boolean | undefined>;
export const DialogSurfaceProvider: React_2.Provider<boolean | undefined>;

// @public (undocumented)
export type DialogSurfaceSlots = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createContext, useContext } from 'react';
import * as React from 'react';

export type DialogSurfaceContextValue = boolean;

const defaultContextValue: DialogSurfaceContextValue = false;

export const DialogSurfaceContext = createContext<DialogSurfaceContextValue | undefined>(undefined);
export const DialogSurfaceContext = React.createContext<DialogSurfaceContextValue | undefined>(undefined);

export const DialogSurfaceProvider = DialogSurfaceContext.Provider;

export const useDialogSurfaceContext_unstable = () => useContext(DialogSurfaceContext) ?? defaultContextValue;
export const useDialogSurfaceContext_unstable = () => React.useContext(DialogSurfaceContext) ?? defaultContextValue;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useFluent_unstable } from '@fluentui/react-shared-contexts';
import { useCallback } from 'react';

import { useBodyNoScrollStyles, useHTMLNoScrollStyles } from './useDisableBodyScroll.styles';

Expand All @@ -15,7 +15,7 @@ export function useDisableBodyScroll(): {
const bodyNoScrollStyles = useBodyNoScrollStyles();
const { targetDocument } = useFluent_unstable();

const disableBodyScroll = useCallback(() => {
const disableBodyScroll = React.useCallback(() => {
if (!targetDocument) {
return;
}
Expand All @@ -31,7 +31,7 @@ export function useDisableBodyScroll(): {
return;
}, [targetDocument, htmlNoScrollStyles, bodyNoScrollStyles]);

const enableBodyScroll = useCallback(() => {
const enableBodyScroll = React.useCallback(() => {
if (!targetDocument) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export type OverlayDrawerSlots = {

// @public
export type OverlayDrawerState = ComponentState<OverlayDrawerInternalSlots> & Required<DrawerBaseState> & Pick<OverlayDrawerProps, 'mountNode'> & {
hasMountNodeElement?: boolean;
hasMountNodeElement: boolean;
};

// @public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import type { MiddlewareArguments } from '@floating-ui/dom';
import { matchTargetSize, matchTargetSizeCssVar } from './matchTargetSize';
import { CSSProperties } from 'react';

describe('matchTargetSize', () => {
const middlewareFn = matchTargetSize().fn;
const createElementMock = () => ({
style: { setProperty: jest.fn() } as CSSProperties & { setProperty: jest.Mock },
style: { setProperty: jest.fn() } as React.CSSProperties & { setProperty: jest.Mock },
});
it('should match reference width if not same', async () => {
expect.assertions(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
PeopleRegular,
} from '@fluentui/react-icons';
import * as React from 'react';
import { useState } from 'react';

const columnNames: { [key: TableColumnId]: string } = {
file: 'File',
Expand Down Expand Up @@ -162,8 +161,8 @@ const items: Item[] = [
];

export const ResizableColumnsControlled = () => {
const [columns, setColumns] = useState<TableColumnDefinition<Item>[]>(columnsDef);
const [columnSizingOptions, setColumnSizingOptions] = useState<TableColumnSizingOptions>({
const [columns, setColumns] = React.useState<TableColumnDefinition<Item>[]>(columnsDef);
const [columnSizingOptions, setColumnSizingOptions] = React.useState<TableColumnSizingOptions>({
file: {
idealWidth: 300,
minWidth: 190,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { MoverMemorizedElementEventName } from 'tabster';
import { MoverMoveFocusEvent } from 'tabster';
import { MoverMoveFocusEventName } from 'tabster';
import * as React_2 from 'react';
import type { RefObject } from 'react';
import { TabsterMoveFocusEvent } from 'tabster';
import { TabsterMoveFocusEventName } from 'tabster';
import { Types } from 'tabster';
Expand Down Expand Up @@ -1486,7 +1485,7 @@ export function useFocusWithin<TElement extends HTMLElement = HTMLElement>(): Re
export function useIsNavigatingWithKeyboard(): () => boolean;

// @public
export function useKeyboardNavAttribute<E extends HTMLElement>(): RefObject<E>;
export function useKeyboardNavAttribute<E extends HTMLElement>(): React_2.RefObject<E>;

// @internal
export const useMergedTabsterAttributes_unstable: (...attributes: (Partial<Types.TabsterDOMAttribute> | null | undefined)[]) => Types.TabsterDOMAttribute;
Expand Down
Loading

0 comments on commit e1b642f

Please sign in to comment.