mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] SubmitBar: add suffix-label prop
This commit is contained in:
parent
19efe4b316
commit
0f68edb8fd
@ -104,6 +104,7 @@
|
|||||||
### SubmitBar
|
### SubmitBar
|
||||||
|
|
||||||
- 新增`tip-icon`属性
|
- 新增`tip-icon`属性
|
||||||
|
- 新增`suffix-label`属性
|
||||||
|
|
||||||
### Steps
|
### Steps
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ Use slot to add custom contents.
|
|||||||
| Attribute | Description | Type | Default |
|
| Attribute | Description | Type | Default |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| price | Price | `Number` | - |
|
| price | Price | `Number` | - |
|
||||||
| label | Price label | `String` | `合计:` |
|
| label | Price left label | `String` | `Total:` |
|
||||||
|
| suffix-label | Price right label | `String` | - |
|
||||||
| button-text | Button text | `String` | - |
|
| button-text | Button text | `String` | - |
|
||||||
| button-type | Button type | `String` | `danger` |
|
| button-type | Button type | `String` | `danger` |
|
||||||
| tip | Tip | `String` | - |
|
| tip | Tip | `String` | - |
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
&__bar {
|
&__bar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
@ -46,6 +47,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__suffix-label {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
&__price {
|
&__price {
|
||||||
color: @red;
|
color: @red;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
@ -17,6 +17,7 @@ export type SubmitBarProps = {
|
|||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
buttonType: ButtonType;
|
buttonType: ButtonType;
|
||||||
buttonText?: string;
|
buttonText?: string;
|
||||||
|
suffixLabel?: string;
|
||||||
decimalLength: number;
|
decimalLength: number;
|
||||||
safeAreaInsetBottom?: boolean;
|
safeAreaInsetBottom?: boolean;
|
||||||
};
|
};
|
||||||
@ -35,7 +36,34 @@ function SubmitBar(
|
|||||||
ctx: RenderContext<SubmitBarProps>
|
ctx: RenderContext<SubmitBarProps>
|
||||||
) {
|
) {
|
||||||
const { tip, price, tipIcon } = props;
|
const { tip, price, tipIcon } = props;
|
||||||
const hasPrice = typeof price === 'number';
|
|
||||||
|
function Text() {
|
||||||
|
if (typeof price === 'number') {
|
||||||
|
const priceText = `${props.currency} ${(price / 100).toFixed(props.decimalLength)}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={bem('text')}>
|
||||||
|
<span>{props.label || t('label')}</span>
|
||||||
|
<span class={bem('price')}>{priceText}</span>
|
||||||
|
{props.suffixLabel && (
|
||||||
|
<span class={bem('suffix-label')}>{props.suffixLabel}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Tip() {
|
||||||
|
if (slots.tip || tip) {
|
||||||
|
return (
|
||||||
|
<div class={bem('tip')}>
|
||||||
|
{tipIcon && <Icon class={bem('tip-icon')} name={tipIcon} />}
|
||||||
|
{tip && <span class={bem('tip-text')}>{tip}</span>}
|
||||||
|
{slots.tip && slots.tip()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -43,27 +71,10 @@ function SubmitBar(
|
|||||||
{...inherit(ctx)}
|
{...inherit(ctx)}
|
||||||
>
|
>
|
||||||
{slots.top && slots.top()}
|
{slots.top && slots.top()}
|
||||||
{(slots.tip || tip) && (
|
{Tip()}
|
||||||
<div class={bem('tip')}>
|
|
||||||
{tipIcon && (
|
|
||||||
<Icon class={bem('tip-icon')} name={tipIcon} />
|
|
||||||
)}
|
|
||||||
{tip && (
|
|
||||||
<span class={bem('tip-text')}>{tip}</span>
|
|
||||||
)}
|
|
||||||
{slots.tip && slots.tip()}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div class={bem('bar')}>
|
<div class={bem('bar')}>
|
||||||
{slots.default && slots.default()}
|
{slots.default && slots.default()}
|
||||||
<div class={bem('text')}>
|
{Text()}
|
||||||
{hasPrice && [
|
|
||||||
<span>{props.label || t('label')}</span>,
|
|
||||||
<span class={bem('price')}>{`${props.currency} ${(
|
|
||||||
(price as number) / 100
|
|
||||||
).toFixed(props.decimalLength)}`}</span>
|
|
||||||
]}
|
|
||||||
</div>
|
|
||||||
<Button
|
<Button
|
||||||
square
|
square
|
||||||
size="large"
|
size="large"
|
||||||
@ -87,6 +98,7 @@ SubmitBar.props = {
|
|||||||
loading: Boolean,
|
loading: Boolean,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
buttonText: String,
|
buttonText: String,
|
||||||
|
suffixLabel: String,
|
||||||
safeAreaInsetBottom: Boolean,
|
safeAreaInsetBottom: Boolean,
|
||||||
price: {
|
price: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`decimal length 1`] = `
|
exports[`decimal-length prop 1`] = `
|
||||||
<div class="van-submit-bar">
|
<div class="van-submit-bar">
|
||||||
<div class="van-submit-bar__bar">
|
<div class="van-submit-bar__bar">
|
||||||
<div class="van-submit-bar__text"><span>合计:</span><span class="van-submit-bar__price">¥ 1.1</span></div><button class="van-button van-button--danger van-button--large van-button--square"><span class="van-button__text"></span></button>
|
<div class="van-submit-bar__text"><span>合计:</span><span class="van-submit-bar__price">¥ 1.1</span></div><button class="van-button van-button--danger van-button--large van-button--square"><span class="van-button__text"></span></button>
|
||||||
@ -15,3 +15,22 @@ exports[`disable submit 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`suffix-label prop 1`] = `
|
||||||
|
<div class="van-submit-bar">
|
||||||
|
<div class="van-submit-bar__bar">
|
||||||
|
<div class="van-submit-bar__text"><span>Label</span><span class="van-submit-bar__price">¥ 1.11</span><span class="van-submit-bar__suffix-label">Suffix Label</span></div><button class="van-button van-button--danger van-button--large van-button--square"><span class="van-button__text"></span></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`top slot 1`] = `
|
||||||
|
<div class="van-submit-bar">top<div class="van-submit-bar__bar"><button class="van-button van-button--danger van-button--large van-button--square"><span class="van-button__text"></span></button></div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`without price 1`] = `
|
||||||
|
<div class="van-submit-bar">
|
||||||
|
<div class="van-submit-bar__bar"><button class="van-button van-button--danger van-button--large van-button--square"><span class="van-button__text"></span></button></div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import SubmitBar from '..';
|
import SubmitBar from '..';
|
||||||
import { mount } from '../../../test/utils';
|
import { mount } from '../../../test/utils';
|
||||||
|
|
||||||
test('submit', () => {
|
test('submit event', () => {
|
||||||
const submit = jest.fn();
|
const submit = jest.fn();
|
||||||
const wrapper = mount(SubmitBar, {
|
const wrapper = mount(SubmitBar, {
|
||||||
context: {
|
context: {
|
||||||
@ -37,7 +37,29 @@ test('disable submit', () => {
|
|||||||
expect(submit).toHaveBeenCalledTimes(0);
|
expect(submit).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('decimal length', () => {
|
test('without price', () => {
|
||||||
|
const wrapper = mount(SubmitBar, {
|
||||||
|
context: {
|
||||||
|
props: {
|
||||||
|
label: 'Label'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('top slot', () => {
|
||||||
|
const wrapper = mount(SubmitBar, {
|
||||||
|
scopedSlots: {
|
||||||
|
top: () => 'top'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('decimal-length prop', () => {
|
||||||
const wrapper = mount(SubmitBar, {
|
const wrapper = mount(SubmitBar, {
|
||||||
context: {
|
context: {
|
||||||
props: {
|
props: {
|
||||||
@ -49,3 +71,17 @@ test('decimal length', () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('suffix-label prop', () => {
|
||||||
|
const wrapper = mount(SubmitBar, {
|
||||||
|
context: {
|
||||||
|
props: {
|
||||||
|
price: 111,
|
||||||
|
label: 'Label',
|
||||||
|
suffixLabel: 'Suffix Label'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
@ -69,7 +69,8 @@ Vue.use(SubmitBar);
|
|||||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| price | 价格(单位分) | `Number` | - | - |
|
| price | 价格(单位分) | `Number` | - | - |
|
||||||
| label | 价格文案 | `String` | `合计:` | - |
|
| label | 价格左侧文案 | `String` | `合计:` | - |
|
||||||
|
| suffix-label | 价格右侧文案 | `String` | - | 2.0.0 |
|
||||||
| button-text | 按钮文字 | `String` | - | - |
|
| button-text | 按钮文字 | `String` | - | - |
|
||||||
| button-type | 按钮类型 | `String` | `danger` | - |
|
| button-type | 按钮类型 | `String` | `danger` | - |
|
||||||
| tip | 提示文案 | `String` | - | - |
|
| tip | 提示文案 | `String` | - | - |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user