import * as React from 'react'; import { Customizations } from './Customizations'; import { hoistStatics } from '../hoistStatics'; import { CustomizerContext } from './CustomizerContext'; import { concatStyleSets, makeShadowConfig } from '@fluentui/merge-styles'; import { MergeStylesShadowRootConsumer } from '../shadowDom/contexts/MergeStylesShadowRootConsumer'; import { getWindow } from '../dom/getWindow'; import { WindowContext } from '@fluentui/react-window-provider'; import type { ICustomizerContext } from './CustomizerContext'; import type { ShadowConfig } from '@fluentui/merge-styles'; import { memoizeFunction } from '../memoize'; import type { JSXElement } from '../jsx'; const memoizedMakeShadowConfig = memoizeFunction(makeShadowConfig); const mergeComponentStyles = memoizeFunction( // eslint-disable-next-line @typescript-eslint/no-explicit-any (defaultStyles: any, componentStyles: any, shadowConfig: ShadowConfig): any => { const styles = componentStyles ?? defaultStyles ?? {}; styles.__shadowConfig__ = shadowConfig; return styles; }, ); export function customizable( scope: string, fields: string[], concatStyles?: boolean, // eslint-disable-next-line @typescript-eslint/no-explicit-any ):
(ComposedComponent: React.ComponentType
) => any { // eslint-disable-next-line @typescript-eslint/no-explicit-any return function customizableFactory
(ComposedComponent: React.ComponentType
): any { const resultClass = class ComponentWithInjectedProps extends React.Component
{
public static displayName: string = 'Customized' + scope;
public static contextType = WindowContext;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public context!: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _styleCache: { default?: any; component?: any; merged?: any } = {};
constructor(props: P) {
super(props);
this._onSettingChanged = this._onSettingChanged.bind(this);
}
public componentDidMount(): void {
Customizations.observe(this._onSettingChanged);
}
public componentWillUnmount(): void {
Customizations.unobserve(this._onSettingChanged);
}
public render(): JSXElement {
return (