Skip to content

react-theme: support custom theme creation API #21181

@khmakoto

Description

@khmakoto

Spinning from comment thread in #20651.

We should look at how to support a self-explanatory API for consumers to create a custom theme.

We could do that by modifying the signature of mergeThemes to allow for this type of functionality:

export function mergeThemes<TTheme extends Theme = Theme, TPartialTheme extends PartialTheme = PartialTheme>(a: TTheme | undefined, b: TPartialTheme | undefined): TTheme & TPartialTheme {
   ...
}

And then we could do:

import { mergeThemes, webLightTheme } from '@fluentui/react-theme';

const customTokens = {...};
const customTheme = mergeTheme(webLightTheme, customTokens);
// easily accessible shape inferred from source of truth - actual implementation
type CustomTheme = typeof customTheme;

Metadata

Metadata

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions