content logo

React Popups:

React Popup Inside a Border with Float in Effect

In this post, there is a black box at the top of the page. This box does not have a green button. The green button and black box have an outer shadow. Clicking on this green button will display the pop-up from the top of the screen. This pop-up has a closing icon.

#

Free React Popup Code

#

HTML Popup Inside Boredr

#

Animating React Popup

#

Float in React Popup

<!-- This script got from frontendfreecode.com -->
<a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
const StyleFrame = {
  borderRadius: "3%",
  borderWidth: "8px",
  borderColor: "black",
  maxWidth: "200px",
  margin: "0 auto",
  boxShadow: "0 0 20px gray",
  padding: "10px",
  fontFamily: "Lato, sans-serif",
  fontSize: "100%",
  textAlign: "center" };
const StyleClose = {
  fontSize: "1.3rem",
  fontWeight: "bold",
  position: "absolute",
  top: "-4px",
  right: "0px",
  width: "20px",
  height: "20px",
  textDecoration: "none",
  border: 0,
  outline: 0,
  background: "none",
  verticalAlign: "top" };
const StyleTrigger = {
  fontSize: "20px",
  fontWeight: "bold",
  textAlign: "center",
  lineHeight: "50px",
  position: "relative",
  overflow: "visible",
  width: "170px",
  marginTop: "10px",
  borderRadius: "50em",
  background: "#35a785",
  color: "inherit",
  border: "0",
  outline: "0",
  boxShadow: "3px 3px 20px gray" };
const StyleContainer = {
  padding: "2px",
  maxWidth: "200px",
  transitionDuration: ".3s",
  transitionProperty: "transform",
  transform: "translateY(-40px)",
  textAlign: "center",
  borderRadius: ".25em .25em .4em .4em",
  boxShadow: "0 0 20px rgba(0, 0, 0, .2)" };
const StylePopup = {
  visibility: "hidden",
  transition: "opacity .3s 0s, visibility 0s .3s",
  opacity: "0" };
class Popup extends React.Component {
  handleClose() {
    this.props.handleClose({ keyCode: 27 });
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { style: this.props.stylePopup }, /*#__PURE__*/
      React.createElement("div", { style: this.props.styleContainer }, /*#__PURE__*/
      React.createElement("p", null, "Some text"), /*#__PURE__*/
      React.createElement("button", { style: StyleClose, onClick: this.handleClose.bind(this) }, "\xD7"))));
  }}
class ShowPopup extends React.Component {
  constructor() {
    super();
    this.state = {
      opened: false,
      stylePopup: StylePopup,
      styleContainer: StyleContainer };
    this.handleClose = this.handleClose.bind(this);
    this.handleClick = this.handleClick.bind(this);
  }
  componentDidMount() {
    document.addEventListener('keydown', this.handleClose);
  }
  handleClose(e) {
    const ESC = 27;
    if (e.keyCode === ESC) {
      this.setState({
        opened: false,
        stylePopup: {
          ...this.state.stylePopup,
          transition: "opacity .3s 0s, visibility 0s .3s",
          visibility: "hidden",
          opacity: "0" },
        styleContainer: {
          ...this.state.styleContainer,
          transform: "translateY(-40px)" } });
    };
  }
  handleClick() {
    if (this.state.opened) {
      this.setState({
        opened: false,
        stylePopup: {
          ...this.state.stylePopup,
          transition: "opacity .3s 0s, visibility 0s .3s",
          visibility: "hidden",
          opacity: "0" },
        styleContainer: {
          ...this.state.styleContainer,
          transform: "translateY(-40px)" } });
    } else {
      this.setState({
        opened: true,
        stylePopup: {
          ...this.state.stylePopup,
          transition: "opacity .3s 0s, visibility 0s 0s",
          visibility: "visible",
          opacity: "1" },
        styleContainer: {
          ...this.state.styleContainer,
          transform: "translateY(0px)" } });
    };
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", { style: StyleFrame }, /*#__PURE__*/
      React.createElement(Popup, { stylePopup: this.state.stylePopup, styleContainer: this.state.styleContainer, handleClose: this.handleClose.bind(this) }), /*#__PURE__*/
      React.createElement("button", { style: StyleTrigger, type: "button", onClick: this.handleClick }, "View Pop-up")));
  }}
ReactDOM.render( /*#__PURE__*/React.createElement(ShowPopup, null), document.querySelector('body'));
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js'></script>
</head>
<body>
<div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
const StyleFrame = {
  borderRadius: "3%",
  borderWidth: "8px",
  borderColor: "black",
  maxWidth: "200px",
  margin: "0 auto",
  boxShadow: "0 0 20px gray",
  padding: "10px",
  fontFamily: "Lato, sans-serif",
  fontSize: "100%",
  textAlign: "center" };
const StyleClose = {
  fontSize: "1.3rem",
  fontWeight: "bold",
  position: "absolute",
  top: "-4px",
  right: "0px",
  width: "20px",
  height: "20px",
  textDecoration: "none",
  border: 0,
  outline: 0,
  background: "none",
  verticalAlign: "top" };
const StyleTrigger = {
  fontSize: "20px",
  fontWeight: "bold",
  textAlign: "center",
  lineHeight: "50px",
  position: "relative",
  overflow: "visible",
  width: "170px",
  marginTop: "10px",
  borderRadius: "50em",
  background: "#35a785",
  color: "inherit",
  border: "0",
  outline: "0",
  boxShadow: "3px 3px 20px gray" };
const StyleContainer = {
  padding: "2px",
  maxWidth: "200px",
  transitionDuration: ".3s",
  transitionProperty: "transform",
  transform: "translateY(-40px)",
  textAlign: "center",
  borderRadius: ".25em .25em .4em .4em",
  boxShadow: "0 0 20px rgba(0, 0, 0, .2)" };
const StylePopup = {
  visibility: "hidden",
  transition: "opacity .3s 0s, visibility 0s .3s",
  opacity: "0" };
class Popup extends React.Component {
  handleClose() {
    this.props.handleClose({ keyCode: 27 });
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { style: this.props.stylePopup }, /*#__PURE__*/
      React.createElement("div", { style: this.props.styleContainer }, /*#__PURE__*/
      React.createElement("p", null, "Some text"), /*#__PURE__*/
      React.createElement("button", { style: StyleClose, onClick: this.handleClose.bind(this) }, "\xD7"))));
  }}
class ShowPopup extends React.Component {
  constructor() {
    super();
    this.state = {
      opened: false,
      stylePopup: StylePopup,
      styleContainer: StyleContainer };
    this.handleClose = this.handleClose.bind(this);
    this.handleClick = this.handleClick.bind(this);
  }
  componentDidMount() {
    document.addEventListener('keydown', this.handleClose);
  }
  handleClose(e) {
    const ESC = 27;
    if (e.keyCode === ESC) {
      this.setState({
        opened: false,
        stylePopup: {
          ...this.state.stylePopup,
          transition: "opacity .3s 0s, visibility 0s .3s",
          visibility: "hidden",
          opacity: "0" },
        styleContainer: {
          ...this.state.styleContainer,
          transform: "translateY(-40px)" } });
    };
  }
  handleClick() {
    if (this.state.opened) {
      this.setState({
        opened: false,
        stylePopup: {
          ...this.state.stylePopup,
          transition: "opacity .3s 0s, visibility 0s .3s",
          visibility: "hidden",
          opacity: "0" },
        styleContainer: {
          ...this.state.styleContainer,
          transform: "translateY(-40px)" } });
    } else {
      this.setState({
        opened: true,
        stylePopup: {
          ...this.state.stylePopup,
          transition: "opacity .3s 0s, visibility 0s 0s",
          visibility: "visible",
          opacity: "1" },
        styleContainer: {
          ...this.state.styleContainer,
          transform: "translateY(0px)" } });
    };
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("fieldset", { style: StyleFrame }, /*#__PURE__*/
      React.createElement(Popup, { stylePopup: this.state.stylePopup, styleContainer: this.state.styleContainer, handleClose: this.handleClose.bind(this) }), /*#__PURE__*/
      React.createElement("button", { style: StyleTrigger, type: "button", onClick: this.handleClick }, "View Pop-up")));
  }}
ReactDOM.render( /*#__PURE__*/React.createElement(ShowPopup, null), document.querySelector('body'));
</script>

</body>
</html>
Preview