2020-10-24 21:15:55 +08:00
|
|
|
import { flattenChildren } from '../_util/props-util';
|
2021-06-26 09:35:40 +08:00
|
|
|
import type { ExtractPropTypes, PropType } from 'vue';
|
2022-03-12 09:56:32 +08:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2020-11-01 15:03:33 +08:00
|
|
|
import { withInstall } from '../_util/type';
|
2023-01-27 16:00:17 +08:00
|
|
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
2020-09-30 12:11:23 +08:00
|
|
|
|
2022-03-26 22:52:54 +08:00
|
|
|
export const dividerProps = () => ({
|
2021-06-07 17:35:03 +08:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
plain: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-03-12 09:56:32 +08:00
|
|
|
orientationMargin: [String, Number],
|
2022-03-26 22:52:54 +08:00
|
|
|
});
|
|
|
|
export type DividerProps = Partial<ExtractPropTypes<ReturnType<typeof dividerProps>>>;
|
2021-06-07 17:35:03 +08:00
|
|
|
|
2020-09-30 12:11:23 +08:00
|
|
|
const Divider = defineComponent({
|
2022-09-26 21:33:41 +08:00
|
|
|
compatConfig: { MODE: 3 },
|
2020-09-30 12:11:23 +08:00
|
|
|
name: 'ADivider',
|
2022-03-26 22:52:54 +08:00
|
|
|
props: dividerProps(),
|
2020-09-30 12:11:23 +08:00
|
|
|
setup(props, { slots }) {
|
2022-03-12 09:56:32 +08:00
|
|
|
const { prefixCls: prefixClsRef, direction } = useConfigInject('divider', props);
|
|
|
|
const hasCustomMarginLeft = computed(
|
|
|
|
() => props.orientation === 'left' && props.orientationMargin != null,
|
|
|
|
);
|
|
|
|
const hasCustomMarginRight = computed(
|
|
|
|
() => props.orientation === 'right' && props.orientationMargin != null,
|
|
|
|
);
|
2020-09-30 12:11:23 +08:00
|
|
|
const classString = computed(() => {
|
2021-06-07 17:35:03 +08:00
|
|
|
const { type, dashed, plain } = props;
|
|
|
|
const prefixCls = prefixClsRef.value;
|
2020-09-30 12:11:23 +08:00
|
|
|
return {
|
2021-06-07 17:35:03 +08:00
|
|
|
[prefixCls]: true,
|
|
|
|
[`${prefixCls}-${type}`]: true,
|
|
|
|
[`${prefixCls}-dashed`]: !!dashed,
|
|
|
|
[`${prefixCls}-plain`]: !!plain,
|
2022-03-12 09:56:32 +08:00
|
|
|
[`${prefixCls}-rtl`]: direction.value === 'rtl',
|
|
|
|
[`${prefixCls}-no-default-orientation-margin-left`]: hasCustomMarginLeft.value,
|
|
|
|
[`${prefixCls}-no-default-orientation-margin-right`]: hasCustomMarginRight.value,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const innerStyle = computed(() => {
|
|
|
|
const marginValue =
|
|
|
|
typeof props.orientationMargin === 'number'
|
|
|
|
? `${props.orientationMargin}px`
|
|
|
|
: props.orientationMargin;
|
|
|
|
return {
|
|
|
|
...(hasCustomMarginLeft.value && { marginLeft: marginValue }),
|
|
|
|
...(hasCustomMarginRight.value && { marginRight: marginValue }),
|
2020-09-30 12:11:23 +08:00
|
|
|
};
|
|
|
|
});
|
2021-06-07 17:35:03 +08:00
|
|
|
const orientationPrefix = computed(() =>
|
|
|
|
props.orientation.length > 0 ? '-' + props.orientation : props.orientation,
|
|
|
|
);
|
|
|
|
|
2020-09-30 12:11:23 +08:00
|
|
|
return () => {
|
2020-10-24 21:15:55 +08:00
|
|
|
const children = flattenChildren(slots.default?.());
|
2020-09-30 12:11:23 +08:00
|
|
|
return (
|
2021-06-07 17:35:03 +08:00
|
|
|
<div
|
|
|
|
class={[
|
|
|
|
classString.value,
|
|
|
|
children.length
|
|
|
|
? `${prefixClsRef.value}-with-text ${prefixClsRef.value}-with-text${orientationPrefix.value}`
|
|
|
|
: '',
|
|
|
|
]}
|
|
|
|
role="separator"
|
|
|
|
>
|
|
|
|
{children.length ? (
|
2022-03-12 09:56:32 +08:00
|
|
|
<span class={`${prefixClsRef.value}-inner-text`} style={innerStyle.value}>
|
|
|
|
{children}
|
|
|
|
</span>
|
2021-06-07 17:35:03 +08:00
|
|
|
) : null}
|
2020-09-30 12:11:23 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-11-01 15:03:33 +08:00
|
|
|
export default withInstall(Divider);
|