fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

MergeStyles: Provide a stylesheet instance contextually

Open yajiex opened this issue 7 years ago • 2 comments

Describe the feature that you would like added

Would it be possible to get all style rules applied to one specific component? Something like following

<DefaultButton
    onInsertRules: (rules) => {
      // Here we got all style rules applied to the component, hence we can extract them and inject it other iframe
    }
/>

The scenario would be, now with the method mentioned in https://github.com/OfficeDev/office-ui-fabric-react/issues/1659#issuecomment-469488915, we can prevent default style rules DOM injection and get all the rules, injecting them to other iframes. However, since StyleSheet is a singleton, we can't control which part of style rules of get. For example, if there're following rules injected from fabric, we would get all of them, there's no way to get rules only applied to a specific component.

.ms-button1 {
}

.ms-button2 {
}

What component or utility would this be added to

All components

Have you discussed this feature with our team, and if so, who

Additional context/screenshots

yajiex avatar Mar 05 '19 08:03 yajiex

This would only be possible if we encapsulated the stylesheet in react context and passed it along with the styles to mergeStyles.

This would first require a change to mergeStyles to have something like mergeStylesWithStylesheet(sheet, ...rules) so that we could pass an instance in, rather than resolving the page-scoped stylesheet.

Then to be able to scope areas to use a different sheet, we'd need a context solution to provide the stylesheet.

Then every component would need to consume the context prior to rendering, so that it could pass in the custom sheet.

It's possible to leverage the theme object to gather contextual data.

I don't think we will be getting to this in a while. It's possible to work around if needing to project new rules, but it's a large amount of work with high risk of regression.

dzearing avatar Mar 05 '19 16:03 dzearing

Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

msft-fluent-ui-bot avatar Apr 26 '21 17:04 msft-fluent-ui-bot