scroll to top added

This commit is contained in:
Kakabay 2024-11-09 15:38:15 +05:00
parent 5d4c5d6317
commit a4ebae2e7d
6 changed files with 94 additions and 23 deletions

View File

@ -0,0 +1,24 @@
'use client';
import ScrollToTop from '@/components/global/ScrollToTop';
import useScrollToTop from '@/lib/hooks/useScrollToTop';
import { ChevronUp } from 'lucide-react';
import React, { PropsWithChildren, useEffect, useState } from 'react';
const layout = ({ children }: PropsWithChildren) => {
const [clicked, setClicked] = useState(0);
useEffect(() => {
window.scrollTo(0, -100);
}, [clicked]);
return (
<div className="w-full">
<div onClick={() => setClicked((prev) => prev + 1)}>
<ScrollToTop />
</div>
{children}
</div>
);
};
export default layout;

View File

@ -0,0 +1,36 @@
'use client';
import useScrollToTop from '@/lib/hooks/useScrollToTop';
import { cn } from '@/lib/utils';
import { ChevronUp } from 'lucide-react';
import React, { useEffect, useState } from 'react';
const ScrollToTop = () => {
const [scrollY, setScrollY] = useState(false);
const handleScroll = () => {
setScrollY(window.scrollY > 500 ? true : false);
};
useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
return (
<div
className={cn(
'fixed md:bottom-10 md:right-10 bottom-4 right-4 p-3 shadow-md bg-fillBGBlockbg rounded-full cursor-pointer z-20 transition-all duration-300 ease-in-out',
{
'opacity-100 pointer-events-auto': scrollY,
'opacity-0 pointer-events-none': !scrollY,
},
)}>
<ChevronUp />
</div>
);
};
export default ScrollToTop;

View File

@ -223,7 +223,7 @@ const QuizAccordion = ({ finished, questionId }: TProps) => {
className={`w-full ${ className={`w-full ${
opened ? 'bg-fillRed text-white' : 'bg-fillButtonLowContrastDefault text-textDarkt' opened ? 'bg-fillRed text-white' : 'bg-fillButtonLowContrastDefault text-textDarkt'
} flex items-center justify-center text-xs md:text-base uppercase leading-[150%] p-[8px] md:py-5 gap-[5px] md:gap-[10px] transition-all delay-[0.2s] font-medium `}> } flex items-center justify-center text-xs md:text-base uppercase leading-[150%] p-[8px] md:py-5 gap-[5px] md:gap-[10px] transition-all delay-[0.2s] font-medium `}>
Taryhy r Netijeler
<div> <div>
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"

View File

@ -15,26 +15,26 @@ type TProps = {
}; };
const numbers = [ const numbers = [
'Birinji sorag', 'Birinji sowal',
'Ikinji sorag', 'Ikinji sowal',
'Üçünji sorag', 'Üçünji sowal',
'Dördünji sorag', 'Dördünji sowal',
'Bäşinji sorag', 'Bäşinji sowal',
'Altynjy sorag', 'Altynjy sowal',
'Ýedinji sorag', 'Ýedinji sowal',
'Sekizinji sorag', 'Sekizinji sowal',
'Dokuzynjy sorag', 'Dokuzynjy sowal',
'Onunjy sorag', 'Onunjy sowal',
'On Birinji sorag', 'On Birinji sowal',
'On Ikinji sorag', 'On Ikinji sowal',
'On Üçünji sorag', 'On Üçünji sowal',
'On Dördünji sorag', 'On Dördünji sowal',
'On Bäşinji sorag', 'On Bäşinji sowal',
'On Altynji sorag', 'On Altynji sowal',
'On Ýeddi sorag', 'On Ýeddi sowal',
'On Sekiznji sorag', 'On Sekiznji sowal',
'On Dokuzunji sorag', 'On Dokuzunji sowal',
'Ýigrinci sorag', 'Ýigrinci sowal',
]; ];
const QuizQuestion = ({ const QuizQuestion = ({

View File

@ -331,12 +331,12 @@ const QuizWinnerTable = ({ quizId, quizFinished, smsNumber }: IProps) => {
{winnersData?.data[0].total_score_of_client ? ( {winnersData?.data[0].total_score_of_client ? (
<div className="text-center flex justify-center items-center text-xs text-textBlack leading-[125%] font-semibold max-w-[75px] w-[100%]"> <div className="text-center flex justify-center items-center text-xs text-textBlack leading-[125%] font-semibold max-w-[75px] w-[100%]">
<span>Балы за быстроту</span> <span>Soraglara jogap berilişiň nobaty </span>
</div> </div>
) : null} ) : null}
{winnersData?.data[0].total_score_of_client ? ( {winnersData?.data[0].total_score_of_client ? (
<div className="text-center flex justify-center items-center text-xs text-textBlack leading-[125%] font-semibold max-w-[99px] w-[100%]"> <div className="text-center flex justify-center items-center text-xs text-textBlack leading-[125%] font-semibold max-w-[99px] w-[100%]">
<span>Utuklaryň jemi</span> <span>Nobatlaryň jemi</span>
</div> </div>
) : null} ) : null}
</div> </div>

View File

@ -0,0 +1,11 @@
'use client';
import { useEffect } from 'react';
const useScrollToTop = (dependecies?: any) => {
useEffect(() => {
window.scrollTo(0, 0);
console.log('first');
}, [dependecies]);
};
export default useScrollToTop;