Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(skeleton): 修复skeleton响应性问题 #238

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 37 additions & 32 deletions src/skeleton/skeleton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';
import { defineComponent, computed, toRefs, watchEffect, ref } from 'vue';
import { isNumber } from '../shared';

import config from '../config';
Expand All @@ -39,24 +39,27 @@ export default defineComponent({
components: {},
props: SkeletonProps,
setup(props) {
const showContent = !props.loading;
const { loading, theme, animation } = toRefs(props);
const showContent = computed(() => !loading.value);

const rootClasses = computed(() => [`${name}`, `${name}--${props.theme}`]);

const rowCols = [];
const rowCols = ref<any>([]);

if (props.theme === 'avatar-text') {
rowCols.push(...defaultRowcols);
} else if (props.rowCol) {
rowCols.push(...props.rowCol);
} else {
rowCols.push(...defaultRowcols);
}
watchEffect(() => {
if (theme.value === 'avatar-text') {
rowCols.value = [...defaultRowcols];
} else if (props.rowCol) {
rowCols.value = [...props.rowCol];
} else {
rowCols.value = [...defaultRowcols];
}
});

const rowClass = `${name}__row`;
const colClass = computed(() => [
`${name}__col`,
{ [`${name}--animation-${props.animation}`]: props.animation },
{ [`${name}--animation-${animation.value}`]: animation.value },
`${name}--type-text`,
]);

Expand Down Expand Up @@ -86,31 +89,33 @@ export default defineComponent({
return style;
};

const parsedRowcols = rowCols.map((item) => {
if (isNumber(item)) {
const parsedRowcols = computed(() => {
return rowCols.value.map((item: any) => {
if (isNumber(item)) {
return [
{
type: 'text',
style: {},
},
];
}
if (Array.isArray(item)) {
return item.map((col) => {
return {
...col,
style: getColItemStyle(col),
};
});
}

const nItem = item as SkeletonRowColObj;
return [
{
type: 'text',
style: {},
...nItem,
style: getColItemStyle(nItem),
},
];
}
if (Array.isArray(item)) {
return item.map((col) => {
return {
...col,
style: getColItemStyle(col),
};
});
}

const nItem = item as SkeletonRowColObj;
return [
{
...nItem,
style: getColItemStyle(nItem),
},
];
});
});

return {
Expand Down
110 changes: 96 additions & 14 deletions test/snap/__snapshots__/csr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26384,40 +26384,40 @@ exports[`csr snapshot test > csr test ./src/icon/demos/iconfont-enhanced.vue 1`]
>
<div>
<i
class="t-icon cps-icon cps-icon-home-sheep"
class="cps-icon cps-icon-home-sheep"
/>
<i
class="t-icon cps-icon cps-icon-home-sheep t-size-m"
class="cps-icon cps-icon-home-sheep t-size-m"
/>
<i
class="t-icon cps-icon cps-icon-home-sheep t-size-l"
class="cps-icon cps-icon-home-sheep t-size-l"
/>
<i
class="t-icon cps-icon cps-icon-home-sheep"
class="cps-icon cps-icon-home-sheep"
style="font-size: 25px;"
/>
<i
class="t-icon cps-icon cps-icon-home-sheep"
class="cps-icon cps-icon-home-sheep"
style="font-size: 2em;"
/>
</div>
<br />
<div>
<i
class="t-icon cps-icon cps-icon-home-sheep"
class="cps-icon cps-icon-home-sheep"
style="color: red;"
/>
<i
class="t-icon cps-icon cps-icon-home-sheep"
class="cps-icon cps-icon-home-sheep"
style="color: green;"
/>
<i
class="t-icon cps-icon cps-icon-home-sheep"
class="cps-icon cps-icon-home-sheep"
style="color: orange;"
/>
<!-- 引入新 Icon 之后,内置 Icon 依旧有效。name 传入图标名称全称。 -->
<i
class="t-icon t-icon-home"
class="t-icon-home t-icon"
/>
</div>
<br />
Expand Down Expand Up @@ -66764,7 +66764,7 @@ exports[`csr snapshot test > csr test ./src/toast/demos/mobile.vue 1`] = `
>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle t-is-block"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
Expand All @@ -66778,7 +66778,7 @@ exports[`csr snapshot test > csr test ./src/toast/demos/mobile.vue 1`] = `
</button>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle t-is-block"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
Expand All @@ -66792,7 +66792,7 @@ exports[`csr snapshot test > csr test ./src/toast/demos/mobile.vue 1`] = `
</button>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle t-is-block"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
Expand All @@ -66804,6 +66804,20 @@ exports[`csr snapshot test > csr test ./src/toast/demos/mobile.vue 1`] = `

</span>
</button>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
<span
class="t-button__text"
>

显示 5 秒

</span>
</button>
</div>

</div>
Expand All @@ -66818,15 +66832,83 @@ exports[`csr snapshot test > csr test ./src/toast/demos/mobile.vue 1`] = `
<p
class="tdesign-mobile-demo-block__summary"
>
弹窗可显示遮罩,禁止滑动和点击
弹窗可显示遮罩,可配置 Overlay 属性
</p>

<div
class="toast-demo"
>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle t-is-block"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
<span
class="t-button__text"
>

弹窗显示遮罩

</span>
</button>
</div>

</div>
<div
class="tdesign-mobile-demo-block"
>
<h2
class="tdesign-mobile-demo-block__title"
>
04 透传 Overlay
</h2>
<p
class="tdesign-mobile-demo-block__summary"
>
向 Overlay 遮罩透传属性
</p>

<div
class="toast-demo"
>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
<span
class="t-button__text"
>

可滑动和点击透明遮罩

</span>
</button>
</div>

</div>
<div
class="tdesign-mobile-demo-block"
>
<h2
class="tdesign-mobile-demo-block__title"
>
05 禁止滑动和点击
</h2>
<p
class="tdesign-mobile-demo-block__summary"
>
弹窗禁止滑动和点击
</p>

<div
class="toast-demo"
>
<button
aria-disabled="false"
class="t-button t-size-l t-button--outline t-button--default t-button--shape-rectangle"
role="button"
>
<!---->
Expand Down
Loading