Skip to content

Instantly share code, notes, and snippets.

@selimdoyranli
Created February 8, 2020 18:02
Show Gist options
  • Save selimdoyranli/d0512096ccbbb12090891dad102738dc to your computer and use it in GitHub Desktop.
Save selimdoyranli/d0512096ccbbb12090891dad102738dc to your computer and use it in GitHub Desktop.
Atomic heading component with h tag size validation. (Vue.js)
<template>
<component class="a-heading" :is="`h${headingLevel}`" :style="{'font-weight': weight}">{{text}}</component>
</template>
<script>
export default {
name: 'a_Heading',
props: {
level: {
type: Number,
required: true
},
text: {
type: String,
required: true
},
weight: {
type: String,
required: false,
default: 'normal'
}
},
computed: {
headingLevel() {
let headingLevel = null
if (this.level < 1) {
headingLevel = 1
} else if (this.level > 6) {
headingLevel = 6
} else {
headingLevel = this.level
}
return headingLevel
}
}
}
</script>
<style lang="scss" scoped>
.a-heading {
position: relative;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment