Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "remove export useTheme",
"packageName": "@fluentui/react-provider",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "remove useTheme from exports",
"packageName": "@fluentui/react-shared-contexts",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type { Slot } from '@fluentui/react-utilities';
import { SlotClassNames } from '@fluentui/react-utilities';
import { Theme } from '@fluentui/react-theme';
import type { ThemeClassNameContextValue } from '@fluentui/react-shared-contexts';
import type { ThemeContextValue } from '@fluentui/react-shared-contexts';
import type { TooltipContextType } from '@fluentui/react-shared-contexts';
import { useFluent } from '@fluentui/react-shared-contexts';
import { useTheme } from '@fluentui/react-shared-contexts';

// @public (undocumented)
export const FluentProvider: React_2.ForwardRefExoticComponent<Omit<ComponentProps<FluentProviderSlots, "root">, "dir"> & {
Expand Down Expand Up @@ -49,7 +49,7 @@ export type FluentProviderSlots = {

// @public (undocumented)
export type FluentProviderState = ComponentState<FluentProviderSlots> & Pick<FluentProviderProps, 'targetDocument'> & Required<Pick<FluentProviderProps, 'dir'>> & {
theme: Theme | Partial<Theme> | undefined;
theme: ThemeContextValue;
themeClassName: string;
};

Expand All @@ -70,8 +70,6 @@ export const useFluentProviderStyles_unstable: (state: FluentProviderState) => F
// @public
export const useFluentProviderThemeStyleTag: (options: Pick<FluentProviderState, 'theme' | 'targetDocument'>) => string;

export { useTheme }

// (No @packageDocumentation comment for this package)

```
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
Member 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
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);
}
2 changes: 1 addition & 1 deletion packages/react-components/react-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export type {
FluentProviderSlots,
} from './FluentProvider';

export { useFluent, useTheme } from '@fluentui/react-shared-contexts';
export { useFluent } from '@fluentui/react-shared-contexts';
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export const ThemeClassNameContext: React_2.Context<string>;
export type ThemeClassNameContextValue = string;

// @public (undocumented)
export const ThemeContext: React_2.Context<Theme | Partial<Theme> | undefined>;
export const ThemeContext: React_2.Context<ThemeContextValue>;

// @public (undocumented)
export type ThemeContextValue = Theme | Partial<Theme> | undefined;

// @public
export const TooltipContext: React_2.Context<TooltipContextType>;
Expand All @@ -38,9 +41,6 @@ export type TooltipContextType = {
// @public (undocumented)
export function useFluent(): ProviderContextValue;

// @public (undocumented)
export function useTheme(): Theme | Partial<Theme> | undefined;

// @public (undocumented)
export function useThemeClassName(): ThemeClassNameContextValue;

Expand Down
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,4 +1,5 @@
export { ThemeContext, useTheme } from './ThemeContext';
export { ThemeContext } from './ThemeContext';
export type { ThemeContextValue } from './ThemeContext';
Copy link
Member

Choose a reason for hiding this comment

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

in #23325 we are moving react-shared-contexts to unstable. Does this have any effect on exporting this type from the unstable package?

export { ThemeClassNameContext, useThemeClassName } from './ThemeClassNameContext';
export type { ThemeClassNameContextValue } from './ThemeClassNameContext';
export { TooltipContext } from './TooltipContext';
Expand Down