Files
notesnook/packages/editor-mobile/src/components/header.tsx

180 lines
5.0 KiB
TypeScript
Raw Normal View History

2022-06-23 19:14:55 +05:00
import ArrowBackIcon from "mdi-react/ArrowBackIcon";
import CloudUploadOutlineIcon from "mdi-react/CloudUploadOutlineIcon";
import CrownIcon from "mdi-react/CrownIcon";
import DotsHorizontalIcon from "mdi-react/DotsHorizontalIcon";
import MagnifyIcon from "mdi-react/MagnifyIcon";
2022-06-27 18:39:59 +05:00
import React, { useEffect } from "react";
2022-06-23 19:14:55 +05:00
import { useSafeArea } from "../hooks/useSafeArea";
import { useSettings } from "../hooks/useSettings";
import { EventTypes } from "../utils";
import styles from "./styles.module.css";
const Button = ({
onPress,
children,
style,
}: {
onPress: () => void;
children: React.ReactNode;
style: React.CSSProperties;
}) => {
return (
<button
className={styles.btn_header}
style={style}
onMouseUp={(e) => {
e.preventDefault();
}}
onMouseDown={(e) => e.preventDefault()}
onTouchEnd={(e) => {
e.preventDefault();
e.stopPropagation();
onPress();
}}
onTouchStart={(e) => {
editor?.commands.blur();
e.preventDefault();
}}
>
{children}
</button>
);
};
2022-06-30 09:47:04 +05:00
export default React.memo(
function Header({ noHeader }: { noHeader: boolean }) {
const insets = useSafeArea();
const settings = useSettings();
return (
2022-06-23 19:14:55 +05:00
<div
style={{
display: "flex",
2022-06-30 09:47:04 +05:00
alignItems: "center",
height: noHeader ? `${insets.top}px` : `${50 + insets.top}px`,
backgroundColor: "var(--nn_bg)",
position: "sticky",
width: "100vw",
2022-06-23 19:14:55 +05:00
}}
>
2022-06-30 09:47:04 +05:00
{noHeader ? null : (
<div
style={{
display: "flex",
width: "100%",
justifyContent: "space-between",
flexDirection: "row",
paddingTop: insets.top,
}}
>
2022-06-23 19:14:55 +05:00
<Button
onPress={() => {
2022-06-30 09:47:04 +05:00
post(EventTypes.back);
2022-06-23 19:14:55 +05:00
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
2022-06-30 09:47:04 +05:00
marginLeft: 6,
width: 40,
height: 40,
2022-06-23 19:14:55 +05:00
display: "flex",
justifyContent: "center",
2022-06-30 09:47:04 +05:00
alignItems: "start",
flexDirection: "column",
2022-06-23 19:14:55 +05:00
}}
>
2022-06-30 09:47:04 +05:00
<ArrowBackIcon size={28} color="var(--nn_pri)" />
2022-06-23 19:14:55 +05:00
</Button>
2022-06-30 09:47:04 +05:00
<div
style={{
display: "flex",
alignItems: "center",
flexDirection: "row",
}}
>
{!settings.premium && (
<Button
onPress={() => {
post(EventTypes.pro);
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<CrownIcon size={28} color="orange" />
</Button>
)}
<Button
onPress={() => {
//
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
2022-06-23 19:14:55 +05:00
2022-06-30 09:47:04 +05:00
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<MagnifyIcon size={28} color="var(--nn_pri)" />
</Button>
<Button
onPress={() => {
post(EventTypes.monograph);
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<CloudUploadOutlineIcon size={28} color="var(--nn_pri)" />
</Button>
<Button
onPress={() => {
post(EventTypes.properties);
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 12,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<DotsHorizontalIcon size={28} color="var(--nn_pri)" />
</Button>
</div>
</div>
)}
2022-06-23 19:14:55 +05:00
</div>
2022-06-30 09:47:04 +05:00
);
},
(prev, next) => prev.noHeader !== next.noHeader
);