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

230 lines
6.6 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";
2022-07-07 18:40:05 +05:00
import ArrowULeftTopIcon from "mdi-react/ArrowULeftTopIcon";
import ArrowURightTopIcon from "mdi-react/ArrowURightTopIcon";
2022-06-23 19:14:55 +05:00
import MagnifyIcon from "mdi-react/MagnifyIcon";
import React from "react";
2022-06-23 19:14:55 +05:00
import { useSafeArea } from "../hooks/useSafeArea";
import { EventTypes, Settings } from "../utils";
2022-06-23 19:14:55 +05:00
import styles from "./styles.module.css";
const Button = ({
onPress,
children,
style,
preventDefault = true,
2022-06-23 19:14:55 +05:00
}: {
onPress: () => void;
children: React.ReactNode;
style: React.CSSProperties;
preventDefault?: boolean;
2022-06-23 19:14:55 +05:00
}) => {
return (
<button
className={styles.btn_header}
style={style}
2022-07-07 18:40:05 +05:00
onMouseDown={(e) => {
if (preventDefault) e.preventDefault();
2022-06-23 19:14:55 +05:00
onPress();
}}
>
{children}
</button>
);
};
2022-06-30 09:47:04 +05:00
export default React.memo(
function Header({
noHeader,
settings,
2022-07-07 18:40:05 +05:00
hasUndo,
hasRedo,
}: {
noHeader: boolean;
settings: Settings;
2022-07-07 18:40:05 +05:00
hasUndo: boolean;
hasRedo: boolean;
}) {
2022-06-30 09:47:04 +05:00
const insets = useSafeArea();
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-07-08 14:54:09 +05:00
height: 50,
alignItems: "center",
2022-06-30 09:47:04 +05:00
}}
>
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
}}
preventDefault={false}
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",
2022-06-30 09:47:04 +05:00
}}
>
2022-07-07 18:40:05 +05:00
<Button
onPress={() => {
editor?.commands.undo();
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
2022-07-07 18:40:05 +05:00
}}
>
<ArrowULeftTopIcon size={28} color={"var(--nn_pri)"} />
</Button>
<Button
onPress={() => {
editor?.commands.redo();
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
2022-07-07 18:40:05 +05:00
}}
>
<ArrowURightTopIcon size={28} color={"var(--nn_pri)"} />
</Button>
2022-06-30 09:47:04 +05:00
{!settings.premium && (
<Button
onPress={() => {
post(EventTypes.pro);
}}
preventDefault={false}
2022-06-30 09:47:04 +05:00
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
2022-06-30 09:47:04 +05:00
}}
>
<CrownIcon size={28} color="orange" />
</Button>
)}
<Button
onPress={() => {
2022-07-07 14:34:39 +05:00
editor?.commands.startSearch();
2022-06-30 09:47:04 +05:00
}}
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",
2022-06-30 09:47:04 +05:00
}}
>
<MagnifyIcon size={28} color="var(--nn_pri)" />
</Button>
<Button
onPress={() => {
post(EventTypes.monograph);
}}
preventDefault={false}
2022-06-30 09:47:04 +05:00
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
2022-06-30 09:47:04 +05:00
}}
>
<CloudUploadOutlineIcon size={28} color="var(--nn_pri)" />
</Button>
<Button
onPress={() => {
post(EventTypes.properties);
}}
preventDefault={false}
2022-06-30 09:47:04 +05:00
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 12,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
2022-06-30 09:47:04 +05:00
}}
>
<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 ||
2022-07-07 18:40:05 +05:00
prev.settings.premium !== next.settings.premium ||
prev.hasRedo !== next.hasRedo ||
prev.hasUndo !== next.hasUndo
2022-06-30 09:47:04 +05:00
);