mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
Update the nuxt3 version. Co-authored-by: Jonathan Adeline <jonathan@baserow.io> Co-authored-by: Bram Wiepjes <bramw@protonmail.com> Co-authored-by: Cezary <cezary@baserow.io> Co-authored-by: Tsering Paljor <tsering@baserow.io> Co-authored-by: Przemyslaw Kukulski <przemyslaw+gh@baserow.io> Co-authored-by: Bram <bram2w@users.noreply.github.com>
95 lines
2.3 KiB
Vue
95 lines
2.3 KiB
Vue
<template>
|
|
<Dropdown :value="fontWeightValue" fixed-items @input="emit($event)">
|
|
<DropdownItem
|
|
v-for="fontWeight in fontWeights"
|
|
:key="fontWeight.type"
|
|
:value="fontWeight.type"
|
|
:name="fontWeight.name"
|
|
/>
|
|
</Dropdown>
|
|
</template>
|
|
|
|
<script>
|
|
import { FONT_WEIGHTS } from '@baserow/modules/builder/fontWeights'
|
|
|
|
export default {
|
|
name: 'FontWeightSelector',
|
|
props: {
|
|
value: {
|
|
type: String,
|
|
default: undefined,
|
|
},
|
|
modelValue: {
|
|
type: String,
|
|
default: undefined,
|
|
},
|
|
font: {
|
|
type: String,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
},
|
|
emits: ['input', 'update:modelValue'],
|
|
computed: {
|
|
currentValue() {
|
|
return this.modelValue !== undefined
|
|
? this.modelValue
|
|
: this.value || 'Regular'
|
|
},
|
|
supportedWeights() {
|
|
return this.font ? this.fontFamilyType.weights : ['regular']
|
|
},
|
|
fontFamilyType() {
|
|
return this.$registry.get('fontFamily', this.font)
|
|
},
|
|
fontWeights() {
|
|
return Object.entries(FONT_WEIGHTS)
|
|
.map(([fontType, weight]) => {
|
|
return {
|
|
type: fontType,
|
|
name: this.getFontLabel(fontType),
|
|
weight,
|
|
}
|
|
})
|
|
.filter((fontWeight) => this.supportedWeights.includes(fontWeight.type))
|
|
.sort((a, b) => a.weight - b.weight)
|
|
},
|
|
fontWeightValue: {
|
|
get() {
|
|
return this.currentValue
|
|
},
|
|
set(newValue) {
|
|
this.emit(newValue)
|
|
},
|
|
},
|
|
},
|
|
|
|
watch: {
|
|
/**
|
|
* Check if the updated font supports the currently selected weight. If not,
|
|
* set the font weight to 'regular', which should be supported by all fonts.
|
|
*/
|
|
font() {
|
|
if (!this.supportedWeights.includes(this.currentValue)) {
|
|
this.fontWeightValue = this.fontFamilyType.defaultWeight
|
|
}
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
getFontLabel(fontType) {
|
|
// Convert kebab cased font type, e.g. 'extra-light' to
|
|
// its camel case equivalent, e.g. 'extraLight'
|
|
const fontTypeKebab = fontType.replace(/-([a-z])/g, (_, char) =>
|
|
char.toUpperCase()
|
|
)
|
|
return this.$t(`fontWeightType.${fontTypeKebab}`)
|
|
},
|
|
emit(newValue) {
|
|
this.$emit('input', newValue)
|
|
this.$emit('update:modelValue', newValue)
|
|
},
|
|
},
|
|
}
|
|
</script>
|