Hi there!
I'm creating a sandbox inside an iFrame. I'm using React and REdux for the dashboard.
The user can import the HTML.
The user can enter tailwindcss classes - if the user types tex it should show all text-* styles in the menu, like a recommendation/IDE.
The user can modify the tailwind with the tailwind.config.js, however, via the browser. So I will show the JSON data inside the browser, and let the user modify any part they like.
How do I compile tailwindcss so I can have the recommendation like the IDE, so if someone types pt-300 its going to know it doesn't exist, but if the user extends the config, and adds in pt-300 it will.
How do I do that? I'm also thinking o performance here as I don't want to blow up the computer, though I can always pre-load some of the stuff on the boot of the app, but then if the user wants to change it directly, that will need to be compiled anyway. I've seem some do this, and there is no lag when changing the config.
I'm using this for the iFrame as well if it makes any difference https://github.com/ryanseddon/react-frame-component
So far I've been doing this basically:
function containerTailwind() {
// <script src="https://cdn.tailwindcss.com"></script>
// Inject CSS
const initialContent = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="bg-white">
<div></div>
</body>
</html>
`;
<Frame
initialContent={frameState.initialContent}
onLoad={event => event.stopPropagation()}
ref={iframeRef}
className="bg-white h-full w-full relative"
style={{ "pointerEvents": "auto"}}
loading="lazy"
>
<div dangerouslySetInnerHTML={{__html: buildJSONfromHTML(pages.pages.data.pages[pages.activePageID - 1].html) }} />
<FrameContent />
</Frame>
Now I'm thinking about
const injectCSS = () => {
if(!document) return
const head = document?.querySelector('head');
const style = document?.createElement('style');
head?.appendChild(style);
}
But then, where will the styles even be stored, how do I compile them, how do I tell it to use X config?
My biggest question is how do I let the user inject their own config file (from the input I provide) and let it compile without blowing the browser or taking 10seconds to do so.
I've also discovered this so I might prob need to use that I Guess https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
I just have no idea how to go about injecting tailwindcss based on what the user puts in their own config.