feat(SubmitBar): add placeholder prop (#10725)

This commit is contained in:
neverland
2022-06-18 18:38:23 +08:00
committed by GitHub
parent a1c79f42ff
commit 7ca4db9c64
7 changed files with 57 additions and 27 deletions
-1
View File
@@ -42,7 +42,6 @@
"@types/fs-extra": "^9.0.13",
"@types/less": "^3.0.3",
"@types/markdown-it": "^12.2.3",
"@types/react": "^18",
"@jest/types": "^27",
"vue": "^3.2.27",
"react": "^18",
+1
View File
@@ -106,6 +106,7 @@ export default {
| disabled | Whether to disable button | _boolean_ | `false` |
| loading | Whether to show loading icon | _boolean_ | `false` |
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | _boolean_ | `true` |
| placeholder `v3.5.1` | Whether to generate a placeholder element | _boolean_ | `false` |
### Events
@@ -113,6 +113,7 @@ export default {
| disabled | 是否禁用按钮 | _boolean_ | `false` |
| loading | 是否显示将按钮显示为加载中状态 | _boolean_ | `false` |
| safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` |
| placeholder `v3.5.1` | 是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
### Events
+20 -2
View File
@@ -1,4 +1,9 @@
import { defineComponent, type PropType, type ExtractPropTypes } from 'vue';
import {
ref,
defineComponent,
type PropType,
type ExtractPropTypes,
} from 'vue';
import {
truthProp,
makeStringProp,
@@ -9,6 +14,7 @@ import {
// Components
import { Icon } from '../icon';
import { Button, ButtonType } from '../button';
import { usePlaceholder } from '../composables/use-placeholder';
const [name, bem, t] = createNamespace('submit-bar');
@@ -27,6 +33,7 @@ const submitBarProps = {
buttonType: makeStringProp<ButtonType>('danger'),
buttonColor: String,
suffixLabel: String,
placeholder: Boolean,
decimalLength: makeNumericProp(2),
safeAreaInsetBottom: truthProp,
};
@@ -41,6 +48,9 @@ export default defineComponent({
emits: ['submit'],
setup(props, { emit, slots }) {
const root = ref<HTMLElement>();
const renderPlaceholder = usePlaceholder(root, bem);
const renderText = () => {
const { price, label, currency, textAlign, suffixLabel, decimalLength } =
props;
@@ -99,8 +109,9 @@ export default defineComponent({
);
};
return () => (
const renderSubmitBar = () => (
<div
ref={root}
class={[bem(), { 'van-safe-area-bottom': props.safeAreaInsetBottom }]}
>
{slots.top?.()}
@@ -112,5 +123,12 @@ export default defineComponent({
</div>
</div>
);
return () => {
if (props.placeholder) {
return renderPlaceholder(renderSubmitBar);
}
return renderSubmitBar();
};
},
});
@@ -47,6 +47,23 @@ exports[`should render disabled submit button correctly 1`] = `
</button>
`;
exports[`should render placeholder element when using placeholder prop 1`] = `
<div class="van-submit-bar__placeholder"
style="height: 50px;"
>
<div class="van-submit-bar van-safe-area-bottom">
<div class="van-submit-bar__bar">
<button type="button"
class="van-button van-button--danger van-button--normal van-button--round van-submit-bar__button van-submit-bar__button--danger"
>
<div class="van-button__content">
</div>
</button>
</div>
</div>
</div>
`;
exports[`should render suffix-label correctly 1`] = `
<div class="van-submit-bar__text">
<span>
@@ -1,5 +1,5 @@
import { SubmitBar } from '..';
import { mount } from '../../../test';
import { later, mockGetBoundingClientRect, mount } from '../../../test';
test('should emit submit event when submit button is clicked', () => {
const wrapper = mount(SubmitBar);
@@ -107,3 +107,16 @@ test('should render button slot correctly', () => {
});
expect(wrapper.html()).toMatchSnapshot();
});
test('should render placeholder element when using placeholder prop', async () => {
const restore = mockGetBoundingClientRect({ height: 50 });
const wrapper = mount(SubmitBar, {
props: {
placeholder: true,
},
});
await later();
expect(wrapper.html()).toMatchSnapshot();
restore();
});