|
| 1 | +import { Component, createMemo, type JSX } from "solid-js" |
| 2 | +import { Select } from "@opencode-ai/ui/select" |
| 3 | +import { Switch } from "@opencode-ai/ui/switch" |
| 4 | +import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme" |
| 5 | +import { useSettings } from "@/context/settings" |
| 6 | + |
| 7 | +export const SettingsGeneral: Component = () => { |
| 8 | + const theme = useTheme() |
| 9 | + const settings = useSettings() |
| 10 | + |
| 11 | + const themeOptions = createMemo(() => |
| 12 | + Object.entries(theme.themes()).map(([id, def]) => ({ id, name: def.name ?? id })), |
| 13 | + ) |
| 14 | + |
| 15 | + const colorSchemeOptions: { value: ColorScheme; label: string }[] = [ |
| 16 | + { value: "system", label: "System setting" }, |
| 17 | + { value: "light", label: "Light" }, |
| 18 | + { value: "dark", label: "Dark" }, |
| 19 | + ] |
| 20 | + |
| 21 | + const fontOptions = [ |
| 22 | + { value: "ibm-plex-mono", label: "IBM Plex Mono" }, |
| 23 | + { value: "fira-code", label: "Fira Code" }, |
| 24 | + { value: "jetbrains-mono", label: "JetBrains Mono" }, |
| 25 | + { value: "source-code-pro", label: "Source Code Pro" }, |
| 26 | + ] |
| 27 | + |
| 28 | + return ( |
| 29 | + <div class="flex flex-col h-full overflow-y-auto no-scrollbar"> |
| 30 | + <div class="flex flex-col gap-8 p-8 max-w-[720px]"> |
| 31 | + {/* Header */} |
| 32 | + <h2 class="text-16-medium text-text-strong">General</h2> |
| 33 | + |
| 34 | + {/* Appearance Section */} |
| 35 | + <div class="flex flex-col gap-1"> |
| 36 | + <h3 class="text-14-medium text-text-strong pb-2">Appearance</h3> |
| 37 | + |
| 38 | + <SettingsRow title="Appearance" description="Customise how OpenCode looks on your device"> |
| 39 | + <Select |
| 40 | + options={colorSchemeOptions} |
| 41 | + current={colorSchemeOptions.find((o) => o.value === theme.colorScheme())} |
| 42 | + value={(o) => o.value} |
| 43 | + label={(o) => o.label} |
| 44 | + onSelect={(option) => option && theme.setColorScheme(option.value)} |
| 45 | + variant="secondary" |
| 46 | + size="small" |
| 47 | + /> |
| 48 | + </SettingsRow> |
| 49 | + |
| 50 | + <SettingsRow |
| 51 | + title="Theme" |
| 52 | + description={ |
| 53 | + <> |
| 54 | + Customise how OpenCode is themed.{" "} |
| 55 | + <a href="#" class="text-text-interactive-base"> |
| 56 | + Learn more |
| 57 | + </a> |
| 58 | + </> |
| 59 | + } |
| 60 | + > |
| 61 | + <Select |
| 62 | + options={themeOptions()} |
| 63 | + current={themeOptions().find((o) => o.id === theme.themeId())} |
| 64 | + value={(o) => o.id} |
| 65 | + label={(o) => o.name} |
| 66 | + onSelect={(option) => option && theme.setTheme(option.id)} |
| 67 | + variant="secondary" |
| 68 | + size="small" |
| 69 | + /> |
| 70 | + </SettingsRow> |
| 71 | + |
| 72 | + <SettingsRow title="Font" description="Customise the mono font used in code blocks"> |
| 73 | + <Select |
| 74 | + options={fontOptions} |
| 75 | + current={fontOptions.find((o) => o.value === settings.appearance.font())} |
| 76 | + value={(o) => o.value} |
| 77 | + label={(o) => o.label} |
| 78 | + onSelect={(option) => option && settings.appearance.setFont(option.value)} |
| 79 | + variant="secondary" |
| 80 | + size="small" |
| 81 | + /> |
| 82 | + </SettingsRow> |
| 83 | + </div> |
| 84 | + |
| 85 | + {/* System notifications Section */} |
| 86 | + <div class="flex flex-col gap-1"> |
| 87 | + <h3 class="text-14-medium text-text-strong pb-2">System notifications</h3> |
| 88 | + |
| 89 | + <SettingsRow |
| 90 | + title="Agent" |
| 91 | + description="Show system notification when the agent is complete or needs attention" |
| 92 | + > |
| 93 | + <Switch |
| 94 | + checked={settings.notifications.agent()} |
| 95 | + onChange={(checked) => settings.notifications.setAgent(checked)} |
| 96 | + /> |
| 97 | + </SettingsRow> |
| 98 | + |
| 99 | + <SettingsRow title="Permissions" description="Show system notification when a permission is required"> |
| 100 | + <Switch |
| 101 | + checked={settings.notifications.permissions()} |
| 102 | + onChange={(checked) => settings.notifications.setPermissions(checked)} |
| 103 | + /> |
| 104 | + </SettingsRow> |
| 105 | + |
| 106 | + <SettingsRow title="Errors" description="Show system notification when an error occurs"> |
| 107 | + <Switch |
| 108 | + checked={settings.notifications.errors()} |
| 109 | + onChange={(checked) => settings.notifications.setErrors(checked)} |
| 110 | + /> |
| 111 | + </SettingsRow> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + ) |
| 116 | +} |
| 117 | + |
| 118 | +interface SettingsRowProps { |
| 119 | + title: string |
| 120 | + description: string | JSX.Element |
| 121 | + children: JSX.Element |
| 122 | +} |
| 123 | + |
| 124 | +const SettingsRow: Component<SettingsRowProps> = (props) => { |
| 125 | + return ( |
| 126 | + <div class="flex items-center justify-between gap-4 py-3 border-b border-border-weak-base last:border-none"> |
| 127 | + <div class="flex flex-col gap-0.5"> |
| 128 | + <span class="text-14-medium text-text-strong">{props.title}</span> |
| 129 | + <span class="text-12-regular text-text-weak">{props.description}</span> |
| 130 | + </div> |
| 131 | + <div class="flex-shrink-0">{props.children}</div> |
| 132 | + </div> |
| 133 | + ) |
| 134 | +} |
0 commit comments