File size: 6,892 Bytes
1e92f2d |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
import type { CSSProperties } from 'react';
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } 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'];
}
/**
* @desc Divider 组件的 Token
* @descEN Token for Divider component
*/
interface DividerToken extends FullToken<'Divider'> {
/**
* @desc 尺寸边距
* @descEN Size padding edge horizontal
*/
sizePaddingEdgeHorizontal: number | string;
/**
* @desc 带文本的水平分割线的外边距
* @descEN Horizontal margin of divider with text
*/
dividerHorizontalWithTextGutterMargin: number | string;
}
// ============================== Size ================================
const genSizeDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject => {
const { componentCls } = token;
return {
[componentCls]: {
'&-horizontal': {
[`&${componentCls}`]: {
'&-sm': {
marginBlock: token.marginXS,
},
'&-md': {
marginBlock: token.margin,
},
},
},
},
};
};
// ============================== Shared ==============================
const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject => {
const {
componentCls,
sizePaddingEdgeHorizontal,
colorSplit,
lineWidth,
textPaddingInline,
orientationMargin,
verticalMarginInline,
} = token;
return {
[componentCls]: {
...resetComponent(token),
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}`,
'&::before, &::after': {
position: 'relative',
width: '50%',
borderBlockStart: `${unit(lineWidth)} solid transparent`,
// Chrome not accept `inherit` in `border-top`
borderBlockStartColor: 'inherit',
borderBlockEnd: 0,
transform: 'translateY(50%)',
content: "''",
},
},
[`&-horizontal${componentCls}-with-text-start`]: {
'&::before': {
width: `calc(${orientationMargin} * 100%)`,
},
'&::after': {
width: `calc(100% - ${orientationMargin} * 100%)`,
},
},
[`&-horizontal${componentCls}-with-text-end`]: {
'&::before': {
width: `calc(100% - ${orientationMargin} * 100%)`,
},
'&::after': {
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`,
},
[`&-horizontal${componentCls}-with-text${componentCls}-dashed`]: {
'&::before, &::after': {
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`,
},
[`&-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`]:
{
'&::before': {
width: 0,
},
'&::after': {
width: '100%',
},
[`${componentCls}-inner-text`]: {
paddingInlineStart: sizePaddingEdgeHorizontal,
},
},
[`&-horizontal${componentCls}-with-text-end${componentCls}-no-default-orientation-margin-end`]:
{
'&::before': {
width: '100%',
},
'&::after': {
width: 0,
},
[`${componentCls}-inner-text`]: {
paddingInlineEnd: sizePaddingEdgeHorizontal,
},
},
},
};
};
export const prepareComponentToken: GetDefaultToken<'Divider'> = (token) => ({
textPaddingInline: '1em',
orientationMargin: 0.05,
verticalMarginInline: token.marginXS,
});
// ============================== Export ==============================
export default genStyleHooks(
'Divider',
(token) => {
const dividerToken = mergeToken<DividerToken>(token, {
dividerHorizontalWithTextGutterMargin: token.margin,
sizePaddingEdgeHorizontal: 0,
});
return [genSharedDividerStyle(dividerToken), genSizeDividerStyle(dividerToken)];
},
prepareComponentToken,
{
unitless: {
orientationMargin: true,
},
},
);
|