types(Layout): use tsx

This commit is contained in:
chenjiahan
2020-09-21 18:42:40 +08:00
parent 5359120ed3
commit 4c468ffd74
2 changed files with 43 additions and 19 deletions
+53
View File
@@ -0,0 +1,53 @@
import { computed, PropType } from 'vue';
import { createNamespace } from '../utils';
import { useParent } from '../composition/use-relation';
import { ROW_KEY, RowProvide } from '../row';
const [createComponent, bem] = createNamespace('col');
export default createComponent({
props: {
offset: [Number, String],
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'div',
},
span: {
type: [Number, String],
default: 0,
},
},
setup(props, { slots }) {
const { parent, index } = useParent<RowProvide>(ROW_KEY, () => +props.span);
const style = computed(() => {
if (!parent) {
return;
}
const { spaces } = parent;
if (spaces && spaces.value && spaces.value[index!.value]) {
const { left, right } = spaces.value[index!.value];
return {
paddingLeft: left ? `${left}px` : null,
paddingRight: right ? `${right}px` : null,
};
}
});
return () => {
const { tag, span, offset } = props;
return (
<tag
style={style.value}
class={bem({ [span]: span, [`offset-${offset}`]: offset })}
>
{slots.default?.()}
</tag>
);
};
},
});