- {slots.default}
-
- {hasPrice && [
- {props.label || t('label')},
- {`${props.currency} ${(price / 100).toFixed(2)}`}
- ]}
-
-
+ return (
+
+ {slots.top && slots.top()}
+ {(slots.tip || tip) && (
+
+ {tip}
+ {slots.tip && slots.tip()}
+ )}
+
+ {slots.default && slots.default()}
+
+ {hasPrice && [
+ {props.label || t('label')},
+ {`${props.currency} ${(
+ price / 100
+ ).toFixed(2)}`}
+ ]}
+
+
- );
+
+ );
+}
+
+SubmitBar.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'
}
-});
+};
+
+export default sfc(SubmitBar);
diff --git a/packages/switch-cell/index.js b/packages/switch-cell/index.js
index 8da552669..367508ef1 100644
--- a/packages/switch-cell/index.js
+++ b/packages/switch-cell/index.js
@@ -2,31 +2,32 @@ import { use } from '../utils';
import { inherit } from '../utils/functional';
import Cell from '../cell';
import Switch from '../switch';
-import SwitchMixin from '../mixins/switch';
+import { switchProps } from '../switch/shared';
const [sfc, bem] = use('switch-cell');
-export default sfc({
- functional: true,
+function SwitchCell(h, props, slots, ctx) {
+ return (
+
+
+ |
+ );
+}
- mixins: [SwitchMixin],
-
- props: {
- title: String,
- border: Boolean,
- size: {
- type: String,
- default: '24px'
- }
- },
-
- render(h, context) {
- const { props } = context;
-
- return (
-
-
- |
- );
+SwitchCell.props = {
+ ...switchProps,
+ title: String,
+ border: Boolean,
+ size: {
+ type: String,
+ default: '24px'
}
-});
+};
+
+export default sfc(SwitchCell);
diff --git a/packages/switch/index.js b/packages/switch/index.js
index 07815f6dd..315cbdae7 100644
--- a/packages/switch/index.js
+++ b/packages/switch/index.js
@@ -1,11 +1,11 @@
import { use } from '../utils';
import Loading from '../loading';
-import SwitchMixin from '../mixins/switch';
+import { switchProps } from './shared';
const [sfc, bem] = use('switch');
export default sfc({
- mixins: [SwitchMixin],
+ props: switchProps,
methods: {
onClick() {
diff --git a/packages/switch/shared.ts b/packages/switch/shared.ts
new file mode 100644
index 000000000..c5443f849
--- /dev/null
+++ b/packages/switch/shared.ts
@@ -0,0 +1,23 @@
+/**
+ * Common Switch Props
+ */
+
+export const switchProps = {
+ value: null,
+ loading: Boolean,
+ disabled: Boolean,
+ activeColor: String,
+ inactiveColor: String,
+ activeValue: {
+ type: null,
+ default: true
+ },
+ inactiveValue: {
+ type: null,
+ default: false
+ },
+ size: {
+ type: String,
+ default: '30px'
+ }
+};
diff --git a/packages/tag/index.js b/packages/tag/index.js
index 18e5efc0b..82a703737 100644
--- a/packages/tag/index.js
+++ b/packages/tag/index.js
@@ -9,44 +9,41 @@ const COLOR_MAP = {
success: GREEN
};
-export default sfc({
- functional: true,
+function Tag(h, props, slots, ctx) {
+ const { mark, plain, round, size } = ctx.props;
- props: {
- size: String,
- type: String,
- mark: Boolean,
- color: String,
- plain: Boolean,
- round: Boolean,
- textColor: String
- },
+ const color = props.color || COLOR_MAP[props.type] || GRAY_DARK;
+ const key = plain ? 'color' : 'backgroundColor';
+ const style = { [key]: color };
- 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 (props.textColor) {
- style.color = props.textColor;
- }
-
- return (
-
- {context.children}
-
- );
+ if (props.textColor) {
+ style.color = props.textColor;
}
-});
+
+ return (
+
+ {slots.default && slots.default()}
+
+ );
+}
+
+Tag.props = {
+ size: String,
+ type: String,
+ mark: Boolean,
+ color: String,
+ plain: Boolean,
+ round: Boolean,
+ textColor: String
+};
+
+export default sfc(Tag);
diff --git a/packages/utils/functional.ts b/packages/utils/functional.ts
index adc91613b..3242d790d 100644
--- a/packages/utils/functional.ts
+++ b/packages/utils/functional.ts
@@ -1,5 +1,4 @@
import { RenderContext, VNodeData } from 'vue/types';
-import { ScopedSlot } from 'vue/types/vnode';
type ObjectIndex = {
[key: string]: any;
@@ -47,17 +46,3 @@ export function emit(context: Context, eventName: string, ...args: any[]) {
}
}
}
-
-// unify slots & scopedSlots
-export function unifySlots(context: Context) {
- const { scopedSlots } = context;
- const slots = context.slots();
-
- Object.keys(slots).forEach(key => {
- if (!scopedSlots[key]) {
- scopedSlots[key] = () => slots[key];
- }
- });
-
- return scopedSlots;
-}
diff --git a/packages/utils/use/sfc.ts b/packages/utils/use/sfc.ts
index ee38fd201..c1fc6be35 100644
--- a/packages/utils/use/sfc.ts
+++ b/packages/utils/use/sfc.ts
@@ -4,13 +4,29 @@
import '../../locale';
import { camelize } from '..';
import SlotsMixin from '../../mixins/slots';
-import Vue, { VueConstructor, ComponentOptions } from 'vue';
+import Vue, {
+ VueConstructor,
+ ComponentOptions,
+ CreateElement,
+ RenderContext
+} from 'vue/types';
+import { VNode, ScopedSlot } from 'vue/types/vnode';
type VantComponentOptions = ComponentOptions
& {
functional?: boolean;
install?: (Vue: VueConstructor) => void;
};
+type VantPureComponent = {
+ (
+ h: CreateElement,
+ props: { [key: string]: any },
+ slots: { [key: string]: ScopedSlot | undefined },
+ context: RenderContext
+ ): VNode;
+ props: any;
+};
+
const arrayProp = {
type: Array,
default: () => []
@@ -39,15 +55,46 @@ function install(this: ComponentOptions, Vue: VueConstructor) {
}
}
-export default (name: string) => (sfc: VantComponentOptions) => {
- sfc.name = name;
- sfc.install = install;
- sfc.mixins = sfc.mixins || [];
- sfc.mixins.push(SlotsMixin);
+// unify slots & scopedSlots
+export function unifySlots(context: RenderContext) {
+ const { scopedSlots } = context;
+ const slots = context.slots();
+
+ Object.keys(slots).forEach(key => {
+ if (!scopedSlots[key]) {
+ scopedSlots[key] = () => slots[key];
+ }
+ });
+
+ return scopedSlots;
+}
+
+function transformPureComponent(pure: VantPureComponent): VantComponentOptions {
+ return {
+ functional: true,
+ props: pure.props,
+ render: (h, context) => pure(h, context.props, unifySlots(context), context)
+ };
+}
+
+export default (name: string) => (
+ sfc: VantComponentOptions | VantPureComponent
+) => {
+ if (typeof sfc === 'function') {
+ sfc = transformPureComponent(sfc);
+ }
+
+ if (!sfc.functional) {
+ sfc.mixins = sfc.mixins || [];
+ sfc.mixins.push(SlotsMixin);
+ }
if (sfc.props) {
defaultProps(sfc.props);
}
+ sfc.name = name;
+ sfc.install = install;
+
return sfc;
};