Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new setting to select line height options #3034

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions components/settings/SettingsLineHeight.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script setup lang="ts">
import type { LineHeight } from '~/composables/settings'

const userSettings = useUserSettings()

const sizes = [
{
icon: 'i-ri-collapse-vertical-line',
label: 'settings.interface.narrow',
size: 'narrow',
},
{
icon: 'i-ri-line-height',
label: 'settings.interface.normal',
size: 'normal',
},
{
icon: 'i-ri-expand-vertical-line',
label: 'settings.interface.wide',
size: 'wide',
},
] as const

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>
<p id="interface-lh-desc" pb-2>
{{ $t('settings.interface.reload_app') }}
</p>
<div flex="~ gap4 wrap" p2 role="group" aria-labelledby="interface-lh" aria-describedby="interface-lh-desc">
<button
v-for="{ icon, label, 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)"
>
<span :class="`${icon}`" />
{{ $t(label) }}
</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
7 changes: 6 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,13 @@
"font_size": "Font Size",
"label": "Interface",
"light_mode": "Light",
"line_height": "Line Height",
"narrow": "Narrow",
"normal": "Normal",
"reload_app": "Reload the app for the changes to take effect.",
"system_mode": "System",
"theme_color": "Theme Color"
"theme_color": "Theme Color",
"wide": "Wide"
},
"language": {
"display_language": "Display Language",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"@emoji-mart/data": "^1.1.2",
"@fnando/sparkline": "^0.3.10",
"@iconify-emoji/twemoji": "^1.0.2",
"@iconify/json": "^2.2.170",
"@iconify/utils": "^2.1.22",
"@iconify/json": "^2.2.266",
"@iconify/utils": "^2.1.33",
"@nuxt/devtools": "^1.5.2",
"@nuxt/test-utils": "^3.14.3",
"@nuxtjs/color-mode": "^3.4.4",
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
29 changes: 7 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unit em following the recommendation by MDN (https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#values):

In most cases, this is the preferred way to set line-height and avoid unexpected results due to inheritance.

.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