functional: CellGroup, Icon, Info, Loading, GoodsAction (#2674)

This commit is contained in:
neverland 2019-02-02 11:33:22 +08:00 committed by GitHub
parent f0056297c6
commit 3c6c32e305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 141 additions and 109 deletions

View File

@ -2,7 +2,8 @@ import { use } from '../utils';
const [sfc, bem] = use('cell-group'); const [sfc, bem] = use('cell-group');
export default sfc({ export default sfc(
{
props: { props: {
border: { border: {
type: Boolean, type: Boolean,
@ -10,11 +11,16 @@ export default sfc({
} }
}, },
render(h) { render(h, context) {
return ( return (
<div class={[bem(), { 'van-hairline--top-bottom': this.border }]}> <div
{this.$slots.default} class={[bem(), { 'van-hairline--top-bottom': context.props.border }]}
{...context.data}
>
{context.children}
</div> </div>
); );
} }
}); },
true
);

View File

@ -2,8 +2,15 @@ import { use } from '../utils';
const [sfc, bem] = use('goods-action'); const [sfc, bem] = use('goods-action');
export default sfc({ export default sfc(
render(h) { {
return <div class={bem()}>{this.$slots.default}</div>; render(h, context) {
return (
<div class={bem()} {...context.data}>
{context.children}
</div>
);
} }
}); },
true
);

View File

@ -4,7 +4,8 @@ import isSrc from '../utils/validate/src';
const [sfc] = use('icon'); const [sfc] = use('icon');
export default sfc({ export default sfc(
{
props: { props: {
name: String, name: String,
size: String, size: String,
@ -16,29 +17,28 @@ export default sfc({
} }
}, },
computed: { render(h, context) {
isSrc() { const { props } = context;
return isSrc(this.name); const urlIcon = isSrc(props.name);
}
},
render(h) {
return ( return (
<i <i
class={[ class={[
this.classPrefix, props.classPrefix,
this.isSrc ? 'van-icon--image' : `${this.classPrefix}-${this.name}` urlIcon ? 'van-icon--image' : `${props.classPrefix}-${props.name}`
]} ]}
style={{ style={{
color: this.color, color: props.color,
fontSize: this.size fontSize: props.size
}} }}
{...{ on: this.$listeners }} {...context.data}
> >
{this.$slots.default} {context.children}
{this.isSrc && <img src={this.name} />} {urlIcon && <img src={props.name} />}
<Info info={this.info} /> <Info info={props.info} />
</i> </i>
); );
} }
}); },
true
);

View File

@ -2,12 +2,21 @@ import { use, isDef } from '../utils';
const [sfc, bem] = use('info'); const [sfc, bem] = use('info');
export default sfc({ export default sfc(
{
props: { props: {
info: [String, Number] info: [String, Number]
}, },
render(h) { render(h, { props, data }) {
return isDef(this.info) && <div class={bem()}>{this.info}</div>; return (
isDef(props.info) && (
<div class={bem()} {...data}>
{props.info}
</div>
)
);
} }
}); },
true
);

View File

@ -3,7 +3,8 @@ import { use } from '../utils';
const [sfc, bem] = use('loading'); const [sfc, bem] = use('loading');
const DEFAULT_COLOR = '#c9c9c9'; const DEFAULT_COLOR = '#c9c9c9';
export default sfc({ export default sfc(
{
props: { props: {
size: String, size: String,
type: { type: {
@ -16,8 +17,8 @@ export default sfc({
} }
}, },
render(h) { render(h, context) {
const { color, size, type } = this; const { color, size, type } = context.props;
const colorType = color === 'white' || color === 'black' ? color : ''; const colorType = color === 'white' || color === 'black' ? color : '';
@ -41,7 +42,7 @@ export default sfc({
); );
return ( return (
<div class={bem([type, colorType])} style={style}> <div class={bem([type, colorType])} style={style} {...context.data}>
<span class={bem('spinner', type)}> <span class={bem('spinner', type)}>
{Spin} {Spin}
{Circular} {Circular}
@ -49,4 +50,6 @@ export default sfc({
</div> </div>
); );
} }
}); },
true
);

View File

@ -30,10 +30,17 @@ function install(Vue) {
Vue.component((camelize(`-${name}`)), this); Vue.component((camelize(`-${name}`)), this);
} }
export default name => sfc => { export default name => (sfc, functional) => {
sfc.name = name; sfc.name = name;
sfc.install = install; sfc.install = install;
sfc.props && defaultProps(sfc.props);
if (sfc.props) {
defaultProps(sfc.props);
}
if (functional) {
sfc.functional = true;
}
return sfc; return sfc;
}; };