I am using TypeScript in React. I would like to create custom alerts and add to them images. I used this method:
private alert() {
alert("This is an Alert Dialog");
}
Do you have any idea how to customize it?
Thans in advance for tips.
I am using TypeScript in React. I would like to create custom alerts and add to them images. I used this method:
private alert() {
alert("This is an Alert Dialog");
}
Do you have any idea how to customize it?
Thans in advance for tips.
The alert box is a system object, and not subject to CSS. You might want to use a third party library for that or add your own alert popup. Either way you can't style the default alert box.
What you may want to look for is a modal box, as you could style that so display alerts.
This page can help you get started: https://www.w3schools.com/howto/howto_css_modals.asp
Or look into bootstrap which simplifies modals a lot: https://getbootstrap.com/docs/4.0/components/modal/
You need to use modals. Here it is a sample:
import React from "react";
export const Modal = ({modalContent, style}) => {
return (
<div className="modal" style={style}>
{modalContent}
</div>
);
};
And usage is like this:
import { Modal } from '../Shared/Modal';
....
{this.state.Modal && <Modal style={{ animation: "fadeIn 1s, scaleUp 1s" }}
modalContent={
<div className="Add-BillRange">
<h1> MODAL </h1>
</div>
}
/>}
this.state.Modal
controls if the modal should be showed or not.