Support merging, concatenating style functions for mergeStyleSets, concatStyleSets
Describe the feature that you would like added The current implementation of mergeStyleSest, concateStyleSets takes input of IStyleSet as follows:
export declare function mergeStyleSets(...styleSets: Array<IStyleSet<any> | undefined | false | null>): IProcessedStyleSet<any>;
We hope it can support merging/concatenating IStyleFunctionOrObject as well.
Eg.
mergeStyleSets(IStyleFunction1, IStyleSet1, IStyleFunction2): IStyleFunction
So basically, the function will return a IStyleFunction which knows to take an input of IStyleProps, and invoke IStyleFunction1 first to get an style object. Then IStyleSet1 will merge with it to override/extend a part of the style object. Finally it invokes the IStyleFunction2 and use its result to merge with the previous result.
A use case would be that I have an intermediate component that wraps a Fabric component. This intermediate component creates some pre-defined styles, which is supposed to be influenced by the user input to the intermediate component. User input might only need to be slightly modify the work of the intermediate component.
After upgrading to Fabric 6, we found that a lot of places have started to use IStyleFunctionOrObject. To make sure such usage pattern is adopted across, we expect the user of the intermediate component pass in a IStyleFunctionOrObject as well.
What component or utility would this be added to mergeStyleSets, concatStyleSets
Have you discussed this feature with our team, and if so, who No Additional context/screenshots
Fabric actually has various helper functions above mergeStyleSets to take care of style functions...
There is the getClassNames function and styled function which internally calls _resolve (in styled.tsx), both in utilities package I believe.
We cannot change mergeStyleSets to return a Style Function - it would be a big breaking change that will adversely affect a lot of code currently calling mergeStyleSets.
May I recommend writing your own wrapper around mergeStyleSets if getClassNames and styled does not do what you want?
It is not clear to me how styled could help our scenario: we have multiple levels of custom styles passed in. And the styled function only opens the baseStyles to pass in. The returned component class
return Wrapped as (props: TComponentProps) => JSX.Element;
removed the parameter of context. Then how is the function supposed to grab context and get context.customizations ? Without the styles from context.customizations, I don't see how it can merge with baseStyles?
On the other hand, _resolve is almost what we need (but unfortunately it is not exported). The only problem is that it does not return a IStyleFunction, otherwise I can directly pass a IStyleFunction to the wrapped component. I imagine a usage would have to be that I create a function that calls _resolve internally (assuming that it would be exported from Fabric).
I don't have to expect changing mergeStyleSets. If there would be another utility created that handles my use case gracefully, I am all for it :)
@changsi-an Are you still awaiting this capability? concatStyleSet actually has much of the logic you want but it operates within subComponentStyles only.
I can try thinking about refactoring the logic out if this capability is still needed.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 5 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React!