Skip to content

Commit b24b53c

Browse files
committed
feat: add new setting to select line height options
1 parent 32ccc9f commit b24b53c

File tree

8 files changed

+87
-7
lines changed

8 files changed

+87
-7
lines changed
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script setup lang="ts">
2+
import type { LineHeight } from '~/composables/settings'
3+
4+
const userSettings = useUserSettings()
5+
6+
const sizes = [
7+
{
8+
icon: 'i-ri-collapse-vertical-line',
9+
label: 'settings.interface.narrow',
10+
size: 'narrow',
11+
},
12+
{
13+
icon: 'i-ri-line-height',
14+
label: 'settings.interface.normal',
15+
size: 'normal',
16+
},
17+
{
18+
icon: 'i-ri-expand-vertical-line',
19+
label: 'settings.interface.wide',
20+
size: 'wide',
21+
},
22+
] as const
23+
24+
const currentSize = computed(() => userSettings.value.lineHeight || sizes[1])
25+
26+
function setLineHeight(size: LineHeight) {
27+
userSettings.value.lineHeight = size
28+
}
29+
</script>
30+
31+
<template>
32+
<section space-y-2>
33+
<h2 id="interface-lh" font-medium>
34+
{{ $t('settings.interface.line_height') }}
35+
</h2>
36+
<p id="interface-lh-desc" pb-2>
37+
{{ $t('settings.interface.reload_app') }}
38+
</p>
39+
<div flex="~ gap4 wrap" p2 role="group" aria-labelledby="interface-lh" aria-describedby="interface-lh-desc">
40+
<button
41+
v-for="{ icon, label, size } in sizes"
42+
:key="size"
43+
type="button"
44+
btn-text flex-1 flex="~ gap-1 center" p4 border="~ base rounded" bg-base ws-nowrap
45+
:aria-pressed="currentSize === size ? 'true' : 'false'"
46+
:class="currentSize === size ? 'pointer-events-none' : 'filter-saturate-0'"
47+
@click="setLineHeight(size)"
48+
>
49+
<span :class="`${icon}`" />
50+
{{ $t(label) }}
51+
</button>
52+
</div>
53+
</section>
54+
</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

+6-1
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,13 @@
462462
"font_size": "Font Size",
463463
"label": "Interface",
464464
"light_mode": "Light",
465+
"line_height": "Line Height",
466+
"narrow": "Narrow",
467+
"normal": "Normal",
468+
"reload_app": "Reload the app for the changes to take effect.",
465469
"system_mode": "System",
466-
"theme_color": "Theme Color"
470+
"theme_color": "Theme Color",
471+
"wide": "Wide"
467472
},
468473
"language": {
469474
"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)