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

chore: use consistent react imports #33252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e3e9436
chore(eslint-plugin): enforce consistent react imports
mainframev Nov 11, 2024
4b7f2f2
chore: update react imports to be more consistent
mainframev Nov 11, 2024
78545a0
chore(docsite-v9): use consistent react imports
mainframev Nov 11, 2024
120c3c6
chore(react-virtualizer): use consistent react imports
mainframev Nov 11, 2024
0e0ec7c
chore(react-table): use consistent react imports
mainframev Nov 11, 2024
b2f201c
chore(theme-designer): use consistent react imports
mainframev Nov 11, 2024
89d08e7
chore(react-docsite-components): use consistent react imports
mainframev Nov 11, 2024
a09a3e4
chore(react-experiments): use consistent react imports
mainframev Nov 11, 2024
be7a6ea
chore(react): use consistent react imports
mainframev Nov 11, 2024
8da2e9a
chore(v8): use consistent react imports
mainframev Nov 11, 2024
3c88cc9
chore(v8): update react.api.md
mainframev Nov 11, 2024
255fa65
chore: update change files
mainframev Nov 11, 2024
2b96330
chore(react-dialog): use consistent react imports
mainframev Nov 12, 2024
ab081d0
chore(react-text): use consistent react imports
mainframev Nov 12, 2024
c18cb89
chore(react-tabster): use consistent react imports
mainframev Nov 12, 2024
a8b336b
chore(react-utilities): use consistent react imports
mainframev Nov 12, 2024
c10c767
chore(react-teaching-popover): use consistent react imports
mainframev Nov 12, 2024
761a938
chore(react-combobox): use consistent react imports
mainframev Nov 12, 2024
1ea19cb
chore(react-carousel): use consistent react imports
mainframev Nov 12, 2024
143514b
chore(react-positioning): use consistent react imports
mainframev Nov 12, 2024
55e6b0a
chore(react-hooks): use consistent react imports
mainframev Nov 12, 2024
7cda74f
chore(react-drawer): update api.md
mainframev Nov 12, 2024
00a61a3
Update change/@fluentui-react-virtualizer-14fe38c6-aec9-4600-af3a-a64…
mainframev Nov 19, 2024
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
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';
mainframev marked this conversation as resolved.
Show resolved Hide resolved
mainframev marked this conversation as resolved.
Show resolved Hide resolved
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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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": "vgenaev@gmail.com",
"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;
spmonahan marked this conversation as resolved.
Show resolved Hide resolved
};

// @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
Loading