diff --git a/components/Atoms/Button.tsx b/components/Atoms/Button.tsx
index fa67689b..e60827c2 100644
--- a/components/Atoms/Button.tsx
+++ b/components/Atoms/Button.tsx
@@ -6,10 +6,9 @@ import React from "react";
type ButtonVariant = "filled" | "outlined" | "ghost";
interface ButtonProps {
- action: string | (() => void);
+ onClick: string | (() => void);
variant: ButtonVariant;
children: React.ReactNode;
- isSamePage?: boolean;
}
/**
@@ -18,44 +17,28 @@ interface ButtonProps {
* - filled: a filled button with a background color
* - outlined: a button with a border and no background color
* - ghost: a button with no background color and no border
- * This button can redirect to a different page or scroll to an element on the same page.
*
- * @param to (string | (() => void)) The path to navigate to or a function to execute
- * @param variant (ButtonVariant) The variant of the button
- * @param children (React.ReactNode) The content of the button
- * @param isSamePage (boolean) Whether the button is on the same page or not
- * @returns (JSX.Element): a button
+ * @param onClick (string | function): the action to be performed when the button is clicked
+ * @param variant (ButtonVariant): the variant of the button
+ * @param children (React.ReactNode): the content of the button
+ *
+ * @returns (JSX.Element): button component
*/
-const Button = ({
- action,
- variant,
- children,
- isSamePage = false,
-}: ButtonProps) => {
+const Button = ({ onClick, variant, children }: ButtonProps) => {
const router = useRouter();
/**
- * Handles the click event on the button.
- * If the button is on the same page, it scrolls to the element with the id specified in the "to" prop.
- * If the button is on a different page, it navigates to the path specified in the "to" prop.
+ * Handles the click event of the button.
+ * If the onClick prop is a function, it will execute the function.
+ * If the onClick prop is a string, it will redirect to the page.
*/
const handleClick = () => {
- if (typeof action === "function") {
- // if to is a function, execute it
- action();
- } else if (isSamePage) {
- // if to is a string, scroll to the element with the id specified
- const element = document.getElementById(action as string);
- if (element) {
- window.scrollTo({
- top: element.offsetTop,
- behavior: "smooth",
- });
- }
- } else {
- // if to is a string, navigate to the specified path
- router.push(action as string);
+ if (typeof onClick === "function") {
+ onClick();
+ } else if (typeof onClick === "string") {
+ router.push(onClick);
}
+ return;
};
const baseStyle = `
diff --git a/components/Content/HeroSection.tsx b/components/Content/HeroSection.tsx
index 0ab16036..a5cbb98b 100644
--- a/components/Content/HeroSection.tsx
+++ b/components/Content/HeroSection.tsx
@@ -11,15 +11,27 @@ import HeadingOne from "./Text/HeadingOne";
* Contains a short description of myself, a picture and a link to the projects section.
*/
const HeroSection = () => {
+ /**
+ * Allows the user to scroll to a specific section of the page.
+ *
+ * @param sectionName (string): the name of the section to scroll to
+ */
+ const scrollToSection = (sectionName: string) => {
+ const element = document.getElementById(sectionName as string);
+ if (element) {
+ window.scrollTo({
+ top: element.offsetTop,
+ behavior: "smooth",
+ });
+ }
+ };
+
return (
-