Skip to content

Commit

Permalink
Panel shadow on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Oct 12, 2023
1 parent f8ea99a commit 5abf62b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 10 additions & 2 deletions packages/web-console/src/components/Panel/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import styled from "styled-components"
import { color } from "../../utils"
import { Text } from "../../components/Text"

export const Root = styled.div`
export const Root = styled.div<{ shadow?: boolean }>`
position: relative;
display: flex;
justify-content: space-between;
Expand All @@ -38,6 +38,12 @@ export const Root = styled.div`
background: ${color("backgroundLighter")};
border-top: 1px solid transparent;
z-index: 5;
${({ shadow }) =>
shadow &&
`
box-shadow: 0 2px 10px 0 rgba(23, 23, 23, 0.65)
`}
`

const Title = styled(Text)`
Expand All @@ -51,11 +57,13 @@ const Title = styled(Text)`
export const Header = ({
title,
afterTitle,
shadow,
}: {
title: React.ReactNode
afterTitle?: React.ReactNode
shadow?: boolean
}) => (
<Root>
<Root shadow={shadow}>
<Title color="foreground">{title}</Title>
{afterTitle}
</Root>
Expand Down
17 changes: 9 additions & 8 deletions packages/web-console/src/scenes/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,13 @@ const Schema = ({
const { updateSettings } = useLocalStorage()
const dispatch = useDispatch()
const { appendQuery } = useEditor()
const [scrollAtTop, setScrollAtTop] = useState(false)
const scrollerRef = useRef<HTMLDivElement | null>(null)

const handleChange = useCallback((name: string) => {
setOpened(name)
}, [])

const handleScrollingStateChange = useCallback(
(isScrolling) => {
setIsScrolling(isScrolling)
},
[setIsScrolling],
)

const listItemContent = useCallback(
(index: number) => {
if (tables) {
Expand Down Expand Up @@ -213,6 +208,10 @@ const Schema = ({
})
}, [errorRef, fetchTables])

useEffect(() => {
setScrollAtTop(scrollerRef.current?.scrollTop === 0)
}, [isScrolling])

return (
<Wrapper ref={innerRef} {...rest}>
<Panel.Header
Expand All @@ -236,6 +235,7 @@ const Schema = ({
)}
</div>
}
shadow={!scrollAtTop}
/>
<Content _loading={loading}>
{loading ? (
Expand All @@ -244,9 +244,10 @@ const Schema = ({
<LoadingError error={loadingError} />
) : (
<VirtualList
isScrolling={handleScrollingStateChange}
isScrolling={setIsScrolling}
itemContent={listItemContent}
totalCount={tables?.length}
scrollerRef={(ref) => (scrollerRef.current = ref as HTMLDivElement)}
/>
)}
{!loading && <FlexSpacer />}
Expand Down

0 comments on commit 5abf62b

Please sign in to comment.