Skip to content

Commit 26b8f6b

Browse files
committed
feat: add new setting to select line height options
1 parent 54cc0e4 commit 26b8f6b

File tree

8 files changed

+66
-7
lines changed

8 files changed

+66
-7
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script setup lang="ts">
2+
import type { LineHeight } from '~/composables/settings'
3+
4+
const userSettings = useUserSettings()
5+
6+
const sizes: LineHeight[] = ['narrow', 'normal', 'wide']
7+
8+
const currentSize = computed(() => userSettings.value.lineHeight || sizes[1])
9+
10+
function setLineHeight(size: LineHeight) {
11+
userSettings.value.lineHeight = size
12+
}
13+
</script>
14+
15+
<template>
16+
<section space-y-2>
17+
<h2 id="interface-lh" font-medium>
18+
{{ $t('settings.interface.line_height') }}
19+
</h2>
20+
<div flex="~ gap4 wrap" p2 role="group" aria-labelledby="interface-lh">
21+
<button
22+
v-for="size in sizes"
23+
:key="size"
24+
type="button"
25+
btn-text flex-1 flex="~ gap-1 center" p4 border="~ base rounded" bg-base ws-nowrap
26+
:aria-pressed="currentSize === size ? 'true' : 'false'"
27+
:class="currentSize === size ? 'pointer-events-none' : 'filter-saturate-0'"
28+
@click="setLineHeight(size)"
29+
>
30+
{{ $t(`settings.interface.${size}`) }}
31+
</button>
32+
</div>
33+
</section>
34+
</template>

components/status/StatusBody.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,25 @@ const vnode = computed(() => {
2626
inReplyToStatus: newer,
2727
})
2828
})
29+
30+
const userSettings = useUserSettings()
31+
const lineHeight = userSettings.value.lineHeight
2932
</script>
3033

3134
<template>
3235
<div class="status-body" whitespace-pre-wrap break-words :class="{ 'with-action': withAction }" relative>
3336
<span
3437
v-if="status.content"
35-
class="content-rich line-compact" dir="auto"
38+
class="content-rich" :class="[`line-height-${lineHeight}`]"
39+
dir="auto"
3640
:lang="('language' in status && status.language) || undefined"
3741
>
3842
<component :is="vnode" v-if="vnode" />
3943
</span>
4044
<div v-else />
4145
<template v-if="translation.visible">
4246
<div my2 h-px border="b base" bg-base />
43-
<ContentRich v-if="translation.success" class="line-compact" :content="translation.text" :emojis="status.emojis" />
47+
<ContentRich v-if="translation.success" class="content-rich" :class="[`line-height-${lineHeight}`]" :content="translation.text" :emojis="status.emojis" />
4448
<div v-else text-red-4>
4549
Error: {{ translation.error }}
4650
</div>

components/status/StatusPreviewStackBlitz.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const vnodeCode = computed(() => {
4747
})
4848
return vnode
4949
})
50+
51+
const userSettings = useUserSettings()
52+
const lineHeight = userSettings.value.lineHeight
5053
</script>
5154

5255
<template>
@@ -60,7 +63,7 @@ const vnodeCode = computed(() => {
6063
pb-2
6164
>
6265
<div whitespace-pre-wrap break-words>
63-
<span v-if="vnodeCode" class="content-rich line-compact" dir="auto">
66+
<span v-if="vnodeCode" class="content-rich" :class="[`line-height-${lineHeight}`]" dir="auto">
6467
<component :is="vnodeCode" />
6568
</span>
6669
</div>

composables/settings/definition.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { DEFAULT_FONT_SIZE } from '~/constants'
1+
import { DEFAULT_FONT_SIZE, DEFAULT_LINE_HEIGHT } from '~/constants'
22

33
export type FontSize = `${number}px`
44

5+
export type LineHeight = 'narrow' | 'normal' | 'wide'
6+
57
// Temporary type for backward compatibility
68
export type OldFontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
79

@@ -38,6 +40,7 @@ export interface UserSettings {
3840
preferences: Partial<PreferencesSettings>
3941
colorMode?: ColorMode
4042
fontSize: FontSize
43+
lineHeight: LineHeight
4144
language: string
4245
disabledTranslationLanguages: string[]
4346
themeColors?: ThemeColors
@@ -94,6 +97,7 @@ export function getDefaultUserSettings(locales: string[]): UserSettings {
9497
return {
9598
language: getDefaultLanguage(locales),
9699
fontSize: DEFAULT_FONT_SIZE,
100+
lineHeight: DEFAULT_LINE_HEIGHT,
97101
disabledTranslationLanguages: [],
98102
preferences: DEFAULT__PREFERENCES_SETTINGS,
99103
}

constants/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const APP_NAME = 'Elk'
44

55
export const DEFAULT_POST_CHARS_LIMIT = 500
66
export const DEFAULT_FONT_SIZE = '15px'
7+
export const DEFAULT_LINE_HEIGHT = 'normal'
78

89
export const ELK_PAGE_LIFECYCLE_FROZEN = 'elk-frozen'
910

locales/en.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,12 @@
462462
"font_size": "Font Size",
463463
"label": "Interface",
464464
"light_mode": "Light",
465+
"line_height": "Line Height",
466+
"narrow": "Narrow",
467+
"normal": "Normal",
465468
"system_mode": "System",
466-
"theme_color": "Theme Color"
469+
"theme_color": "Theme Color",
470+
"wide": "Wide"
467471
},
468472
"language": {
469473
"display_language": "Display Language",

pages/settings/interface/index.vue

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ useHydratedHead({
1515
</template>
1616
<div px-6 pt-3 pb-6 flex="~ col gap6">
1717
<SettingsFontSize />
18+
<SettingsLineHeight />
1819
<SettingsColorMode />
1920
<SettingsThemeColors />
2021
<SettingsBottomNav />

styles/global.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,16 @@ em-emoji-picker {
125125
}
126126
}
127127

128-
.line-compact {
129-
line-height: calc(4 / 3 * 1em);
128+
.line-height-narrow {
129+
line-height: 1.15;
130+
}
131+
132+
.line-height-normal {
133+
line-height: calc(4 / 3);
134+
}
135+
136+
.line-height-wide {
137+
line-height: 1.5;
130138
}
131139

132140
.content-editor {

0 commit comments

Comments
 (0)