[improvement] Row: jsx (#2620)

This commit is contained in:
neverland 2019-01-25 21:43:53 +08:00 committed by GitHub
parent 2d4da81401
commit eeb6893892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 48 deletions

39
packages/row/index.js Normal file
View File

@ -0,0 +1,39 @@
import { use } from '../utils';
const [sfc, bem] = use('row');
export default sfc({
props: {
type: String,
align: String,
justify: String,
tag: {
type: String,
default: 'div'
},
gutter: {
type: [Number, String],
default: 0
}
},
render(h) {
const { align, justify } = this;
const flex = this.type === 'flex';
const margin = `-${Number(this.gutter) / 2}px`;
const style = this.gutter ? { marginLeft: margin, marginRight: margin } : {};
return (
<this.tag
style={style}
class={bem({
flex,
[`align-${align}`]: flex && align,
[`justify-${justify}`]: flex && justify
})}
>
{this.$slots.default}
</this.tag>
);
}
});

View File

@ -1,48 +0,0 @@
<template>
<component
:is="tag"
:class="b({
flex,
[`align-${align}`]: flex && align,
[`justify-${justify}`]: flex && justify
})"
:style="style"
>
<slot />
</component>
</template>
<script>
import create from '../utils/create';
export default create({
name: 'row',
props: {
type: String,
align: String,
justify: String,
tag: {
type: String,
default: 'div'
},
gutter: {
type: [Number, String],
default: 0
}
},
computed: {
flex() {
return this.type === 'flex';
},
style() {
const margin = `-${Number(this.gutter) / 2}px`;
return this.gutter
? { marginLeft: margin, marginRight: margin }
: {};
}
}
});
</script>