Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type {
ProviderContextValue,
TooltipContextType,
ThemeClassNameContextValue,
ThemeContextValue,
} from '@fluentui/react-shared-contexts';
import type { PartialTheme, Theme } from '@fluentui/react-theme';
import type { PartialTheme } from '@fluentui/react-theme';
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';

export type FluentProviderSlots = {
Expand All @@ -23,7 +24,7 @@ export type FluentProviderProps = Omit<ComponentProps<FluentProviderSlots>, 'dir
export type FluentProviderState = ComponentState<FluentProviderSlots> &
Pick<FluentProviderProps, 'targetDocument'> &
Required<Pick<FluentProviderProps, 'dir'>> & {
theme: Theme | Partial<Theme> | undefined;
theme: ThemeContextValue;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were 5 or 6 instances of this specific typing, so I extracted it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to the useTheme change?

themeClassName: string;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useKeyboardNavAttribute } from '@fluentui/react-tabster';
import type { Theme } from '@fluentui/react-theme';
import { useFluent, useTheme } from '@fluentui/react-shared-contexts';
import { ThemeContext, ThemeContextValue, useFluent } from '@fluentui/react-shared-contexts';
import { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities';
import * as React from 'react';
import { useFluentProviderThemeStyleTag } from './useFluentProviderThemeStyleTag';
Expand Down Expand Up @@ -60,7 +59,7 @@ export const useFluentProvider_unstable = (
};
};

function mergeThemes(a: Theme | Partial<Theme> | undefined, b: typeof a): Theme | Partial<Theme> | undefined {
function mergeThemes(a: ThemeContextValue, b: ThemeContextValue): ThemeContextValue {
// Merge impacts perf: we should like to avoid it if it's possible
if (a && b) {
return { ...a, ...b };
Expand All @@ -72,3 +71,7 @@ function mergeThemes(a: Theme | Partial<Theme> | undefined, b: typeof a): Theme

return b;
}

function useTheme(): ThemeContextValue {
return React.useContext(ThemeContext);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import type { Theme } from '@fluentui/react-theme';

export const ThemeContext = React.createContext<Theme | Partial<Theme> | undefined>(undefined);
export type ThemeContextValue = Theme | Partial<Theme> | undefined;

export function useTheme(): Theme | Partial<Theme> | undefined {
return React.useContext(ThemeContext);
}
export const ThemeContext = React.createContext<ThemeContextValue>(undefined);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { MenuContext, useMenuContext } from './MenuContext';
export type { MinimalMenuProps } from './MenuContext';
export { ThemeContext, useTheme } from './ThemeContext';
export { ThemeContext, ThemeContextValue } from './ThemeContext';
export { ThemeClassNameContext, useThemeClassName } from './ThemeClassNameContext';
export type { ThemeClassNameContextValue } from './ThemeClassNameContext';
export { TooltipContext } from './TooltipContext';
Expand Down