-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdivider.tsx
More file actions
executable file
·59 lines (55 loc) · 1.63 KB
/
divider.tsx
File metadata and controls
executable file
·59 lines (55 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { DividerProps } from './types';
const Divider = React.memo(React.forwardRef<HTMLDivElement, DividerProps>((props, ref) => {
const {
orientation = 'horizontal',
variant = 'solid',
titlePlacement = 'center',
plain = false,
titleGap,
prefixCls: customisedCls,
className,
children,
style,
...otherProps
} = props;
const configContext = useContext(ConfigContext);
const prefixCls = getPrefixCls('divider', configContext.prefixCls, customisedCls);
const hasChildren = children !== null && children !== undefined;
const hasInnerText = orientation === 'horizontal' && hasChildren;
const cls = classNames(
prefixCls,
className,
`${prefixCls}_${orientation}`,
`${prefixCls}_${variant}`,
hasInnerText && `${prefixCls}_${titlePlacement}`,
{
[`${prefixCls}_text`]: hasInnerText,
[`${prefixCls}_plain`]: plain,
},
);
const mergedStyle = hasInnerText && titleGap !== undefined
? {
...style,
['--ty-divider-title-gap' as string]:
typeof titleGap === 'number' ? `${titleGap}px` : titleGap,
}
: style;
return (
<div
{...otherProps}
ref={ref}
role="separator"
aria-orientation={orientation}
className={cls}
style={mergedStyle}
>
{hasInnerText && <span className={`${prefixCls}_inner-text`}>{children}</span>}
</div>
);
}));
Divider.displayName = 'Divider';
export default Divider;