2022-12-19 15:59:14 -08:00
|
|
|
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%;
|
2022-12-21 01:27:29 -08:00
|
|
|
height: ${(props) => props.height || '60px'};
|
2022-12-19 15:59:14 -08:00
|
|
|
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;
|
|
|
|
|
}
|
2022-12-21 01:27:29 -08:00
|
|
|
|
|
|
|
|
input {
|
|
|
|
|
-webkit-app-region: no-drag;
|
|
|
|
|
}
|
2022-12-19 15:59:14 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
};
|