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

284 lines
7.9 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,
2022-07-09 15:51:25 +05:00
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,
2022-07-09 15:51:25 +05:00
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",
2022-07-09 15:51:25 +05:00
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,
2022-07-09 15:51:25 +05:00
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-07-09 15:51:25 +05:00
alignItems: "center",
flexDirection: "column",
2022-07-09 15:51:25 +05:00
position: "relative"
2022-06-23 19:14:55 +05:00
}}
>
2022-07-09 15:51:25 +05:00
<ArrowBackIcon
size={27}
style={{
position: "absolute"
}}
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",
2022-07-09 15:51:25 +05:00
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-09 15:51:25 +05:00
position: "relative"
2022-07-07 18:40:05 +05:00
}}
>
2022-07-08 18:33:54 +05:00
<ArrowULeftTopIcon
color={!hasUndo ? "var(--nn_nav)" : "var(--nn_pri)"}
2022-07-09 15:51:25 +05:00
size={25}
style={{
position: "absolute"
}}
2022-07-08 18:33:54 +05:00
/>
2022-07-07 18:40:05 +05:00
</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-09 15:51:25 +05:00
position: "relative"
2022-07-07 18:40:05 +05:00
}}
>
2022-07-08 18:33:54 +05:00
<ArrowURightTopIcon
color={!hasRedo ? "var(--nn_nav)" : "var(--nn_pri)"}
2022-07-09 15:51:25 +05:00
size={25}
style={{
position: "absolute"
}}
2022-07-08 18:33:54 +05:00
/>
2022-07-07 18:40:05 +05:00
</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-07-09 15:51:25 +05:00
position: "relative"
2022-06-30 09:47:04 +05:00
}}
>
2022-07-09 15:51:25 +05:00
<CrownIcon
size={25}
style={{
position: "absolute"
}}
color="orange"
/>
2022-06-30 09:47:04 +05:00
</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,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
2022-07-09 15:51:25 +05:00
position: "relative"
2022-06-30 09:47:04 +05:00
}}
>
2022-07-09 15:51:25 +05:00
<MagnifyIcon
size={25}
style={{
position: "absolute"
}}
color="var(--nn_pri)"
/>
2022-06-30 09:47:04 +05:00
</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-07-09 15:51:25 +05:00
position: "relative"
2022-06-30 09:47:04 +05:00
}}
>
2022-07-09 15:51:25 +05:00
<CloudUploadOutlineIcon
size={25}
style={{
position: "absolute"
}}
color="var(--nn_pri)"
/>
2022-06-30 09:47:04 +05:00
</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-07-09 15:51:25 +05:00
position: "relative"
2022-06-30 09:47:04 +05:00
}}
>
2022-07-09 15:51:25 +05:00
<DotsHorizontalIcon
size={25}
style={{
position: "absolute"
}}
color="var(--nn_pri)"
/>
2022-06-30 09:47:04 +05:00
</Button>
</div>
</div>
)}
2022-06-23 19:14:55 +05:00
</div>
2022-06-30 09:47:04 +05:00
);
},
2022-07-08 18:33:54 +05:00
(prev, next) => {
if (
prev.noHeader !== next.noHeader ||
prev.settings.premium !== next.settings.premium ||
prev.hasRedo !== next.hasRedo ||
prev.hasUndo !== next.hasUndo
)
return false;
return true;
}
2022-06-30 09:47:04 +05:00
);