From a95b4c48e4386c8ba89c6bf2a2a19a443de4c8c2 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 13 Jan 2022 16:06:01 +0100 Subject: [PATCH 1/9] feat(react-theme): remove mergeThemes API --- packages/react-theme/etc/react-theme.api.md | 3 --- .../react-theme/src/utils/mergeThemes.test.ts | 21 ------------------- packages/react-theme/src/utils/mergeThemes.ts | 14 ------------- 3 files changed, 38 deletions(-) delete mode 100644 packages/react-theme/src/utils/mergeThemes.test.ts delete mode 100644 packages/react-theme/src/utils/mergeThemes.ts diff --git a/packages/react-theme/etc/react-theme.api.md b/packages/react-theme/etc/react-theme.api.md index e3ded6b1c57c9..473bde88d248f 100644 --- a/packages/react-theme/etc/react-theme.api.md +++ b/packages/react-theme/etc/react-theme.api.md @@ -363,9 +363,6 @@ export type LineHeightTokens = { lineHeightHero1000: string; }; -// @public (undocumented) -export function mergeThemes(a: Theme | undefined, b: PartialTheme | Theme | undefined): Theme; - // @public (undocumented) export type PartialTheme = Partial; diff --git a/packages/react-theme/src/utils/mergeThemes.test.ts b/packages/react-theme/src/utils/mergeThemes.test.ts deleted file mode 100644 index e77d9fe2b212f..0000000000000 --- a/packages/react-theme/src/utils/mergeThemes.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { teamsLightTheme } from '../themes'; -import { mergeThemes } from './mergeThemes'; -import type { PartialTheme, Theme } from '../types'; - -describe('mergeThemes', () => { - it('performs a merge of themes', () => { - // TODO: we should not use real themes in tests - const a: Theme = teamsLightTheme; - const b: PartialTheme = { colorBrandBackground: 'red' }; - - const result = mergeThemes(a, b); - - expect(a.colorBrandBackground).not.toBe('red'); - expect(result.colorBrandBackground).toBe('red'); - }); - - it('avoids unnecessary merges', () => { - expect(mergeThemes(teamsLightTheme, undefined)).toBe(teamsLightTheme); - expect(mergeThemes(undefined, teamsLightTheme)).toBe(teamsLightTheme); - }); -}); diff --git a/packages/react-theme/src/utils/mergeThemes.ts b/packages/react-theme/src/utils/mergeThemes.ts deleted file mode 100644 index 9c47d6e445064..0000000000000 --- a/packages/react-theme/src/utils/mergeThemes.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { PartialTheme, Theme } from '../types'; - -export function mergeThemes(a: Theme | undefined, b: PartialTheme | Theme | undefined): Theme { - // Merge impacts perf: we should like to avoid it if it's possible - if (a && b) { - return { ...a, ...b }; - } - - if (a) { - return a; - } - - return b as Theme; -} From aeb709d2161a427f3be10c21e6abd53e0ddd5d4e Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 13 Jan 2022 16:07:25 +0100 Subject: [PATCH 2/9] feat(react-components): remove mergeThemes from public API --- packages/react-components/etc/react-components.api.md | 3 --- packages/react-components/src/index.ts | 1 - 2 files changed, 4 deletions(-) diff --git a/packages/react-components/etc/react-components.api.md b/packages/react-components/etc/react-components.api.md index 4af1953d77b4f..af0fd01bc72bb 100644 --- a/packages/react-components/etc/react-components.api.md +++ b/packages/react-components/etc/react-components.api.md @@ -188,7 +188,6 @@ import { MenuTriggerContextProvider } from '@fluentui/react-menu'; import { MenuTriggerProps } from '@fluentui/react-menu'; import { MenuTriggerState } from '@fluentui/react-menu'; import { mergeClasses } from '@fluentui/react-make-styles'; -import { mergeThemes } from '@fluentui/react-theme'; import { OnOpenChangeData } from '@fluentui/react-popover'; import { OnVisibleChangeData } from '@fluentui/react-tooltip'; import { OpenPopoverEvents } from '@fluentui/react-popover'; @@ -743,8 +742,6 @@ export { MenuTriggerState } export { mergeClasses } -export { mergeThemes } - export { OnOpenChangeData } export { OnVisibleChangeData } diff --git a/packages/react-components/src/index.ts b/packages/react-components/src/index.ts index 670e45be40939..06e49cd0cc9b1 100644 --- a/packages/react-components/src/index.ts +++ b/packages/react-components/src/index.ts @@ -32,7 +32,6 @@ export { createHighContrastTheme, createLightTheme, createTeamsDarkTheme, - mergeThemes, teamsDarkTheme, teamsHighContrastTheme, teamsLightTheme, From bef6fa777a750f44f4b470e8751cd59e9cffbe4e Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 13 Jan 2022 16:09:14 +0100 Subject: [PATCH 3/9] fixup! feat(react-theme): remove mergeThemes API --- packages/react-theme/src/utils/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/react-theme/src/utils/index.ts b/packages/react-theme/src/utils/index.ts index db48867fb14cb..4e9d99a66a299 100644 --- a/packages/react-theme/src/utils/index.ts +++ b/packages/react-theme/src/utils/index.ts @@ -2,5 +2,3 @@ export * from './createLightTheme'; export * from './createDarkTheme'; export * from './createTeamsDarkTheme'; export * from './createHighContrastTheme'; - -export { mergeThemes } from './mergeThemes'; From c717774cd35694aa5eee62ab40a0df2275e6fcd6 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 13 Jan 2022 16:14:36 +0100 Subject: [PATCH 4/9] refactor(react-provider): replace mergeThemes functionality from react-theme --- .../FluentProvider/useFluentProvider.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/react-provider/src/components/FluentProvider/useFluentProvider.ts b/packages/react-provider/src/components/FluentProvider/useFluentProvider.ts index ffaa30fb3ce53..de471183e0424 100644 --- a/packages/react-provider/src/components/FluentProvider/useFluentProvider.ts +++ b/packages/react-provider/src/components/FluentProvider/useFluentProvider.ts @@ -1,5 +1,5 @@ import { useKeyboardNavAttribute } from '@fluentui/react-tabster'; -import { mergeThemes } from '@fluentui/react-theme'; +import type { Theme } from '@fluentui/react-theme'; import { useFluent, useTheme } from '@fluentui/react-shared-contexts'; import { getNativeElementProps, useMergedRefs } from '@fluentui/react-utilities'; import * as React from 'react'; @@ -44,3 +44,16 @@ export const useFluentProvider = (props: FluentProviderProps, ref: React.Ref | Theme | undefined): Theme { + // Merge impacts perf: we should like to avoid it if it's possible + if (a && b) { + return { ...a, ...b }; + } + + if (a) { + return a; + } + + return b as Theme; +} From 3ad1b52b3c618b5063180df618cf1b8b053584f0 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 13 Jan 2022 16:15:55 +0100 Subject: [PATCH 5/9] Change files --- ...ct-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json | 7 +++++++ ...eact-provider-d474a580-e643-4191-96db-4d4abf014352.json | 7 +++++++ ...i-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json create mode 100644 change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json create mode 100644 change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json diff --git a/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json b/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json new file mode 100644 index 0000000000000..1d43acd94fe74 --- /dev/null +++ b/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "feat(react-components): remove mergeThemes from public API", + "packageName": "@fluentui/react-components", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json b/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json new file mode 100644 index 0000000000000..af12bf7082a94 --- /dev/null +++ b/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "refactor(react-provider): replace mergeThemes functionality from react-theme", + "packageName": "@fluentui/react-provider", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json b/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json new file mode 100644 index 0000000000000..8c33d1b07cc7d --- /dev/null +++ b/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "feat(react-theme): remove mergeThemes API", + "packageName": "@fluentui/react-theme", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "patch" +} From 7ccb5b375e0dcd0f338d569e6feeab68d329fa0b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 13 Jan 2022 16:29:09 +0100 Subject: [PATCH 6/9] fixup! fixup! feat(react-theme): remove mergeThemes API --- packages/react-theme/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-theme/package.json b/packages/react-theme/package.json index c602176524963..42e0e58e6667d 100644 --- a/packages/react-theme/package.json +++ b/packages/react-theme/package.json @@ -20,7 +20,7 @@ "lint": "just-scripts lint", "start": "yarn storybook", "storybook": "start-storybook", - "test": "jest", + "test": "jest --passWithNoTests", "docs": "api-extractor run --config=config/api-extractor.local.json --local", "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-theme/src && yarn docs", "type-check": "tsc -b tsconfig.json" From 9d98e817ba5e9b5205b026103d46f93ada7a8638 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 14 Jan 2022 11:12:20 +0100 Subject: [PATCH 7/9] Update change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json Co-authored-by: Oleksandr Fediashov --- ...uentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json b/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json index 8c33d1b07cc7d..be6fd7e3eb481 100644 --- a/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json +++ b/change/@fluentui-react-theme-4896497c-3947-4f7c-b2af-97b5cbf1c335.json @@ -1,6 +1,6 @@ { "type": "prerelease", - "comment": "feat(react-theme): remove mergeThemes API", + "comment": "remove mergeThemes API", "packageName": "@fluentui/react-theme", "email": "martinhochel@microsoft.com", "dependentChangeType": "patch" From dbd3d65f255e2a8cce06e2366fce82097e243605 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 14 Jan 2022 11:12:27 +0100 Subject: [PATCH 8/9] Update change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json Co-authored-by: Oleksandr Fediashov --- ...tui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json b/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json index af12bf7082a94..8160a1cb91cdb 100644 --- a/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json +++ b/change/@fluentui-react-provider-d474a580-e643-4191-96db-4d4abf014352.json @@ -1,6 +1,6 @@ { "type": "prerelease", - "comment": "refactor(react-provider): replace mergeThemes functionality from react-theme", + "comment": "replace mergeThemes functionality from react-theme", "packageName": "@fluentui/react-provider", "email": "martinhochel@microsoft.com", "dependentChangeType": "patch" From 39b6a1ff50fb5f08b38d0cacf45d790937358b20 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 14 Jan 2022 11:12:35 +0100 Subject: [PATCH 9/9] Update change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json Co-authored-by: Oleksandr Fediashov --- ...i-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json b/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json index 1d43acd94fe74..9fd4486e3e6fb 100644 --- a/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json +++ b/change/@fluentui-react-components-f34f712d-15c2-4cc9-be35-95c55efad70b.json @@ -1,6 +1,6 @@ { "type": "prerelease", - "comment": "feat(react-components): remove mergeThemes from public API", + "comment": "remove mergeThemes from public API", "packageName": "@fluentui/react-components", "email": "martinhochel@microsoft.com", "dependentChangeType": "patch"