From 255f730fd493cd37424006391913eafbc054a156 Mon Sep 17 00:00:00 2001 From: Meolocious <90854445+Meolocious@users.noreply.github.com> Date: Thu, 9 May 2024 15:22:08 +0200 Subject: [PATCH] [B2BP-559] - Implementing 'Header' EC inside B2BP (#268) * Commit migrate Header * Commit changeset * Commit fix Header files * commit code fix * commit review changes * commit file fix * commit review changes * commit review changes --- .changeset/happy-beans-fry.md | 5 + .../components/Header/Header.helpers.tsx | 33 ++++ .../components/Header/Header.tsx | 120 ++++++++++++++ .../Header/components/HamburgerMenu.tsx | 29 ++++ .../Header/components/MenuDropdown.tsx | 153 ++++++++++++++++++ .../Header/components/Navigation.tsx | 16 ++ .../components/Header/components/Title.tsx | 59 +++++++ .../react-components/components/index.ts | 2 + .../types/Header/Header.types.ts | 43 +++++ .../react-components/types/index.ts | 4 +- apps/nextjs-website/src/components/Header.tsx | 44 +---- 11 files changed, 466 insertions(+), 42 deletions(-) create mode 100644 .changeset/happy-beans-fry.md create mode 100644 apps/nextjs-website/react-components/components/Header/Header.helpers.tsx create mode 100644 apps/nextjs-website/react-components/components/Header/Header.tsx create mode 100644 apps/nextjs-website/react-components/components/Header/components/HamburgerMenu.tsx create mode 100644 apps/nextjs-website/react-components/components/Header/components/MenuDropdown.tsx create mode 100644 apps/nextjs-website/react-components/components/Header/components/Navigation.tsx create mode 100644 apps/nextjs-website/react-components/components/Header/components/Title.tsx create mode 100644 apps/nextjs-website/react-components/types/Header/Header.types.ts diff --git a/.changeset/happy-beans-fry.md b/.changeset/happy-beans-fry.md new file mode 100644 index 000000000..b4e3a1605 --- /dev/null +++ b/.changeset/happy-beans-fry.md @@ -0,0 +1,5 @@ +--- +"nextjs-website": minor +--- + +Migrate Header component from EC to B2BP diff --git a/apps/nextjs-website/react-components/components/Header/Header.helpers.tsx b/apps/nextjs-website/react-components/components/Header/Header.helpers.tsx new file mode 100644 index 000000000..ebe35f94e --- /dev/null +++ b/apps/nextjs-website/react-components/components/Header/Header.helpers.tsx @@ -0,0 +1,33 @@ +import { Stack, useTheme, type Theme } from '@mui/material'; +import { DialogBubbleProps } from '../../types/Header/Header.types'; + +const useStyles = (muiTheme: Theme) => ({ + bubbleContainer: { + transform: 'rotate(180deg)', + position: 'absolute', + marginTop: '42px', + padding: muiTheme.spacing(2), + direction: 'rtl', + textAlign: 'left', + borderRadius: '4px', + }, + bubble: { transform: 'rotate(180deg)' }, +}); + +export const DialogBubble = ({ + children, + ...stackProps +}: DialogBubbleProps) => { + const muiTheme = useTheme(); + const styles = useStyles(muiTheme); + return ( + + + {children} + + + ); +}; diff --git a/apps/nextjs-website/react-components/components/Header/Header.tsx b/apps/nextjs-website/react-components/components/Header/Header.tsx new file mode 100644 index 000000000..d28b07bc9 --- /dev/null +++ b/apps/nextjs-website/react-components/components/Header/Header.tsx @@ -0,0 +1,120 @@ +import Box from '@mui/material/Box'; +import Stack from '@mui/material/Stack'; +import { useEffect, useState } from 'react'; +import { HamburgerMenu } from './components/HamburgerMenu'; +import { Navigation } from './components/Navigation'; +import { HeaderTitle } from './components/Title'; +import { HeaderProps } from '@react-components/types/Header/Header.types'; +import { CtaButtons } from '../common/Common'; +import { BackgroundColor } from '../common/Common.helpers'; + +const Header = ({ + product, + theme, + menu, + ctaButtons, + avatar, + beta, + logo, +}: HeaderProps) => { + const backgroundColor = BackgroundColor(theme); + + const [menuOpen, setMenuOpen] = useState(false); + + const openHeader = () => { + setMenuOpen(true); + }; + + const closeHeader = () => { + setMenuOpen(false); + }; + + useEffect(() => { + window.addEventListener('resize', closeHeader); + + return () => { + window.removeEventListener('resize', closeHeader); + }; + }, []); + + const HeaderCtas = () => { + return ctaButtons && ctaButtons.length > 0 ? ( + + {CtaButtons({ + ctaButtons: ctaButtons.map((CtaButton) => ({ + ...CtaButton, + sx: { width: { md: 'auto', xs: '100%' } }, + })), + theme, + })} + + ) : null; + }; + + return ( + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default Header; diff --git a/apps/nextjs-website/react-components/components/Header/components/HamburgerMenu.tsx b/apps/nextjs-website/react-components/components/Header/components/HamburgerMenu.tsx new file mode 100644 index 000000000..531ac078e --- /dev/null +++ b/apps/nextjs-website/react-components/components/Header/components/HamburgerMenu.tsx @@ -0,0 +1,29 @@ +import CloseIcon from '@mui/icons-material/Close'; +import MenuIcon from '@mui/icons-material/Menu'; + +interface HamburgerMenuProps { + open: boolean; + onOpen: () => void; + onClose: () => void; +} + +export const HamburgerMenu = ({ open, onOpen, onClose }: HamburgerMenuProps) => + open ? ( + + ) : ( +