diff --git a/packages/button/index.js b/packages/button/index.js index 11944c04e..f8f824d38 100644 --- a/packages/button/index.js +++ b/packages/button/index.js @@ -3,70 +3,69 @@ import Loading from '../loading'; const [sfc, bem] = use('button'); -export default sfc( - { - props: { - text: String, - block: Boolean, - plain: Boolean, - round: Boolean, - square: Boolean, - loading: Boolean, - disabled: Boolean, - nativeType: String, - bottomAction: Boolean, - tag: { - type: String, - default: 'button' - }, - type: { - type: String, - default: 'default' - }, - size: { - type: String, - default: 'normal' - } +export default sfc({ + functional: true, + + props: { + text: String, + block: Boolean, + plain: Boolean, + round: Boolean, + square: Boolean, + loading: Boolean, + disabled: Boolean, + nativeType: String, + bottomAction: Boolean, + tag: { + type: String, + default: 'button' }, - - render(h, context, inherit) { - const { props, listeners } = context; - const { type, disabled, loading } = props; - - const onClick = event => { - if (!loading && !disabled && listeners.click) { - listeners.click(event); - } - }; - - return ( - - {loading ? ( - - ) : ( - {context.children || props.text} - )} - - ); + type: { + type: String, + default: 'default' + }, + size: { + type: String, + default: 'normal' } }, - true -); + + render(h, context, inherit) { + const { props, listeners } = context; + const { type, disabled, loading } = props; + + const onClick = event => { + if (!loading && !disabled && listeners.click) { + listeners.click(event); + } + }; + + return ( + + {loading ? ( + + ) : ( + {context.children || props.text} + )} + + ); + } +}); diff --git a/packages/cell-group/index.js b/packages/cell-group/index.js index d1a39d2c9..e80a2d503 100644 --- a/packages/cell-group/index.js +++ b/packages/cell-group/index.js @@ -2,25 +2,21 @@ import { use } from '../utils'; const [sfc, bem] = use('cell-group'); -export default sfc( - { - props: { - border: { - type: Boolean, - default: true - } - }, +export default sfc({ + functional: true, - render(h, context) { - return ( -
- {context.children} -
- ); + props: { + border: { + type: Boolean, + default: true } }, - true -); + + render(h, context) { + return ( +
+ {context.children} +
+ ); + } +}); diff --git a/packages/contact-list/index.js b/packages/contact-list/index.js index e3bc0cd2f..3b5ecaed7 100644 --- a/packages/contact-list/index.js +++ b/packages/contact-list/index.js @@ -7,57 +7,56 @@ 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({ + functional: true, - render(h, context, inherit) { - const { props, listeners } = context; - - const List = props.list.map((item, index) => ( - { - listeners.input && listeners.input(item.id); - listeners.select && listeners.select(item, index); - }} - > - -
{`${item.name},${item.tel}`}
-
- { - event.stopPropagation(); - listeners.edit && listeners.edit(item, index); - }} - /> -
- )); - - return ( -
- - {List} - -
- ); - } + props: { + value: null, + list: Array, + addText: String }, - true -); + + render(h, context, inherit) { + const { props, listeners } = context; + + const List = props.list.map((item, index) => ( + { + listeners.input && listeners.input(item.id); + listeners.select && listeners.select(item, index); + }} + > + +
{`${item.name},${item.tel}`}
+
+ { + event.stopPropagation(); + listeners.edit && listeners.edit(item, index); + }} + /> +
+ )); + + return ( +
+ + {List} + +
+ ); + } +}); diff --git a/packages/goods-action/index.js b/packages/goods-action/index.js index d997bfe5f..d201ad9a7 100644 --- a/packages/goods-action/index.js +++ b/packages/goods-action/index.js @@ -2,15 +2,14 @@ import { use } from '../utils'; const [sfc, bem] = use('goods-action'); -export default sfc( - { - render(h, context) { - return ( -
- {context.children} -
- ); - } - }, - true -); +export default sfc({ + functional: true, + + render(h, context) { + return ( +
+ {context.children} +
+ ); + } +}); diff --git a/packages/icon/index.js b/packages/icon/index.js index b0b6a4ade..d7d7b9ec2 100644 --- a/packages/icon/index.js +++ b/packages/icon/index.js @@ -4,41 +4,40 @@ import isSrc from '../utils/validate/src'; const [sfc] = use('icon'); -export default sfc( - { - props: { - name: String, - size: String, - color: String, - info: [String, Number], - classPrefix: { - type: String, - default: 'van-icon' - } - }, +export default sfc({ + functional: true, - render(h, context) { - const { props } = context; - const urlIcon = isSrc(props.name); - - return ( - - {context.children} - {urlIcon && } - - - ); + props: { + name: String, + size: String, + color: String, + info: [String, Number], + classPrefix: { + type: String, + default: 'van-icon' } }, - true -); + + render(h, context) { + const { props } = context; + const urlIcon = isSrc(props.name); + + return ( + + {context.children} + {urlIcon && } + + + ); + } +}); diff --git a/packages/info/index.js b/packages/info/index.js index e8bb3b5e6..e98c33bad 100644 --- a/packages/info/index.js +++ b/packages/info/index.js @@ -2,21 +2,20 @@ import { use, isDef } from '../utils'; const [sfc, bem] = use('info'); -export default sfc( - { - props: { - info: [String, Number] - }, +export default sfc({ + functional: true, - render(h, { props, data }) { - return ( - isDef(props.info) && ( -
- {props.info} -
- ) - ); - } + props: { + info: [String, Number] }, - true -); + + render(h, { props, data }) { + return ( + isDef(props.info) && ( +
+ {props.info} +
+ ) + ); + } +}); diff --git a/packages/loading/index.js b/packages/loading/index.js index f11dd9027..9c038242a 100644 --- a/packages/loading/index.js +++ b/packages/loading/index.js @@ -3,53 +3,52 @@ import { use } from '../utils'; const [sfc, bem] = use('loading'); const DEFAULT_COLOR = '#c9c9c9'; -export default sfc( - { - props: { - size: String, - type: { - type: String, - default: 'circular' - }, - color: { - type: String, - default: DEFAULT_COLOR - } +export default sfc({ + functional: true, + + props: { + size: String, + type: { + type: String, + default: 'circular' }, - - render(h, context) { - const { color, size, type } = context.props; - - const colorType = color === 'white' || color === 'black' ? color : ''; - - const style = { - color: color === 'black' ? DEFAULT_COLOR : color, - width: size, - height: size - }; - - const Spin = []; - if (type === 'spinner') { - for (let i = 0; i < 12; i++) { - Spin.push(); - } - } - - const Circular = type === 'circular' && ( - - - - ); - - return ( -
- - {Spin} - {Circular} - -
- ); + color: { + type: String, + default: DEFAULT_COLOR } }, - true -); + + render(h, context) { + const { color, size, type } = context.props; + + const colorType = color === 'white' || color === 'black' ? color : ''; + + const style = { + color: color === 'black' ? DEFAULT_COLOR : color, + width: size, + height: size + }; + + const Spin = []; + if (type === 'spinner') { + for (let i = 0; i < 12; i++) { + Spin.push(); + } + } + + const Circular = type === 'circular' && ( + + + + ); + + return ( +
+ + {Spin} + {Circular} + +
+ ); + } +}); diff --git a/packages/nav-bar/index.js b/packages/nav-bar/index.js index 945738627..bc2f04089 100644 --- a/packages/nav-bar/index.js +++ b/packages/nav-bar/index.js @@ -3,53 +3,46 @@ 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 - }, - zIndex: { - type: Number, - default: 1 - } +export default sfc({ + functional: true, + + props: { + title: String, + fixed: Boolean, + leftText: String, + rightText: String, + leftArrow: Boolean, + border: { + type: Boolean, + default: true }, - - render(h, context, inherit) { - 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})} -
-
- ); + zIndex: { + type: Number, + default: 1 } }, - true -); + + render(h, context, inherit) { + 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})} +
+
+ ); + } +}); diff --git a/packages/panel/index.js b/packages/panel/index.js index a0c03c61d..9251fcafb 100644 --- a/packages/panel/index.js +++ b/packages/panel/index.js @@ -4,35 +4,34 @@ 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({ + functional: true, - render(h, context) { - const { props } = context; - const slots = context.slots(); - - return ( - - {slots.header || ( - - )} -
{slots.default}
- {slots.footer &&
{slots.footer}
} -
- ); - } + props: { + icon: String, + desc: String, + title: String, + status: String }, - true -); + + render(h, context) { + const { props } = context; + const slots = context.slots(); + + return ( + + {slots.header || ( + + )} +
{slots.default}
+ {slots.footer &&
{slots.footer}
} +
+ ); + } +}); diff --git a/packages/password-input/index.js b/packages/password-input/index.js index 147a498e8..5a109c356 100644 --- a/packages/password-input/index.js +++ b/packages/password-input/index.js @@ -2,50 +2,49 @@ import { use } from '../utils'; const [sfc, bem] = use('password-input'); -export default sfc( - { - props: { - info: String, - errorInfo: String, - value: { - type: String, - default: '' - }, - length: { - type: Number, - default: 6 - } +export default sfc({ + functional: true, + + props: { + info: String, + errorInfo: String, + value: { + type: String, + default: '' }, - - render(h, context) { - const { props, listeners } = context; - const info = props.errorInfo || props.info; - - const Points = []; - for (let i = 0; i < props.length; i++) { - Points.push( -
  • - -
  • - ); - } - - return ( -
    -
      { - event.stopPropagation(); - listeners.focus && listeners.focus(); - }} - {...context.data} - > - {Points} -
    - {info &&
    {info}
    } -
    - ); + length: { + type: Number, + default: 6 } }, - true -); + + render(h, context) { + const { props, listeners } = context; + const info = props.errorInfo || props.info; + + const Points = []; + for (let i = 0; i < props.length; i++) { + Points.push( +
  • + +
  • + ); + } + + return ( +
    +
      { + event.stopPropagation(); + listeners.focus && listeners.focus(); + }} + {...context.data} + > + {Points} +
    + {info &&
    {info}
    } +
    + ); + } +}); diff --git a/packages/submit-bar/index.js b/packages/submit-bar/index.js index eeb6bd1ae..7210fc77b 100644 --- a/packages/submit-bar/index.js +++ b/packages/submit-bar/index.js @@ -3,64 +3,63 @@ 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 - }, - currency: { - type: String, - default: '¥' - }, - buttonType: { - type: String, - default: 'danger' - } +export default sfc({ + functional: true, + + props: { + tip: String, + label: String, + loading: Boolean, + disabled: Boolean, + buttonText: String, + price: { + type: Number, + default: null }, - - render(h, context, inherit) { - 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)}`} - ]} -
    -
    -
    - ); + currency: { + type: String, + default: '¥' + }, + buttonType: { + type: String, + default: 'danger' } }, - true -); + + render(h, context, inherit) { + 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)}`} + ]} +
    +
    +
    + ); + } +}); diff --git a/packages/switch-cell/index.js b/packages/switch-cell/index.js index 8533b7e09..4db47370f 100644 --- a/packages/switch-cell/index.js +++ b/packages/switch-cell/index.js @@ -5,34 +5,27 @@ import SwitchMixin from '../mixins/switch'; const [sfc, bem] = use('switch-cell'); -export default sfc( - { - mixins: [SwitchMixin], +export default sfc({ + functional: true, - props: { - title: String, - border: Boolean, - size: { - type: String, - default: '24px' - } - }, + mixins: [SwitchMixin], - render(h, context, inherit) { - const { props } = context; - - return ( - - - - ); + props: { + title: String, + border: Boolean, + size: { + type: String, + default: '24px' } }, - true -); + + render(h, context, inherit) { + const { props } = context; + + return ( + + + + ); + } +}); diff --git a/packages/tag/index.js b/packages/tag/index.js index 51d433534..18e5efc0b 100644 --- a/packages/tag/index.js +++ b/packages/tag/index.js @@ -9,45 +9,44 @@ 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({ + functional: true, - 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} - - ); - } + props: { + size: String, + type: String, + mark: Boolean, + color: String, + plain: Boolean, + round: Boolean, + textColor: String }, - true -); + + 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} + + ); + } +}); diff --git a/packages/utils/use/sfc.js b/packages/utils/use/sfc.js index 183a392b7..10ea2dfbe 100644 --- a/packages/utils/use/sfc.js +++ b/packages/utils/use/sfc.js @@ -36,7 +36,6 @@ const mapInheritKey = { nativeOn: 'on' }; function functional(sfc) { const { render } = sfc; - sfc.functional = true; sfc.render = (h, context) => { const inherit = inheritKey.reduce((obj, key) => { if (context.data[key]) { @@ -48,7 +47,7 @@ function functional(sfc) { }; } -export default name => (sfc, isFunctional) => { +export default name => sfc => { sfc.name = name; sfc.install = install; sfc.mixins = sfc.mixins || []; @@ -58,7 +57,7 @@ export default name => (sfc, isFunctional) => { defaultProps(sfc.props); } - if (isFunctional) { + if (sfc.functional) { functional(sfc); }