This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
import * as React from 'react';
import type { Orientation, SemanticClassNamesType, SemanticStylesType } from '../_util/hooks';
import type { SizeType } from '../config-provider/SizeContext';
export type TitlePlacement = 'left' | 'right' | 'center' | 'start' | 'end';
export type DividerSemanticName = keyof DividerSemanticClassNames & keyof DividerSemanticStyles;
export type DividerSemanticClassNames = {
root?: string;
rail?: string;
content?: string;
};
export type DividerSemanticStyles = {
root?: React.CSSProperties;
rail?: React.CSSProperties;
content?: React.CSSProperties;
};
export type DividerClassNamesType = SemanticClassNamesType<DividerProps, DividerSemanticClassNames>;
export type DividerStylesType = SemanticStylesType<DividerProps, DividerSemanticStyles>;
export interface DividerProps {
prefixCls?: string;
/** @deprecated please use `orientation`*/
type?: Orientation;
orientation?: Orientation;
vertical?: boolean;
titlePlacement?: TitlePlacement;
/** @deprecated please use `styles.content.margin` */
orientationMargin?: string | number;
className?: string;
rootClassName?: string;
children?: React.ReactNode;
dashed?: boolean;
/**
* @since 5.20.0
* @default solid
*/
variant?: 'dashed' | 'dotted' | 'solid';
style?: React.CSSProperties;
size?: SizeType;
plain?: boolean;
classNames?: DividerClassNamesType;
styles?: DividerStylesType;
}
declare const Divider: React.FC<DividerProps>;
export default Divider;
+132
View File
@@ -0,0 +1,132 @@
"use client";
import * as React from 'react';
import { clsx } from 'clsx';
import { useMergeSemantic, useOrientation } from '../_util/hooks';
import { isNumber } from '../_util/is';
import { devUseWarning } from '../_util/warning';
import { useComponentConfig } from '../config-provider/context';
import useSize from '../config-provider/hooks/useSize';
import useStyle from './style';
const titlePlacementList = ['left', 'right', 'center', 'start', 'end'];
const Divider = props => {
const {
getPrefixCls,
direction,
className: contextClassName,
style: contextStyle,
classNames: contextClassNames,
styles: contextStyles
} = useComponentConfig('divider');
const {
prefixCls: customizePrefixCls,
type,
orientation,
vertical,
titlePlacement,
orientationMargin,
className,
rootClassName,
children,
dashed,
variant = 'solid',
plain,
style,
size: customSize,
classNames,
styles,
...restProps
} = props;
const prefixCls = getPrefixCls('divider', customizePrefixCls);
const railCls = `${prefixCls}-rail`;
const [hashId, cssVarCls] = useStyle(prefixCls);
const sizeFullName = useSize(customSize);
const hasChildren = !!children;
const validTitlePlacement = titlePlacementList.includes(orientation || '');
const mergedTitlePlacement = React.useMemo(() => {
const placement = titlePlacement ?? (validTitlePlacement ? orientation : 'center');
if (placement === 'left') {
return direction === 'rtl' ? 'end' : 'start';
}
if (placement === 'right') {
return direction === 'rtl' ? 'start' : 'end';
}
return placement;
}, [direction, orientation, titlePlacement, validTitlePlacement]);
const hasMarginStart = mergedTitlePlacement === 'start' && orientationMargin != null;
const hasMarginEnd = mergedTitlePlacement === 'end' && orientationMargin != null;
const [mergedOrientation, mergedVertical] = useOrientation(orientation, vertical, type);
// ========================= Semantic =========================
const mergedProps = {
...props,
orientation: mergedOrientation,
titlePlacement: mergedTitlePlacement,
size: sizeFullName
};
const [mergedClassNames, mergedStyles] = useMergeSemantic([contextClassNames, classNames], [contextStyles, styles], {
props: mergedProps
});
const classString = clsx(prefixCls, contextClassName, hashId, cssVarCls, `${prefixCls}-${mergedOrientation}`, {
[`${prefixCls}-with-text`]: hasChildren,
[`${prefixCls}-with-text-${mergedTitlePlacement}`]: hasChildren,
[`${prefixCls}-dashed`]: !!dashed,
[`${prefixCls}-${variant}`]: variant !== 'solid',
[`${prefixCls}-plain`]: !!plain,
[`${prefixCls}-rtl`]: direction === 'rtl',
[`${prefixCls}-no-default-orientation-margin-start`]: hasMarginStart,
[`${prefixCls}-no-default-orientation-margin-end`]: hasMarginEnd,
[`${prefixCls}-md`]: sizeFullName === 'medium' || sizeFullName === 'middle',
[`${prefixCls}-sm`]: sizeFullName === 'small',
[railCls]: !children,
[mergedClassNames.rail]: mergedClassNames.rail && !children
}, className, rootClassName, mergedClassNames.root);
const memoizedPlacementMargin = React.useMemo(() => {
if (isNumber(orientationMargin)) {
return orientationMargin;
}
if (/^\d+$/.test(orientationMargin)) {
return Number(orientationMargin);
}
return orientationMargin;
}, [orientationMargin]);
const innerStyle = {
marginInlineStart: hasMarginStart ? memoizedPlacementMargin : undefined,
marginInlineEnd: hasMarginEnd ? memoizedPlacementMargin : undefined
};
// =================== Warning =====================
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning('Divider');
process.env.NODE_ENV !== "production" ? warning(!children || !mergedVertical, 'usage', '`children` not working in `vertical` mode.') : void 0;
process.env.NODE_ENV !== "production" ? warning(!validTitlePlacement, 'usage', '`orientation` is used for direction, please use `titlePlacement` replace this') : void 0;
[['type', 'orientation'], ['orientationMargin', 'styles.content.margin']].forEach(([deprecatedName, newName]) => {
warning.deprecated(!(deprecatedName in props), deprecatedName, newName);
});
}
return /*#__PURE__*/React.createElement("div", {
className: classString,
style: {
...contextStyle,
...mergedStyles.root,
...(children ? {} : mergedStyles.rail),
...style
},
...restProps,
role: "separator"
}, children && !mergedVertical && (/*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
className: clsx(railCls, `${railCls}-start`, mergedClassNames.rail),
style: mergedStyles.rail
}), /*#__PURE__*/React.createElement("span", {
className: clsx(`${prefixCls}-inner-text`, mergedClassNames.content),
style: {
...innerStyle,
...mergedStyles.content
}
}, children), /*#__PURE__*/React.createElement("div", {
className: clsx(railCls, `${railCls}-end`, mergedClassNames.rail),
style: mergedStyles.rail
}))));
};
if (process.env.NODE_ENV !== 'production') {
Divider.displayName = 'Divider';
}
export default Divider;
+23
View File
@@ -0,0 +1,23 @@
import type { CSSProperties } from 'react';
import type { GetDefaultToken } from '../../theme/internal';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
/**
* @desc 文本横向内间距
* @descEN Horizontal padding of text
*/
textPaddingInline: CSSProperties['paddingInline'];
/**
* @desc 文本与边缘距离,取值 0 ~ 1
* @descEN Distance between text and edge, which should be a number between 0 and 1.
*/
orientationMargin?: number;
/**
* @desc 纵向分割线的横向外间距
* @descEN Horizontal margin of vertical Divider
*/
verticalMarginInline: CSSProperties['marginInline'];
}
export declare const prepareComponentToken: GetDefaultToken<'Divider'>;
declare const _default: (prefixCls: string, rootCls?: string) => readonly [string, string];
export default _default;
+188
View File
@@ -0,0 +1,188 @@
import { unit } from '@ant-design/cssinjs';
import { resetComponent } from '../../style';
import { genStyleHooks, mergeToken } from '../../theme/internal';
// ============================== Size ================================
const genSizeDividerStyle = token => {
const {
componentCls
} = token;
return {
[componentCls]: {
'&-horizontal': {
[`&${componentCls}`]: {
'&-sm': {
marginBlock: token.marginXS
},
'&-md': {
marginBlock: token.margin
}
}
}
}
};
};
// ============================== Shared ==============================
const genSharedDividerStyle = token => {
const {
componentCls,
sizePaddingEdgeHorizontal,
colorSplit,
lineWidth,
textPaddingInline,
orientationMargin,
verticalMarginInline
} = token;
const railCls = `${componentCls}-rail`;
return {
[componentCls]: {
...resetComponent(token),
borderBlockStart: `${unit(lineWidth)} solid ${colorSplit}`,
[railCls]: {
borderBlockStart: `${unit(lineWidth)} solid ${colorSplit}`
},
// vertical
'&-vertical': {
position: 'relative',
top: '-0.06em',
display: 'inline-block',
height: '0.9em',
marginInline: verticalMarginInline,
marginBlock: 0,
verticalAlign: 'middle',
borderTop: 0,
borderInlineStart: `${unit(lineWidth)} solid ${colorSplit}`
},
'&-horizontal': {
display: 'flex',
clear: 'both',
width: '100%',
minWidth: '100%',
// Fix https://github.com/ant-design/ant-design/issues/10914
margin: `${unit(token.marginLG)} 0`
},
[`&-horizontal${componentCls}-with-text`]: {
display: 'flex',
alignItems: 'center',
margin: `${unit(token.dividerHorizontalWithTextGutterMargin)} 0`,
color: token.colorTextHeading,
fontWeight: 500,
fontSize: token.fontSizeLG,
whiteSpace: 'nowrap',
textAlign: 'center',
borderBlockStart: `0 ${colorSplit}`,
[`${railCls}-start, ${railCls}-end`]: {
width: '50%',
// Chrome not accept `inherit` in `border-top`
borderBlockStartColor: 'inherit',
borderBlockEnd: 0,
content: "''"
}
},
[`&-horizontal${componentCls}-with-text-start`]: {
[`${railCls}-start`]: {
width: `calc(${orientationMargin} * 100%)`
},
[`${railCls}-end`]: {
width: `calc(100% - ${orientationMargin} * 100%)`
}
},
[`&-horizontal${componentCls}-with-text-end`]: {
[`${railCls}-start`]: {
width: `calc(100% - ${orientationMargin} * 100%)`
},
[`${railCls}-end`]: {
width: `calc(${orientationMargin} * 100%)`
}
},
[`${componentCls}-inner-text`]: {
display: 'inline-block',
paddingBlock: 0,
paddingInline: textPaddingInline
},
'&-dashed': {
background: 'none',
borderColor: colorSplit,
borderStyle: 'dashed',
borderWidth: `${unit(lineWidth)} 0 0`,
[railCls]: {
borderBlockStart: `${unit(lineWidth)} dashed ${colorSplit}`
}
},
[`&-horizontal${componentCls}-with-text${componentCls}-dashed`]: {
[`${railCls}-start, ${railCls}-end`]: {
borderStyle: 'dashed none none'
}
},
[`&-vertical${componentCls}-dashed`]: {
borderInlineStartWidth: lineWidth,
borderInlineEnd: 0,
borderBlockStart: 0,
borderBlockEnd: 0
},
'&-dotted': {
background: 'none',
borderColor: colorSplit,
borderStyle: 'dotted',
borderWidth: `${unit(lineWidth)} 0 0`,
[railCls]: {
borderBlockStart: `${unit(lineWidth)} dotted ${colorSplit}`
}
},
[`&-horizontal${componentCls}-with-text${componentCls}-dotted`]: {
'&::before, &::after': {
borderStyle: 'dotted none none'
}
},
[`&-vertical${componentCls}-dotted`]: {
borderInlineStartWidth: lineWidth,
borderInlineEnd: 0,
borderBlockStart: 0,
borderBlockEnd: 0
},
[`&-plain${componentCls}-with-text`]: {
color: token.colorText,
fontWeight: 'normal',
fontSize: token.fontSize
},
[`&-horizontal${componentCls}-with-text-start${componentCls}-no-default-orientation-margin-start`]: {
[`${railCls}-start`]: {
width: 0
},
[`${railCls}-end`]: {
width: '100%'
},
[`${componentCls}-inner-text`]: {
paddingInlineStart: sizePaddingEdgeHorizontal
}
},
[`&-horizontal${componentCls}-with-text-end${componentCls}-no-default-orientation-margin-end`]: {
[`${railCls}-start`]: {
width: '100%'
},
[`${railCls}-end`]: {
width: 0
},
[`${componentCls}-inner-text`]: {
paddingInlineEnd: sizePaddingEdgeHorizontal
}
}
}
};
};
export const prepareComponentToken = token => ({
textPaddingInline: '1em',
orientationMargin: 0.05,
verticalMarginInline: token.marginXS
});
// ============================== Export ==============================
export default genStyleHooks('Divider', token => {
const dividerToken = mergeToken(token, {
dividerHorizontalWithTextGutterMargin: token.margin,
sizePaddingEdgeHorizontal: 0
});
return [genSharedDividerStyle(dividerToken), genSizeDividerStyle(dividerToken)];
}, prepareComponentToken, {
unitless: {
orientationMargin: true
}
});