Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show line number toggle (#81) #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/(navigation)/(code)/components/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import ExportButton from "./ExportButton";
import LanguageControl from "./LanguageControl";
import PaddingControl from "./PaddingControl";
import ThemeControl from "./ThemeControl";
import LineNumberControl from "./LineNumberControl";

const Controls: React.FC = () => {
return (
<div className={styles.controls}>
<ThemeControl />
<BackgroundControl />
<DarkModeControl />
<LineNumberControl />
<PaddingControl />
<LanguageControl />
</div>
Expand Down
1 change: 1 addition & 0 deletions app/(navigation)/(code)/components/InfoDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function InfoDialog() {
<Shortcut keys={["C"]}>Change colors</Shortcut>
<Shortcut keys={["B"]}>Toggle background</Shortcut>
<Shortcut keys={["D"]}>Toggle dark mode</Shortcut>
<Shortcut keys={["N"]}>Toggle line number</Shortcut>
<Shortcut keys={["P"]}>Change padding</Shortcut>
<Shortcut keys={["L"]}>Select language</Shortcut>
<Shortcut keys={["⌥", "click"]}>Highlight line</Shortcut>
Expand Down
22 changes: 22 additions & 0 deletions app/(navigation)/(code)/components/LineNumberControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useAtom } from "jotai";
import React, { useCallback } from "react";
import useHotkeys from "../../../../utils/useHotkeys";
import ControlContainer from "./ControlContainer";
import { Switch } from "@/components/switch";
import { showLineNumbersAtom } from "../store";

const LineNumberControl: React.FC = () => {
const [showLineNumber, setShowLineNumber] = useAtom(showLineNumbersAtom);

const toggleShowLineNumber = useCallback(() => setShowLineNumber((old) => !old), [setShowLineNumber]);

useHotkeys("n", toggleShowLineNumber);

return (
<ControlContainer title="Line number">
<Switch checked={showLineNumber} onCheckedChange={setShowLineNumber} />
</ControlContainer>
);
};

export default LineNumberControl;
1 change: 1 addition & 0 deletions app/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export default function Components() {
<Shortcut keys={["C"]}>Change colors</Shortcut>
<Shortcut keys={["B"]}>Toggle background</Shortcut>
<Shortcut keys={["D"]}>Toggle dark mode</Shortcut>
<Shortcut keys={["N"]}>Toggle line number</Shortcut>
<Shortcut keys={["P"]}>Change padding</Shortcut>
<Shortcut keys={["L"]}>Select language</Shortcut>
<Shortcut keys={["⌥", "click"]}>Highlight line</Shortcut>
Expand Down