diff --git a/package.json b/package.json index 55bed93722..4df302b1b5 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@popperjs/core": "^2.4.4", "@reach/dialog": "^0.10.3", "@reach/portal": "^0.10.3", + "@react-hook/window-scroll": "^1.3.0", "@reduxjs/toolkit": "^1.3.5", "@storybook/addon-actions": "^6.1.17", "@storybook/addon-essentials": "^6.1.17", diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index c936d511d7..af1a084da9 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -1,4 +1,5 @@ import { ChainId } from '@uniswap/sdk-core' +import useScrollPosition from '@react-hook/window-scroll' import React, { useState } from 'react' import { Text } from 'rebass' import { NavLink } from 'react-router-dom' @@ -29,7 +30,7 @@ import { Dots } from '../swap/styleds' import Modal from '../Modal' import UniBalanceContent from './UniBalanceContent' -const HeaderFrame = styled.div` +const HeaderFrame = styled.div<{ showBackground: boolean }>` display: grid; grid-template-columns: 120px 1fr 120px; align-items: center; @@ -39,12 +40,17 @@ const HeaderFrame = styled.div` width: 100%; top: 0; position: relative; - /* border-bottom: 1px solid ${({ theme }) => theme.bg2}; */ padding: 1rem; z-index: 21; - /* background-color: ${({ theme }) => theme.bg1}; */ position: relative; + /* Background slide effect on scroll. */ + background-image: ${({ theme }) => `linear-gradient(to bottom, transparent 50%, ${theme.bg0} 50% )}}`} + background-position: ${({ showBackground }) => (showBackground ? '0 -100%' : '0 0')}; + background-size: 100% 200%; + box-shadow: 0px 0px 0px 1px ${({ theme, showBackground }) => (showBackground ? theme.bg2 : 'transparent;')}; + transition: background-position .1s, box-shadow .1s; + ${({ theme }) => theme.mediaWidth.upToMedium` padding: 1rem; grid-template-columns: 120px 1fr; @@ -319,8 +325,10 @@ export default function Header() { const [showUniBalanceModal, setShowUniBalanceModal] = useState(false) const showClaimPopup = useShowClaimPopup() + const scrollY = useScrollPosition() + return ( - + 45}> setShowUniBalanceModal(false)}> diff --git a/yarn.lock b/yarn.lock index 737dd8e4ab..dc7f483f10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2409,6 +2409,38 @@ tslib "^2.0.0" warning "^4.0.3" +"@react-hook/event@^1.2.1": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@react-hook/event/-/event-1.2.3.tgz#cfe86d5cf36f53e85b367ff619990d001b5c82ae" + integrity sha512-WMBwLnYY2rubLeecsi4skl1imfx0oiXTgazV/1ByPT6WkmLvxUao3hC+mxps5D/+JK4Fq3uG9OWU/dn5jMtXyg== + dependencies: + "@react-hook/passive-layout-effect" "^1.2.0" + +"@react-hook/latest@^1.0.2": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@react-hook/latest/-/latest-1.0.3.tgz#c2d1d0b0af8b69ec6e2b3a2412ba0768ac82db80" + integrity sha512-dy6duzl+JnAZcDbNTfmaP3xHiKtbXYOaz3G51MGVljh548Y8MWzTr+PHLOfvpypEVW9zwvl+VyKjbWKEVbV1Rg== + +"@react-hook/passive-layout-effect@^1.2.0": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@react-hook/passive-layout-effect/-/passive-layout-effect-1.2.1.tgz#c06dac2d011f36d61259aa1c6df4f0d5e28bc55e" + integrity sha512-IwEphTD75liO8g+6taS+4oqz+nnroocNfWVHWz7j+N+ZO2vYrc6PV1q7GQhuahL0IOR7JccFTsFKQ/mb6iZWAg== + +"@react-hook/throttle@^2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@react-hook/throttle/-/throttle-2.2.0.tgz#d0402714a06e1ba0bc1da1fdf5c3c5cd0e08d45a" + integrity sha512-LJ5eg+yMV8lXtqK3lR+OtOZ2WH/EfWvuiEEu0M3bhR7dZRfTyEJKxH1oK9uyBxiXPtWXiQggWbZirMCXam51tg== + dependencies: + "@react-hook/latest" "^1.0.2" + +"@react-hook/window-scroll@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@react-hook/window-scroll/-/window-scroll-1.3.0.tgz#07914239a452075c7eb28d15ed0e2fd45aa2d65b" + integrity sha512-LdYnCL22pFI+LTs85Fi2OQHSKWkzIuHFgv8lA+wwuaPxLOEhWR5bzJ21iygUH9X4meeLVRZKEbfpYi3OWWD4GQ== + dependencies: + "@react-hook/event" "^1.2.1" + "@react-hook/throttle" "^2.2.0" + "@reduxjs/toolkit@^1.3.5": version "1.5.1" resolved "https://registry.yarnpkg.com/@reduxjs/toolkit/-/toolkit-1.5.1.tgz#05daa2f6eebc70dc18cd98a90421fab7fa565dc5"