From 6068f44a3faadfbf0630f8a430b80d290c3ffab9 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 26 Jan 2019 08:46:57 +0800 Subject: [PATCH] [improvement] Steps: jsx (#2623) --- packages/step/index.js | 46 +++++++++++++ packages/step/index.vue | 57 ---------------- packages/steps/index.js | 57 ++++++++++++++++ packages/steps/index.vue | 66 ------------------- .../test/__snapshots__/demo.spec.js.snap | 2 - 5 files changed, 103 insertions(+), 125 deletions(-) create mode 100644 packages/step/index.js delete mode 100644 packages/step/index.vue create mode 100644 packages/steps/index.js delete mode 100644 packages/steps/index.vue diff --git a/packages/step/index.js b/packages/step/index.js new file mode 100644 index 000000000..b883ace67 --- /dev/null +++ b/packages/step/index.js @@ -0,0 +1,46 @@ +import { use } from '../utils'; +import Icon from '../icon'; + +const [sfc, bem] = use('step'); + +export default sfc({ + beforeCreate() { + this.$parent.steps.push(this); + }, + + computed: { + status() { + const index = this.$parent.steps.indexOf(this); + const { active } = this.$parent; + + if (index < active) { + return 'finish'; + } + if (index === active) { + return 'process'; + } + } + }, + + render(h) { + const { status } = this; + const { activeColor, direction } = this.$parent; + const titleStyle = status === 'process' && { color: activeColor }; + + return ( +
+
+ {this.$slots.default} +
+
+ {status !== 'process' ? ( + + ) : ( + + )} +
+
+
+ ); + } +}); diff --git a/packages/step/index.vue b/packages/step/index.vue deleted file mode 100644 index 6d985a7a3..000000000 --- a/packages/step/index.vue +++ /dev/null @@ -1,57 +0,0 @@ - - - diff --git a/packages/steps/index.js b/packages/steps/index.js new file mode 100644 index 000000000..944bb0cb1 --- /dev/null +++ b/packages/steps/index.js @@ -0,0 +1,57 @@ +import { use } from '../utils'; +import { GREEN } from '../utils/color'; +import Icon from '../icon'; + +const [sfc, bem] = use('steps'); + +export default sfc({ + props: { + icon: String, + title: String, + active: Number, + iconClass: String, + description: String, + direction: { + type: String, + default: 'horizontal' + }, + activeColor: { + type: String, + default: GREEN + } + }, + + data() { + return { + steps: [] + }; + }, + + render(h) { + const { icon, title, description, $slots } = this; + + const StatusIcon = ($slots.icon || icon) && ( +
{$slots.icon || }
+ ); + + const StatusMessage = ( +
+
{title}
+
{description}
+
+ ); + + return ( +
+ {(title || description) && ( +
+ {StatusIcon} + {StatusMessage} + {$slots['message-extra']} +
+ )} +
{$slots.default}
+
+ ); + } +}); diff --git a/packages/steps/index.vue b/packages/steps/index.vue deleted file mode 100644 index b47c792f3..000000000 --- a/packages/steps/index.vue +++ /dev/null @@ -1,66 +0,0 @@ - - - diff --git a/packages/steps/test/__snapshots__/demo.spec.js.snap b/packages/steps/test/__snapshots__/demo.spec.js.snap index e186510ea..79dee2390 100644 --- a/packages/steps/test/__snapshots__/demo.spec.js.snap +++ b/packages/steps/test/__snapshots__/demo.spec.js.snap @@ -4,7 +4,6 @@ exports[`renders demo correctly 1`] = `
-
买家下单
@@ -32,7 +31,6 @@ exports[`renders demo correctly 1`] = `
-