From 0ef384d5d276aef766995e9fbb890e7bbfee4bfc Mon Sep 17 00:00:00 2001 From: philipcheung Date: Sun, 2 Nov 2025 18:43:04 +0800 Subject: [PATCH] header height adjust --- src/components/header.tsx | 44 +++++++++++++++++++++++++++++------- src/components/ui/drawer.tsx | 12 ++++++++-- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/components/header.tsx b/src/components/header.tsx index d2be61a..3ccb9e2 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -1,15 +1,12 @@ import { Box, Flex, Image, VStack, Text, Link } from '@chakra-ui/react'; import { GiHamburgerMenu } from "react-icons/gi"; import { colors } from '../colors'; -import { useState } from 'react'; +import { useState, useRef, useLayoutEffect } from 'react'; import { - DrawerBackdrop, DrawerBody, DrawerCloseTrigger, DrawerContent, - DrawerHeader, DrawerRoot, - DrawerTitle, } from '@/components/ui/drawer'; interface HeaderProps { @@ -18,6 +15,14 @@ interface HeaderProps { function Header({ showMenu = false }: HeaderProps) { const [isDrawerOpen, setIsDrawerOpen] = useState(false); + const [headerHeight, setHeaderHeight] = useState(0); + const headerRef = useRef(null); + + useLayoutEffect(() => { + if (headerRef.current) { + setHeaderHeight(headerRef.current.offsetHeight); + } + }, []); const menuItems = [ { label: '40+常見健康問題', href: '#health-issues' }, @@ -28,7 +33,15 @@ function Header({ showMenu = false }: HeaderProps) { return ( <> - + Logo {showMenu && ( @@ -52,13 +65,28 @@ function Header({ showMenu = false }: HeaderProps) { setIsDrawerOpen(e.open)} placement="end"> - - + {menuItems.map((item, index) => ( offset?: ChakraDrawer.ContentProps["padding"] + positionerProps?: React.ComponentProps } export const DrawerContent = React.forwardRef< HTMLDivElement, DrawerContentProps >(function DrawerContent(props, ref) { - const { children, portalled = true, portalRef, offset, ...rest } = props + const { + children, + portalled = true, + portalRef, + offset, + positionerProps, + ...rest + } = props return ( - + {children}