@austere sedge Thanks! I ended with something like this:
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = chrome.runtime.getURL('/styles/mantine/styles.css')
shadowRoot.append(link)
It works well. My other issue was that webpack's previous configuration used style-loader on the mantine css file. Hence the injection into the document head.
@late arrow When injecting a Shadow DOM into a host website (let's say through a Chrome extension using Mantine), sizing of elements could be different since rem is used for calculations.
Is there a way to tell Mantine to use px instead of rem?
Currently I'm taking the DEFAULT_THEME, convert rem to px, merge it with my theme override, and finally pass it to the Provider.
const convertDefaultTheme = () => {
const stringified = JSON.stringify(DEFAULT_THEME)
const replaced = stringified.replace(/(\d*\.?\d+)rem/g, (_, remValue) => {
const pixels = Math.round(parseFloat(remValue) * 16)
return `${pixels}px`
})
return JSON.parse(replaced)
}
const convertedDefaultTheme = convertDefaultTheme()
const mantineTheme = createTheme({
colors: {
brand,
},
primaryColor: 'brand',
})
const merged = mergeMantineTheme(convertedDefaultTheme, mantineTheme)
<MantineProvider theme={merged}></MantineProvider>
Do you think, there's more idiomatic way to go about this?