Commit 335506628e15e29e08df55d4b7e7cf6333fe25be
1 parent
a0b09e74
fix: fix expandTransition
Showing
5 changed files
with
120 additions
and
37 deletions
.vscode/settings.json
@@ -116,15 +116,21 @@ | @@ -116,15 +116,21 @@ | ||
116 | // ================ Eslint =================== | 116 | // ================ Eslint =================== |
117 | // =========================================== | 117 | // =========================================== |
118 | "eslint.enable": true, // 是否开启eslint | 118 | "eslint.enable": true, // 是否开启eslint |
119 | - | ||
120 | "eslint.options": { | 119 | "eslint.options": { |
121 | // 配置 | 120 | // 配置 |
122 | - "plugins": ["html", "vue", "javascript", "jsx", "typescript"] | 121 | + "plugins": [ |
122 | + "html", | ||
123 | + "vue", | ||
124 | + "javascript", | ||
125 | + "jsx", | ||
126 | + "typescript" | ||
127 | + ] | ||
123 | }, | 128 | }, |
124 | "eslint.autoFixOnSave": true, // 保存自动格式化 | 129 | "eslint.autoFixOnSave": true, // 保存自动格式化 |
125 | // =========================================== | 130 | // =========================================== |
126 | // ================ Vetur ==================== | 131 | // ================ Vetur ==================== |
127 | // =========================================== | 132 | // =========================================== |
133 | + "vetur.experimental.templateInterpolationService": true, | ||
128 | "vetur.format.options.tabSize": 2, | 134 | "vetur.format.options.tabSize": 2, |
129 | "vetur.format.defaultFormatter.html": "js-beautify-html", // 使用js-beautify-html格式化 | 135 | "vetur.format.defaultFormatter.html": "js-beautify-html", // 使用js-beautify-html格式化 |
130 | "vetur.format.defaultFormatter.scss": "prettier", // 使用js-beautify-html格式化 | 136 | "vetur.format.defaultFormatter.scss": "prettier", // 使用js-beautify-html格式化 |
@@ -244,7 +250,9 @@ | @@ -244,7 +250,9 @@ | ||
244 | "[markdown]": { | 250 | "[markdown]": { |
245 | "editor.defaultFormatter": "esbenp.prettier-vscode" | 251 | "editor.defaultFormatter": "esbenp.prettier-vscode" |
246 | }, | 252 | }, |
247 | - "cSpell.words": ["yfboilerplate"], | 253 | + "cSpell.words": [ |
254 | + "yfboilerplate" | ||
255 | + ], | ||
248 | "editor.codeActionsOnSave": { | 256 | "editor.codeActionsOnSave": { |
249 | "source.fixAll.eslint": true | 257 | "source.fixAll.eslint": true |
250 | } | 258 | } |
src/components/Transition/index.ts
1 | -import { | ||
2 | - // createSimpleTransition, | ||
3 | - createJavascriptTransition, | ||
4 | -} from './src/CreateTransition'; | 1 | +// import { |
2 | +// // createSimpleTransition, | ||
3 | +// createJavascriptTransition, | ||
4 | +// } from './src/CreateTransition'; | ||
5 | 5 | ||
6 | -import ExpandTransitionGenerator from './src/ExpandTransition'; | 6 | +// import ExpandTransitionGenerator from './src/ExpandTransition'; |
7 | 7 | ||
8 | export { default as CollapseTransition } from './src/CollapseTransition'; | 8 | export { default as CollapseTransition } from './src/CollapseTransition'; |
9 | +// export { default as CollapseTransition } from './src/CollapseTransition'; | ||
9 | 10 | ||
10 | // export const FadeTransition = createSimpleTransition('fade-transition'); | 11 | // export const FadeTransition = createSimpleTransition('fade-transition'); |
11 | // export const ScaleTransition = createSimpleTransition('scale-transition'); | 12 | // export const ScaleTransition = createSimpleTransition('scale-transition'); |
@@ -20,12 +21,14 @@ export { default as CollapseTransition } from './src/CollapseTransition'; | @@ -20,12 +21,14 @@ export { default as CollapseTransition } from './src/CollapseTransition'; | ||
20 | // export const ScaleRotateTransition = createSimpleTransition('scale-rotate-transition'); | 21 | // export const ScaleRotateTransition = createSimpleTransition('scale-rotate-transition'); |
21 | 22 | ||
22 | // Javascript transitions | 23 | // Javascript transitions |
23 | -export const ExpandTransition = createJavascriptTransition( | ||
24 | - 'expand-transition', | ||
25 | - ExpandTransitionGenerator() | ||
26 | -); | 24 | +// export const ExpandTransition = createJavascriptTransition( |
25 | +// 'expand-transition', | ||
26 | +// ExpandTransitionGenerator() | ||
27 | +// ); | ||
27 | 28 | ||
28 | // export const ExpandXTransition = createJavascriptTransition( | 29 | // export const ExpandXTransition = createJavascriptTransition( |
29 | // 'expand-x-transition', | 30 | // 'expand-x-transition', |
30 | // ExpandTransitionGenerator('', true) | 31 | // ExpandTransitionGenerator('', true) |
31 | // ); | 32 | // ); |
33 | + | ||
34 | +export { default as ExpandTransition } from './src/ExpandTransition.vue'; |
src/components/Transition/src/CollapseTransition.tsx
1 | -import type { PropType } from 'vue'; | ||
2 | - | ||
3 | // collapse 展开折叠 | 1 | // collapse 展开折叠 |
4 | import { defineComponent } from 'vue'; | 2 | import { defineComponent } from 'vue'; |
5 | import { getSlot } from '/@/utils/helper/tsxHelper'; | 3 | import { getSlot } from '/@/utils/helper/tsxHelper'; |
6 | -import { createJavascriptTransition } from './CreateTransition'; | ||
7 | -import ExpandTransitionGenerator from './ExpandTransition'; | 4 | +// import { createJavascriptTransition } from './CreateTransition'; |
5 | +import ExpandTransition from './ExpandTransition.vue'; | ||
8 | 6 | ||
9 | -export const ExpandTransition = createJavascriptTransition( | ||
10 | - 'expand-transition', | ||
11 | - ExpandTransitionGenerator() | ||
12 | -); | 7 | +// export const ExpandTransition = createJavascriptTransition( |
8 | +// 'expand-transition', | ||
9 | +// ExpandTransitionGenerator() | ||
10 | +// ); | ||
13 | export default defineComponent({ | 11 | export default defineComponent({ |
14 | name: 'CollapseTransition', | 12 | name: 'CollapseTransition', |
15 | - components: { | ||
16 | - ExpandTransition, | ||
17 | - }, | ||
18 | - props: { | ||
19 | - // 是否打开折叠功能 | ||
20 | - enable: { | ||
21 | - type: Boolean as PropType<boolean>, | ||
22 | - default: true, | ||
23 | - }, | ||
24 | - }, | ||
25 | - setup(props, { slots }) { | ||
26 | - return () => | ||
27 | - props.enable ? <ExpandTransition>{() => getSlot(slots)}</ExpandTransition> : getSlot(slots); | 13 | + setup(_, { slots }) { |
14 | + return () => <ExpandTransition>{() => getSlot(slots)}</ExpandTransition>; | ||
28 | }, | 15 | }, |
29 | }); | 16 | }); |
src/components/Transition/src/ExpandTransition.ts
@@ -34,9 +34,9 @@ export default function (expandedParentClass = '', x = false) { | @@ -34,9 +34,9 @@ export default function (expandedParentClass = '', x = false) { | ||
34 | 34 | ||
35 | el.style.setProperty('transition', 'none', 'important'); | 35 | el.style.setProperty('transition', 'none', 'important'); |
36 | el.style.overflow = 'hidden'; | 36 | el.style.overflow = 'hidden'; |
37 | - const offset = `${el[offsetProperty]}px`; | 37 | + // const offset = `${el[offsetProperty]}px`; |
38 | 38 | ||
39 | - el.style[sizeProperty] = '0'; | 39 | + // el.style[sizeProperty] = '0'; |
40 | 40 | ||
41 | void el.offsetHeight; // force reflow | 41 | void el.offsetHeight; // force reflow |
42 | 42 | ||
@@ -47,7 +47,7 @@ export default function (expandedParentClass = '', x = false) { | @@ -47,7 +47,7 @@ export default function (expandedParentClass = '', x = false) { | ||
47 | } | 47 | } |
48 | 48 | ||
49 | requestAnimationFrame(() => { | 49 | requestAnimationFrame(() => { |
50 | - el.style[sizeProperty] = offset; | 50 | + // el.style[sizeProperty] = offset; |
51 | }); | 51 | }); |
52 | }, | 52 | }, |
53 | 53 | ||
@@ -84,6 +84,6 @@ export default function (expandedParentClass = '', x = false) { | @@ -84,6 +84,6 @@ export default function (expandedParentClass = '', x = false) { | ||
84 | const size = el._initialStyle[sizeProperty]; | 84 | const size = el._initialStyle[sizeProperty]; |
85 | el.style.overflow = el._initialStyle.overflow!; | 85 | el.style.overflow = el._initialStyle.overflow!; |
86 | if (size != null) el.style[sizeProperty] = size; | 86 | if (size != null) el.style[sizeProperty] = size; |
87 | - delete (el as any)._initialStyle; | 87 | + Reflect.deleteProperty(el, '_initialStyle'); |
88 | } | 88 | } |
89 | } | 89 | } |
src/components/Transition/src/ExpandTransition.vue
0 → 100644
1 | +<template> | ||
2 | + <transition v-on="on"> | ||
3 | + <slot></slot> | ||
4 | + </transition> | ||
5 | +</template> | ||
6 | +<script lang="ts"> | ||
7 | + import { addClass, removeClass } from '/@/utils/domUtils'; | ||
8 | + import { defineComponent } from 'vue'; | ||
9 | + export default defineComponent({ | ||
10 | + name: 'CollapseTransition', | ||
11 | + setup() { | ||
12 | + return { | ||
13 | + on: { | ||
14 | + beforeEnter(el: any) { | ||
15 | + addClass(el, 'collapse-transition'); | ||
16 | + if (!el.dataset) el.dataset = {}; | ||
17 | + | ||
18 | + el.dataset.oldPaddingTop = el.style.paddingTop; | ||
19 | + el.dataset.oldPaddingBottom = el.style.paddingBottom; | ||
20 | + | ||
21 | + el.style.height = '0'; | ||
22 | + el.style.paddingTop = 0; | ||
23 | + el.style.paddingBottom = 0; | ||
24 | + }, | ||
25 | + | ||
26 | + enter(el: any) { | ||
27 | + el.dataset.oldOverflow = el.style.overflow; | ||
28 | + if (el.scrollHeight !== 0) { | ||
29 | + el.style.height = el.scrollHeight + 'px'; | ||
30 | + el.style.paddingTop = el.dataset.oldPaddingTop; | ||
31 | + el.style.paddingBottom = el.dataset.oldPaddingBottom; | ||
32 | + } else { | ||
33 | + el.style.height = ''; | ||
34 | + el.style.paddingTop = el.dataset.oldPaddingTop; | ||
35 | + el.style.paddingBottom = el.dataset.oldPaddingBottom; | ||
36 | + } | ||
37 | + | ||
38 | + el.style.overflow = 'hidden'; | ||
39 | + }, | ||
40 | + | ||
41 | + afterEnter(el: any) { | ||
42 | + // for safari: remove class then reset height is necessary | ||
43 | + removeClass(el, 'collapse-transition'); | ||
44 | + el.style.height = ''; | ||
45 | + el.style.overflow = el.dataset.oldOverflow; | ||
46 | + }, | ||
47 | + | ||
48 | + beforeLeave(el: any) { | ||
49 | + if (!el.dataset) el.dataset = {}; | ||
50 | + el.dataset.oldPaddingTop = el.style.paddingTop; | ||
51 | + el.dataset.oldPaddingBottom = el.style.paddingBottom; | ||
52 | + el.dataset.oldOverflow = el.style.overflow; | ||
53 | + | ||
54 | + el.style.height = el.scrollHeight + 'px'; | ||
55 | + el.style.overflow = 'hidden'; | ||
56 | + }, | ||
57 | + | ||
58 | + leave(el: any) { | ||
59 | + if (el.scrollHeight !== 0) { | ||
60 | + // for safari: add class after set height, or it will jump to zero height suddenly, weired | ||
61 | + addClass(el, 'collapse-transition'); | ||
62 | + el.style.height = 0; | ||
63 | + el.style.paddingTop = 0; | ||
64 | + el.style.paddingBottom = 0; | ||
65 | + } | ||
66 | + }, | ||
67 | + | ||
68 | + afterLeave(el: any) { | ||
69 | + removeClass(el, 'collapse-transition'); | ||
70 | + el.style.height = ''; | ||
71 | + el.style.overflow = el.dataset.oldOverflow; | ||
72 | + el.style.paddingTop = el.dataset.oldPaddingTop; | ||
73 | + el.style.paddingBottom = el.dataset.oldPaddingBottom; | ||
74 | + }, | ||
75 | + }, | ||
76 | + }; | ||
77 | + }, | ||
78 | + }); | ||
79 | +</script> | ||
80 | +<style lang="less" scoped> | ||
81 | + .collapse-transition { | ||
82 | + transition: 0.2s height ease-in-out, 0.2s padding-top ease-in-out, | ||
83 | + 0.2s padding-bottom ease-in-out; | ||
84 | + } | ||
85 | +</style> |