feat(SubmitBar): enable safe-area-inset-bottom by default (#5956)

This commit is contained in:
neverland 2020-03-31 07:23:23 +08:00 committed by GitHub
parent b87fd71959
commit 75e832f05a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 24 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<demo-section> <demo-section>
<demo-block :title="t('basicUsage')"> <demo-block :title="t('basicUsage')">
<van-goods-action :safe-area-inset-bottom="false"> <van-goods-action>
<van-goods-action-icon <van-goods-action-icon
icon="chat-o" icon="chat-o"
:text="t('icon1')" :text="t('icon1')"
@ -26,7 +26,7 @@
</demo-block> </demo-block>
<demo-block :title="t('iconBadge')"> <demo-block :title="t('iconBadge')">
<van-goods-action :safe-area-inset-bottom="false"> <van-goods-action>
<van-goods-action-icon icon="chat-o" dot :text="t('icon1')" /> <van-goods-action-icon icon="chat-o" dot :text="t('icon1')" />
<van-goods-action-icon icon="cart-o" badge="5" :text="t('icon2')" /> <van-goods-action-icon icon="cart-o" badge="5" :text="t('icon2')" />
<van-goods-action-icon icon="shop-o" badge="12" :text="t('icon3')" /> <van-goods-action-icon icon="shop-o" badge="12" :text="t('icon3')" />
@ -36,7 +36,7 @@
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('customIconColor')"> <demo-block v-if="!isWeapp" :title="t('customIconColor')">
<van-goods-action :safe-area-inset-bottom="false"> <van-goods-action>
<van-goods-action-icon <van-goods-action-icon
icon="chat-o" icon="chat-o"
:text="t('icon1')" :text="t('icon1')"
@ -54,7 +54,7 @@
</demo-block> </demo-block>
<demo-block :title="t('customButtonColor')"> <demo-block :title="t('customButtonColor')">
<van-goods-action :safe-area-inset-bottom="false"> <van-goods-action>
<van-goods-action-icon icon="chat-o" :text="t('icon1')" /> <van-goods-action-icon icon="chat-o" :text="t('icon1')" />
<van-goods-action-icon icon="cart-o" :text="t('icon2')" /> <van-goods-action-icon icon="cart-o" :text="t('icon2')" />
<van-goods-action-button <van-goods-action-button
@ -117,6 +117,7 @@ export default {
.demo-goods-action { .demo-goods-action {
.van-goods-action { .van-goods-action {
position: relative; position: relative;
padding-bottom: 0;
} }
} }
</style> </style>

View File

@ -15,7 +15,7 @@ export default createComponent({
render() { render() {
return ( return (
<div class={bem({ 'safe-area-inset-bottom': this.safeAreaInsetBottom })}> <div class={bem({ unfit: !this.safeAreaInsetBottom })}>
{this.slots()} {this.slots()}
</div> </div>
); );

View File

@ -9,10 +9,11 @@
align-items: center; align-items: center;
box-sizing: content-box; box-sizing: content-box;
height: @goods-action-height; height: @goods-action-height;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
background-color: @goods-action-background-color; background-color: @goods-action-background-color;
&--safe-area-inset-bottom { &--unfit {
padding-bottom: constant(safe-area-inset-bottom); padding-bottom: 0;
padding-bottom: env(safe-area-inset-bottom);
} }
} }

View File

@ -31,3 +31,5 @@ exports[`Icon render icon slot with info 1`] = `
</div>Text </div>Text
</div> </div>
`; `;
exports[`disable safe-area-inset-bottom prop 1`] = `<div class="van-goods-action van-goods-action--unfit"></div>`;

View File

@ -1,3 +1,4 @@
import GoodsAction from '..';
import Button from '../../goods-action-button'; import Button from '../../goods-action-button';
import Icon from '../../goods-action-icon'; import Icon from '../../goods-action-icon';
import { mount } from '../../../test'; import { mount } from '../../../test';
@ -84,3 +85,13 @@ test('Icon render icon slot with dot', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
test('disable safe-area-inset-bottom prop', () => {
const wrapper = mount(GoodsAction, {
propsData: {
safeAreaInsetBottom: false,
},
});
expect(wrapper).toMatchSnapshot();
});

View File

@ -60,9 +60,9 @@ Use slot to add custom contents.
@submit="onSubmit" @submit="onSubmit"
> >
<van-checkbox v-model="checked">Check</van-checkbox> <van-checkbox v-model="checked">Check</van-checkbox>
<template #tip> <template #tip>
Some tips, <span @click="onClickEditAddress">Link</span> Some tips, <span @click="onClickEditAddress">Link</span>
</template> </template>
</van-submit-bar> </van-submit-bar>
``` ```
@ -84,7 +84,7 @@ Use slot to add custom contents.
| decimal-length | number of digits to appear after the decimal point | *number \| string* | `2` | | decimal-length | number of digits to appear after the decimal point | *number \| string* | `2` |
| disabled | Whether to disable button | *boolean* | `false` | | disabled | Whether to disable button | *boolean* | `false` |
| loading | Whether to show loading icon | *boolean* | `false` | | loading | Whether to show loading icon | *boolean* | `false` |
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | *boolean* | `false` | | safe-area-inset-bottom | Whether to enable bottom safe area adaptation | *boolean* | `true` |
### Events ### Events

View File

@ -60,9 +60,9 @@ Vue.use(SubmitBar);
@submit="onSubmit" @submit="onSubmit"
> >
<van-checkbox v-model="checked">全选</van-checkbox> <van-checkbox v-model="checked">全选</van-checkbox>
<template #tip> <template #tip>
你的收货地址不支持同城送, <span @click="onClickEditAddress">修改地址</span> 你的收货地址不支持同城送, <span @click="onClickEditAddress">修改地址</span>
</template> </template>
</van-submit-bar> </van-submit-bar>
``` ```
@ -84,7 +84,7 @@ Vue.use(SubmitBar);
| decimal-length | 价格小数点后位数 | *number \| string* | `2` | | decimal-length | 价格小数点后位数 | *number \| string* | `2` |
| disabled | 是否禁用按钮 | *boolean* | `false` | | disabled | 是否禁用按钮 | *boolean* | `false` |
| loading | 是否显示加载中的按钮 | *boolean* | `false` | | loading | 是否显示加载中的按钮 | *boolean* | `false` |
| safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/quickstart#di-bu-an-quan-qu-gua-pei) | *boolean* | `false` | | safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/quickstart#di-bu-an-quan-qu-gua-pei) | *boolean* | `true` |
### Events ### Events

View File

@ -92,6 +92,7 @@ export default {
.demo-submit-bar { .demo-submit-bar {
.van-submit-bar { .van-submit-bar {
position: relative; position: relative;
padding-bottom: 0;
} }
.edit-address { .edit-address {

View File

@ -6,6 +6,8 @@
left: 0; left: 0;
z-index: @submit-bar-z-index; z-index: @submit-bar-z-index;
width: 100%; width: 100%;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
background-color: @submit-bar-background-color; background-color: @submit-bar-background-color;
user-select: none; user-select: none;
@ -75,8 +77,7 @@
} }
} }
&--safe-area-inset-bottom { &--unfit {
padding-bottom: constant(safe-area-inset-bottom); padding-bottom: 0;
padding-bottom: env(safe-area-inset-bottom);
} }
} }

View File

@ -77,10 +77,7 @@ function SubmitBar(
} }
return ( return (
<div <div class={bem({ unfit: !props.safeAreaInsetBottom })} {...inherit(ctx)}>
class={bem({ 'safe-area-inset-bottom': props.safeAreaInsetBottom })}
{...inherit(ctx)}
>
{slots.top && slots.top()} {slots.top && slots.top()}
{Tip()} {Tip()}
<div class={bem('bar')}> <div class={bem('bar')}>
@ -112,7 +109,10 @@ SubmitBar.props = {
textAlign: String, textAlign: String,
buttonText: String, buttonText: String,
suffixLabel: String, suffixLabel: String,
safeAreaInsetBottom: Boolean, safeAreaInsetBottom: {
type: Boolean,
default: true,
},
decimalLength: { decimalLength: {
type: [Number, String], type: [Number, String],
default: 2, default: 2,

View File

@ -8,6 +8,12 @@ exports[`decimal-length prop 1`] = `
</div> </div>
`; `;
exports[`disable safe-area-inset-bottom prop 1`] = `
<div class="van-submit-bar van-submit-bar--unfit">
<div class="van-submit-bar__bar"><button class="van-button van-button--danger van-button--normal van-button--round van-submit-bar__button van-submit-bar__button--danger"></button></div>
</div>
`;
exports[`disable submit 1`] = ` exports[`disable submit 1`] = `
<div class="van-submit-bar"> <div class="van-submit-bar">
<div class="van-submit-bar__bar"> <div class="van-submit-bar__bar">

View File

@ -97,3 +97,14 @@ test('text-align prop', () => {
}); });
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
test('disable safe-area-inset-bottom prop', () => {
const wrapper = mount(SubmitBar, {
context: {
props: {
safeAreaInsetBottom: false,
},
},
});
expect(wrapper).toMatchSnapshot();
});