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