UNPKG

@cimpress/react-components

Version:
111 lines 3.77 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useState, useEffect } from 'react'; import { css, cx } from '@emotion/css'; import { BlockButton } from '../internal'; import { teal } from '../colors'; const overlayCss = css ` position: absolute; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: 0.5s ease; background-color: rgba(255, 255, 255, 0.8); `; const flexCenterCss = css ` display: -ms-flexbox; display: flex; -ms-flex-pack: center; justify-content: center; -ms-flex-align: center; align-items: center; `; const itemCss = css ` position: absolute; top: 0; opacity: 0; left: 0; right: 0; width: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; perspective: 1000px; `; const overlayContainerCss = css ` &:hover { .crc-carousel-slide_overlay { opacity: 1; } } `; const activeCss = css ` opacity: 1; `; const transitionLeftIn = css ` left: 100%; transform: translateX(-100%); transition: 0.6s ease-in-out transform; `; const transitionRightIn = css ` left: -100%; transform: translateX(100%); transition: 0.6s ease-in-out transform; `; const transitionLeftOut = css ` transform: translateX(-100%); transition: 0.6s ease-in-out transform; `; const transitionRightOut = css ` transform: translateX(100%); transition: 0.6s ease-in-out transform; `; const clickableCss = css ` cursor: pointer; .crc-carousel-slide_overlay { cursor: pointer; } `; const CarouselSlide = (_a) => { var { active, animateIn, animateOut, direction, index, onCarouselClick, showZoomOverlay, zoomOverlayContent } = _a, props = __rest(_a, ["active", "animateIn", "animateOut", "direction", "index", "onCarouselClick", "showZoomOverlay", "zoomOverlayContent"]); const [classes, setClasses] = useState({ [itemCss]: true }); const shouldRenderZoomOverlay = showZoomOverlay && !!onCarouselClick; useEffect(() => { const initialClasses = { [itemCss]: true, [clickableCss]: !!onCarouselClick && active && !animateIn, [activeCss]: active || animateIn || animateOut, [overlayContainerCss]: shouldRenderZoomOverlay, }; if (direction && animateIn) { initialClasses[transitionLeftIn] = direction === 'next'; initialClasses[transitionRightIn] = direction === 'prev'; } if (direction && animateOut) { initialClasses[transitionLeftOut] = direction === 'next'; initialClasses[transitionRightOut] = direction === 'prev'; } setClasses(initialClasses); }, [onCarouselClick, active, animateIn, animateOut, shouldRenderZoomOverlay, direction]); const onClick = () => { onCarouselClick && onCarouselClick(index); }; const zoomContent = zoomOverlayContent || React.createElement("span", null, "Zoom In"); return (React.createElement(BlockButton, { onClick: onClick, className: cx('crc-carousel-slide', classes) }, props.children, shouldRenderZoomOverlay ? (React.createElement("div", { className: cx(overlayCss, flexCenterCss, 'crc-carousel-slide_overlay'), style: { color: teal.base } }, zoomContent)) : null)); }; export default CarouselSlide; //# sourceMappingURL=CarouselSlide.js.map