Skip to content

Commit

Permalink
feat: add new setting to select line height options
Browse files Browse the repository at this point in the history
  • Loading branch information
shuuji3 committed Oct 31, 2024
1 parent 54cc0e4 commit 26b8f6b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 7 deletions.
34 changes: 34 additions & 0 deletions components/settings/SettingsLineHeight.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script setup lang="ts">
import type { LineHeight } from '~/composables/settings'
const userSettings = useUserSettings()
const sizes: LineHeight[] = ['narrow', 'normal', 'wide']
const currentSize = computed(() => userSettings.value.lineHeight || sizes[1])
function setLineHeight(size: LineHeight) {
userSettings.value.lineHeight = size
}
</script>

<template>
<section space-y-2>
<h2 id="interface-lh" font-medium>
{{ $t('settings.interface.line_height') }}
</h2>
<div flex="~ gap4 wrap" p2 role="group" aria-labelledby="interface-lh">
<button
v-for="size in sizes"
:key="size"
type="button"
btn-text flex-1 flex="~ gap-1 center" p4 border="~ base rounded" bg-base ws-nowrap
:aria-pressed="currentSize === size ? 'true' : 'false'"
:class="currentSize === size ? 'pointer-events-none' : 'filter-saturate-0'"
@click="setLineHeight(size)"
>
{{ $t(`settings.interface.${size}`) }}
</button>
</div>
</section>
</template>
8 changes: 6 additions & 2 deletions components/status/StatusBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ const vnode = computed(() => {
inReplyToStatus: newer,
})
})
const userSettings = useUserSettings()
const lineHeight = userSettings.value.lineHeight
</script>

<template>
<div class="status-body" whitespace-pre-wrap break-words :class="{ 'with-action': withAction }" relative>
<span
v-if="status.content"
class="content-rich line-compact" dir="auto"
class="content-rich" :class="[`line-height-${lineHeight}`]"
dir="auto"
:lang="('language' in status && status.language) || undefined"
>
<component :is="vnode" v-if="vnode" />
</span>
<div v-else />
<template v-if="translation.visible">
<div my2 h-px border="b base" bg-base />
<ContentRich v-if="translation.success" class="line-compact" :content="translation.text" :emojis="status.emojis" />
<ContentRich v-if="translation.success" class="content-rich" :class="[`line-height-${lineHeight}`]" :content="translation.text" :emojis="status.emojis" />
<div v-else text-red-4>
Error: {{ translation.error }}
</div>
Expand Down
5 changes: 4 additions & 1 deletion components/status/StatusPreviewStackBlitz.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const vnodeCode = computed(() => {
})
return vnode
})
const userSettings = useUserSettings()
const lineHeight = userSettings.value.lineHeight
</script>

<template>
Expand All @@ -60,7 +63,7 @@ const vnodeCode = computed(() => {
pb-2
>
<div whitespace-pre-wrap break-words>
<span v-if="vnodeCode" class="content-rich line-compact" dir="auto">
<span v-if="vnodeCode" class="content-rich" :class="[`line-height-${lineHeight}`]" dir="auto">
<component :is="vnodeCode" />
</span>
</div>
Expand Down
6 changes: 5 additions & 1 deletion composables/settings/definition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DEFAULT_FONT_SIZE } from '~/constants'
import { DEFAULT_FONT_SIZE, DEFAULT_LINE_HEIGHT } from '~/constants'

export type FontSize = `${number}px`

export type LineHeight = 'narrow' | 'normal' | 'wide'

// Temporary type for backward compatibility
export type OldFontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'

Expand Down Expand Up @@ -38,6 +40,7 @@ export interface UserSettings {
preferences: Partial<PreferencesSettings>
colorMode?: ColorMode
fontSize: FontSize
lineHeight: LineHeight
language: string
disabledTranslationLanguages: string[]
themeColors?: ThemeColors
Expand Down Expand Up @@ -94,6 +97,7 @@ export function getDefaultUserSettings(locales: string[]): UserSettings {
return {
language: getDefaultLanguage(locales),
fontSize: DEFAULT_FONT_SIZE,
lineHeight: DEFAULT_LINE_HEIGHT,
disabledTranslationLanguages: [],
preferences: DEFAULT__PREFERENCES_SETTINGS,
}
Expand Down
1 change: 1 addition & 0 deletions constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const APP_NAME = 'Elk'

export const DEFAULT_POST_CHARS_LIMIT = 500
export const DEFAULT_FONT_SIZE = '15px'
export const DEFAULT_LINE_HEIGHT = 'normal'

export const ELK_PAGE_LIFECYCLE_FROZEN = 'elk-frozen'

Expand Down
6 changes: 5 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,12 @@
"font_size": "Font Size",
"label": "Interface",
"light_mode": "Light",
"line_height": "Line Height",
"narrow": "Narrow",
"normal": "Normal",
"system_mode": "System",
"theme_color": "Theme Color"
"theme_color": "Theme Color",
"wide": "Wide"
},
"language": {
"display_language": "Display Language",
Expand Down
1 change: 1 addition & 0 deletions pages/settings/interface/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ useHydratedHead({
</template>
<div px-6 pt-3 pb-6 flex="~ col gap6">
<SettingsFontSize />
<SettingsLineHeight />
<SettingsColorMode />
<SettingsThemeColors />
<SettingsBottomNav />
Expand Down
12 changes: 10 additions & 2 deletions styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,16 @@ em-emoji-picker {
}
}

.line-compact {
line-height: calc(4 / 3 * 1em);
.line-height-narrow {
line-height: 1.15;
}

.line-height-normal {
line-height: calc(4 / 3);
}

.line-height-wide {
line-height: 1.5;
}

.content-editor {
Expand Down

0 comments on commit 26b8f6b

Please sign in to comment.