diff --git a/apps/web/scripts/build.sh b/apps/web/scripts/build.sh index 1b3fe3c..2440dcf 100644 --- a/apps/web/scripts/build.sh +++ b/apps/web/scripts/build.sh @@ -3,4 +3,4 @@ rm -rf ./.parcel-cache sh scripts/monaco.sh -npx parcel build src/web/index.html --public-url "." +npx parcel build src/index.html --public-url "." diff --git a/apps/web/src/editor/input/create.ts b/apps/web/src/editor/input/create.ts index c120855..daef290 100644 --- a/apps/web/src/editor/input/create.ts +++ b/apps/web/src/editor/input/create.ts @@ -1,6 +1,7 @@ import * as monaco from "monaco-editor"; import { RefObject, useEffect } from "react"; import { SAMPLE_TAILWIND } from "../../samples/tailwind"; +import { Settings } from "../../settings/type"; import { EditorState } from "../type"; const envDone = { current: false }; @@ -67,10 +68,11 @@ const OPTIONS: monaco.editor.IStandaloneEditorConstructionOptions = { interface Params { setEditor: EditorState["setEditor"]; containerRef: RefObject; + settings: Settings; } export const useEditorCreate = (params: Params): void => { - const { setEditor, containerRef } = params; + const { setEditor, containerRef, settings } = params; useEffect(() => { const container = containerRef.current; @@ -79,6 +81,7 @@ export const useEditorCreate = (params: Params): void => { createEnv(); const editor = monaco.editor.create(container, { ...OPTIONS, + lineNumbers: settings.lines, value: SAMPLE_TAILWIND, // value: "", }); diff --git a/apps/web/src/editor/input/input.tsx b/apps/web/src/editor/input/input.tsx index ddaae39..000056f 100644 --- a/apps/web/src/editor/input/input.tsx +++ b/apps/web/src/editor/input/input.tsx @@ -16,7 +16,7 @@ export const EditorInput = (props: Props): JSX.Element => { const containerRef = useRef(null); - useEditorCreate({ containerRef, setEditor }); + useEditorCreate({ containerRef, setEditor, settings }); useEditorLayout({ containerRef, editor, settings }); useEditorTypography({ editor, settings }); diff --git a/apps/web/src/settings/lines/lines.tsx b/apps/web/src/settings/lines/lines.tsx new file mode 100644 index 0000000..3bcc7c3 --- /dev/null +++ b/apps/web/src/settings/lines/lines.tsx @@ -0,0 +1,28 @@ +import { Editor } from "../../editor/type"; +import { SettingsRadioGroup } from "../radio/group"; +import { Settings, SettingsState } from "../type"; + +interface Props extends SettingsState { + editor: Editor; +} + +export const SettingsLines = (props: Props): JSX.Element => { + const { settings, setSettings, editor } = props; + return ( + }, + { label: "Normal", value: "on", icon: <> }, + { label: "Relative", value: "relative", icon: <> }, + ]} + value={settings.lines} + onValueChange={(value) => { + const lines = value as Settings["lines"]; + setSettings((prev) => ({ ...prev, lines })); + + editor.updateOptions({ lineNumbers: lines }); + }} + /> + ); +}; diff --git a/apps/web/src/settings/panel.tsx b/apps/web/src/settings/panel.tsx index b9e2fce..ca3b2f2 100644 --- a/apps/web/src/settings/panel.tsx +++ b/apps/web/src/settings/panel.tsx @@ -6,6 +6,7 @@ import { SettingsTheme } from "./theme/theme"; import { SettingsState } from "./type"; import { SettingsWrapColumn } from "./wrap-column"; import * as s from "./panel.module.css"; +import { SettingsLines } from "./lines/lines"; interface Props extends SettingsState, LayoutState {} @@ -16,6 +17,7 @@ export const SettingsPanel = (props: Props): JSX.Element => { , , , + , , , ].map((element, index) => ( diff --git a/apps/web/src/settings/radio/option.tsx b/apps/web/src/settings/radio/option.tsx index ae05021..991376c 100644 --- a/apps/web/src/settings/radio/option.tsx +++ b/apps/web/src/settings/radio/option.tsx @@ -16,7 +16,9 @@ export const SettingsRadioOption = (props: Props): JSX.Element => { value={value} className={[s.container, outline.onFocus].join(" ")} > - {icon} + {!!Object.keys(icon.props).length && ( + {icon} + )} {label} ); diff --git a/apps/web/src/settings/state.ts b/apps/web/src/settings/state.ts index 1141a7f..0e96ba3 100644 --- a/apps/web/src/settings/state.ts +++ b/apps/web/src/settings/state.ts @@ -8,6 +8,7 @@ const fallback: Settings = { fontSize: 20, wrapColumn: 80, template: "tailwind", + lines: "off", }; export const useSettingsState = (): SettingsState => { diff --git a/apps/web/src/settings/type.ts b/apps/web/src/settings/type.ts index 72d08a0..5d4bba5 100644 --- a/apps/web/src/settings/type.ts +++ b/apps/web/src/settings/type.ts @@ -8,6 +8,7 @@ export interface Settings { fontSize: number; wrapColumn: number; template: string; + lines: "on" | "off" | "relative"; } export interface SettingsState {