UNPKG

2.8 kBJavaScriptView Raw
1/*!
2 * vue-slim-tabs v0.4.0
3 * (c) egoist <0x142857@gmail.com>
4 * Released under the MIT License.
5 */
6(function (global, factory) {
7 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
8 typeof define === 'function' && define.amd ? define(['exports'], factory) :
9 (global = global || self, factory(global.VueSlimTabs = {}));
10}(this, function (exports) { 'use strict';
11
12 var Tabs = {
13 name: "tabs",
14 props: {
15 defaultIndex: {
16 default: 0,
17 type: Number
18 },
19 onSelect: {
20 type: Function
21 }
22 },
23 data: function data() {
24 return {
25 selectedIndex: this.defaultIndex
26 };
27 },
28 methods: {
29 switchTab: function switchTab(e, index, isDisabled) {
30 if (!isDisabled) {
31 this.selectedIndex = index;
32 this.onSelect && this.onSelect(e, index);
33 }
34 }
35 },
36 render: function render() {
37 var _this = this;
38
39 var h = arguments[0];
40 var tabs = this.$slots.default.filter(function (component) {
41 return component.componentOptions;
42 });
43 var tabList = [];
44 tabs.forEach(function (child, index) {
45 var _child$componentOptio = child.componentOptions.propsData,
46 title = _child$componentOptio.title,
47 titleSlot = _child$componentOptio.titleSlot,
48 disabled = _child$componentOptio.disabled;
49 var content = titleSlot ? _this.$slots[titleSlot] : title;
50 var isDisabled = disabled === true || disabled === "";
51 tabList.push(h("li", {
52 "class": "vue-tab",
53 attrs: {
54 role: "tab",
55 "aria-selected": _this.selectedIndex === index ? "true" : "false",
56 "aria-disabled": isDisabled ? "true" : "false"
57 },
58 on: {
59 "click": function click(e) {
60 return _this.switchTab(e, index, isDisabled);
61 }
62 }
63 }, [content]));
64 });
65 return h("div", {
66 "class": "vue-tabs",
67 attrs: {
68 role: "tabs"
69 }
70 }, [h("ul", {
71 "class": "vue-tablist",
72 attrs: {
73 role: "tablist"
74 }
75 }, [this.$slots.left, tabList, this.$slots.right]), tabs[this.selectedIndex]]);
76 }
77 };
78 var Tab = {
79 name: "tab",
80 props: ["title", "titleSlot", "disabled"],
81 render: function render() {
82 var h = arguments[0];
83 return h("div", {
84 "class": "vue-tabpanel",
85 attrs: {
86 role: "tabpanel"
87 }
88 }, [this.$slots.default]);
89 }
90 };
91 function install(Vue) {
92 Vue.component(Tabs.name, Tabs);
93 Vue.component(Tab.name, Tab);
94 }
95
96 exports.Tab = Tab;
97 exports.Tabs = Tabs;
98 exports.install = install;
99
100 Object.defineProperty(exports, '__esModule', { value: true });
101
102}));