Note: anytime I refer to a “component”, I’m referring to the type of components that can be created in the editor.
I’m building a Toaster component to generate toasts. I’m almost exclusively using custom javascript. At the moment, I generate a toast by creating a div in the dom and then assigning it styles like below:
const toast = wwLib.getFrontDocument().createElement('div');
toast.className = 'toast';
toast.textContent = message;
Object.assign(toast.style, {
background: '#333',
color: '#fff',
height: '50px', // Fixed height for easy management
padding: '10px 20px',
borderRadius: '6px',
boxShadow: '0 4px 6px rgba(0, 0, 0, 0.2)',
opacity: '0',
pointerEvents: 'auto',
position: 'absolute',
left: '50%',
transform: 'translateX(-50%) translateY(100%)',
transition: `transform ${TOASTS_EXPAND_TIME / 1000}s ease`,
});
In place of this, it would be great if I could build a Toast component and then simply add it to the dom with any relevant properties using javascript. Perhaps weweb has an api that would allow this. This would make the design of the toasts easier and would keep the Toaster code cleaner. Is this possible?