2020-10-24 21:15:55 +08:00
|
|
|
import { flattenChildren } from '../_util/props-util';
|
2020-10-14 17:57:38 +08:00
|
|
|
import { App, computed, defineComponent, inject, PropType } from 'vue';
|
2020-09-30 12:11:23 +08:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
|
|
|
|
|
|
|
const Divider = defineComponent({
|
|
|
|
name: 'ADivider',
|
|
|
|
props: {
|
|
|
|
prefixCls: String,
|
|
|
|
type: {
|
|
|
|
type: String as PropType<'horizontal' | 'vertical' | ''>,
|
|
|
|
default: 'horizontal',
|
|
|
|
},
|
|
|
|
dashed: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
orientation: {
|
|
|
|
type: String as PropType<'left' | 'right' | 'center'>,
|
|
|
|
default: 'center',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const { getPrefixCls } = inject('configProvider', defaultConfigProvider);
|
|
|
|
const prefixCls = computed(() => getPrefixCls('divider', props.prefixCls));
|
|
|
|
|
|
|
|
const classString = computed(() => {
|
|
|
|
const { type, dashed, orientation } = props;
|
|
|
|
const orientationPrefix = orientation.length > 0 ? '-' + orientation : orientation;
|
2020-10-14 17:57:38 +08:00
|
|
|
const prefixClsRef = prefixCls.value;
|
2020-09-30 12:11:23 +08:00
|
|
|
return {
|
|
|
|
[prefixClsRef]: true,
|
|
|
|
[`${prefixClsRef}-${type}`]: true,
|
|
|
|
[`${prefixClsRef}-with-text${orientationPrefix}`]: slots.default,
|
|
|
|
[`${prefixClsRef}-dashed`]: !!dashed,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
2020-10-24 21:15:55 +08:00
|
|
|
const children = flattenChildren(slots.default?.());
|
2020-09-30 12:11:23 +08:00
|
|
|
return (
|
|
|
|
<div class={classString.value} role="separator">
|
2020-10-24 21:15:55 +08:00
|
|
|
{children.length ? <span class={`${prefixCls.value}-inner-text`}>{children}</span> : null}
|
2020-09-30 12:11:23 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
/* istanbul ignore next */
|
|
|
|
Divider.install = function(app: App) {
|
|
|
|
app.component(Divider.name, Divider);
|
2020-10-13 19:14:56 +08:00
|
|
|
return app;
|
2020-09-30 12:11:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Divider;
|