UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

96 lines 3.51 kB
import * as React from "react"; import styled, { css } from "styled-components"; import mq from "../utils/mediaQuery"; import Stack from "../Stack"; import defaultTheme from "../defaultTheme"; import Text from "../Text"; import { fadeIn, fadeOut, lightAnimation, getPositionStyle } from "./helpers"; import useTheme from "../hooks/useTheme"; import useSwipe from "./hooks/useSwipe"; const StyledWrapper = styled(({ className, children, ariaLive }) => /*#__PURE__*/React.createElement("div", { className: className, "aria-live": ariaLive, role: "status" }, children)).withConfig({ displayName: "ToastMessage__StyledWrapper", componentId: "sc-15ayrs7-0" })(["", ""], ({ theme, placement, offsetY, offsetX, opacity }) => css(["z-index:", ";will-change:transform;cursor:grab;opacity:", ";transition:all ", " ease-in-out;transform:translate(", "px,", "px);", ";"], theme.orbit.zIndexOnTheTop, opacity, theme.orbit.durationNormal, offsetX, offsetY, getPositionStyle(placement))); StyledWrapper.defaultProps = { theme: defaultTheme }; const StyledInnerWrapper = styled.div.withConfig({ displayName: "ToastMessage__StyledInnerWrapper", componentId: "sc-15ayrs7-1" })(["", ""], ({ theme, visible, duration, isPaused }) => css(["position:relative;border-radius:", ";background:", ";padding:", ";width:100%;overflow:hidden;will-change:transform;pointer-events:", ";animation:", " ", " forwards;animation-play-state:", ";svg{min-height:20px;}", " ", ""], theme.orbit.borderRadiusLarge, theme.orbit.paletteInkDark, theme.orbit.spaceXSmall, visible ? "auto" : "none", visible ? fadeIn : fadeOut, theme.orbit.durationNormal, isPaused ? "paused" : "running", mq.largeMobile(css(["max-width:360px;width:initial;padding:", ";"], theme.orbit.spaceSmall)), css(["&:before{content:\"\";will-change:transform;position:absolute;border-radius:", ";top:0;z-index:1;left:0;width:100%;height:100%;background:", ";opacity:0.1;animation:", " ", "ms linear;animation-play-state:", ";}"], theme.orbit.borderRadiusLarge, theme.orbit.paletteWhite, lightAnimation, duration, isPaused ? "paused" : "running"))); StyledInnerWrapper.defaultProps = { theme: defaultTheme }; const ToastMessage = ({ onMouseEnter, onMouseLeave, visible, onDismiss, dismissTimeout, placement, icon, children, offset, ariaLive }) => { const theme = useTheme(); const ref = React.useRef(null); const [isPaused, setPaused] = React.useState(false); const { swipeOffset, swipeOpacity } = useSwipe(ref, onDismiss, 50, placement.match(/right|center/) ? "right" : "left"); return /*#__PURE__*/React.createElement(StyledWrapper, { ariaLive: ariaLive, opacity: swipeOpacity, visible: visible, offsetY: offset, offsetX: swipeOffset, placement: placement }, /*#__PURE__*/React.createElement(StyledInnerWrapper, { visible: visible, ref: ref, isPaused: isPaused, duration: dismissTimeout, onMouseEnter: () => { onMouseEnter(); setPaused(true); }, onMouseLeave: () => { onMouseLeave(); setPaused(false); } }, /*#__PURE__*/React.createElement(Stack, { flex: true, shrink: true, spacing: "XSmall" }, icon && /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/ // @ts-expect-error TODO: fix this React.cloneElement(icon, { size: "small", customColor: theme.orbit.paletteWhite }), /*#__PURE__*/React.createElement(Text, { type: "white" }, children)))); }; export default ToastMessage;