diff --git a/packages/contact-list/index.js b/packages/contact-list/index.js index 1f37cc6e9..58ad9f4c2 100644 --- a/packages/contact-list/index.js +++ b/packages/contact-list/index.js @@ -1,4 +1,4 @@ -import { use } from '../utils'; +import { use, noop } from '../utils'; import Icon from '../icon'; import Cell from '../cell'; import Button from '../button'; @@ -7,55 +7,57 @@ import RadioGroup from '../radio-group'; const [sfc, bem, t] = use('contact-list'); -export default sfc({ - props: { - value: null, - list: Array, - addText: String - }, +export default sfc( + { + props: { + value: null, + list: Array, + addText: String + }, - render(h) { - return ( -
- { - this.$emit('input', event); + render(h, context) { + const { props, listeners } = context; + + const List = props.list.map((item, index) => ( + { + listeners.input && listeners.input(item.id); + listeners.select && listeners.select(item, index); }} > - {this.list.map((item, index) => ( - - { - this.$emit('select', item, index); - }} - > -
{`${item.name},${item.tel}`}
-
- { - this.$emit('edit', item, index); - }} - /> -
- ))} -
-
- ); - } -}); + +
{`${item.name},${item.tel}`}
+
+ { + event.stopPropagation(); + listeners.edit && listeners.edit(item, index); + }} + /> + + )); + + return ( +
+ + {List} + +
+ ); + } + }, + true +); diff --git a/packages/contact-list/index.less b/packages/contact-list/index.less index 052d99dce..41c55b7cc 100644 --- a/packages/contact-list/index.less +++ b/packages/contact-list/index.less @@ -19,16 +19,24 @@ margin-left: 27px; } - .van-radio__input { + .van-radio__icon { top: 50%; left: 0; - font-size: 16px; + height: 16px; position: absolute; + line-height: 16px; transform: translate(0, -50%); + + .van-icon { + width: 16px; + height: 16px; + font-size: 12px; + } } - .van-icon-checked { - color: @red; + .van-radio__icon--checked .van-icon { + border-color: @red; + background-color: @red; } &__group { diff --git a/packages/nav-bar/index.js b/packages/nav-bar/index.js index 279ea11ea..8013014d5 100644 --- a/packages/nav-bar/index.js +++ b/packages/nav-bar/index.js @@ -1,53 +1,55 @@ -import { use } from '../utils'; +import { use, noop } from '../utils'; import Icon from '../icon'; const [sfc, bem] = use('nav-bar'); -export default sfc({ - props: { - title: String, - fixed: Boolean, - leftText: String, - rightText: String, - leftArrow: Boolean, - border: { - type: Boolean, - default: true +export default sfc( + { + props: { + title: String, + fixed: Boolean, + leftText: String, + rightText: String, + leftArrow: Boolean, + border: { + type: Boolean, + default: true + }, + zIndex: { + type: Number, + default: 1 + } }, - zIndex: { - type: Number, - default: 1 + + render(h, context) { + const { props, listeners } = context; + const slots = context.slots(); + + return ( +
+
+ {slots.left || [ + props.leftArrow && , + props.leftText && {props.leftText} + ]} +
+
{slots.title || props.title}
+
+ {slots.right || (props.rightText && {props.rightText})} +
+
+ ); } }, - - render(h) { - return ( -
-
{ - this.$emit('click-left'); - }} - > - {this.$slots.left || [ - this.leftArrow && , - this.leftText && {this.leftText} - ]} -
-
{this.$slots.title || this.title}
-
{ - this.$emit('click-right'); - }} - > - {this.$slots.right || - (this.rightText && {this.rightText})} -
-
- ); - } -}); + true +); diff --git a/packages/panel/index.js b/packages/panel/index.js index 59f84225e..a0c03c61d 100644 --- a/packages/panel/index.js +++ b/packages/panel/index.js @@ -4,31 +4,35 @@ import CellGroup from '../cell-group'; const [sfc, bem] = use('panel'); -export default sfc({ - props: { - icon: String, - desc: String, - title: String, - status: String +export default sfc( + { + props: { + icon: String, + desc: String, + title: String, + status: String + }, + + render(h, context) { + const { props } = context; + const slots = context.slots(); + + return ( + + {slots.header || ( + + )} +
{slots.default}
+ {slots.footer &&
{slots.footer}
} +
+ ); + } }, - - render(h) { - const slots = this.$slots; - - return ( - - {slots.header || ( - - )} -
{slots.default}
- {slots.footer &&
{slots.footer}
} -
- ); - } -}); + true +); diff --git a/packages/submit-bar/index.js b/packages/submit-bar/index.js index e3e6639d9..60b678b27 100644 --- a/packages/submit-bar/index.js +++ b/packages/submit-bar/index.js @@ -1,63 +1,66 @@ -import { use } from '../utils'; +import { use, noop } from '../utils'; import Button from '../button'; const [sfc, bem, t] = use('submit-bar'); -export default sfc({ - props: { - tip: String, - label: String, - loading: Boolean, - disabled: Boolean, - buttonText: String, - price: { - type: Number, - default: null +export default sfc( + { + props: { + tip: String, + label: String, + loading: Boolean, + disabled: Boolean, + buttonText: String, + price: { + type: Number, + default: null + }, + currency: { + type: String, + default: '¥' + }, + buttonType: { + type: String, + default: 'danger' + } }, - currency: { - type: String, - default: '¥' - }, - buttonType: { - type: String, - default: 'danger' + + render(h, context) { + const { props, listeners } = context; + const { tip, price } = props; + const slots = context.slots(); + const hasPrice = typeof price === 'number'; + + return ( +
+ {slots.top} + {(slots.tip || tip) && ( +
+ {tip} + {slots.tip} +
+ )} +
+ {slots.default} +
+ {hasPrice && [ + {props.label || t('label')}, + {`${props.currency} ${(price / 100).toFixed(2)}`} + ]} +
+
+
+ ); } }, - - render(h) { - const { tip, price, $slots } = this; - const hasPrice = typeof price === 'number'; - - return ( -
- {$slots.top} - {($slots.tip || tip) && ( -
- {tip} - {$slots.tip} -
- )} -
- {$slots.default} -
- {hasPrice && [ - {this.label || t('label')}, - {`${this.currency} ${(price / 100).toFixed(2)}`} - ]} -
-
-
- ); - } -}); + true +); diff --git a/packages/submit-bar/test/__snapshots__/index.spec.js.snap b/packages/submit-bar/test/__snapshots__/index.spec.js.snap index f0acf4f87..be6067098 100644 --- a/packages/submit-bar/test/__snapshots__/index.spec.js.snap +++ b/packages/submit-bar/test/__snapshots__/index.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`submit 1`] = ` +exports[`disable submit 1`] = `
合计:¥ 0.00
diff --git a/packages/submit-bar/test/index.spec.js b/packages/submit-bar/test/index.spec.js index 48882b688..5184bfe83 100644 --- a/packages/submit-bar/test/index.spec.js +++ b/packages/submit-bar/test/index.spec.js @@ -2,10 +2,30 @@ import SubmitBar from '..'; import { mount } from '../../../test/utils'; test('submit', () => { + const submit = jest.fn(); const wrapper = mount(SubmitBar, { - propsData: { - price: 0.01, - disabled: true + context: { + props: { + price: 0.01 + }, + on: { submit } + } + }); + + const button = wrapper.find('.van-button'); + button.trigger('click'); + expect(submit.mock.calls[0]).toBeTruthy(); +}); + +test('disable submit', () => { + const submit = jest.fn(); + const wrapper = mount(SubmitBar, { + context: { + props: { + price: 0.01, + disabled: true + }, + on: { submit } } }); @@ -14,10 +34,5 @@ test('submit', () => { // disabled const button = wrapper.find('.van-button'); button.trigger('click'); - expect(wrapper.emitted('submit')).toBeFalsy(); - - // submit - wrapper.vm.disabled = false; - button.trigger('click'); - expect(wrapper.emitted('submit')).toBeTruthy(); + expect(submit.mock.calls[0]).toBeFalsy(); }); diff --git a/packages/switch-cell/index.js b/packages/switch-cell/index.js index 770f6cb49..e9e297683 100644 --- a/packages/switch-cell/index.js +++ b/packages/switch-cell/index.js @@ -5,34 +5,34 @@ import SwitchMixin from '../mixins/switch'; const [sfc, bem] = use('switch-cell'); -export default sfc({ - mixins: [SwitchMixin], +export default sfc( + { + mixins: [SwitchMixin], - props: { - title: String, - border: Boolean, - size: { - type: String, - default: '24px' + props: { + title: String, + border: Boolean, + size: { + type: String, + default: '24px' + } + }, + + render(h, context) { + const { props } = context; + + return ( + + + + ); } }, - - watch: { - value() { - this.$emit('change', this.value); - } - }, - - render(h) { - return ( - - { - this.$emit('input', value); - }} - /> - - ); - } -}); + true +); diff --git a/packages/switch-cell/test/index.spec.js b/packages/switch-cell/test/index.spec.js index ff1f0248a..e48e9b527 100644 --- a/packages/switch-cell/test/index.spec.js +++ b/packages/switch-cell/test/index.spec.js @@ -1,13 +1,20 @@ import SwitchCell from '..'; import { mount } from '../../../test/utils'; -test('emit event', () => { - const wrapper = mount(SwitchCell); +test('change event', () => { + const onChange = jest.fn(); + const wrapper = mount(SwitchCell, { + context: { + on: { + change: onChange + } + } + }); wrapper.vm.$on('input', value => { wrapper.setProps({ value }); }); wrapper.find('.van-switch').trigger('click'); - expect(wrapper.emitted('change')).toBeTruthy(); + expect(onChange.mock.calls[0]).toBeTruthy(); }); diff --git a/packages/tag/index.js b/packages/tag/index.js index c44dca03e..51d433534 100644 --- a/packages/tag/index.js +++ b/packages/tag/index.js @@ -9,51 +9,45 @@ const COLOR_MAP = { success: GREEN }; -export default sfc({ - props: { - size: String, - type: String, - mark: Boolean, - color: String, - plain: Boolean, - round: Boolean, - textColor: String - }, +export default sfc( + { + props: { + size: String, + type: String, + mark: Boolean, + color: String, + plain: Boolean, + round: Boolean, + textColor: String + }, - computed: { - style() { - const color = this.color || COLOR_MAP[this.type] || GRAY_DARK; - const key = this.plain ? 'color' : 'backgroundColor'; + render(h, context) { + const { props } = context; + const { mark, plain, round, size } = context.props; + + const color = props.color || COLOR_MAP[props.type] || GRAY_DARK; + const key = plain ? 'color' : 'backgroundColor'; const style = { [key]: color }; - if (this.textColor) { - style.color = this.textColor; + if (props.textColor) { + style.color = props.textColor; } - return style; + return ( + + {context.children} + + ); } }, - - render(h) { - const { - mark, - plain, - round, - size - } = this; - - return ( - - {this.$slots.default} - - ); - } -}); + true +); diff --git a/packages/utils/index.js b/packages/utils/index.js index 21a5d2ca1..d3c7d3549 100644 --- a/packages/utils/index.js +++ b/packages/utils/index.js @@ -4,6 +4,8 @@ export { use, useSlots } from './use'; export const isServer = Vue.prototype.$isServer; +export function noop() {} + export function isDef(value) { return value !== undefined && value !== null; }