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

327 lines
9.1 KiB
TypeScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
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-07-11 13:00:06 +05:00
import FullscreenIcon from "mdi-react/FullscreenIcon";
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-07-11 13:00:06 +05:00
export default function Header({
noHeader,
settings,
hasUndo,
hasRedo
}: {
noHeader: boolean;
settings: Settings;
hasUndo: boolean;
hasRedo: boolean;
}) {
const insets = useSafeArea();
return (
<div
style={{
display: "flex",
alignItems: "center",
height: noHeader ? `${insets.top}px` : `${50 + insets.top}px`,
backgroundColor: "var(--nn_bg)",
position: "sticky",
width: "100vw"
}}
2022-07-11 13:00:06 +05:00
>
{noHeader ? null : (
<div
style={{
display: "flex",
width: "100%",
justifyContent: "space-between",
flexDirection: "row",
paddingTop: insets.top,
height: 50,
alignItems: "center"
}}
id='header'
2022-07-11 13:00:06 +05:00
>
{settings.deviceMode !== "mobile" && !settings.fullscreen ? (
<div />
) : (
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-07-11 13:00:06 +05:00
)}
2022-06-23 19:14:55 +05:00
2022-07-11 13:00:06 +05:00
<div
style={{
display: "flex",
alignItems: "center",
flexDirection: "row"
}}
>
<Button
onPress={() => {
editor?.commands.undo();
}}
2022-06-30 09:47:04 +05:00
style={{
2022-07-11 13:00:06 +05:00
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
2022-06-30 09:47:04 +05:00
display: "flex",
2022-07-11 13:00:06 +05:00
justifyContent: "center",
2022-06-30 09:47:04 +05:00
alignItems: "center",
2022-07-11 13:00:06 +05:00
position: "relative"
2022-06-30 09:47:04 +05:00
}}
>
2022-07-11 13:00:06 +05:00
<ArrowULeftTopIcon
color={!hasUndo ? "var(--nn_nav)" : "var(--nn_pri)"}
size={25}
2022-07-07 18:40:05 +05:00
style={{
2022-07-11 13:00:06 +05:00
position: "absolute"
2022-07-07 18:40:05 +05:00
}}
2022-07-11 13:00:06 +05:00
/>
</Button>
2022-07-07 18:40:05 +05:00
2022-07-11 13:00:06 +05:00
<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",
position: "relative"
}}
>
<ArrowURightTopIcon
color={!hasRedo ? "var(--nn_nav)" : "var(--nn_pri)"}
size={25}
style={{
position: "absolute"
}}
/>
</Button>
{!settings.premium && (
2022-07-07 18:40:05 +05:00
<Button
onPress={() => {
2022-07-11 13:00:06 +05:00
post(EventTypes.pro);
2022-07-07 18:40:05 +05:00
}}
2022-07-11 13:00:06 +05:00
preventDefault={false}
2022-07-07 18:40:05 +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-07-07 18:40:05 +05:00
}}
>
2022-07-11 13:00:06 +05:00
<CrownIcon
2022-07-09 15:51:25 +05:00
size={25}
style={{
position: "absolute"
}}
2022-07-11 13:00:06 +05:00
color="orange"
2022-07-08 18:33:54 +05:00
/>
2022-07-07 18:40:05 +05:00
</Button>
2022-07-11 13:00:06 +05:00
)}
<Button
onPress={() => {
editor?.commands.startSearch();
}}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
position: "relative"
}}
>
<MagnifyIcon
size={25}
style={{
position: "absolute"
2022-06-30 09:47:04 +05:00
}}
2022-07-11 13:00:06 +05:00
color="var(--nn_pri)"
/>
</Button>
<Button
onPress={() => {
post(EventTypes.monograph);
}}
preventDefault={false}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 10,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
position: "relative"
}}
>
<CloudUploadOutlineIcon
size={25}
2022-06-30 09:47:04 +05:00
style={{
2022-07-11 13:00:06 +05:00
position: "absolute"
2022-06-30 09:47:04 +05:00
}}
2022-07-11 13:00:06 +05:00
color="var(--nn_pri)"
/>
</Button>
{settings.deviceMode !== "mobile" && !settings.fullscreen ? (
2022-06-30 09:47:04 +05:00
<Button
onPress={() => {
2022-07-11 13:00:06 +05:00
post(EventTypes.fullscreen);
2022-06-30 09:47:04 +05:00
}}
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-11 13:00:06 +05:00
<FullscreenIcon
2022-07-09 15:51:25 +05:00
size={25}
style={{
position: "absolute"
}}
color="var(--nn_pri)"
/>
2022-06-30 09:47:04 +05:00
</Button>
2022-07-11 13:00:06 +05:00
) : null}
2022-06-30 09:47:04 +05:00
2022-07-11 13:00:06 +05:00
<Button
onPress={() => {
post(EventTypes.properties);
}}
preventDefault={false}
style={{
borderWidth: 0,
borderRadius: 100,
color: "var(--nn_icon)",
marginRight: 12,
width: 39,
height: 39,
display: "flex",
justifyContent: "center",
alignItems: "center",
position: "relative"
}}
>
<DotsHorizontalIcon
size={25}
2022-06-30 09:47:04 +05:00
style={{
2022-07-11 13:00:06 +05:00
position: "absolute"
2022-06-30 09:47:04 +05:00
}}
2022-07-11 13:00:06 +05:00
color="var(--nn_pri)"
/>
</Button>
2022-06-30 09:47:04 +05:00
</div>
2022-07-11 13:00:06 +05:00
</div>
)}
</div>
);
}