Skip to content

Commit

Permalink
Merge pull request #247 from OliaKr/whatnow-scroll
Browse files Browse the repository at this point in the history
Adding a scroll behavior for a button
  • Loading branch information
Darkmift authored Apr 18, 2024
2 parents 7210ea7 + 441d2d9 commit e061b18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
24 changes: 21 additions & 3 deletions components/Home/WhatNow.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
'use client';
import React from 'react';
import SectionTitle from '../Common/SectionTitle';
import { useTranslations } from 'next-intl';

function WhatNow() {
const t = useTranslations('Components.home.whatNow');

const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
const targetId = e.currentTarget.getAttribute('href');
if (targetId) {
const targetElement = document.querySelector(targetId) as HTMLElement; // Type assertion
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop,
behavior: 'smooth',
});
}
}
};

return (
<div className="relative flex flex-col justify-around gap-3 pb-10 mt-36">
<div className="hidden sm:flex flex-col gap-2 items-center sm:flex-row-reverse sm:justify-end">
Expand All @@ -20,12 +36,14 @@ function WhatNow() {
</div>
<div className="flex flex-col gap-7 sm:pr-4 sm:flex-wrap sm:content-end ">
<h4 className="sm:w-1/2 sm:pl-6 h4-roman">{t('paragraph')}</h4>
<button
<a
href="#paths"
data-testid={`whatNowButton`}
className="bg-purple-400 dark:bg-purple-500 text-white body-bold px-6 py-3.5 sm:w-1/6 sm:rounded-full rounded-md sm:mx-0 mx-5"
className="bg-purple-400 dark:bg-purple-500 text-white body-bold px-6 py-3.5 sm:w-1/6 sm:rounded-full rounded-md sm:mx-0 mx-5 flex items-center justify-center" // Added flex, items-center, and justify-center
onClick={handleClick}
>
{t('startButton')}
</button>
</a>
</div>
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion components/Paths/Paths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const variants = {

export default function Paths() {
return (
<section className="flex flex-col justify-start py-32 darkmode-section">
<section
id="paths"
className="flex flex-col justify-start py-32 darkmode-section"
>
<div
data-testid={`pathsTitle`}
className="flex flex-col-reverse md:flex-row self-start md:items-center"
Expand Down

0 comments on commit e061b18

Please sign in to comment.