Skip to content

Commit

Permalink
added height change
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaDemchenko committed Jan 29, 2024
1 parent 28652d4 commit 94ec4e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/components/demo-scroll/DemoScroll.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
max-height: 80vh;
}

.max-height .list-container {
max-height: 100%;
overflow-y: hidden;
}

.list-container::-webkit-scrollbar-track {
background: transparent;
}
Expand Down
18 changes: 14 additions & 4 deletions src/components/demo-scroll/DemoScroll.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useRef, useState } from 'react'
import { Pokemon } from '../../types/pokemon-data'
import { InfiniteScroll } from '../infinite-scroll/InfiniteScroll'
import { InputCheckBox } from '../input-check-box/InputCheckBox'
Expand Down Expand Up @@ -43,6 +43,7 @@ const getDataFunc = async (page: number, itemsPerPage: number) => {
export const DemoScroll = () => {
const [isVideoVisible, setIsVideoVisible] = useState(false)
const [isScrollByCameraOn, setIsScrollByCameraOn] = useState(false)
const mainContainerRef = useRef<HTMLDivElement>(null)

const handleScrollByCamera = () => {
setIsScrollByCameraOn(!isScrollByCameraOn)
Expand All @@ -52,11 +53,20 @@ export const DemoScroll = () => {
setIsVideoVisible(!isVideoVisible)
}

const changeHeightOfContainer = () => {
if (!mainContainerRef.current) return

mainContainerRef.current.classList.toggle('max-height')
}

return (
<div className="main-container">
<div ref={mainContainerRef} className="main-container max-height">
<InputCheckBox
isChecked={isScrollByCameraOn}
onChange={handleScrollByCamera}
onChange={() => {
handleScrollByCamera()
changeHeightOfContainer()
}}
labelText={'Scroll by camera'}
/>
{isScrollByCameraOn && (
Expand All @@ -70,7 +80,7 @@ export const DemoScroll = () => {
getDataFunc={getDataFunc}
renderItem={renderItem}
maxItemsInList={500}
itemsPerPage={5}
itemsPerPage={10}
isScrollByCameraOn={isScrollByCameraOn}
isCameraPreviewOn={isVideoVisible}
/>
Expand Down

0 comments on commit 94ec4e6

Please sign in to comment.