diff --git a/src/goods-action-button/index.js b/src/goods-action-button/index.js new file mode 100644 index 000000000..dc905122b --- /dev/null +++ b/src/goods-action-button/index.js @@ -0,0 +1,59 @@ +import { createNamespace } from '../utils'; +import { route, routeProps } from '../utils/router'; +import { ChildrenMixin } from '../mixins/relation'; +import Button from '../button'; + +const [createComponent, bem] = createNamespace('goods-action-button'); + +export default createComponent({ + mixins: [ChildrenMixin('vanGoodsAction')], + + props: { + ...routeProps, + type: String, + text: String, + loading: Boolean, + disabled: Boolean + }, + + computed: { + isFirst() { + const prev = this.parent && this.parent.children[this.index - 1]; + return !prev || prev.$options.name !== this.$options.name; + }, + + isLast() { + const next = this.parent && this.parent.children[this.index + 1]; + return !next || next.$options.name !== this.$options.name; + } + }, + + methods: { + onClick(event) { + this.$emit('click', event); + route(this.$router, this); + } + }, + + render(h) { + return ( + + ); + } +}); diff --git a/src/goods-action-button/index.less b/src/goods-action-button/index.less index f2e023870..dba89109d 100644 --- a/src/goods-action-button/index.less +++ b/src/goods-action-button/index.less @@ -2,8 +2,33 @@ .van-goods-action-button { flex: 1; + height: 36px; + font-weight: 500; + font-size: @font-size-md; + line-height: 34px; + border: none; + + &--first { + margin-left: 5px; + border-top-left-radius: 18px; + border-bottom-left-radius: 18px; + } + + &--last { + margin-right: 5px; + border-top-right-radius: 18px; + border-bottom-right-radius: 18px; + } + + &--warning { + background: linear-gradient(to right, #ffd01e, #ff8917); + } + + &--danger { + background: linear-gradient(to right, #ff6034, #ee0a24); + } @media (max-width: 321px) { - font-size: 15px; + font-size: 13px; } } diff --git a/src/goods-action-button/index.tsx b/src/goods-action-button/index.tsx deleted file mode 100644 index aa149994c..000000000 --- a/src/goods-action-button/index.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { createNamespace } from '../utils'; -import Button, { ButtonType, ButtonEvents } from '../button'; -import { emit, inherit } from '../utils/functional'; -import { functionalRoute, routeProps, RouteProps } from '../utils/router'; - -// Types -import { CreateElement, RenderContext } from 'vue/types'; -import { DefaultSlots } from '../utils/types'; - -export type GoodsActionButtonProps = RouteProps & { - text?: string; - type?: ButtonType; - primary?: boolean; - loading?: boolean; - disabled?: boolean; -}; - -const [createComponent, bem] = createNamespace('goods-action-button'); - -function GoodsActionButton( - h: CreateElement, - props: GoodsActionButtonProps, - slots: DefaultSlots, - ctx: RenderContext -) { - function onClick(event: Event) { - emit(ctx, 'click', event); - functionalRoute(ctx); - } - - return ( - - ); -} - -GoodsActionButton.props = { - ...routeProps, - type: String, - text: String, - loading: Boolean, - disabled: Boolean -}; - -export default createComponent(GoodsActionButton); diff --git a/src/goods-action-icon/index.js b/src/goods-action-icon/index.js new file mode 100644 index 000000000..f30699157 --- /dev/null +++ b/src/goods-action-icon/index.js @@ -0,0 +1,43 @@ +import { createNamespace } from '../utils'; +import { route, routeProps } from '../utils/router'; +import { ChildrenMixin } from '../mixins/relation'; +import Icon from '../icon'; + +const [createComponent, bem] = createNamespace('goods-action-icon'); + +export default createComponent({ + mixins: [ChildrenMixin('vanGoodsAction')], + + props: { + ...routeProps, + text: String, + icon: String, + info: [Number, String], + iconClass: null + }, + + methods: { + onClick(event) { + this.$emit('click', event); + route(this.$router, this); + } + }, + + render(h) { + return ( +
+ {this.slots('icon') ? ( +
{this.slots('icon')}
+ ) : ( + + )} + {this.slots() || this.text} +
+ ); + } +}); diff --git a/src/goods-action-icon/index.tsx b/src/goods-action-icon/index.tsx deleted file mode 100644 index 57877072c..000000000 --- a/src/goods-action-icon/index.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { createNamespace } from '../utils'; -import Icon, { IconEvents } from '../icon'; -import { emit, inherit } from '../utils/functional'; -import { functionalRoute, routeProps, RouteProps } from '../utils/router'; - -// Types -import { CreateElement, RenderContext } from 'vue/types'; -import { DefaultSlots, ScopedSlot } from '../utils/types'; - -export type GoodsActionIconProps = RouteProps & { - icon: string; - text?: string; - info?: string | number; - iconClass?: any; -}; - -export type GoodsActionIconSlots = DefaultSlots & { - icon?: ScopedSlot; -}; - -const [createComponent, bem] = createNamespace('goods-action-icon'); - -function GoodsActionIcon( - h: CreateElement, - props: GoodsActionIconProps, - slots: GoodsActionIconSlots, - ctx: RenderContext -) { - function onClick(event: Event) { - emit(ctx, 'click', event); - functionalRoute(ctx); - } - - return ( -
- {slots.icon ? ( -
{slots.icon()}
- ) : ( - - )} - {slots.default ? slots.default() : props.text} -
- ); -} - -GoodsActionIcon.props = { - ...routeProps, - text: String, - icon: String, - info: [Number, String], - iconClass: null as any -}; - -export default createComponent(GoodsActionIcon); diff --git a/src/goods-action/index.js b/src/goods-action/index.js new file mode 100644 index 000000000..38574af2f --- /dev/null +++ b/src/goods-action/index.js @@ -0,0 +1,20 @@ +import { createNamespace } from '../utils'; +import { ParentMixin } from '../mixins/relation'; + +const [createComponent, bem] = createNamespace('goods-action'); + +export default createComponent({ + mixins: [ParentMixin('vanGoodsAction')], + + props: { + safeAreaInsetBottom: Boolean + }, + + render(h) { + return ( +
+ {this.slots()} +
+ ); + } +}); diff --git a/src/goods-action/index.less b/src/goods-action/index.less index 7ecc676cf..460b52c15 100644 --- a/src/goods-action/index.less +++ b/src/goods-action/index.less @@ -6,6 +6,7 @@ bottom: 0; left: 0; display: flex; + align-items: center; background-color: @goods-action-background-color; &--safe-area-inset-bottom { diff --git a/src/goods-action/index.tsx b/src/goods-action/index.tsx deleted file mode 100644 index 6b8d063da..000000000 --- a/src/goods-action/index.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { createNamespace } from '../utils'; -import { inherit } from '../utils/functional'; - -// Types -import { CreateElement, RenderContext } from 'vue/types'; -import { DefaultSlots } from '../utils/types'; - -export type GoodsActionProps = { - safeAreaInsetBottom?: boolean; -}; - -const [createComponent, bem] = createNamespace('goods-action'); - -function GoodsAction( - h: CreateElement, - props: GoodsActionProps, - slots: DefaultSlots, - ctx: RenderContext -) { - return ( -
- {slots.default && slots.default()} -
- ); -} - -GoodsAction.props = { - safeAreaInsetBottom: Boolean -}; - -export default createComponent(GoodsAction); diff --git a/src/goods-action/test/__snapshots__/demo.spec.js.snap b/src/goods-action/test/__snapshots__/demo.spec.js.snap index 65bb28287..1dfc42768 100644 --- a/src/goods-action/test/__snapshots__/demo.spec.js.snap +++ b/src/goods-action/test/__snapshots__/demo.spec.js.snap @@ -13,7 +13,7 @@ exports[`renders demo correctly 1`] = `
购物车 - +
@@ -32,7 +32,7 @@ exports[`renders demo correctly 1`] = `
店铺 -
+ diff --git a/src/goods-action/test/__snapshots__/index.spec.js.snap b/src/goods-action/test/__snapshots__/index.spec.js.snap index d60b67aff..fdaef8b25 100644 --- a/src/goods-action/test/__snapshots__/index.spec.js.snap +++ b/src/goods-action/test/__snapshots__/index.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Button render default slot 1`] = ``; +exports[`Button render default slot 1`] = ``; exports[`Icon render default slot 1`] = `
diff --git a/src/goods-action/test/index.spec.js b/src/goods-action/test/index.spec.js index a93294be7..20ff21ec5 100644 --- a/src/goods-action/test/index.spec.js +++ b/src/goods-action/test/index.spec.js @@ -3,31 +3,15 @@ import Icon from '../../goods-action-icon'; import { mount } from '../../../test/utils'; test('Button click event', () => { - const click = jest.fn(); - const wrapper = mount(Button, { - context: { - on: { - click - } - } - }); - + const wrapper = mount(Button); wrapper.trigger('click'); - expect(click).toHaveBeenCalledTimes(1); + expect(wrapper.emitted('click').length).toEqual(1); }); test('Icon click event', () => { - const click = jest.fn(); - const wrapper = mount(Icon, { - context: { - on: { - click - } - } - }); - + const wrapper = mount(Icon); wrapper.trigger('click'); - expect(click).toHaveBeenCalledTimes(1); + expect(wrapper.emitted('click').length).toEqual(1); }); test('Button render default slot', () => {