feishin/src/renderer/components/page-header/index.tsx

92 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-12-31 17:50:05 -08:00
import { Flex, FlexProps } from '@mantine/core';
2022-12-19 15:59:14 -08:00
import { motion } from 'framer-motion';
2023-01-02 02:05:30 -08:00
import { useRef } from 'react';
2022-12-19 15:59:14 -08:00
import styled from 'styled-components';
import { useShouldPadTitlebar } from '/@/renderer/hooks';
2022-12-31 17:50:05 -08:00
const Container = styled(motion(Flex))<{ $isHidden?: boolean; height?: string; position?: string }>`
position: ${(props) => props.position || 'relative'};
z-index: 2000;
2022-12-19 15:59:14 -08:00
width: 100%;
2022-12-21 01:27:29 -08:00
height: ${(props) => props.height || '60px'};
2022-12-31 17:50:05 -08:00
opacity: ${(props) => (props.$isHidden ? 0 : 1)};
2022-12-19 15:59:14 -08:00
transition: opacity 0.3s ease-in-out;
2022-12-31 17:50:05 -08:00
user-select: ${(props) => (props.$isHidden ? 'none' : 'auto')};
pointer-events: ${(props) => (props.$isHidden ? 'none' : 'auto')};
2022-12-19 15:59:14 -08:00
`;
const Header = styled(motion.div)<{ $padRight?: boolean }>`
2022-12-31 17:50:05 -08:00
position: relative;
2022-12-29 18:50:57 -08:00
z-index: 15;
2022-12-31 17:50:05 -08:00
width: 100%;
2022-12-19 15:59:14 -08:00
height: 100%;
margin-right: ${(props) => props.$padRight && '170px'};
-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
`;
2022-12-31 17:50:05 -08:00
const BackgroundImage = styled.div<{ background: string }>`
position: absolute;
top: 0;
z-index: 1;
width: 100%;
height: 100%;
background: ${(props) => props.background || 'var(--titlebar-bg)'};
`;
2022-12-29 18:50:57 -08:00
2022-12-31 17:50:05 -08:00
const BackgroundImageOverlay = styled.div`
position: absolute;
top: 0;
left: 0;
z-index: 2;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 30%), var(--background-noise);
`;
2022-12-29 18:50:57 -08:00
2022-12-31 17:50:05 -08:00
interface PageHeaderProps
extends Omit<FlexProps, 'onAnimationStart' | 'onDragStart' | 'onDragEnd' | 'onDrag'> {
2022-12-19 15:59:14 -08:00
backgroundColor?: string;
children?: React.ReactNode;
height?: string;
2022-12-31 17:50:05 -08:00
isHidden?: boolean;
2022-12-29 18:50:57 -08:00
position?: string;
2022-12-19 15:59:14 -08:00
}
2022-12-29 18:50:57 -08:00
export const PageHeader = ({
position,
height,
backgroundColor,
2022-12-31 17:50:05 -08:00
isHidden,
2022-12-29 18:50:57 -08:00
children,
2022-12-31 17:50:05 -08:00
...props
2022-12-29 18:50:57 -08:00
}: PageHeaderProps) => {
2022-12-19 15:59:14 -08:00
const ref = useRef(null);
const padRight = useShouldPadTitlebar();
return (
<Container
ref={ref}
2022-12-31 17:50:05 -08:00
$isHidden={isHidden}
2022-12-19 15:59:14 -08:00
height={height}
2022-12-29 18:50:57 -08:00
position={position}
2022-12-31 17:50:05 -08:00
{...props}
2022-12-19 15:59:14 -08:00
>
2022-12-31 17:50:05 -08:00
<Header $padRight={padRight}>{!isHidden && <>{children}</>}</Header>
{backgroundColor && (
<>
<BackgroundImage background={'var(--titlebar-bg)' || ''} />
<BackgroundImageOverlay />
</>
)}
2022-12-19 15:59:14 -08:00
</Container>
);
};