使用实质性用户界面创建弹出框

时间:2020-01-09 20:14:00

标签: javascript reactjs

我有一个React组件Experience,它在6个div中有6个不同的类别,并且每种体验都有一个弹出窗口,并希望根据类别用一系列图像(gastronomiaExperiences,deportesExperiences等)填充它。

我有弹出窗口,并且有每组图像的数组。但是,如何用一系列图像填充弹出窗口。

这是我的“体验”组件的外观。

enter image description here

这是我希望我的弹出窗口看起来像的图片

enter image description here

这是我的组成部分

    import React, { memo, useCallback } from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/styles';
import Typography from '@material-ui/core/Typography';
import clsx from 'clsx';

import { mod } from 'react-swipeable-views-core';
import Popper from '@material-ui/core/Popper';
import gastronomia from 'assets/experiences/gastronomia.jpg';
import productos from 'assets/experiences/productos.jpg';
import giftcard from 'assets/experiences/giftcard.jpg';
import diversion from 'assets/experiences/diversion.jpg';
import deporte from 'assets/experiences/deporte.jpg';
import belleza from 'assets/experiences/belleza.jpg';
import gastronomiaExperiences from 'data/gastronomia';
import productosExperiences from 'data/productos';
import giftcardExperiences from 'data/giftcard';
import diversionExperiences from 'data/diversion';
import deporteExperiences from 'data/deporte';
import bellezaExperiences from 'data/belleza';

// Proptypes definitions to the component.
const propTypes = {
  /** Custom root className. */
  className: PropTypes.string,

};

// Default props definitions.
const defaultProps = {
  className: null,
};

// Component's styles
const useStyles = makeStyles(theme => ({
  root: {
    display: 'block',
    margin: '0 auto',
    maxWidth: '50%',
    [theme.breakpoints.down('md')]: {
      maxWidth: '70%',
    },
    [theme.breakpoints.down('sm')]: {
      maxWidth: '100%',
    },
    '& .experiences-column': {
      display: 'inline-block',
      verticalAlign: 'top',
      textAlign: 'center',
      '&.col1': {
        width: '36.31%',
        [theme.breakpoints.down('sm')]: {
          width: 'initial',
        },
      },
      '&.col2': {
        width: '63.69%',
        [theme.breakpoints.down('sm')]: {
          width: 'initial',
        },
      },
      '& .experience': {
        padding: 2,
        position: 'relative',
        '& img': {
          width: '100%',
          display: 'block',
        },
        '& .experience-title': {
          position: 'absolute',
          bottom: 30,
          left: 0,
          right: 0,
          textAlign: 'center',
        },
      },
    },
  },
}), { name: 'ExperiencesStyle' });



/**
 * Component used to render a grid of experiences.
 *
 * @param {object} props - The component's props.
 * @returns {object} React element.
 */
const Experiences = memo(
  (props) => {
    const { className } = props;
    const classes = useStyles(props);

    const [anchorEl, setAnchorEl] = React.useState(null);

    const handleClick = event => {
    setAnchorEl(anchorEl ? null : event.currentTarget);
    };

  const open = Boolean(anchorEl);
  const id = open ? 'simple-popper' : undefined;

    const experience = useCallback((img, title, category, id, open, anchorEl, popoverCategory) => (
      <div className="experience" aria-describedby={id} onClick={handleClick} >
        <img
          data-sizes="auto"
          className="lazyload"
          data-src={img}
          alt={title}
        />
        <div className="experience-title">
          <Typography
            color="textSecondary"
            variant="subtitle2"
            className="highlight highlight1"
            display="inline"
          >
            { title }
          </Typography>
        </div>

        <Popper id={id} open={open} anchorEl={anchorEl}>
          <div className={classes.paper}>
            <img
          data-sizes="auto"
          className="lazyload"
          data-src={popoverCategory}
          alt="Puntospoint"
        />
          </div>
        </Popper>
      </div>

    ), []);


    return (
      <div className={clsx(classes.root, className)}>
        <div className="experiences-column col1">
          {experience(gastronomia, 'GASTRONOMÍA', 'gastronomia', id, open, anchorEl, gastronomiaExperiences)}
          {experience(giftcard, 'GIFT CARD', 'giftcard', id, open, anchorEl, giftcardExperiences)}
          {experience(deporte, 'DEPORTE', 'deporte', id, open, anchorEl, deporteExperiences)}
        </div>
        <div className="experiences-column col2">
          {experience(productos, 'PRODUCTOS', 'productos', id, open, anchorEl, productosExperiences)}
          {experience(diversion, 'DIVERSIÓN', 'diversion', id, open, anchorEl, diversionExperiences)}
          {experience(belleza, 'BELLEZA', 'belleza', id, open, anchorEl, bellezaExperiences)}
        </div>
      </div>
    );
  },
);

// Component proptypes.
Experiences.propTypes = propTypes;

// Component default props.
Experiences.defaultProps = defaultProps;

export default Experiences;

1 个答案:

答案 0 :(得分:0)

我认为没有一个组件可以真正实现您想要的目标。我认为最接近的是全屏显示为true时的\d组件。

看看它们的组成部分: https://codesandbox.io/embed/material-demo-rljy7?fontsize=14&hidenavigation=1&theme=dark

由于不存在完全匹配的内容,因此您可能需要创建自己的组件,因此以下是实际的,组件的源代码:Souce Code,通过阅读它,您可能会了解如何使用Dialog组件。更具体地说,组件的全屏样式如下: Link

Full screen styles

我想您可以将高度设置为小于100%,并可能在项目位置上稍作调整,以使其停留在页面底部。

我希望这有助于您走上正确的轨道!