lkt-tabs 1.0.7

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.
@@ -0,0 +1,144 @@
1
+ import { defineComponent as H, ref as g, computed as i, watch as $, openBlock as l, createElementBlock as r, unref as u, renderSlot as h, createCommentVNode as P, getCurrentInstance as q, normalizeClass as C, withDirectives as F, createElementVNode as y, Fragment as _, renderList as b, withModifiers as V, vShow as M, normalizeStyle as x, createBlock as z, withCtx as D } from "vue";
2
+ import { generateRandomString as E, isString as K, getSlots as S } from "lkt-tools";
3
+ import { getSessionStorage as U, setSessionStorage as R } from "lkt-session";
4
+ const B = (a) => `lkt-tabs.${window.location.host}${window.location.pathname}.${a}`, Y = (a) => U(B(a)), G = (a, c, e) => {
5
+ R(B(a), c, e * 60);
6
+ }, J = ["id"], Q = {
7
+ name: "LktTab",
8
+ inheritAttrs: !1,
9
+ customOptions: {}
10
+ }, A = /* @__PURE__ */ H({
11
+ ...Q,
12
+ props: {
13
+ id: { type: String, default: "" },
14
+ name: { type: String, required: !0 },
15
+ hash: { type: String, default: "" },
16
+ activeHash: { type: String, default: "" },
17
+ isDisabled: { type: Boolean, default: !1 }
18
+ },
19
+ emits: ["is-active"],
20
+ setup(a, { emit: c }) {
21
+ const e = a, n = g(!1), o = g(E(8)), m = i(() => e.id ? e.id : K(e.name) && e.name.length > 0 ? e.name.toLowerCase().replace(/ /g, "-") : o.value), p = () => {
22
+ n.value = e.activeHash === e.hash, c("is-active", n.value);
23
+ };
24
+ return $(() => e.activeHash, p), p(), (d, T) => n.value ? (l(), r("section", {
25
+ key: 0,
26
+ "data-lkt": "tab-content",
27
+ id: u(m),
28
+ role: "tabpanel"
29
+ }, [
30
+ h(d.$slots, "default")
31
+ ], 8, J)) : P("", !0);
32
+ }
33
+ }), W = { class: "lkt-tabs__list" }, X = ["href", "onClick"], Z = ["innerHTML", "onClick", "href"], tt = { "data-lkt": "tab" }, et = {
34
+ name: "LktTabs",
35
+ inheritAttrs: !1,
36
+ customOptions: {},
37
+ components: { LktTab: A }
38
+ }, st = /* @__PURE__ */ H({
39
+ ...et,
40
+ props: {
41
+ id: { type: String, default: "" },
42
+ modelValue: { type: [String, Number], default: "" },
43
+ useSession: { type: Boolean, default: !1 },
44
+ cacheLifetime: { type: Number, default: 5 },
45
+ contentPad: { type: String, default: void 0 },
46
+ palette: { type: String, default: void 0 },
47
+ titles: {
48
+ type: Object,
49
+ default() {
50
+ return {};
51
+ }
52
+ }
53
+ },
54
+ emits: ["update:modelValue"],
55
+ setup(a, { emit: c }) {
56
+ const e = a, { ctx: n } = q(), o = g("");
57
+ if (e.useSession) {
58
+ n.id || console.warn("[LKT Tabs] You're trying to use session provided tabs without the required id. Please, add id attr");
59
+ let t = Y(n.id);
60
+ t && (o.value = t);
61
+ }
62
+ $(() => e.modelValue, (t, f) => {
63
+ typeof t == "string" && (o.value = t);
64
+ }), $(o, (t, f) => {
65
+ c("update:modelValue"), n.$nextTick(() => {
66
+ n.$forceUpdate();
67
+ }), e.useSession && G(n.id, t, e.cacheLifetime);
68
+ });
69
+ const m = i(() => {
70
+ let t = [];
71
+ return e.palette && t.push(`lkt-tabs--${e.palette}`), t.join(" ");
72
+ }), p = i(() => {
73
+ let t = [];
74
+ return e.contentPad && t.push(`padding: ${e.contentPad}`), t.join(";");
75
+ }), d = i(() => S(n.$slots, "tab-")), T = i(() => S(n.$slots, "title-")), I = i(() => S(n.$slots, "li-")), v = i(() => {
76
+ let t = {};
77
+ for (let f in n.$refs)
78
+ t[f] = n.$refs[f].hash;
79
+ return t;
80
+ }), j = i(() => Object.keys(d.value).length > 1), k = (t = "") => v.value.length > 0 && v.value[t] ? "#" + v.value[t] : "#", w = (t = "") => e.titles && e.titles[t] ? e.titles[t] : t, N = () => {
81
+ n.$forceUpdate();
82
+ };
83
+ for (let t in d.value)
84
+ o.value === "" && (o.value = t);
85
+ return (t, f) => (l(), r("div", {
86
+ class: C(["lkt-tabs", u(m)])
87
+ }, [
88
+ F(y("ul", W, [
89
+ (l(!0), r(_, null, b(u(d), (L, s) => (l(), r("li", {
90
+ key: s,
91
+ class: C(["lkt-tab", { "is-active": s === o.value }]),
92
+ role: "presentation"
93
+ }, [
94
+ u(T)[s] ? (l(), r("a", {
95
+ key: 0,
96
+ href: k(s),
97
+ onClick: V((O) => o.value = s, ["prevent"]),
98
+ role: "tab"
99
+ }, [
100
+ h(t.$slots, "title-" + s)
101
+ ], 8, X)) : (l(), r("a", {
102
+ key: 1,
103
+ innerHTML: w(s),
104
+ onClick: V((O) => o.value = s, ["prevent"]),
105
+ href: k(s),
106
+ role: "tab"
107
+ }, null, 8, Z))
108
+ ], 2))), 128)),
109
+ (l(!0), r(_, null, b(u(I), (L, s) => (l(), r("li", tt, [
110
+ h(t.$slots, "li-" + s)
111
+ ]))), 256))
112
+ ], 512), [
113
+ [M, u(j)]
114
+ ]),
115
+ y("div", {
116
+ class: "lkt-tabs__content",
117
+ style: x(u(p))
118
+ }, [
119
+ (l(!0), r(_, null, b(u(d), (L, s) => (l(), z(A, {
120
+ ref_for: !0,
121
+ ref: s,
122
+ hash: s,
123
+ id: s,
124
+ name: w(s),
125
+ "active-hash": o.value,
126
+ onIsActive: N
127
+ }, {
128
+ default: D(() => [
129
+ h(t.$slots, "tab-" + s)
130
+ ]),
131
+ _: 2
132
+ }, 1032, ["hash", "id", "name", "active-hash"]))), 256))
133
+ ], 4)
134
+ ], 2));
135
+ }
136
+ });
137
+ const lt = {
138
+ install: (a, c) => {
139
+ a.component("lkt-tabs", st);
140
+ }
141
+ };
142
+ export {
143
+ lt as default
144
+ };
@@ -0,0 +1 @@
1
+ (function(t,a){typeof exports=="object"&&typeof module<"u"?module.exports=a(require("vue"),require("lkt-tools"),require("lkt-session")):typeof define=="function"&&define.amd?define(["vue","lkt-tools","lkt-session"],a):(t=typeof globalThis<"u"?globalThis:t||self,t.LktTabs=a(t.Vue,t.LktTools,t.LktSession))})(this,function(t,a,u){"use strict";const h=r=>`lkt-tabs.${window.location.host}${window.location.pathname}.${r}`,B=r=>u.getSessionStorage(h(r)),$=(r,i,n)=>{u.setSessionStorage(h(r),i,n*60)},L=["id"],T={name:"LktTab",inheritAttrs:!1,customOptions:{}},S=t.defineComponent({...T,props:{id:{type:String,default:""},name:{type:String,required:!0},hash:{type:String,default:""},activeHash:{type:String,default:""},isDisabled:{type:Boolean,default:!1}},emits:["is-active"],setup(r,{emit:i}){const n=r,o=t.ref(!1),l=t.ref(a.generateRandomString(8)),p=t.computed(()=>n.id?n.id:a.isString(n.name)&&n.name.length>0?n.name.toLowerCase().replace(/ /g,"-"):l.value),f=()=>{o.value=n.activeHash===n.hash,i("is-active",o.value)};return t.watch(()=>n.activeHash,f),f(),(c,k)=>o.value?(t.openBlock(),t.createElementBlock("section",{key:0,"data-lkt":"tab-content",id:t.unref(p),role:"tabpanel"},[t.renderSlot(c.$slots,"default")],8,L)):t.createCommentVNode("",!0)}}),w={class:"lkt-tabs__list"},C=["href","onClick"],y=["innerHTML","onClick","href"],E={"data-lkt":"tab"},V={name:"LktTabs",inheritAttrs:!1,customOptions:{},components:{LktTab:S}},H=t.defineComponent({...V,props:{id:{type:String,default:""},modelValue:{type:[String,Number],default:""},useSession:{type:Boolean,default:!1},cacheLifetime:{type:Number,default:5},contentPad:{type:String,default:void 0},palette:{type:String,default:void 0},titles:{type:Object,default(){return{}}}},emits:["update:modelValue"],setup(r,{emit:i}){const n=r,{ctx:o}=t.getCurrentInstance(),l=t.ref("");if(n.useSession){o.id||console.warn("[LKT Tabs] You're trying to use session provided tabs without the required id. Please, add id attr");let e=B(o.id);e&&(l.value=e)}t.watch(()=>n.modelValue,(e,d)=>{typeof e=="string"&&(l.value=e)}),t.watch(l,(e,d)=>{i("update:modelValue"),o.$nextTick(()=>{o.$forceUpdate()}),n.useSession&&$(o.id,e,n.cacheLifetime)});const p=t.computed(()=>{let e=[];return n.palette&&e.push(`lkt-tabs--${n.palette}`),e.join(" ")}),f=t.computed(()=>{let e=[];return n.contentPad&&e.push(`padding: ${n.contentPad}`),e.join(";")}),c=t.computed(()=>a.getSlots(o.$slots,"tab-")),k=t.computed(()=>a.getSlots(o.$slots,"title-")),q=t.computed(()=>a.getSlots(o.$slots,"li-")),m=t.computed(()=>{let e={};for(let d in o.$refs)e[d]=o.$refs[d].hash;return e}),j=t.computed(()=>Object.keys(c.value).length>1),_=(e="")=>m.value.length>0&&m.value[e]?"#"+m.value[e]:"#",b=(e="")=>n.titles&&n.titles[e]?n.titles[e]:e,A=()=>{o.$forceUpdate()};for(let e in c.value)l.value===""&&(l.value=e);return(e,d)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["lkt-tabs",t.unref(p)])},[t.withDirectives(t.createElementVNode("ul",w,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(c),(g,s)=>(t.openBlock(),t.createElementBlock("li",{key:s,class:t.normalizeClass(["lkt-tab",{"is-active":s===l.value}]),role:"presentation"},[t.unref(k)[s]?(t.openBlock(),t.createElementBlock("a",{key:0,href:_(s),onClick:t.withModifiers(F=>l.value=s,["prevent"]),role:"tab"},[t.renderSlot(e.$slots,"title-"+s)],8,C)):(t.openBlock(),t.createElementBlock("a",{key:1,innerHTML:b(s),onClick:t.withModifiers(F=>l.value=s,["prevent"]),href:_(s),role:"tab"},null,8,y))],2))),128)),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(q),(g,s)=>(t.openBlock(),t.createElementBlock("li",E,[t.renderSlot(e.$slots,"li-"+s)]))),256))],512),[[t.vShow,t.unref(j)]]),t.createElementVNode("div",{class:"lkt-tabs__content",style:t.normalizeStyle(t.unref(f))},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(c),(g,s)=>(t.openBlock(),t.createBlock(S,{ref_for:!0,ref:s,hash:s,id:s,name:b(s),"active-hash":l.value,onIsActive:A},{default:t.withCtx(()=>[t.renderSlot(e.$slots,"tab-"+s)]),_:2},1032,["hash","id","name","active-hash"]))),256))],4)],2))}}),I="";return{install:(r,i)=>{r.component("lkt-tabs",H)}}});
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .lkt-tabs{max-width:100%}.lkt-tabs__list{gap:var(--lkt-tab-gap);border-bottom:var(--lkt-tab-border-width) var(--lkt-tab-border-style) var(--lkt-tab-border-color);padding:var(--lkt-tab-padding);display:flex;overflow-x:auto}.lkt-tab{background:var(--lkt-tab-bg);color:var(--lkt-tab-color);border:var(--lkt-tab-border-width) var(--lkt-tab-border-style) var(--lkt-tab-border-color);border-radius:var(--lkt-tab-border-radius);font-size:var(--lkt-tab-font-size);line-height:var(--lkt-tab-line-height);transition:var(--lkt-tab-transition);display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.lkt-tab.is-active{background:var(--lkt-tab-bg-active);color:var(--lkt-tab-color-active)}.lkt-tab:hover{background:var(--lkt-tab-bg-hover);color:var(--lkt-tab-color-hover)}.lkt-tab a{color:inherit;padding:var(--lkt-tab-padding)}.lkt-tabs--target .lkt-tab{color:var(--target-color);background:var(--target-contrast);border-color:var(--target-color)}.lkt-tabs--target .lkt-tab.is-active{color:var(--target-color);background:var(--target-contrast)}.lkt-tabs--alert .lkt-tab{color:var(--alert-color);background:var(--alert-contrast);border-color:var(--alert-color)}.lkt-tabs--alert .lkt-tab.is-active{color:var(--alert-color);background:var(--alert-contrast)}.lkt-tabs--danger .lkt-tab{color:var(--danger-color);background:var(--danger-contrast);border-color:var(--danger-color)}.lkt-tabs--danger .lkt-tab.is-active{color:var(--danger-color);background:var(--danger-contrast)}.lkt-tabs--success .lkt-tab{color:var(--success-color);background:var(--success-contrast);border-color:var(--success-color)}.lkt-tabs--success .lkt-tab.is-active{color:var(--success-color);background:var(--success-contrast)}.lkt-tabs--info .lkt-tab{color:var(--info-color);background:var(--info-contrast);border-color:var(--info-color)}.lkt-tabs--info .lkt-tab.is-active{color:var(--info-color);background:var(--info-contrast)}.lkt-tabs--warning .lkt-tab{color:var(--warning-color);background:var(--warning-contrast);border-color:var(--warning-color)}.lkt-tabs--warning .lkt-tab.is-active{color:var(--warning-color);background:var(--warning-contrast)}
@@ -0,0 +1,155 @@
1
+ declare const _default: {
2
+ new (...args: any[]): {
3
+ $: import("vue").ComponentInternalInstance;
4
+ $data: {};
5
+ $props: Partial<{
6
+ id: string;
7
+ hash: string;
8
+ activeHash: string;
9
+ isDisabled: boolean;
10
+ }> & Omit<Readonly<import("vue").ExtractPropTypes<{
11
+ id: {
12
+ type: StringConstructor;
13
+ default: string;
14
+ };
15
+ name: {
16
+ type: StringConstructor;
17
+ required: true;
18
+ };
19
+ hash: {
20
+ type: StringConstructor;
21
+ default: string;
22
+ };
23
+ activeHash: {
24
+ type: StringConstructor;
25
+ default: string;
26
+ };
27
+ isDisabled: {
28
+ type: BooleanConstructor;
29
+ default: boolean;
30
+ };
31
+ }>> & {
32
+ "onIs-active"?: ((...args: any[]) => any) | undefined;
33
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "id" | "hash" | "activeHash" | "isDisabled">;
34
+ $attrs: {
35
+ [x: string]: unknown;
36
+ };
37
+ $refs: {
38
+ [x: string]: unknown;
39
+ };
40
+ $slots: Readonly<{
41
+ [name: string]: import("vue").Slot | undefined;
42
+ }>;
43
+ $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
44
+ $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
45
+ $emit: (event: "is-active", ...args: any[]) => void;
46
+ $el: any;
47
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
48
+ id: {
49
+ type: StringConstructor;
50
+ default: string;
51
+ };
52
+ name: {
53
+ type: StringConstructor;
54
+ required: true;
55
+ };
56
+ hash: {
57
+ type: StringConstructor;
58
+ default: string;
59
+ };
60
+ activeHash: {
61
+ type: StringConstructor;
62
+ default: string;
63
+ };
64
+ isDisabled: {
65
+ type: BooleanConstructor;
66
+ default: boolean;
67
+ };
68
+ }>> & {
69
+ "onIs-active"?: ((...args: any[]) => any) | undefined;
70
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "is-active"[], string, {
71
+ id: string;
72
+ hash: string;
73
+ activeHash: string;
74
+ isDisabled: boolean;
75
+ }> & {
76
+ beforeCreate?: ((() => void) | (() => void)[]) | undefined;
77
+ created?: ((() => void) | (() => void)[]) | undefined;
78
+ beforeMount?: ((() => void) | (() => void)[]) | undefined;
79
+ mounted?: ((() => void) | (() => void)[]) | undefined;
80
+ beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
81
+ updated?: ((() => void) | (() => void)[]) | undefined;
82
+ activated?: ((() => void) | (() => void)[]) | undefined;
83
+ deactivated?: ((() => void) | (() => void)[]) | undefined;
84
+ beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
85
+ beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
86
+ destroyed?: ((() => void) | (() => void)[]) | undefined;
87
+ unmounted?: ((() => void) | (() => void)[]) | undefined;
88
+ renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
89
+ renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
90
+ errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void)[]) | undefined;
91
+ };
92
+ $forceUpdate: () => void;
93
+ $nextTick: typeof import("vue").nextTick;
94
+ $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
95
+ } & Readonly<import("vue").ExtractPropTypes<{
96
+ id: {
97
+ type: StringConstructor;
98
+ default: string;
99
+ };
100
+ name: {
101
+ type: StringConstructor;
102
+ required: true;
103
+ };
104
+ hash: {
105
+ type: StringConstructor;
106
+ default: string;
107
+ };
108
+ activeHash: {
109
+ type: StringConstructor;
110
+ default: string;
111
+ };
112
+ isDisabled: {
113
+ type: BooleanConstructor;
114
+ default: boolean;
115
+ };
116
+ }>> & {
117
+ "onIs-active"?: ((...args: any[]) => any) | undefined;
118
+ } & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
119
+ __isFragment?: undefined;
120
+ __isTeleport?: undefined;
121
+ __isSuspense?: undefined;
122
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
123
+ id: {
124
+ type: StringConstructor;
125
+ default: string;
126
+ };
127
+ name: {
128
+ type: StringConstructor;
129
+ required: true;
130
+ };
131
+ hash: {
132
+ type: StringConstructor;
133
+ default: string;
134
+ };
135
+ activeHash: {
136
+ type: StringConstructor;
137
+ default: string;
138
+ };
139
+ isDisabled: {
140
+ type: BooleanConstructor;
141
+ default: boolean;
142
+ };
143
+ }>> & {
144
+ "onIs-active"?: ((...args: any[]) => any) | undefined;
145
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "is-active"[], "is-active", {
146
+ id: string;
147
+ hash: string;
148
+ activeHash: string;
149
+ isDisabled: boolean;
150
+ }> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
151
+ $slots: {
152
+ default: (_: {}) => any;
153
+ };
154
+ });
155
+ export default _default;
@@ -0,0 +1 @@
1
+ declare const SESSION_STORAGE_KEY = "lkt-tabs.cache";
@@ -0,0 +1,2 @@
1
+ export declare const loadSelectedTabFromSession: (uniqueId: string) => any;
2
+ export declare const setSelectedTabFromSession: (uniqueId: string, value: string, lifeTime: number) => void;
@@ -0,0 +1,6 @@
1
+ import { App } from "vue";
2
+ import "../style.css";
3
+ declare const LktTabs: {
4
+ install: (app: App, options: any) => void;
5
+ };
6
+ export default LktTabs;
@@ -0,0 +1,194 @@
1
+ declare const _default: {
2
+ new (...args: any[]): {
3
+ $: import("vue").ComponentInternalInstance;
4
+ $data: {};
5
+ $props: Partial<{
6
+ id: string;
7
+ modelValue: string | number;
8
+ useSession: boolean;
9
+ cacheLifetime: number;
10
+ contentPad: string;
11
+ palette: string;
12
+ titles: Record<string, any>;
13
+ }> & Omit<Readonly<import("vue").ExtractPropTypes<{
14
+ id: {
15
+ type: StringConstructor;
16
+ default: string;
17
+ };
18
+ modelValue: {
19
+ type: (StringConstructor | NumberConstructor)[];
20
+ default: string;
21
+ };
22
+ useSession: {
23
+ type: BooleanConstructor;
24
+ default: boolean;
25
+ };
26
+ cacheLifetime: {
27
+ type: NumberConstructor;
28
+ default: number;
29
+ };
30
+ contentPad: {
31
+ type: StringConstructor;
32
+ default: undefined;
33
+ };
34
+ palette: {
35
+ type: StringConstructor;
36
+ default: undefined;
37
+ };
38
+ titles: {
39
+ type: ObjectConstructor;
40
+ default(): {};
41
+ };
42
+ }>> & {
43
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
44
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "id" | "modelValue" | "useSession" | "cacheLifetime" | "contentPad" | "palette" | "titles">;
45
+ $attrs: {
46
+ [x: string]: unknown;
47
+ };
48
+ $refs: {
49
+ [x: string]: unknown;
50
+ };
51
+ $slots: Readonly<{
52
+ [name: string]: import("vue").Slot | undefined;
53
+ }>;
54
+ $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
55
+ $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
56
+ $emit: (event: "update:modelValue", ...args: any[]) => void;
57
+ $el: any;
58
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
59
+ id: {
60
+ type: StringConstructor;
61
+ default: string;
62
+ };
63
+ modelValue: {
64
+ type: (StringConstructor | NumberConstructor)[];
65
+ default: string;
66
+ };
67
+ useSession: {
68
+ type: BooleanConstructor;
69
+ default: boolean;
70
+ };
71
+ cacheLifetime: {
72
+ type: NumberConstructor;
73
+ default: number;
74
+ };
75
+ contentPad: {
76
+ type: StringConstructor;
77
+ default: undefined;
78
+ };
79
+ palette: {
80
+ type: StringConstructor;
81
+ default: undefined;
82
+ };
83
+ titles: {
84
+ type: ObjectConstructor;
85
+ default(): {};
86
+ };
87
+ }>> & {
88
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
89
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], string, {
90
+ id: string;
91
+ modelValue: string | number;
92
+ useSession: boolean;
93
+ cacheLifetime: number;
94
+ contentPad: string;
95
+ palette: string;
96
+ titles: Record<string, any>;
97
+ }> & {
98
+ beforeCreate?: ((() => void) | (() => void)[]) | undefined;
99
+ created?: ((() => void) | (() => void)[]) | undefined;
100
+ beforeMount?: ((() => void) | (() => void)[]) | undefined;
101
+ mounted?: ((() => void) | (() => void)[]) | undefined;
102
+ beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
103
+ updated?: ((() => void) | (() => void)[]) | undefined;
104
+ activated?: ((() => void) | (() => void)[]) | undefined;
105
+ deactivated?: ((() => void) | (() => void)[]) | undefined;
106
+ beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
107
+ beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
108
+ destroyed?: ((() => void) | (() => void)[]) | undefined;
109
+ unmounted?: ((() => void) | (() => void)[]) | undefined;
110
+ renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
111
+ renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
112
+ errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void)[]) | undefined;
113
+ };
114
+ $forceUpdate: () => void;
115
+ $nextTick: typeof import("vue").nextTick;
116
+ $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
117
+ } & Readonly<import("vue").ExtractPropTypes<{
118
+ id: {
119
+ type: StringConstructor;
120
+ default: string;
121
+ };
122
+ modelValue: {
123
+ type: (StringConstructor | NumberConstructor)[];
124
+ default: string;
125
+ };
126
+ useSession: {
127
+ type: BooleanConstructor;
128
+ default: boolean;
129
+ };
130
+ cacheLifetime: {
131
+ type: NumberConstructor;
132
+ default: number;
133
+ };
134
+ contentPad: {
135
+ type: StringConstructor;
136
+ default: undefined;
137
+ };
138
+ palette: {
139
+ type: StringConstructor;
140
+ default: undefined;
141
+ };
142
+ titles: {
143
+ type: ObjectConstructor;
144
+ default(): {};
145
+ };
146
+ }>> & {
147
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
148
+ } & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
149
+ __isFragment?: undefined;
150
+ __isTeleport?: undefined;
151
+ __isSuspense?: undefined;
152
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
153
+ id: {
154
+ type: StringConstructor;
155
+ default: string;
156
+ };
157
+ modelValue: {
158
+ type: (StringConstructor | NumberConstructor)[];
159
+ default: string;
160
+ };
161
+ useSession: {
162
+ type: BooleanConstructor;
163
+ default: boolean;
164
+ };
165
+ cacheLifetime: {
166
+ type: NumberConstructor;
167
+ default: number;
168
+ };
169
+ contentPad: {
170
+ type: StringConstructor;
171
+ default: undefined;
172
+ };
173
+ palette: {
174
+ type: StringConstructor;
175
+ default: undefined;
176
+ };
177
+ titles: {
178
+ type: ObjectConstructor;
179
+ default(): {};
180
+ };
181
+ }>> & {
182
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
183
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", {
184
+ id: string;
185
+ modelValue: string | number;
186
+ useSession: boolean;
187
+ cacheLifetime: number;
188
+ contentPad: string;
189
+ palette: string;
190
+ titles: Record<string, any>;
191
+ }> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
192
+ $slots: Record<string, {}> & Record<string, {}> & Record<string, {}>;
193
+ });
194
+ export default _default;
@@ -0,0 +1,38 @@
1
+ declare namespace _default {
2
+ const plugins: import("vite").Plugin[];
3
+ namespace resolve {
4
+ const alias: {
5
+ '@': string;
6
+ '@test': string;
7
+ };
8
+ }
9
+ namespace build {
10
+ export namespace lib {
11
+ const entry: string;
12
+ const name: string;
13
+ function fileName(format: any): string;
14
+ }
15
+ export { outDir };
16
+ export const minify: boolean;
17
+ export namespace rollupOptions {
18
+ const external: string[];
19
+ namespace output {
20
+ const globals: {
21
+ vue: string;
22
+ "lkt-tools": string;
23
+ "lkt-events": string;
24
+ "lkt-session": string;
25
+ };
26
+ const sourcemapExcludeSources: boolean;
27
+ }
28
+ }
29
+ }
30
+ namespace test {
31
+ namespace coverage {
32
+ const reporter: string[];
33
+ }
34
+ function resolveSnapshotPath(testPath: any, snapExtension: any): string;
35
+ }
36
+ }
37
+ export default _default;
38
+ declare const outDir: string;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "lkt-tabs",
3
+ "version": "1.0.7",
4
+ "description": "",
5
+ "main": "src/index.ts",
6
+ "module": "src/index.ts",
7
+ "files": [
8
+ "dist/*",
9
+ "src/**/*.vue",
10
+ "theme/**/*.css"
11
+ ],
12
+ "sideEffects": false,
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/lkt-tabs.es.js",
16
+ "require": "./dist/lkt-tabs.umd.js"
17
+ },
18
+ "./dist/style.css": "./dist/style.css",
19
+ "./theme": "./theme/default.css",
20
+ "./theme/default": "./theme/default.css"
21
+ },
22
+ "types": "./dist/types/index.d.ts",
23
+ "scripts": {
24
+ "serve": "vite",
25
+ "build": "vite build && vue-tsc --emitDeclarationOnly --project tsconfig.json && mv dist/src dist/types && rm dist/README.md.d.ts && rm dist/vite.config.d.ts",
26
+ "build2": "vite build",
27
+ "preview": "vite preview",
28
+ "test": "vitest",
29
+ "test-coverage": "vitest run --coverage"
30
+ },
31
+ "author": "Antonio Ibáñez",
32
+ "devDependencies": {
33
+ "@babel/types": "^7.18.9",
34
+ "@types/node": "^18.0.6",
35
+ "@vitejs/plugin-vue": "^3.0.1",
36
+ "vue-tsc": "^0.38.9"
37
+ },
38
+ "dependencies": {
39
+ "lkt-events": "^1.0.4",
40
+ "lkt-session": "^1.0.6",
41
+ "lkt-tools": "^1.0.10",
42
+ "vue": "^3.0.5"
43
+ },
44
+ "engines": {
45
+ "node": ">=12"
46
+ }
47
+ }
@@ -0,0 +1,55 @@
1
+ <script lang="ts">
2
+ export default {
3
+ name: "LktTab",
4
+ inheritAttrs: false,
5
+ customOptions: {},
6
+ };
7
+ </script>
8
+
9
+ <script lang="ts" setup>
10
+ import {computed, ref, watch} from "vue";
11
+ import {generateRandomString, isString} from "lkt-tools";
12
+
13
+ const props = defineProps({
14
+ id: {type: String, default: ''},
15
+ name: {type: String, required: true},
16
+ hash: {type: String, default: ''},
17
+ activeHash: {type: String, default: ''},
18
+ isDisabled: {type: Boolean, default: false},
19
+ });
20
+
21
+ const emit = defineEmits(['is-active']);
22
+
23
+ const isActive = ref(false),
24
+ uniqueId = ref(generateRandomString(8));
25
+
26
+
27
+ const computedId = computed(() => {
28
+ if (props.id) return props.id;
29
+ if (isString(props.name) && props.name.length > 0) {
30
+ return props.name.toLowerCase().replace(/ /g, '-');
31
+ }
32
+ return uniqueId.value;
33
+ })
34
+
35
+ const checkIsActive = () => {
36
+ isActive.value = props.activeHash === props.hash;
37
+ emit('is-active', isActive.value);
38
+ }
39
+
40
+ watch(() => props.activeHash, checkIsActive);
41
+
42
+ checkIsActive();
43
+
44
+ </script>
45
+
46
+ <template>
47
+ <section
48
+ data-lkt="tab-content"
49
+ v-if="isActive"
50
+ v-bind:id="computedId"
51
+ role="tabpanel"
52
+ >
53
+ <slot/>
54
+ </section>
55
+ </template>
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import {default as tabs} from "./lib-components/LktTabs.vue";
3
+ import {App} from "vue";
4
+ import "../style.css";
5
+
6
+ const LktTabs = {
7
+ install: (app: App, options: any) => {
8
+ app.component('lkt-tabs', tabs);
9
+ },
10
+ };
11
+
12
+ export default LktTabs;
@@ -0,0 +1,166 @@
1
+ <script lang="ts">
2
+ import LktTab from "../components/LktTab.vue";
3
+
4
+ export default {
5
+ name: 'LktTabs',
6
+ inheritAttrs: false,
7
+ customOptions: {},
8
+ components: {LktTab}
9
+ };
10
+ </script>
11
+
12
+ <script lang="ts" setup>
13
+ import {computed, getCurrentInstance, ref, watch} from 'vue';
14
+ import {getSlots, ILktObject} from "lkt-tools";
15
+ import {loadSelectedTabFromSession, setSelectedTabFromSession} from "../functions/functions";
16
+
17
+ const {ctx: _this}: any = getCurrentInstance();
18
+
19
+ const props = defineProps({
20
+ id: {type: String, default: ''},
21
+ modelValue: {type: [String, Number], default: ''},
22
+ useSession: {type: Boolean, default: false},
23
+ cacheLifetime: {type: Number, default: 5,},
24
+ contentPad: {type: String, default: undefined,},
25
+ palette: {type: String, default: undefined,},
26
+ titles: {
27
+ type: Object,
28
+ default() {
29
+ return {};
30
+ }
31
+ },
32
+ });
33
+
34
+ const emit = defineEmits(['update:modelValue'])
35
+
36
+ const Value = ref('');
37
+
38
+ if (props.useSession) {
39
+ if (!_this.id) {
40
+ console.warn('[LKT Tabs] You\'re trying to use session provided tabs without the required id. Please, add id attr');
41
+ }
42
+
43
+ let sessionVal = loadSelectedTabFromSession(_this.id);
44
+ if (sessionVal) Value.value = sessionVal;
45
+ }
46
+
47
+ watch(() => props.modelValue, (newVal, oldVal) => {
48
+ if (typeof newVal === "string") {
49
+ Value.value = newVal;
50
+ }
51
+ })
52
+
53
+ watch(Value, (newVal, oldVal) => {
54
+ emit('update:modelValue');
55
+ _this.$nextTick(() => {
56
+ _this.$forceUpdate()
57
+ });
58
+ if (props.useSession) {
59
+ setSelectedTabFromSession(_this.id, newVal, props.cacheLifetime);
60
+ }
61
+ })
62
+
63
+ const classes = computed(() => {
64
+ let r = [];
65
+ if (!!props.palette) r.push(`lkt-tabs--${props.palette}`);
66
+ return r.join(' ');
67
+ });
68
+
69
+ const contentStyles = computed(() => {
70
+ let r = [];
71
+ if (!!props.contentPad) r.push(`padding: ${props.contentPad}`);
72
+ return r.join(';');
73
+ });
74
+
75
+ const tabsSlots = computed(() => {
76
+ return getSlots(_this.$slots, 'tab-');
77
+ });
78
+
79
+ const titlesSlots = computed(() => {
80
+ return getSlots(_this.$slots, 'title-');
81
+ });
82
+
83
+ const liSlots = computed(() => {
84
+ return getSlots(_this.$slots, 'li-');
85
+ });
86
+
87
+ const tabsHref = computed(() => {
88
+ let r: ILktObject = {};
89
+ for (let k in _this.$refs) {
90
+ r[k] = _this.$refs[k].hash;
91
+ }
92
+
93
+ return r;
94
+ });
95
+
96
+ const displayButtons = computed(() => {
97
+ return Object.keys(tabsSlots.value).length > 1;
98
+ });
99
+
100
+ const getTabHref = (key: string = '') => {
101
+ if (tabsHref.value.length > 0 && tabsHref.value[key]) {
102
+ return '#' + tabsHref.value[key];
103
+ }
104
+ return '#';
105
+ }
106
+
107
+ const getTabTitle = (key: string = '') => {
108
+ if (props.titles && props.titles[key]) return props.titles[key];
109
+ return key;
110
+ }
111
+
112
+ const refresh = () => {
113
+ _this.$forceUpdate();
114
+ }
115
+
116
+ for (let k in tabsSlots.value) {
117
+ if (Value.value === '') Value.value = k;
118
+ }
119
+ </script>
120
+
121
+
122
+ <template>
123
+ <div class="lkt-tabs" v-bind:class="classes">
124
+ <ul class="lkt-tabs__list" v-show="displayButtons">
125
+ <li
126
+ v-for="(_, key) in tabsSlots"
127
+ v-bind:key="key"
128
+ class="lkt-tab"
129
+ v-bind:class="{'is-active': key === Value}"
130
+ role="presentation"
131
+ >
132
+ <template v-if="!!titlesSlots[key]">
133
+ <a v-bind:href="getTabHref(key)"
134
+ v-on:click.prevent="Value = key"
135
+ role="tab"
136
+ >
137
+ <slot v-bind:name="'title-' + key"></slot>
138
+ </a>
139
+ </template>
140
+ <template v-else>
141
+ <a v-html="getTabTitle(key)"
142
+ v-on:click.prevent="Value = key"
143
+ v-bind:href="getTabHref(key)"
144
+ role="tab"
145
+ ></a>
146
+ </template>
147
+ </li>
148
+ <li v-for="(_, key) in liSlots" data-lkt="tab">
149
+ <slot v-bind:name="'li-' + key"></slot>
150
+ </li>
151
+ </ul>
152
+ <div class="lkt-tabs__content" v-bind:style="contentStyles">
153
+ <lkt-tab
154
+ v-for="(_, key) in tabsSlots"
155
+ v-bind:ref="key"
156
+ v-bind:hash="key"
157
+ v-bind:id="key"
158
+ v-bind:name="getTabTitle(key)"
159
+ v-bind:active-hash="Value"
160
+ v-on:is-active="refresh"
161
+ >
162
+ <slot v-bind:name="'tab-' + key"></slot>
163
+ </lkt-tab>
164
+ </div>
165
+ </div>
166
+ </template>
@@ -0,0 +1,36 @@
1
+ :root {
2
+ /** Font */
3
+ --lkt-tab-font-family: system-ui, Helvetica;
4
+ --lkt-tab-font-size: 16px;
5
+ --lkt-tab-font-weight: 300;
6
+ --lkt-tab-line-height: 1.425;
7
+ --lkt-tab-text-align: left;
8
+
9
+ /** Sizing */
10
+ --lkt-tab-min-width: 100%;
11
+ --lkt-tab-min-height: 35px;
12
+ --lkt-tab-padding: 7px 15px;
13
+ --lkt-tab-gap: 15px;
14
+
15
+ /** Border */
16
+ --lkt-tab-border-radius: 5px;
17
+ --lkt-tab-border-width: 1px;
18
+ --lkt-tab-border-style: solid;
19
+
20
+ /** Colors */
21
+ --lkt-tab-color: #444444;
22
+ --lkt-tab-bg: #e1e1e1;
23
+ --lkt-tab-border-color: #ddd;
24
+
25
+ /** Effects */
26
+ --lkt-tab-shadow: none;
27
+ --lkt-tab-transition: all linear 100ms;
28
+
29
+ /** State: Active */
30
+ --lkt-tab-bg-active: #444444;
31
+ --lkt-tab-color-active: #e1e1e1;
32
+
33
+ /** State: Hover */
34
+ --lkt-tab-bg-hover: #444444;
35
+ --lkt-tab-color-hover: #e1e1e1;
36
+ }