1
This commit is contained in:
+43
@@ -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;
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
"use client";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
var _clsx = require("clsx");
|
||||
var _hooks = require("../_util/hooks");
|
||||
var _is = require("../_util/is");
|
||||
var _warning = require("../_util/warning");
|
||||
var _context = require("../config-provider/context");
|
||||
var _useSize = _interopRequireDefault(require("../config-provider/hooks/useSize"));
|
||||
var _style = _interopRequireDefault(require("./style"));
|
||||
const titlePlacementList = ['left', 'right', 'center', 'start', 'end'];
|
||||
const Divider = props => {
|
||||
const {
|
||||
getPrefixCls,
|
||||
direction,
|
||||
className: contextClassName,
|
||||
style: contextStyle,
|
||||
classNames: contextClassNames,
|
||||
styles: contextStyles
|
||||
} = (0, _context.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] = (0, _style.default)(prefixCls);
|
||||
const sizeFullName = (0, _useSize.default)(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] = (0, _hooks.useOrientation)(orientation, vertical, type);
|
||||
// ========================= Semantic =========================
|
||||
const mergedProps = {
|
||||
...props,
|
||||
orientation: mergedOrientation,
|
||||
titlePlacement: mergedTitlePlacement,
|
||||
size: sizeFullName
|
||||
};
|
||||
const [mergedClassNames, mergedStyles] = (0, _hooks.useMergeSemantic)([contextClassNames, classNames], [contextStyles, styles], {
|
||||
props: mergedProps
|
||||
});
|
||||
const classString = (0, _clsx.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 ((0, _is.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 = (0, _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: (0, _clsx.clsx)(railCls, `${railCls}-start`, mergedClassNames.rail),
|
||||
style: mergedStyles.rail
|
||||
}), /*#__PURE__*/React.createElement("span", {
|
||||
className: (0, _clsx.clsx)(`${prefixCls}-inner-text`, mergedClassNames.content),
|
||||
style: {
|
||||
...innerStyle,
|
||||
...mergedStyles.content
|
||||
}
|
||||
}, children), /*#__PURE__*/React.createElement("div", {
|
||||
className: (0, _clsx.clsx)(railCls, `${railCls}-end`, mergedClassNames.rail),
|
||||
style: mergedStyles.rail
|
||||
}))));
|
||||
};
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Divider.displayName = 'Divider';
|
||||
}
|
||||
var _default = exports.default = Divider;
|
||||
+23
@@ -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;
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.prepareComponentToken = exports.default = void 0;
|
||||
var _cssinjs = require("@ant-design/cssinjs");
|
||||
var _style = require("../../style");
|
||||
var _internal = require("../../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]: {
|
||||
...(0, _style.resetComponent)(token),
|
||||
borderBlockStart: `${(0, _cssinjs.unit)(lineWidth)} solid ${colorSplit}`,
|
||||
[railCls]: {
|
||||
borderBlockStart: `${(0, _cssinjs.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: `${(0, _cssinjs.unit)(lineWidth)} solid ${colorSplit}`
|
||||
},
|
||||
'&-horizontal': {
|
||||
display: 'flex',
|
||||
clear: 'both',
|
||||
width: '100%',
|
||||
minWidth: '100%',
|
||||
// Fix https://github.com/ant-design/ant-design/issues/10914
|
||||
margin: `${(0, _cssinjs.unit)(token.marginLG)} 0`
|
||||
},
|
||||
[`&-horizontal${componentCls}-with-text`]: {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
margin: `${(0, _cssinjs.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: `${(0, _cssinjs.unit)(lineWidth)} 0 0`,
|
||||
[railCls]: {
|
||||
borderBlockStart: `${(0, _cssinjs.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: `${(0, _cssinjs.unit)(lineWidth)} 0 0`,
|
||||
[railCls]: {
|
||||
borderBlockStart: `${(0, _cssinjs.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
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
const prepareComponentToken = token => ({
|
||||
textPaddingInline: '1em',
|
||||
orientationMargin: 0.05,
|
||||
verticalMarginInline: token.marginXS
|
||||
});
|
||||
// ============================== Export ==============================
|
||||
exports.prepareComponentToken = prepareComponentToken;
|
||||
var _default = exports.default = (0, _internal.genStyleHooks)('Divider', token => {
|
||||
const dividerToken = (0, _internal.mergeToken)(token, {
|
||||
dividerHorizontalWithTextGutterMargin: token.margin,
|
||||
sizePaddingEdgeHorizontal: 0
|
||||
});
|
||||
return [genSharedDividerStyle(dividerToken), genSizeDividerStyle(dividerToken)];
|
||||
}, prepareComponentToken, {
|
||||
unitless: {
|
||||
orientationMargin: true
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user