UNPKG

react-floating-balloons

Version:

Floating colorful balloons with custom names and popping feature

71 lines (58 loc) 7.16 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports.StyledBalloon = void 0; var _styledComponents = _interopRequireWildcard(require("styled-components")); var _utils = require("./utils"); var _templateObject, _templateObject2, _templateObject3; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } var balloonsLeftUpKFAnimation = function balloonsLeftUpKFAnimation(_ref) { var x = _ref.x, y = _ref.y, left = _ref.left, hangOnTop = _ref.hangOnTop, rotate = _ref.rotate; // console.log({x,y, left, rotate}); return (0, _styledComponents.keyframes)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n {\n 0%{ \n top: 100vh;\n left: ", ";\n }\n 15%{ \n top: ", ";\n left: ", ";\n }\n 25%{\n top: ", ";\n left: ", ";\n }\n 45%{\n top: ", ";\n left: ", ";\n }\n 80%{\n top: ", ";\n left: ", ";\n }\n 100%{\n top: ", ";\n left: ", ";\n }\n }\n"])), "".concat(left, "vw"), "".concat((0, _utils.random)(70, 80), "vh"), "".concat(left - (0, _utils.random)(10, 20), "vw"), "".concat((0, _utils.random)(45, 55), "vh"), "".concat(left + (0, _utils.random)(15, 20), "vw"), "".concat((0, _utils.random)(25, 40), "vh"), "".concat(left - (0, _utils.random)(20, 30), "vw"), "".concat((0, _utils.random)(5, 15), "vh"), "".concat(left + (0, _utils.random)(20, 30), "vw"), "".concat(hangOnTop ? (0, _utils.random)(-2, 1) : (0, _utils.random)(-60, -70), "vh"), "".concat(hangOnTop ? (0, _utils.random)(0, 50) : left - (0, _utils.random)(30, 50), "vw")); }; var balloonsRightUpKFAnimation = function balloonsRightUpKFAnimation(_ref2) { var x = _ref2.x, y = _ref2.y, left = _ref2.left, rotate = _ref2.rotate, hangOnTop = _ref2.hangOnTop; // console.log({x,y, left, rotate}); return (0, _styledComponents.keyframes)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n {\n 0%{ \n top: 100vh;\n left: ", ";\n }\n 30%{ \n top: ", ";\n left: ", ";\n }\n 55%{\n top: ", ";\n left: ", ";\n }\n 70%{\n top: ", ";\n left: ", ";\n }\n 100%{\n top: ", ";\n left: ", ";\n }\n }\n"])), "".concat(left, "vw"), "".concat((0, _utils.random)(60, 70), "vh"), "".concat(left - (0, _utils.random)(10, 30), "vw"), "".concat((0, _utils.random)(30, 40), "vh"), "".concat(left + (0, _utils.random)(5, 20), "vw"), "".concat((0, _utils.random)(10, 20), "vh"), "".concat(left - (0, _utils.random)(20, 30), "vw"), "".concat(hangOnTop ? (0, _utils.random)(-2, 1) : (0, _utils.random)(-60, -70), "vh"), "".concat(hangOnTop ? (0, _utils.random)(0, 50) : left + (0, _utils.random)(30, 50), "vw")); }; var colorMaps = { yellow: 'rgba(150, 150, 0, .75)', blue: 'rgba(0, 0, 150, .75)', purple: 'rgba(77, 0, 150, 0.75)', green: 'rgba(0, 150, 0, .75)', orange: 'rgba(150, 47, 0, 0.75)', red: 'rgba(150, 0, 0, .75)' }; var StyledBalloon = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n // top: 100px;\n background-color: ", ";\n display: ", ";\n visibility: ", ";\n left: ", ";\n transition: transform 0.5s ease;\n z-index: 10;\n animation: ", " ease-in-out ", ";\n // animation-duration: 3s;\n animation-duration: ", ";\n animation-delay ", ";\n animation-fill-mode: ", ";\n transform-origin:bottom center;\n --balloonDimension: 15vmax; /* 15% of min(viewport width, height) */\n width: var(--balloonDimension);\n height: var(--balloonDimension);\n border-radius: 100% 100% 15% 100%;\n margin: 0 0 0 25px;\n transform: rotateZ(45deg);\n position: fixed;\n bottom: calc(-1 * var(--balloonDimension));\n &::before {\n content: \"\";\n width: 10%;\n height: 25%;\n background: radial-gradient(circle, rgba(255,255,255,.7) 0%, rgba(255,255,255,.1) 100%);\n position: absolute;\n left: 15%;\n top: 45%;\n border-radius: 100%;\n }\n &::after {\n content: \"\";\n width: 13%;\n height: 5%;\n background-color: inherit;\n position: absolute;\n left: 90%;\n top: 94%;\n border-radius: 22%;\n transform: rotateZ(-45deg);\n }\n .string {\n position: absolute;\n background-color: #e2e204;\n border-radius: 50%/100px 100px 0 0;\n width: 4px;\n height: calc(var(--balloonDimension) * .6);\n transform-origin: top center;\n transform: rotateZ(-45deg);\n top: calc(var(--balloonDimension) - 6px);\n left: calc(var(--balloonDimension) - 8px);\n }\n .msg {\n color: #fff;\n font-family: cursive;\n position: absolute;\n top: 30%;\n left: 28%;\n transform: rotate(302deg);\n }\n .show {\n display: block;\n visibility: visible;\n }\n"])), function (props) { return colorMaps[props.color]; }, function (props) { return props.show ? 'block' : 'none'; }, function (props) { return props.visible ? 'visible' : 'hidden'; }, function (props) { return "".concat(props.animate.left, "vw"); }, function (props) { return props.animate.left > 50 ? balloonsRightUpKFAnimation(props.animate) : balloonsLeftUpKFAnimation(props.animate); }, function (props) { return props.animate.loop ? 'infinite' : '1'; }, function (props) { return "".concat(props.animate.duration, "s"); }, function (props) { return "".concat(props.animate.delay, "s"); }, function (props) { return props.animate.hangOnTop ? 'forwards' : 'none'; }); exports.StyledBalloon = StyledBalloon;