better font control custom input

appearance-tab
Henry Jameson 3 months ago
parent a664cf352d
commit eba3a43805

@ -1,9 +1,22 @@
import { set } from 'lodash' import { set } from 'lodash'
import Select from '../select/select.vue' import Select from '../select/select.vue'
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Popover from 'src/components/popover/popover.vue'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'
library.add(
faExclamationTriangle
)
const PRESET_FONTS = new Set(['serif', 'sans-serif', 'monospace', 'inherit'])
export default { export default {
components: { components: {
Select Select,
Checkbox,
Popover
}, },
props: [ props: [
'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit' 'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit'
@ -11,10 +24,11 @@ export default {
emits: ['update:modelValue'], emits: ['update:modelValue'],
data () { data () {
return { return {
lValue: this.modelValue, localValue: this.modelValue,
customFamily: '',
availableOptions: [ availableOptions: [
this.noInherit ? '' : 'inherit', this.noInherit ? '' : 'inherit',
'custom', 'local',
...(this.options || []), ...(this.options || []),
'serif', 'serif',
'monospace', 'monospace',
@ -23,40 +37,52 @@ export default {
} }
}, },
beforeUpdate () { beforeUpdate () {
this.lValue = this.modelValue this.localValue = this.modelValue
}, },
computed: { computed: {
present () { present () {
return typeof this.lValue !== 'undefined' return typeof this.localValue !== 'undefined'
}, },
dValue () { defaultValue () {
return this.lValue || this.fallback || {} return this.localValue || this.fallback || {}
}, },
family: { family: {
get () { get () {
return this.dValue.family return this.defaultValue.family
},
set (v) {
set(this.localValue, 'family', v)
this.$emit('update:modelValue', this.localValue)
}
},
familyCustom: {
get () {
return this.customFamily
}, },
set (v) { set (v) {
set(this.lValue, 'family', v) this.customFamily = v
this.$emit('update:modelValue', this.lValue) if (!PRESET_FONTS.has(this.customFamily)) {
set(this.localValue, 'family', v)
this.$emit('update:modelValue', this.customFamily)
}
} }
}, },
invalidCustom () {
return PRESET_FONTS.has(this.customFamily)
},
isCustom () { isCustom () {
return this.preset === 'custom' return !PRESET_FONTS.has(this.family)
}, },
preset: { preset: {
get () { get () {
if (this.family === 'serif' || if (PRESET_FONTS.has(this.family)) {
this.family === 'sans-serif' ||
this.family === 'monospace' ||
this.family === 'inherit') {
return this.family return this.family
} else { } else {
return 'custom' return 'local'
} }
}, },
set (v) { set (v) {
this.family = v === 'custom' ? '' : v this.family = v === 'local' ? '' : v
} }
} }
} }

@ -1,6 +1,6 @@
<template> <template>
<div <div
class="font-control style-control" class="font-control"
:class="{ custom: isCustom }" :class="{ custom: isCustom }"
> >
<label <label
@ -10,43 +10,59 @@
> >
{{ label }} {{ label }}
</label> </label>
<input {{ ' ' }}
<Checkbox
v-if="typeof fallback !== 'undefined'" v-if="typeof fallback !== 'undefined'"
:id="name + '-o'" :id="name + '-o'"
:aria-labelledby="name + '-label'" :modelValue="present"
class="input -checkbox opt exlcude-disabled visible-for-screenreader-only"
type="checkbox"
:checked="present"
@change="$emit('update:modelValue', typeof modelValue === 'undefined' ? fallback : undefined)" @change="$emit('update:modelValue', typeof modelValue === 'undefined' ? fallback : undefined)"
> >
<label {{ $t('settings.style.themes3.define') }}
v-if="typeof fallback !== 'undefined'" </Checkbox>
class="opt-l" <p>
:for="name + '-o'" <Select
:aria-hidden="true" :id="name + '-font-switcher'"
/> v-model="preset"
{{ ' ' }} :disabled="!present"
<Select class="font-switcher"
:id="name + '-font-switcher'"
v-model="preset"
:disabled="!present"
class="font-switcher"
>
<option
v-for="option in availableOptions"
:key="option"
:value="option"
> >
{{ option === 'custom' ? $t('settings.style.fonts.custom') : option }} <option
</option> v-for="option in availableOptions"
</Select> :key="option"
<input :value="option"
v-if="isCustom" >
:id="name" {{ $t('settings.style.themes3.font.' + option) }}
v-model="family" </option>
class="input custom-font" </Select>
type="text" </p>
> <p>
<input
v-if="isCustom"
:id="name"
v-model="familyCustom"
class="input custom-font"
type="text"
>
<span
v-if="invalidCustom"
class="InvalidIndicator"
>
<Popover
trigger="hover"
:trigger-attrs="{ 'aria-label': $t('settings.style.themes3.font.invalid_custom_reserved') }"
>
<template #trigger>
&nbsp;
<FAIcon icon="exclamation-triangle" />
</template>
<template #content>
<div class="invalid-tooltip">
{{ $t('settings.style.themes3.font.invalid_custom_reserved') }}
</div>
</template>
</Popover>
</span>
</p>
</div> </div>
</template> </template>
@ -55,20 +71,13 @@
<style lang="scss"> <style lang="scss">
.font-control { .font-control {
input.custom-font { input.custom-font {
min-width: 10em; min-width: 12em;
} }
}
&.custom { .invalid-tooltip {
/* TODO Should make proper joiners... */ margin: 0.5em 1em;
.font-switcher { min-width: 10em;
border-top-right-radius: 0; text-align: center;
border-bottom-right-radius: 0;
}
.custom-font {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
} }
</style> </style>

@ -745,6 +745,17 @@
"enable_web_push_always_show_tip": "Some browsers (Chromium, Chrome) require that push messages always result in a notification, otherwise generic 'Website was updated in background' is shown, enable this to prevent this notification from showing, as Chrome seem to hide push notifications if tab is in focus. Can result in showing duplicate notifications on other browsers.", "enable_web_push_always_show_tip": "Some browsers (Chromium, Chrome) require that push messages always result in a notification, otherwise generic 'Website was updated in background' is shown, enable this to prevent this notification from showing, as Chrome seem to hide push notifications if tab is in focus. Can result in showing duplicate notifications on other browsers.",
"more_settings": "More settings", "more_settings": "More settings",
"style": { "style": {
"themes3": {
"define": "Include in theme",
"font": {
"local": "Local font (must be installed on computer)",
"serif": "Serif (browser default)",
"sans-serif": "Sans-serif (browser default)",
"monospace": "Monospace (browser default)",
"inherit": "Same as parent component",
"invalid_custom_reserved": "This is a reserved font name, it will not be saved as custom font - use dropdown instead"
}
},
"switcher": { "switcher": {
"keep_color": "Keep colors", "keep_color": "Keep colors",
"keep_shadows": "Keep shadows", "keep_shadows": "Keep shadows",

Loading…
Cancel
Save