@v-c/collapse 0.0.3 → 0.0.5
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/Collapse.cjs +1 -1
- package/dist/Collapse.js +48 -57
- package/dist/Panel.cjs +1 -1
- package/dist/Panel.js +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/interface.d.ts +0 -2
- package/package.json +4 -1
- package/assets/index.less +0 -117
- package/assets/motion.less +0 -14
- package/docs/collapse.stories.vue +0 -45
- package/docs/custom-icon.vue +0 -185
- package/docs/simple.vue +0 -218
- package/src/Collapse.tsx +0 -110
- package/src/Panel.tsx +0 -178
- package/src/PanelContent.tsx +0 -63
- package/src/hooks/useItems.tsx +0 -202
- package/src/index.ts +0 -8
- package/src/interface.ts +0 -75
- package/tests/__snapshots__/index.test.tsx.snap +0 -3
- package/tests/index.test.tsx +0 -954
- package/tsconfig.json +0 -7
- package/vite.config.ts +0 -18
- package/vitest.config.ts +0 -11
package/dist/Collapse.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue"),b=require("@v-c/util"),S=require("@v-c/util/dist/hooks/useMergedState"),x=require("@v-c/util/dist/omit"),N=require("@v-c/util/dist/pickAttrs"),O=require("./hooks/useItems.cjs");function h(r){let t=r;if(!Array.isArray(t)){const a=typeof t;t=a==="number"||a==="string"?[t]:[]}return t.map(a=>String(a))}const I={prefixCls:"vc-collapse"},M=i.defineComponent({props:i.mergeDefaults({prefixCls:{type:String,required:!1},activeKey:{type:[String,Number,Array],required:!1},defaultActiveKey:{type:[String,Number,Array],required:!1},openMotion:{type:null,required:!1},onChange:{type:Function,required:!1},accordion:{type:Boolean,required:!1},destroyOnHidden:{type:Boolean,required:!1},expandIcon:{type:Function,required:!1},collapsible:{type:String,required:!1},items:{type:Array,required:!1},classNames:{type:Object,required:!1},styles:{type:Object,required:!1}},I),name:"VcCollapse",inheritAttrs:!1,setup(r,{attrs:t,expose:a,slots:d}){const l=i.ref(),[s,f]=S([],{value:i.toRef(r,"activeKey"),onChange:e=>r.onChange?.(e),defaultValue:r.defaultActiveKey,postState:h}),y=e=>r.accordion?s.value[0]===e?[]:[e]:s.value.indexOf(e)>-1?s.value.filter(n=>n!==e):[...s.value,e],p=e=>{s.value=y(e),f(s.value)};return a({ref:l}),()=>{const{prefixCls:e="vc-collapse",openMotion:c,expandIcon:o,collapsible:n,accordion:u,classNames:v,styles:m,items:g,destroyOnHidden:q}=r,A=b.classNames(e,t.class),C={...r,...x(t,["class","style"])},K=O.useItems(g,d.default,{prefixCls:e,accordion:u,openMotion:c,expandIcon:o,collapsible:n,onItemClick:p,activeKey:s.value,destroyOnHidden:q,classNames:v,styles:m});return i.createVNode("div",i.mergeProps({ref:l,class:A,style:t.style,role:u?"tablist":void 0},N(C,{aria:!0,data:!0})),[K])}}});exports.default=M;
|
package/dist/Collapse.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { classNames as
|
|
3
|
-
import
|
|
1
|
+
import { defineComponent as K, mergeDefaults as x, ref as N, toRef as b, createVNode as S, mergeProps as h } from "vue";
|
|
2
|
+
import { classNames as O } from "@v-c/util";
|
|
3
|
+
import I from "@v-c/util/dist/hooks/useMergedState";
|
|
4
|
+
import M from "@v-c/util/dist/omit";
|
|
4
5
|
import V from "@v-c/util/dist/pickAttrs";
|
|
5
|
-
import { useItems as
|
|
6
|
-
function
|
|
7
|
-
let
|
|
8
|
-
if (!Array.isArray(
|
|
9
|
-
const
|
|
10
|
-
|
|
6
|
+
import { useItems as j } from "./hooks/useItems.js";
|
|
7
|
+
function B(r) {
|
|
8
|
+
let t = r;
|
|
9
|
+
if (!Array.isArray(t)) {
|
|
10
|
+
const a = typeof t;
|
|
11
|
+
t = a === "number" || a === "string" ? [t] : [];
|
|
11
12
|
}
|
|
12
|
-
return
|
|
13
|
+
return t.map((a) => String(a));
|
|
13
14
|
}
|
|
14
|
-
const
|
|
15
|
+
const F = {
|
|
15
16
|
prefixCls: "vc-collapse"
|
|
16
|
-
}, $ = /* @__PURE__ */
|
|
17
|
+
}, $ = /* @__PURE__ */ K({
|
|
17
18
|
props: /* @__PURE__ */ x({
|
|
18
19
|
prefixCls: {
|
|
19
20
|
type: String,
|
|
@@ -39,14 +40,6 @@ const H = {
|
|
|
39
40
|
type: Boolean,
|
|
40
41
|
required: !1
|
|
41
42
|
},
|
|
42
|
-
className: {
|
|
43
|
-
type: String,
|
|
44
|
-
required: !1
|
|
45
|
-
},
|
|
46
|
-
style: {
|
|
47
|
-
type: Object,
|
|
48
|
-
required: !1
|
|
49
|
-
},
|
|
50
43
|
destroyOnHidden: {
|
|
51
44
|
type: Boolean,
|
|
52
45
|
required: !1
|
|
@@ -71,61 +64,59 @@ const H = {
|
|
|
71
64
|
type: Object,
|
|
72
65
|
required: !1
|
|
73
66
|
}
|
|
74
|
-
},
|
|
67
|
+
}, F),
|
|
75
68
|
name: "VcCollapse",
|
|
76
69
|
inheritAttrs: !1,
|
|
77
|
-
setup(
|
|
78
|
-
attrs:
|
|
79
|
-
expose:
|
|
70
|
+
setup(r, {
|
|
71
|
+
attrs: t,
|
|
72
|
+
expose: a,
|
|
80
73
|
slots: u
|
|
81
74
|
}) {
|
|
82
|
-
const l =
|
|
83
|
-
value:
|
|
84
|
-
onChange: (e) =>
|
|
85
|
-
defaultValue:
|
|
86
|
-
postState:
|
|
87
|
-
}),
|
|
88
|
-
|
|
75
|
+
const l = N(), [s, f] = I([], {
|
|
76
|
+
value: b(r, "activeKey"),
|
|
77
|
+
onChange: (e) => r.onChange?.(e),
|
|
78
|
+
defaultValue: r.defaultActiveKey,
|
|
79
|
+
postState: B
|
|
80
|
+
}), d = (e) => r.accordion ? s.value[0] === e ? [] : [e] : s.value.indexOf(e) > -1 ? s.value.filter((i) => i !== e) : [...s.value, e], p = (e) => {
|
|
81
|
+
s.value = d(e), f(s.value);
|
|
89
82
|
};
|
|
90
|
-
return
|
|
83
|
+
return a({
|
|
91
84
|
ref: l
|
|
92
85
|
}), () => {
|
|
93
86
|
const {
|
|
94
87
|
prefixCls: e = "vc-collapse",
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
expandIcon: y,
|
|
99
|
-
collapsible: m,
|
|
88
|
+
openMotion: n,
|
|
89
|
+
expandIcon: o,
|
|
90
|
+
collapsible: i,
|
|
100
91
|
accordion: c,
|
|
101
|
-
classNames:
|
|
102
|
-
styles:
|
|
103
|
-
items:
|
|
104
|
-
destroyOnHidden:
|
|
105
|
-
} =
|
|
106
|
-
...
|
|
107
|
-
...
|
|
108
|
-
},
|
|
92
|
+
classNames: y,
|
|
93
|
+
styles: m,
|
|
94
|
+
items: v,
|
|
95
|
+
destroyOnHidden: g
|
|
96
|
+
} = r, A = O(e, t.class), q = {
|
|
97
|
+
...r,
|
|
98
|
+
...M(t, ["class", "style"])
|
|
99
|
+
}, C = j(v, u.default, {
|
|
109
100
|
prefixCls: e,
|
|
110
101
|
accordion: c,
|
|
111
|
-
openMotion:
|
|
112
|
-
expandIcon:
|
|
113
|
-
collapsible:
|
|
102
|
+
openMotion: n,
|
|
103
|
+
expandIcon: o,
|
|
104
|
+
collapsible: i,
|
|
114
105
|
onItemClick: p,
|
|
115
|
-
activeKey:
|
|
116
|
-
destroyOnHidden:
|
|
117
|
-
classNames:
|
|
118
|
-
styles:
|
|
106
|
+
activeKey: s.value,
|
|
107
|
+
destroyOnHidden: g,
|
|
108
|
+
classNames: y,
|
|
109
|
+
styles: m
|
|
119
110
|
});
|
|
120
|
-
return
|
|
111
|
+
return S("div", h({
|
|
121
112
|
ref: l,
|
|
122
|
-
class:
|
|
123
|
-
style:
|
|
113
|
+
class: A,
|
|
114
|
+
style: t.style,
|
|
124
115
|
role: c ? "tablist" : void 0
|
|
125
|
-
}, V(
|
|
116
|
+
}, V(q, {
|
|
126
117
|
aria: !0,
|
|
127
118
|
data: !0
|
|
128
|
-
})), [
|
|
119
|
+
})), [C]);
|
|
129
120
|
};
|
|
130
121
|
}
|
|
131
122
|
});
|
package/dist/Panel.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),o=require("@v-c/util"),y=require("@v-c/util/dist/KeyCode"),O=require("@v-c/util/dist/omit"),R=require("./PanelContent.cjs"),B={showArrow:!0,classNames:{},styles:{}},j=e.defineComponent({props:e.mergeDefaults({id:{type:String,required:!1},header:{type:null,required:!1},prefixCls:{type:String,required:!1},headerClass:{type:String,required:!1},showArrow:{type:Boolean,required:!1},class:{type:String,required:!1},classNames:{type:Object,required:!1},style:{type:Object,required:!1},styles:{type:Object,required:!1},isActive:{type:Boolean,required:!1},openMotion:{type:null,required:!1},destroyOnHidden:{type:Boolean,required:!1},accordion:{type:Boolean,required:!1},forceRender:{type:Boolean,required:!1},extra:{type:null,required:!1},onItemClick:{type:Function,required:!1},expandIcon:{type:Function,required:!1},panelKey:{type:[String,Number],required:!1},role:{type:String,required:!1},collapsible:{type:String,required:!1},children:{type:null,required:!1}},B),name:"CollapsePanel",inheritAttrs:!1,setup(a,{attrs:m,expose:q}){const d=e.computed(()=>a.collapsible==="disabled"),u=e.ref(),N=e.computed(()=>a.extra!==null&&a.extra!==void 0&&typeof a.extra!="boolean"),c=e.computed(()=>({onClick:()=>{a.onItemClick?.(a.panelKey)},onKeydown:
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),o=require("@v-c/util"),y=require("@v-c/util/dist/KeyCode"),O=require("@v-c/util/dist/omit"),R=require("./PanelContent.cjs"),B={showArrow:!0,classNames:{},styles:{}},j=e.defineComponent({props:e.mergeDefaults({id:{type:String,required:!1},header:{type:null,required:!1},prefixCls:{type:String,required:!1},headerClass:{type:String,required:!1},showArrow:{type:Boolean,required:!1},class:{type:String,required:!1},classNames:{type:Object,required:!1},style:{type:Object,required:!1},styles:{type:Object,required:!1},isActive:{type:Boolean,required:!1},openMotion:{type:null,required:!1},destroyOnHidden:{type:Boolean,required:!1},accordion:{type:Boolean,required:!1},forceRender:{type:Boolean,required:!1},extra:{type:null,required:!1},onItemClick:{type:Function,required:!1},expandIcon:{type:Function,required:!1},panelKey:{type:[String,Number],required:!1},role:{type:String,required:!1},collapsible:{type:String,required:!1},children:{type:null,required:!1}},B),name:"CollapsePanel",inheritAttrs:!1,setup(a,{attrs:m,expose:q}){const d=e.computed(()=>a.collapsible==="disabled"),u=e.ref(),N=e.computed(()=>a.extra!==null&&a.extra!==void 0&&typeof a.extra!="boolean"),c=e.computed(()=>({onClick:()=>{a.onItemClick?.(a.panelKey)},onKeydown:r=>{(r.key==="Enter"||r.keyCode===y.ENTER||r.which===y.ENTER)&&a.onItemClick?.(a.panelKey)},role:a.accordion?"tab":"button","aria-expanded":a.isActive,"aria-disabled":d.value,tabIndex:d.value?-1:0}));return q({ref:u}),()=>{const{extra:r,prefixCls:s,isActive:l,class:h,expandIcon:f,forceRender:v,headerClass:C,collapsible:t,accordion:b,openMotion:x={},onItemClick:M,classNames:n={},showArrow:g=!0,destroyOnHidden:P,styles:i={},header:w,panelKey:T,children:S,...$}=a,A=o.classNames(`${s}-item`,{[`${s}-item-active`]:l,[`${s}-item-disabled`]:d.value},h),I={class:o.classNames(C,`${s}-header`,{[`${s}-collapsible-${t}`]:!!t},n.header),style:i.header,...["header","icon"].includes(t)?{}:c.value},p=typeof f=="function"?f(a):e.createVNode("i",{class:"arrow"},null),V=p&&e.createVNode("div",e.mergeProps({class:o.classNames(`${s}-expand-icon`,n?.icon),style:i?.icon},["header","icon"].includes(t)?c.value:{}),[p]),k=e.withDirectives(e.createVNode(R.default,{prefixCls:s,classNames:n,styles:i,isActive:l,forceRender:v,role:b?"tabpanel":void 0},{default:()=>S}),[[e.vShow,l]]),E={appear:!1,...x},K={...$,...O(m,["class"])};return e.createVNode("div",e.mergeProps(K,{ref:u,class:A}),[e.createVNode("div",I,[g&&V,e.createVNode("span",e.mergeProps({class:o.classNames(`${s}-title`,n?.title),style:i?.title},t==="header"?c.value:{}),[w]),N.value&&e.createVNode("div",{class:`${s}-extra`},[r])]),e.createVNode(e.Transition,E,{default:()=>[!P||l?k:null]})])}}});exports.default=j;
|
package/dist/Panel.js
CHANGED
|
@@ -100,7 +100,7 @@ const W = {
|
|
|
100
100
|
attrs: q,
|
|
101
101
|
expose: C
|
|
102
102
|
}) {
|
|
103
|
-
const d = u(() => e.collapsible === "disabled"), p = D(),
|
|
103
|
+
const d = u(() => e.collapsible === "disabled"), p = D(), b = u(() => e.extra !== null && e.extra !== void 0 && typeof e.extra != "boolean"), c = u(() => ({
|
|
104
104
|
onClick: () => {
|
|
105
105
|
e.onItemClick?.(e.panelKey);
|
|
106
106
|
},
|
|
@@ -119,7 +119,7 @@ const W = {
|
|
|
119
119
|
extra: s,
|
|
120
120
|
prefixCls: a,
|
|
121
121
|
isActive: t,
|
|
122
|
-
class:
|
|
122
|
+
class: v,
|
|
123
123
|
expandIcon: y,
|
|
124
124
|
forceRender: x,
|
|
125
125
|
headerClass: N,
|
|
@@ -138,7 +138,7 @@ const W = {
|
|
|
138
138
|
} = e, k = o(`${a}-item`, {
|
|
139
139
|
[`${a}-item-active`]: t,
|
|
140
140
|
[`${a}-item-disabled`]: d.value
|
|
141
|
-
},
|
|
141
|
+
}, v), E = {
|
|
142
142
|
class: o(N, `${a}-header`, {
|
|
143
143
|
[`${a}-collapsible-${r}`]: !!r
|
|
144
144
|
}, n.header),
|
|
@@ -160,7 +160,7 @@ const W = {
|
|
|
160
160
|
default: () => I
|
|
161
161
|
}), [[H, t]]), B = {
|
|
162
162
|
appear: !1,
|
|
163
|
-
|
|
163
|
+
// leaveToClass: `${prefixCls}-panel-hidden`,
|
|
164
164
|
...g
|
|
165
165
|
}, O = {
|
|
166
166
|
...S,
|
|
@@ -172,7 +172,7 @@ const W = {
|
|
|
172
172
|
}), [l("div", E, [P && K, l("span", f({
|
|
173
173
|
class: o(`${a}-title`, n?.title),
|
|
174
174
|
style: i?.title
|
|
175
|
-
}, r === "header" ? c.value : {}), [A]),
|
|
175
|
+
}, r === "header" ? c.value : {}), [A]), b.value && l("div", {
|
|
176
176
|
class: `${a}-extra`
|
|
177
177
|
}, [s])]), l(M, B, {
|
|
178
178
|
default: () => [!$ || t ? R : null]
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as Collapse } from './Collapse';
|
|
2
2
|
import { default as Panel } from './Panel';
|
|
3
|
-
export type { CollapsePanelProps, CollapseProps } from './interface';
|
|
3
|
+
export type { CollapsePanelProps, CollapseProps, ItemType } from './interface';
|
|
4
4
|
export default Collapse;
|
|
5
5
|
export { Panel };
|
package/dist/interface.d.ts
CHANGED
|
@@ -37,8 +37,6 @@ export interface CollapseProps {
|
|
|
37
37
|
openMotion?: TransitionProps;
|
|
38
38
|
onChange?: (key: Key[]) => void;
|
|
39
39
|
accordion?: boolean;
|
|
40
|
-
className?: string;
|
|
41
|
-
style?: object;
|
|
42
40
|
destroyOnHidden?: boolean;
|
|
43
41
|
expandIcon?: (props: object) => any;
|
|
44
42
|
collapsible?: CollapsibleType;
|
package/package.json
CHANGED
package/assets/index.less
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
@prefixCls: vc-collapse;
|
|
2
|
-
@text-color: #666;
|
|
3
|
-
@borderStyle: 1px solid #d9d9d9;
|
|
4
|
-
|
|
5
|
-
@import "./motion.less";
|
|
6
|
-
|
|
7
|
-
#arrow {
|
|
8
|
-
.common() {
|
|
9
|
-
width: 0;
|
|
10
|
-
height: 0;
|
|
11
|
-
font-size: 0;
|
|
12
|
-
line-height: 0;
|
|
13
|
-
}
|
|
14
|
-
.right(@w, @h, @color) {
|
|
15
|
-
border-top: @w solid transparent;
|
|
16
|
-
border-bottom: @w solid transparent;
|
|
17
|
-
border-left: @h solid @color;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.bottom(@w, @h, @color) {
|
|
21
|
-
border-left: @w solid transparent;
|
|
22
|
-
border-right: @w solid transparent;
|
|
23
|
-
border-top: @h solid @color;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.@{prefixCls} {
|
|
28
|
-
background-color: #f7f7f7;
|
|
29
|
-
border-radius: 3px;
|
|
30
|
-
border: @borderStyle;
|
|
31
|
-
|
|
32
|
-
// &-anim-active {
|
|
33
|
-
// transition: height 0.2s ease-out;
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
& > &-item {
|
|
37
|
-
border-top: @borderStyle;
|
|
38
|
-
&:first-child {
|
|
39
|
-
border-top: none;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
> .@{prefixCls}-header {
|
|
43
|
-
display: flex;
|
|
44
|
-
align-items: center;
|
|
45
|
-
line-height: 22px;
|
|
46
|
-
padding: 10px 16px;
|
|
47
|
-
color: #666;
|
|
48
|
-
cursor: pointer;
|
|
49
|
-
.arrow {
|
|
50
|
-
display: inline-block;
|
|
51
|
-
content: "\20";
|
|
52
|
-
#arrow > .common();
|
|
53
|
-
#arrow > .right(3px, 4px, #666);
|
|
54
|
-
vertical-align: middle;
|
|
55
|
-
margin-right: 8px;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.@{prefixCls}-extra {
|
|
59
|
-
margin: 0 16px 0 auto;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
.@{prefixCls}-collapsible-header {
|
|
63
|
-
cursor: default;
|
|
64
|
-
.@{prefixCls}-title {
|
|
65
|
-
cursor: pointer;
|
|
66
|
-
}
|
|
67
|
-
.@{prefixCls}-expand-icon {
|
|
68
|
-
cursor: pointer;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
.@{prefixCls}-collapsible-icon {
|
|
72
|
-
cursor: default;
|
|
73
|
-
.@{prefixCls}-expand-icon {
|
|
74
|
-
cursor: pointer;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
& > &-item-disabled > .@{prefixCls}-header {
|
|
80
|
-
cursor: not-allowed;
|
|
81
|
-
color: #999;
|
|
82
|
-
background-color: #f3f3f3;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
&-panel {
|
|
86
|
-
overflow: hidden;
|
|
87
|
-
color: @text-color;
|
|
88
|
-
padding: 0 16px;
|
|
89
|
-
background-color: #fff;
|
|
90
|
-
|
|
91
|
-
& > &-box {
|
|
92
|
-
margin-top: 16px;
|
|
93
|
-
margin-bottom: 16px;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// &-inactive {
|
|
97
|
-
// display: none;
|
|
98
|
-
// }
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
&-item:last-child {
|
|
102
|
-
> .@{prefixCls}-panel {
|
|
103
|
-
border-radius: 0 0 3px 3px;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
& > &-item-active {
|
|
108
|
-
> .@{prefixCls}-header {
|
|
109
|
-
.arrow {
|
|
110
|
-
position: relative;
|
|
111
|
-
top: 2px;
|
|
112
|
-
#arrow > .bottom(3px, 4px, #666);
|
|
113
|
-
margin-right: 6px;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
package/assets/motion.less
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type { CollapseProps } from '../src/interface'
|
|
3
|
-
import { h } from 'vue'
|
|
4
|
-
import Collapse from '../src/index'
|
|
5
|
-
import CustomIcon from './custom-icon.vue'
|
|
6
|
-
import Simple from './simple.vue'
|
|
7
|
-
import '../assets/index.less'
|
|
8
|
-
|
|
9
|
-
const basicCollapseItems: CollapseProps['items'] = [
|
|
10
|
-
{
|
|
11
|
-
label: h('input', {
|
|
12
|
-
onKeydown: (e: KeyboardEvent) => {
|
|
13
|
-
e.stopPropagation()
|
|
14
|
-
},
|
|
15
|
-
}),
|
|
16
|
-
children: 'content',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
label: 'title 2',
|
|
20
|
-
children: 'content 2',
|
|
21
|
-
collapsible: 'disabled',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
label: 'title 3',
|
|
25
|
-
children: 'content 3',
|
|
26
|
-
onItemClick: console.log,
|
|
27
|
-
},
|
|
28
|
-
]
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
<template>
|
|
32
|
-
<Story title="Collapse">
|
|
33
|
-
<Variant title="Basic">
|
|
34
|
-
<Collapse :items="basicCollapseItems" />
|
|
35
|
-
</Variant>
|
|
36
|
-
|
|
37
|
-
<Variant title="custom icon">
|
|
38
|
-
<CustomIcon />
|
|
39
|
-
</Variant>
|
|
40
|
-
|
|
41
|
-
<Variant title="simple">
|
|
42
|
-
<Simple />
|
|
43
|
-
</Variant>
|
|
44
|
-
</Story>
|
|
45
|
-
</template>
|
package/docs/custom-icon.vue
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type { CollapseProps } from '../src/index'
|
|
3
|
-
import { h, ref, shallowRef, watch } from 'vue'
|
|
4
|
-
import Collapse from '../src/index'
|
|
5
|
-
|
|
6
|
-
const initLength = 3
|
|
7
|
-
|
|
8
|
-
const text = `
|
|
9
|
-
A dog is a type of domesticated animal.
|
|
10
|
-
Known for its loyalty and faithfulness,
|
|
11
|
-
it can be found as a welcome guest in many households across the world.
|
|
12
|
-
`
|
|
13
|
-
|
|
14
|
-
function random() {
|
|
15
|
-
return parseInt((Math.random() * 10).toString(), 10) + 1
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const arrowPath
|
|
19
|
-
= 'M869 487.8L491.2 159.9c-2.9-2.5-6.6-3.9-10.5-3.9h-88'
|
|
20
|
-
+ '.5c-7.4 0-10.8 9.2-5.2 14l350.2 304H152c-4.4 0-8 3.6-8 8v60c0 4.4 3.'
|
|
21
|
-
+ '6 8 8 8h585.1L386.9 854c-5.6 4.9-2.2 14 5.2 14h91.5c1.9 0 3.8-0.7 5.'
|
|
22
|
-
+ '2-2L869 536.2c14.7-12.8 14.7-35.6 0-48.4z'
|
|
23
|
-
|
|
24
|
-
function expandIcon({ isActive }: { isActive: boolean }) {
|
|
25
|
-
return h(
|
|
26
|
-
'i',
|
|
27
|
-
{
|
|
28
|
-
style: {
|
|
29
|
-
'margin-right': '.5rem',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
[
|
|
33
|
-
h(
|
|
34
|
-
'svg',
|
|
35
|
-
{
|
|
36
|
-
viewBox: '0 0 1024 1024',
|
|
37
|
-
width: '1em',
|
|
38
|
-
height: '1em',
|
|
39
|
-
fill: 'currentColor',
|
|
40
|
-
style: {
|
|
41
|
-
verticalAlign: '-.125em',
|
|
42
|
-
transition: 'transform .2s',
|
|
43
|
-
transform: `rotate(${isActive ? 90 : 0}deg)`,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
[
|
|
47
|
-
h('path', {
|
|
48
|
-
d: arrowPath,
|
|
49
|
-
}),
|
|
50
|
-
],
|
|
51
|
-
),
|
|
52
|
-
],
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const rerender = ref(0)
|
|
57
|
-
const accordion = ref(false)
|
|
58
|
-
const activeKey = ref<Array<string | number | bigint>>(['4'])
|
|
59
|
-
|
|
60
|
-
const time = ref(random())
|
|
61
|
-
watch(
|
|
62
|
-
() => [rerender.value, accordion.value, activeKey.value],
|
|
63
|
-
() => {
|
|
64
|
-
time.value = random()
|
|
65
|
-
},
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
function handleSetActiveKey(e: Array<string | number | bigint>) {
|
|
69
|
-
activeKey.value = e
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function getCollapsedHeight(el: HTMLDivElement) {
|
|
73
|
-
el.style.height = '0'
|
|
74
|
-
el.style.opacity = '0'
|
|
75
|
-
}
|
|
76
|
-
function getRealHeight(el: HTMLDivElement) {
|
|
77
|
-
console.log(el.scrollHeight)
|
|
78
|
-
el.style.height = `${el.scrollHeight}px`
|
|
79
|
-
el.style.opacity = '1'
|
|
80
|
-
}
|
|
81
|
-
function getCurrentHeight(el: HTMLDivElement) {
|
|
82
|
-
el.style.height = `${el.offsetHeight}px`
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function skipOpacityTransition(el: HTMLDivElement) {
|
|
86
|
-
el.style.height = ''
|
|
87
|
-
}
|
|
88
|
-
const openMotion = {
|
|
89
|
-
name: 'vc-collapse',
|
|
90
|
-
onBeforeEnter: getCollapsedHeight,
|
|
91
|
-
onEnter: getRealHeight,
|
|
92
|
-
onAfterEnter: skipOpacityTransition,
|
|
93
|
-
onBeforeLeave: getCurrentHeight,
|
|
94
|
-
onLeave: getCollapsedHeight,
|
|
95
|
-
onAfterLeave: skipOpacityTransition,
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const items = shallowRef<CollapseProps['items']>([])
|
|
99
|
-
function handleUpdateItems() {
|
|
100
|
-
items.value = Array.from({ length: initLength })
|
|
101
|
-
.map((_, i) => {
|
|
102
|
-
return {
|
|
103
|
-
label: `This is panel header ${i + 1}`,
|
|
104
|
-
key: i + 1,
|
|
105
|
-
children: h('p', {}, [text.repeat(time.value)]),
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
.concat([
|
|
109
|
-
{
|
|
110
|
-
label: `This is panel header ${initLength + 1}`,
|
|
111
|
-
key: initLength + 1,
|
|
112
|
-
children: h(Collapse, {
|
|
113
|
-
defaultActiveKey: '1',
|
|
114
|
-
expandIcon,
|
|
115
|
-
items: [
|
|
116
|
-
{
|
|
117
|
-
label: 'This is panel nest panel',
|
|
118
|
-
key: '1',
|
|
119
|
-
children: h('p', {}, [text]),
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
}),
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
label: `This is panel header ${initLength + 2}`,
|
|
126
|
-
key: initLength + 2,
|
|
127
|
-
children: h(Collapse, {
|
|
128
|
-
defaultActiveKey: '1',
|
|
129
|
-
items: [
|
|
130
|
-
{
|
|
131
|
-
label: 'This is panel nest panel',
|
|
132
|
-
children: h('form', {}, [
|
|
133
|
-
h(
|
|
134
|
-
'label',
|
|
135
|
-
{
|
|
136
|
-
htmlFor: 'test',
|
|
137
|
-
},
|
|
138
|
-
['Name: '],
|
|
139
|
-
),
|
|
140
|
-
h('input', {
|
|
141
|
-
type: 'text',
|
|
142
|
-
id: 'test',
|
|
143
|
-
}),
|
|
144
|
-
]),
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
}),
|
|
148
|
-
},
|
|
149
|
-
])
|
|
150
|
-
}
|
|
151
|
-
watch(
|
|
152
|
-
() => time.value,
|
|
153
|
-
() => {
|
|
154
|
-
handleUpdateItems()
|
|
155
|
-
},
|
|
156
|
-
{ immediate: true },
|
|
157
|
-
)
|
|
158
|
-
</script>
|
|
159
|
-
|
|
160
|
-
<template>
|
|
161
|
-
<button type="button" @click="rerender += 1">
|
|
162
|
-
reRender
|
|
163
|
-
</button>
|
|
164
|
-
<br>
|
|
165
|
-
<br>
|
|
166
|
-
<button type="button" @click="accordion = !accordion">
|
|
167
|
-
{{ accordion ? "Mode: accordion" : "Mode: collapse" }}
|
|
168
|
-
</button>
|
|
169
|
-
<br>
|
|
170
|
-
<br>
|
|
171
|
-
<button type="button" @click="activeKey = ['2']">
|
|
172
|
-
active header 2
|
|
173
|
-
</button>
|
|
174
|
-
<br>
|
|
175
|
-
<br>
|
|
176
|
-
|
|
177
|
-
<Collapse
|
|
178
|
-
:accordion="accordion"
|
|
179
|
-
:active-key="activeKey"
|
|
180
|
-
:expand-icon="expandIcon"
|
|
181
|
-
:open-motion="openMotion"
|
|
182
|
-
:items="items"
|
|
183
|
-
@change="handleSetActiveKey"
|
|
184
|
-
/>
|
|
185
|
-
</template>
|