My app will be loaded into a parent div that has a specific class (e.g. .my-app).
Is there a way to preprend all the classes generated by styled-components with .my-app .
Given a component like
import React from 'react';
import styled from 'styled-components';
const Button = (props) => {
return <StyledButton type="button">foo</StyledButton>;
};
const StyledButton = styled.button`
color: blue;
`;
export default Button;
normally you might have output like
<style data-styled="active" data-styled-version="5.1.1">
.cuetwY { color: blue; }
</style>
<div class="my-app">
<button class="cuetwY">foo</button>
</div>
But I'm trying to achieve the following:
<style data-styled="active" data-styled-version="5.1.1">
/* Note the additional selector prepended here */
.my-app .cuetwY { color: blue; }
</style>
<div class="my-app">
<button class="cuetwY">foo</button>
</div>
I have tried both babel-plugin-styled-components-css-namespace and stylis-plugin-extra-scope but neither seems to work with newer versions of styled-components and the older versions of sc don't work with React 18.