UNPKG

react-marquee-slider-vertical

Version:

The marquee slider of your wildest dreams. Only for React.js ⛺

66 lines 6.12 kB
"use strict"; var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = __importStar(require("react")); var styled_components_1 = __importStar(require("styled-components")); var Container = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n width: ", "px;\n height: ", "px;\n justify-content: center;\n align-items: center;\n background-color: ", ";\n"], ["\n display: flex;\n width: ", "px;\n height: ", "px;\n justify-content: center;\n align-items: center;\n background-color: ", ";\n"])), function (props) { return props.buffer; }, function (props) { return props.buffer; }, function (props) { return props.backgroundColor; }); var Space = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: relative;\n width: ", "px;\n height: ", "px;\n"], ["\n position: relative;\n width: ", "px;\n height: ", "px;\n"])), function (props) { return props.width; }, function (props) { return props.height; }); var SolarSystem = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: absolute;\n left: 50%;\n top: 50%;\n margin-left: -", "px;\n margin-top: -", "px;\n width: ", "px;\n height: ", "px;\n animation: ", " linear infinite;\n background-color: ", ";\n"], ["\n position: absolute;\n left: 50%;\n top: 50%;\n margin-left: -", "px;\n margin-top: -", "px;\n width: ", "px;\n height: ", "px;\n animation: ", " linear infinite;\n background-color: ", ";\n"])), function (props) { return props.width / 2; }, function (props) { return props.width / 2; }, function (props) { return props.width; }, function (props) { return props.width; }, function (props) { return orbit(props.initDeg, props.direction); }, function (props) { return props.backgroundColor; }); var Earth = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: inline-block;\n animation: ", " linear infinite;\n background-color: ", ";\n"], ["\n display: inline-block;\n animation: ", " linear infinite;\n background-color: ", ";\n"])), function (props) { return reconciliation(props.initDeg, props.direction); }, function (props) { return props.backgroundColor; }); var orbit = function (initDeg, direction) { return styled_components_1.keyframes(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n 0% {\n transform: rotate(", "deg);\n }\n\n 100% {\n transform: rotate(", "deg);\n }\n"], ["\n 0% {\n transform: rotate(", "deg);\n }\n\n 100% {\n transform: rotate(", "deg);\n }\n"])), initDeg, direction === "clockwise" ? initDeg + 360 : initDeg - 360); }; var reconciliation = function (initDeg, direction) { return styled_components_1.keyframes(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n 0% {\n transform: rotate(", "deg);\n }\n\n 100% {\n transform: rotate(", "deg);\n }\n"], ["\n 0% {\n transform: rotate(", "deg);\n }\n\n 100% {\n transform: rotate(", "deg);\n }\n"])), direction === "clockwise" ? 360 - initDeg : 0 - initDeg, direction === "clockwise" ? 0 - initDeg : 360 - initDeg); }; var Motion = function (_a) { var children = _a.children, initDeg = _a.initDeg, direction = _a.direction, velocity = _a.velocity, radius = _a.radius, backgroundColors = _a.backgroundColors; var earthRef = react_1.useRef(null); var _b = react_1.useState({ width: 0, height: 0 }), earthSize = _b[0], setEarthSize = _b[1]; var halfWidth = Math.pow(Math.pow(radius, 2) / 2, 1 / 2); var width = halfWidth * 2; var circumference = 2 * Math.PI * radius; var animationDuration = circumference / velocity; react_1.useEffect(function () { setEarthSize({ width: earthRef.current ? earthRef.current.clientWidth : 0, height: earthRef.current ? earthRef.current.clientHeight : 0, }); }, []); return (react_1.default.createElement(Container, { buffer: radius * 2, backgroundColor: backgroundColors.buffer }, react_1.default.createElement(Space, { width: earthSize.width, height: earthSize.height }, react_1.default.createElement(SolarSystem, { style: { animationDuration: animationDuration + "s" }, width: width, initDeg: initDeg, direction: direction, backgroundColor: backgroundColors.solarSystem }, react_1.default.createElement(Earth, { ref: earthRef, style: { animationDuration: animationDuration + "s" }, initDeg: initDeg, direction: direction, backgroundColor: backgroundColors.earth }, children))))); }; Motion.defaultProps = { initDeg: 0, velocity: 10, radius: 10, direction: "clockwise", backgroundColors: { earth: "transparent", solarSystem: "transparent", buffer: "transparent", }, }; exports.default = Motion; var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6; //# sourceMappingURL=Motion.js.map