From eba3a43805b5777aebb677df88bf5c8533743ead Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 26 Jun 2024 14:17:22 +0300 Subject: [PATCH] better font control custom input --- src/components/font_control/font_control.js | 60 +++++++---- src/components/font_control/font_control.vue | 101 ++++++++++--------- src/i18n/en.json | 11 ++ 3 files changed, 109 insertions(+), 63 deletions(-) diff --git a/src/components/font_control/font_control.js b/src/components/font_control/font_control.js index 92ee3f30..52c3e70a 100644 --- a/src/components/font_control/font_control.js +++ b/src/components/font_control/font_control.js @@ -1,9 +1,22 @@ import { set } from 'lodash' 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 { components: { - Select + Select, + Checkbox, + Popover }, props: [ 'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit' @@ -11,10 +24,11 @@ export default { emits: ['update:modelValue'], data () { return { - lValue: this.modelValue, + localValue: this.modelValue, + customFamily: '', availableOptions: [ this.noInherit ? '' : 'inherit', - 'custom', + 'local', ...(this.options || []), 'serif', 'monospace', @@ -23,40 +37,52 @@ export default { } }, beforeUpdate () { - this.lValue = this.modelValue + this.localValue = this.modelValue }, computed: { present () { - return typeof this.lValue !== 'undefined' + return typeof this.localValue !== 'undefined' }, - dValue () { - return this.lValue || this.fallback || {} + defaultValue () { + return this.localValue || this.fallback || {} }, family: { 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(this.lValue, 'family', v) - this.$emit('update:modelValue', this.lValue) + this.customFamily = v + 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 () { - return this.preset === 'custom' + return !PRESET_FONTS.has(this.family) }, preset: { get () { - if (this.family === 'serif' || - this.family === 'sans-serif' || - this.family === 'monospace' || - this.family === 'inherit') { + if (PRESET_FONTS.has(this.family)) { return this.family } else { - return 'custom' + return 'local' } }, set (v) { - this.family = v === 'custom' ? '' : v + this.family = v === 'local' ? '' : v } } } diff --git a/src/components/font_control/font_control.vue b/src/components/font_control/font_control.vue index d2d1b388..e73862a0 100644 --- a/src/components/font_control/font_control.vue +++ b/src/components/font_control/font_control.vue @@ -1,6 +1,6 @@ @@ -55,20 +71,13 @@ diff --git a/src/i18n/en.json b/src/i18n/en.json index 3116843d..bd18c6ef 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -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.", "more_settings": "More settings", "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": { "keep_color": "Keep colors", "keep_shadows": "Keep shadows",