Skip to content

Commit

Permalink
Add IconDirectionProvider to FluentProvider (#28803)
Browse files Browse the repository at this point in the history
* Add IconDirectionProvider

* change file

* update value provided to IconDirectionProvider

* api update

* code review comments

* api update

* Update iconDirection
  • Loading branch information
tomi-msft committed Aug 28, 2023
1 parent 7d00038 commit ecaa083
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: Add IconDirectionProvider to FluentProvider",
"packageName": "@fluentui/react-provider",
"email": "ololubek@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
```ts

/// <reference types="react" />

import { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
import type { CustomStyleHooksContextValue_unstable } from '@fluentui/react-shared-contexts';
import type { IconDirectionContextValue } from '@fluentui/react-icons';
import { OverridesContextValue_unstable } from '@fluentui/react-shared-contexts';
import type { PartialTheme } from '@fluentui/react-theme';
import type { ProviderContextValue_unstable } from '@fluentui/react-shared-contexts';
Expand Down Expand Up @@ -125,6 +128,7 @@ export type FluentProviderContextValues = Pick<FluentProviderState, 'customStyle
provider: ProviderContextValue_unstable;
themeClassName: ThemeClassNameContextValue_unstable;
textDirection: 'ltr' | 'rtl';
iconDirection: IconDirectionContextValue;
tooltip: TooltipVisibilityContextValue_unstable;
};

Expand Down
1 change: 1 addition & 0 deletions packages/react-components/react-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@fluentui/scripts-tasks": "*"
},
"dependencies": {
"@fluentui/react-icons": "^2.0.207",
"@fluentui/react-shared-contexts": "^9.7.2",
"@fluentui/react-tabster": "^9.12.4",
"@fluentui/react-theme": "^9.1.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IconDirectionContextValue } from '@fluentui/react-icons';
import type {
OverridesContextValue_unstable as OverridesContextValue,
ProviderContextValue_unstable as ProviderContextValue,
Expand Down Expand Up @@ -70,5 +71,6 @@ export type FluentProviderContextValues = Pick<
provider: ProviderContextValue;
themeClassName: ThemeClassNameContextValue;
textDirection: 'ltr' | 'rtl';
iconDirection: IconDirectionContextValue;
tooltip: TooltipVisibilityContextValue;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CustomStyleHooksContextValue_unstable as CustomStyleHooksContextValue,
} from '@fluentui/react-shared-contexts';
import type { FluentProviderContextValues, FluentProviderState, FluentProviderSlots } from './FluentProvider.types';
import { IconDirectionContextProvider } from '@fluentui/react-icons';

/**
* Render the final JSX of FluentProvider
Expand All @@ -37,21 +38,23 @@ export const renderFluentProvider_unstable = (
>
<TooltipVisibilityProvider value={contextValues.tooltip}>
<TextDirectionProvider dir={contextValues.textDirection}>
<OverridesProvider value={contextValues.overrides_unstable}>
<state.root>
{canUseDOM() ? null : (
<style
// Using dangerous HTML because react can escape characters
// which can lead to invalid CSS.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: state.serverStyleProps.cssRule }}
{...state.serverStyleProps.attributes}
/>
)}
<IconDirectionContextProvider value={contextValues.iconDirection}>
<OverridesProvider value={contextValues.overrides_unstable}>
<state.root>
{canUseDOM() ? null : (
<style
// Using dangerous HTML because react can escape characters
// which can lead to invalid CSS.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: state.serverStyleProps.cssRule }}
{...state.serverStyleProps.attributes}
/>
)}

{state.root.children}
</state.root>
</OverridesProvider>
{state.root.children}
</state.root>
</OverridesProvider>
</IconDirectionContextProvider>
</TextDirectionProvider>
</TooltipVisibilityProvider>
</CustomStyleHooksProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function useFluentProviderContextValues_unstable(state: FluentProviderSta
const provider = React.useMemo(() => ({ dir, targetDocument }), [dir, targetDocument]);
// "Tooltip" component mutates an object in this context, instance should be stable
const [tooltip] = React.useState(() => ({}));
const iconDirection = React.useMemo(() => ({ textDirection: dir }), [dir]);

return {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -26,6 +27,7 @@ export function useFluentProviderContextValues_unstable(state: FluentProviderSta
overrides_unstable,
provider,
textDirection: dir,
iconDirection,
tooltip,
theme,
themeClassName: applyStylesToPortals ? root.className! : themeClassName,
Expand Down

0 comments on commit ecaa083

Please sign in to comment.