import type { ReactNode } from "react"; import { useState } from "react"; import { clamp } from "../../lib/clamp"; import { Button } from "../Button"; import { Checkbox } from "../Checkbox"; import { SettingRow, SettingRowBoolean, SettingRowSelect, SettingSelectControl, SettingsList, SettingsSection, } from "./SettingRow"; import { SettingsPage } from "./SettingsPage"; import type { SettingsCallbacks, SettingsEditorKeymap, SettingsInterfaceRow, SettingsView, } from "./types"; const NULL_FONT_VALUE = "__NULL_FONT__"; const fontSizeOptions = [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, ].map((n) => ({ label: `${n}`, value: `${n}` })); const keymaps: { value: SettingsEditorKeymap; label: string }[] = [ { value: "default", label: "Default" }, { value: "vim", label: "Vim" }, { value: "vscode", label: "VSCode" }, { value: "emacs", label: "Emacs" }, ]; export interface SettingsInterfaceProps { view: SettingsView; callbacks: SettingsCallbacks; /** Sections only this app has, shown first, like the client's Workspaces */ leadingSections?: ReactNode; /** Sections only this app has, shown last, like the client's License */ trailingSections?: ReactNode; } export function SettingsInterface({ view, callbacks, leadingSections, trailingSections, }: SettingsInterfaceProps) { const { app, values, fonts } = view; const shown = (row: SettingsInterfaceRow) => !view.hiddenInterfaceRows?.includes(row); return ( {leadingSections} {fonts && ( ({ label: f, value: f })), ...fonts.editorFonts.map((f) => ({ label: f, value: f })), ]} onChange={(v) => callbacks.onChange({ interfaceFont: v === NULL_FONT_VALUE ? null : v }) } /> )} callbacks.onChange({ interfaceFontSize: Number.parseInt(v, 10) })} /> {fonts && ( ({ label: f, value: f })), ]} onChange={(v) => callbacks.onChange({ editorFont: v === NULL_FONT_VALUE ? null : v }) } /> )} callbacks.onChange({ editorFontSize: clamp(Number.parseInt(v, 10) || 14, 8, 30), }) } /> {(shown("editorKeymap") || shown("editorSoftWrap") || shown("coloredMethods")) && ( {shown("editorKeymap") && ( callbacks.onChange({ editorKeymap })} options={keymaps} /> )} {shown("editorSoftWrap") && ( callbacks.onChange({ editorSoftWrap })} /> )} {shown("coloredMethods") && ( callbacks.onChange({ coloredMethods })} /> )} )} {(shown("nativeTitlebar") || view.windowControlsSetting) && ( {shown("nativeTitlebar") && ( )} {view.windowControlsSetting && ( callbacks.onChange({ hideWindowControls })} /> )} )} {trailingSections} ); } function NativeTitlebarSetting({ useNativeTitlebar, onApply, }: { useNativeTitlebar: boolean; onApply: SettingsCallbacks["onApplyNativeTitlebar"]; }) { const [nativeTitlebar, setNativeTitlebar] = useState(useNativeTitlebar); return ( {useNativeTitlebar !== nativeTitlebar && ( )} ); }