Created
February 8, 2020 18:02
-
-
Save selimdoyranli/d0512096ccbbb12090891dad102738dc to your computer and use it in GitHub Desktop.
Atomic heading component with h tag size validation. (Vue.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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