Vue-tabs-with-active-line
Simple Vue 2 component, that allows you to make tabs with moving bottom line
Demo and example
Live demo to play with: Demo-link
Code from the demo: Default-example Disabled-example
Install
via NPM
npm install vue-tabs-with-active-line --save
Usage
Import the component
;
Define the data for props tabs
, currentTab
, and method for onClick
callback
components: Tabs tabs: title: 'Tab 1' value: 'tab1' title: 'Tab 2' value: 'tab2' title: 'Tab 3' value: 'tab3' currentTab: 'tab1' methods: { thiscurrentTab = newTab; } </script>
here's the HTML structure generated from the data entered:
Tab 1 <!-- active tab --> Tab 2 Tab 3
Finally, add some styles for component elements:
.tabs
- component wrapper.tabs__item
- button.tabs__item_active
- active button.tabs__active-line
- bottom line
Be sure to add position: relative;
for .tabs
class
and position: absolute;
with bottom, left, height, background-color
properties for .tabs__active-line
class
Below you'll find basic style in CSS and SCSS
CSS EXAMPLE
SCSS Example
.tabs
Props
props | type | required | description |
---|---|---|---|
tabs | Array |
true |
description |
currentTab | String |
true |
Active tab value |
onClick | Function |
true |
Returns new tab value when clicked |
updated | Boolean/String/Array |
false |
Props for custom update active line |
wrapperClass | String |
false |
Custom class for container |
tabClass | String |
false |
Custom class for tab item |
tabActiveClass | String |
false |
Custom class for active tab item |
lineClass | String |
false |
Custom class for active line |
tabs
type: Array
, required: true
The array must contain objects with the following properties:
-
title
- required, typestring
. Title of tab -
value
- required, typestring
. Value of tab -
disabled
- optional, typeboolean
. Disabled attribute
How to run it locally
- Clone repository:
git clone git@github.com:karambafe/vue-tabs-with-active-line.git
- Install cli-service-global:
npm install -g @vue/cli-service-global
Vue CLI 3 docs - Run any vue file with hot reload and static server:
vue serve demo-src/App.vue
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
This project is licensed under the MIT license, Copyright (c) 2018 karambafe. For more information see LICENSE
.