UNPKG

bobs-layout

Version:

bob's layout library. supports Container, Flex, Grid

28 lines (27 loc) 1.65 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { jsx as _jsx } from "react/jsx-runtime"; import { useScrollContext, ParallaxProvider } from './ParallaxContext'; var Parallax = function (_a) { var image = _a.image, _b = _a.height, height = _b === void 0 ? '100vh' : _b, css = _a.css, children = _a.children; var containerStyles = __assign({ height: height, overflow: 'hidden', background: image && "no-repeat center url(".concat(image, ")"), backgroundSize: 'cover', backgroundAttachment: 'fixed', position: 'relative' }, css); return _jsx(ParallaxProvider, __assign({ css: containerStyles }, { children: children })); }; var Item = function (_a) { var speed = _a.speed, image = _a.image, _b = _a.inset, inset = _b === void 0 ? 0 : _b, css = _a.css, children = _a.children; var yOffsetRatio = useScrollContext().yOffsetRatio; var yOffset = yOffsetRatio * (speed * 50); var parallaxStyles = __assign({ willChange: 'transform', background: image && "url(".concat(image, ") no-repeat center"), backgroundSize: 'cover', transform: "translate3d(0,".concat(yOffset, "px, 0)"), position: 'absolute', inset: inset }, css); return _jsx("div", __assign({ style: parallaxStyles }, { children: children })); }; Parallax.Item = Item; export default Parallax;