mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 02:43:33 +00:00
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
|
|
import { motion } from 'framer-motion';
|
||
|
|
import { useEffect, useRef } from 'react';
|
||
|
|
import styled from 'styled-components';
|
||
|
|
import { useShouldPadTitlebar } from '/@/renderer/hooks';
|
||
|
|
|
||
|
|
const Container = styled(motion.div)<{ $useOpacity?: boolean; height?: string }>`
|
||
|
|
z-index: 100;
|
||
|
|
width: 100%;
|
||
|
|
height: ${(props) => props.height || '55px'};
|
||
|
|
opacity: ${(props) => props.$useOpacity && 'var(--header-opacity)'};
|
||
|
|
transition: opacity 0.3s ease-in-out;
|
||
|
|
`;
|
||
|
|
|
||
|
|
const Header = styled(motion.div)<{ $padRight?: boolean }>`
|
||
|
|
height: 100%;
|
||
|
|
margin-right: ${(props) => props.$padRight && '170px'};
|
||
|
|
padding: 1rem;
|
||
|
|
-webkit-app-region: drag;
|
||
|
|
|
||
|
|
button {
|
||
|
|
-webkit-app-region: no-drag;
|
||
|
|
}
|
||
|
|
`;
|
||
|
|
|
||
|
|
interface PageHeaderProps {
|
||
|
|
backgroundColor?: string;
|
||
|
|
children?: React.ReactNode;
|
||
|
|
height?: string;
|
||
|
|
useOpacity?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const PageHeader = ({ height, backgroundColor, useOpacity, children }: PageHeaderProps) => {
|
||
|
|
const ref = useRef(null);
|
||
|
|
const padRight = useShouldPadTitlebar();
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
const rootElement = document.querySelector(':root') as HTMLElement;
|
||
|
|
rootElement?.style?.setProperty('--header-opacity', '0');
|
||
|
|
}, []);
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Container
|
||
|
|
ref={ref}
|
||
|
|
$useOpacity={useOpacity}
|
||
|
|
animate={{
|
||
|
|
backgroundColor,
|
||
|
|
transition: { duration: 1.5 },
|
||
|
|
}}
|
||
|
|
height={height}
|
||
|
|
>
|
||
|
|
<Header $padRight={padRight}>{children}</Header>
|
||
|
|
</Container>
|
||
|
|
);
|
||
|
|
};
|