@phoenix-cg/v-tabs 0.2.0-beta.0 → 0.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/favicon.ico +0 -0
- package/dist/v-tabs.css +1 -0
- package/dist/v-tabs.es.js +123 -0
- package/dist/v-tabs.umd.js +1 -0
- package/package.json +3 -2
- package/src/export.js +3 -0
- package/vite.config.js +8 -0
- package/export.js +0 -3
package/dist/favicon.ico
ADDED
|
Binary file
|
package/dist/v-tabs.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.v-tabs{position:relative}.v-tabs_inner{display:flex}.v-tabs_tab{padding:10px 20px;background:#ddd;cursor:pointer;-webkit-user-select:none;user-select:none}.v-tabs_tab.__active{background:#b6b5b5}.v-tabs.__disabled{pointer-events:none;opacity:.5}.v-tabs_slider{position:absolute;height:2px;background:#000;left:0;bottom:0;transition:all .2s ease-in-out}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { mergeModels as y, useModel as V, ref as C, useTemplateRef as v, onMounted as x, onBeforeUnmount as z, watch as E, createElementBlock as n, openBlock as s, normalizeClass as b, createElementVNode as L, createCommentVNode as N, Fragment as h, renderList as $, renderSlot as M, toDisplayString as k, createTextVNode as F, normalizeStyle as O, nextTick as q } from "vue";
|
|
2
|
+
const A = { class: "v-tabs_inner" }, D = ["data-id", "onClick"], P = {
|
|
3
|
+
key: 0,
|
|
4
|
+
class: "v-tabs_tab_title"
|
|
5
|
+
}, X = {
|
|
6
|
+
__name: "VTabs",
|
|
7
|
+
props: /* @__PURE__ */ y({
|
|
8
|
+
direction: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: "horizontal"
|
|
11
|
+
},
|
|
12
|
+
trackBy: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: "_id"
|
|
15
|
+
},
|
|
16
|
+
label: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: "title"
|
|
19
|
+
},
|
|
20
|
+
list: {
|
|
21
|
+
type: Array,
|
|
22
|
+
required: !0
|
|
23
|
+
},
|
|
24
|
+
selectFirst: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: !0
|
|
27
|
+
},
|
|
28
|
+
withSlider: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: !1
|
|
31
|
+
},
|
|
32
|
+
initialTab: {
|
|
33
|
+
type: [Number, String],
|
|
34
|
+
default: null
|
|
35
|
+
},
|
|
36
|
+
wrapTitle: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: !1
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
modelValue: {},
|
|
42
|
+
modelModifiers: {}
|
|
43
|
+
}),
|
|
44
|
+
emits: /* @__PURE__ */ y(["update:modelValue"], ["update:modelValue"]),
|
|
45
|
+
setup(a, { emit: S }) {
|
|
46
|
+
const e = a, r = V(a, "modelValue"), g = S, f = C({});
|
|
47
|
+
let i = null;
|
|
48
|
+
const B = v("tabs"), c = v("elRef");
|
|
49
|
+
function w() {
|
|
50
|
+
e.withSlider && (i = new ResizeObserver(() => {
|
|
51
|
+
u();
|
|
52
|
+
}), B.value.forEach((t) => {
|
|
53
|
+
i.observe(t);
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
function T() {
|
|
57
|
+
i == null || i.disconnect(), i = null;
|
|
58
|
+
}
|
|
59
|
+
function d(t) {
|
|
60
|
+
g("update:modelValue", t), u();
|
|
61
|
+
}
|
|
62
|
+
async function u() {
|
|
63
|
+
if (!e.withSlider || !c.value)
|
|
64
|
+
return;
|
|
65
|
+
const t = c.value;
|
|
66
|
+
await q();
|
|
67
|
+
const { left: o } = t.getBoundingClientRect(), [l] = t.getElementsByClassName("__active");
|
|
68
|
+
if (l) {
|
|
69
|
+
const {
|
|
70
|
+
left: m,
|
|
71
|
+
width: _
|
|
72
|
+
} = l.getBoundingClientRect(), R = t.scrollLeft, p = m + R - o;
|
|
73
|
+
f.value = {
|
|
74
|
+
transform: `translateX(${p}px)`,
|
|
75
|
+
width: `${_}px`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return x(() => {
|
|
80
|
+
if (e.selectFirst && e.list.length && !r.value && d(e.list[0]), e.initialTab && e.list.length && !r.value) {
|
|
81
|
+
const t = e.list.find((o) => o[e.trackBy] === e.initialTab);
|
|
82
|
+
t && d(t);
|
|
83
|
+
}
|
|
84
|
+
w();
|
|
85
|
+
}), z(() => {
|
|
86
|
+
T();
|
|
87
|
+
}), E(r, () => {
|
|
88
|
+
e.withSlider && u();
|
|
89
|
+
}), (t, o) => (s(), n("div", {
|
|
90
|
+
class: b(["v-tabs", [`__${e.direction}`]]),
|
|
91
|
+
ref_key: "elRef",
|
|
92
|
+
ref: c
|
|
93
|
+
}, [
|
|
94
|
+
L("div", A, [
|
|
95
|
+
(s(!0), n(h, null, $(e.list, (l) => (s(), n("div", {
|
|
96
|
+
key: l[a.trackBy],
|
|
97
|
+
ref_for: !0,
|
|
98
|
+
ref: "tabs",
|
|
99
|
+
class: b(["v-tabs_tab", {
|
|
100
|
+
__active: r.value && r.value[a.trackBy] === l[a.trackBy],
|
|
101
|
+
_disabled: l && l._disabled
|
|
102
|
+
}]),
|
|
103
|
+
"data-id": l[a.trackBy],
|
|
104
|
+
onClick: (m) => d(l)
|
|
105
|
+
}, [
|
|
106
|
+
M(t.$slots, "single-tab", { tab: l }, () => [
|
|
107
|
+
a.wrapTitle ? (s(), n("div", P, k(l[a.label] || ""), 1)) : (s(), n(h, { key: 1 }, [
|
|
108
|
+
F(k(l[a.label] || ""), 1)
|
|
109
|
+
], 64))
|
|
110
|
+
])
|
|
111
|
+
], 10, D))), 128))
|
|
112
|
+
]),
|
|
113
|
+
e.withSlider ? (s(), n("div", {
|
|
114
|
+
key: 0,
|
|
115
|
+
style: O(f.value),
|
|
116
|
+
class: "v-tabs_slider"
|
|
117
|
+
}, null, 4)) : N("", !0)
|
|
118
|
+
], 2));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
X as default
|
|
123
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,s){typeof exports=="object"&&typeof module<"u"?module.exports=s(require("vue")):typeof define=="function"&&define.amd?define(["vue"],s):(e=typeof globalThis<"u"?globalThis:e||self,e.VTabs=s(e.Vue))})(this,function(e){"use strict";const s={class:"v-tabs_inner"},y=["data-id","onClick"],k={key:0,class:"v-tabs_tab_title"};return{__name:"VTabs",props:e.mergeModels({direction:{type:String,default:"horizontal"},trackBy:{type:String,default:"_id"},label:{type:String,default:"title"},list:{type:Array,required:!0},selectFirst:{type:Boolean,default:!0},withSlider:{type:Boolean,default:!1},initialTab:{type:[Number,String],default:null},wrapTitle:{type:Boolean,default:!1}},{modelValue:{},modelModifiers:{}}),emits:e.mergeModels(["update:modelValue"],["update:modelValue"]),setup(i,{emit:B}){const t=i,o=e.useModel(i,"modelValue"),b=B,m=e.ref({});let a=null;const h=e.useTemplateRef("tabs"),c=e.useTemplateRef("elRef");function p(){t.withSlider&&(a=new ResizeObserver(()=>{f()}),h.value.forEach(l=>{a.observe(l)}))}function g(){a==null||a.disconnect(),a=null}function d(l){b("update:modelValue",l),f()}async function f(){if(!t.withSlider||!c.value)return;const l=c.value;await e.nextTick();const{left:r}=l.getBoundingClientRect(),[n]=l.getElementsByClassName("__active");if(n){const{left:u,width:S}=n.getBoundingClientRect(),T=l.scrollLeft,_=u+T-r;m.value={transform:`translateX(${_}px)`,width:`${S}px`}}}return e.onMounted(()=>{if(t.selectFirst&&t.list.length&&!o.value&&d(t.list[0]),t.initialTab&&t.list.length&&!o.value){const l=t.list.find(r=>r[t.trackBy]===t.initialTab);l&&d(l)}p()}),e.onBeforeUnmount(()=>{g()}),e.watch(o,()=>{t.withSlider&&f()}),(l,r)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["v-tabs",[`__${t.direction}`]]),ref_key:"elRef",ref:c},[e.createElementVNode("div",s,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.list,n=>(e.openBlock(),e.createElementBlock("div",{key:n[i.trackBy],ref_for:!0,ref:"tabs",class:e.normalizeClass(["v-tabs_tab",{__active:o.value&&o.value[i.trackBy]===n[i.trackBy],_disabled:n&&n._disabled}]),"data-id":n[i.trackBy],onClick:u=>d(n)},[e.renderSlot(l.$slots,"single-tab",{tab:n},()=>[i.wrapTitle?(e.openBlock(),e.createElementBlock("div",k,e.toDisplayString(n[i.label]||""),1)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(e.toDisplayString(n[i.label]||""),1)],64))])],10,y))),128))]),t.withSlider?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(m.value),class:"v-tabs_slider"},null,4)):e.createCommentVNode("",!0)],2))}}});
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phoenix-cg/v-tabs",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"module": "./dist/v-tabs.es.js",
|
|
7
|
+
"browser": "dist/v-tabs.umd.js",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"dev": "vite",
|
|
9
10
|
"build": "vite build",
|
package/src/export.js
ADDED
package/vite.config.js
CHANGED
|
@@ -11,6 +11,14 @@ export default defineConfig({
|
|
|
11
11
|
entry: path.resolve(__dirname, 'src/export.js'),
|
|
12
12
|
name: 'VTabs',
|
|
13
13
|
fileName: (format) => `v-tabs.${format}.js`
|
|
14
|
+
},
|
|
15
|
+
rollupOptions: {
|
|
16
|
+
external: ['vue'],
|
|
17
|
+
output: {
|
|
18
|
+
globals: {
|
|
19
|
+
vue: 'Vue',
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
}
|
|
15
23
|
},
|
|
16
24
|
plugins: [
|
package/export.js
DELETED