import type { EditorKeymap } from '@yaakapp-internal/models'; import React from 'react'; import { useActiveWorkspace } from '../../hooks/useActiveWorkspace'; import { useResolvedAppearance } from '../../hooks/useResolvedAppearance'; import { useResolvedTheme } from '../../hooks/useResolvedTheme'; import { useSettings } from '../../hooks/useSettings'; import { useUpdateSettings } from '../../hooks/useUpdateSettings'; import { clamp } from '../../lib/clamp'; import { getThemes } from '../../lib/theme/themes'; import { isThemeDark } from '../../lib/theme/window'; import type { ButtonProps } from '../core/Button'; import { Checkbox } from '../core/Checkbox'; import { Editor } from '../core/Editor/Editor'; import type { IconProps } from '../core/Icon'; import { Icon } from '../core/Icon'; import { IconButton } from '../core/IconButton'; import type { SelectProps } from '../core/Select'; import { Select } from '../core/Select'; import { Separator } from '../core/Separator'; import { HStack, VStack } from '../core/Stacks'; 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: EditorKeymap; label: string }[] = [ { value: 'default', label: 'Default' }, { value: 'vim', label: 'Vim' }, { value: 'vscode', label: 'VSCode' }, { value: 'emacs', label: 'Emacs' }, ]; const buttonColors: ButtonProps['color'][] = [ 'primary', 'info', 'success', 'notice', 'warning', 'danger', 'secondary', 'default', ]; const icons: IconProps['icon'][] = [ 'info', 'box', 'update', 'alert_triangle', 'arrow_big_right_dash', 'download', 'copy', 'magic_wand', 'settings', 'trash', 'sparkles', 'pencil', 'paste', 'search', 'send_horizontal', ]; const { themes } = getThemes(); export function SettingsAppearance() { const workspace = useActiveWorkspace(); const settings = useSettings(); const updateSettings = useUpdateSettings(); const appearance = useResolvedAppearance(); const activeTheme = useResolvedTheme(); if (settings == null || workspace == null) { return null; } const lightThemes: SelectProps['options'] = themes .filter((theme) => !isThemeDark(theme)) .map((theme) => ({ label: theme.name, value: theme.id, })); const darkThemes: SelectProps['options'] = themes .filter((theme) => isThemeDark(theme)) .map((theme) => ({ label: theme.name, value: theme.id, })); return ( updateSettings.mutate({ editorFontSize: clamp(parseInt(v) || 14, 8, 30) })} event="editor-font-size" /> updateSettings.mutate({ appearance })} event="appearance" options={[ { label: 'Automatic', value: 'system' }, { label: 'Light', value: 'light' }, { label: 'Dark', value: 'dark' }, ]} /> {(settings.appearance === 'system' || settings.appearance === 'light') && ( } size="sm" value={activeTheme.dark.id} options={darkThemes} event="theme.dark" onChange={(themeDark) => updateSettings.mutate({ ...settings, themeDark })} /> )} {activeTheme.active.name} (preview) {buttonColors.map((c, i) => ( ))} {buttonColors.map((c, i) => ( ))} ); }