Skip to content

Commit

Permalink
wip: more incremental titlebar refactoring
Browse files Browse the repository at this point in the history
working in 30-60 minute increments in the early AM / late PM. Nearly done, then a bunch of clean-up
  • Loading branch information
cloverich committed Aug 6, 2024
1 parent 6e08010 commit 0f4043f
Show file tree
Hide file tree
Showing 21 changed files with 241 additions and 310 deletions.
4 changes: 2 additions & 2 deletions src/components/Sidesheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SheetOverlay = React.forwardRef<
// Initial use case is for side bar (journal selection) -- imo looks better when backgroud is not faded / covered w/ animation; may want to re-enable
// for other use cases
// "fixed inset-0 z-50 bg-slate-400 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
"no-drag",
"drag-none",
className,
)}
{...props}
Expand All @@ -31,7 +31,7 @@ const SheetOverlay = React.forwardRef<
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;

const sheetVariants = cva(
"no-drag fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-300",
"drag-none fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-300",
{
variants: {
side: {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function createWindow() {
//
titleBarStyle: "hidden",

trafficLightPosition: { x: 10, y: 18 },
trafficLightPosition: { x: 10, y: 16 },
webPreferences: {
nodeIntegration: false,
sandbox: false,
Expand Down
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;

/* --accent: 255, 89%, 62%; */
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;

Expand Down
2 changes: 0 additions & 2 deletions src/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { PropsWithChildren } from "react";
import { Pane, Tablist, Tab } from "evergreen-ui";
import ErrorBoundary from "./error";
import { NavLink, useLocation } from "react-router-dom";
import Titlebar from "./titlebar/macos";

interface Props2 {
children: any;
Expand Down
28 changes: 12 additions & 16 deletions src/titlebar/macos.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import React, { PropsWithChildren } from "react";
import { Pane } from "evergreen-ui";
import { NavLink, useLocation } from "react-router-dom";
import "./styles.css";
import { cn } from "@udecode/cn";

interface Props2 extends PropsWithChildren {}

export default function Titlebar({ children }: Props2) {
const location = useLocation();
interface Props extends PropsWithChildren {
className?: string;
}

export default function Titlebar({ children, className }: Props) {
return (
<div className="TitleBar-macos">
<div
style={{ "-webkit-app-region": "drag" } as React.CSSProperties}
className={cn(
"bg-secondary border-b border-accent text-accent-foreground border-accent flex justify-between items-center py-3 px-2.5 pl-20 fixed w-full h-12 z-10",
className,
)}
>
{children}
{/* <Pane marginRight={25}>
<span className="mono" style={{ color: "#6E62B6" }}>
chronicles
</span>
</Pane>
<Pane flexGrow={1} marginRight={24}>
</Pane> */}
</div>
);
}
37 changes: 0 additions & 37 deletions src/titlebar/styles.css

This file was deleted.

6 changes: 3 additions & 3 deletions src/views/documents/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function Layout(props: Props) {

return (
<>
<Titlebar>
<Titlebar className="pr-16">
<JournalSelectionSidebar
isShown={isSidebarOpen}
setIsShown={setIsSidebarOpen}
Expand All @@ -37,7 +37,7 @@ export function Layout(props: Props) {
border="none"
icon={PanelStatsIcon}
marginRight={8}
className="no-drag"
className="drag-none"
>
Select Journals
</IconButton>
Expand All @@ -48,7 +48,7 @@ export function Layout(props: Props) {
backgroundColor="transparent"
border="none"
icon={EditIcon}
className="no-drag"
className="drag-none"
onClick={() => navigate("/documents/edit/new")}
marginRight={8}
>
Expand Down
2 changes: 1 addition & 1 deletion src/views/documents/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SearchDocuments = (props: Props) => {

return (
<TagInput
className="no-drag"
className="drag-none"
flexGrow={1}
inputProps={{ placeholder: "Search journals" }}
values={props.store.searchTokens}
Expand Down
29 changes: 0 additions & 29 deletions src/views/edit/FrontMatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const FrontMatter = observer(
document: EditableDocument;
journals: JournalResponse[];
}) => {
const navigate = useNavigate();
const searchStore = useSearchStore()!;

function onAddTag(tokens: string[]) {
if (tokens.length > 1) {
// https://evergreen.segment.com/components/tag-input
Expand Down Expand Up @@ -152,34 +149,8 @@ const FrontMatter = observer(
);
}

function goBack() {
if (
!document.dirty ||
confirm(
"Document is unsaved, exiting will discard document. Stop editing anyways?",
)
) {
// This handles the edit case but hmm... if its new... it should be added to the search...
// but in what order? Well... if we aren't paginated... it should be at the top.
searchStore.updateSearch(document);
navigate(-1);
}
}

return (
<>
{/* back button */}
<div style={{ marginBottom: "24px" }}>
<a
onClick={goBack}
className={css`
cursor: pointer;
`}
>
Back
</a>
</div>

{/* Document title */}
<div>
<input
Expand Down
1 change: 0 additions & 1 deletion src/views/edit/PlateContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ import { EditorToolbar } from "./editor/toolbar/EditorToolbar";
import { EditorMode } from "./EditorMode";
import FrontMatter from "./FrontMatter";
import { Pane } from "evergreen-ui";
import { SaveActions } from "./SaveActions";
import { EditableDocument } from "./EditableDocument";
import { JournalResponse } from "../../hooks/useClient";

Expand Down
40 changes: 0 additions & 40 deletions src/views/edit/SaveActions.tsx

This file was deleted.

43 changes: 17 additions & 26 deletions src/views/edit/editor/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { withTooltip } from "./Tooltip";

export const Toolbar = withCn(
ToolbarPrimitive.Root,
"relative flex select-none items-center gap-1 bg-background",
"relative flex select-none items-center gap-1",
);

export const ToolbarToggleGroup = withCn(
Expand All @@ -30,21 +30,24 @@ export const ToolbarSeparator = withCn(

const toolbarButtonVariants = cva(
cn(
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
"inline-flex items-center justify-center text-xs ring-offset-background transition-colors disabled:pointer-events-none disabled:opacity-50",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
"[&_svg:not([data-icon])]:h-5 [&_svg:not([data-icon])]:w-5",
"rounded-sm border border-transparent",
),
{
variants: {
variant: {
default:
"bg-transparent hover:bg-muted hover:text-muted-foreground aria-checked:bg-accent aria-checked:text-accent-foreground",
"hover:bg-slate-50 hover:border-slate-400 hover:border hover:text-accent-foreground aria-checked:text-accent-foreground ", //border-1 border-transparent bg-transparent
outline:
"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",
},
size: {
default: "h-10 px-3",
sm: "h-9 px-2",
lg: "h-11 px-5",
default: "h-7 p-1.5",
xs: "h-5 p-1.5",
sm: "h-7 p-1.5",
lg: "h-9 p-1.5",
},
},
defaultVariants: {
Expand All @@ -54,8 +57,10 @@ const toolbarButtonVariants = cva(
},
);

// todo: fix any
const ToolbarButton: any = withTooltip(
/**
* A styled button for the toolbar.
*/
const ToolbarButton = withTooltip(
// eslint-disable-next-line react/display-name
React.forwardRef<
React.ElementRef<typeof ToolbarToggleItem>,
Expand Down Expand Up @@ -85,22 +90,12 @@ const ToolbarButton: any = withTooltip(
variant,
size,
}),
isDropdown && "my-1 justify-between pr-1",
className,
)}
value={pressed ? "single" : ""}
{...props}
>
{isDropdown ? (
<>
<div className="flex flex-1">{children}</div>
<div>
<Icons.arrowDown className="ml-0.5 h-4 w-4" data-icon />
</div>
</>
) : (
children
)}
{children}
</ToolbarToggleItem>
</ToolbarToggleGroup>
) : (
Expand All @@ -122,7 +117,9 @@ const ToolbarButton: any = withTooltip(
},
),
);

ToolbarButton.displayName = "ToolbarButton";

export { ToolbarButton };

export const ToolbarToggleItem = withVariants(
Expand All @@ -148,13 +145,7 @@ export const ToolbarGroup = withRef<
</div>
)}

<div className="mx-1 flex items-center gap-1">{children}</div>
<div className="mx-1 flex items-center">{children}</div>
</div>
);
});

// Also https://platejs.org/docs/components/toolbar
export const FixedToolbar = withCn(
Toolbar,
"supports-backdrop-blur:bg-background/60 sticky left-0 top-[57px] z-50 w-full overflow-x-auto rounded-t-lg border-b border-b-border bg-background/95 backdrop-blur",
);
7 changes: 4 additions & 3 deletions src/views/edit/editor/read-only-editor/ReadonlyToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { ToolbarGroup, FixedToolbar } from "../components/Toolbar";
import { ToolbarGroup, Toolbar } from "../components/Toolbar";
import { TooltipProvider } from "../components/Tooltip";
import DebugDropdown from "../toolbar/components/DebugDropdown";
import { EditorMode } from "../../EditorMode";
Expand Down Expand Up @@ -36,14 +36,15 @@ export function ReadonlyToolbar({
>
<div className="grow" />
<>
<FixedToolbar>
<Toolbar>
<ToolbarGroup>
<DebugDropdown
selectedEditorMode={selectedEditorMode}
setSelectedEditorMode={setSelectedEditorMode}
deleteDocument={() => {}}
/>
</ToolbarGroup>
</FixedToolbar>
</Toolbar>
</>
</div>
</div>
Expand Down
Loading

0 comments on commit 0f4043f

Please sign in to comment.