ant-design/components/typography/style/index.ts

141 lines
2.8 KiB
TypeScript
Raw Normal View History

import { operationUnit } from '../../style';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal';
import {
getCopyableStyles,
2022-06-22 15:18:03 +08:00
getEditableStyles,
getEllipsisStyles,
2022-06-22 15:18:03 +08:00
getLinkStyles,
getResetStyles,
getTitleStyles,
} from './mixins';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
/**
* @desc
* @descEN Margin top of title
*/
titleMarginTop: number | string;
/**
* @desc
* @descEN Margin bottom of title
*/
titleMarginBottom: number | string;
}
export type TypographyToken = FullToken<'Typography'>;
New Component: Typography (#14250) * text with prefix * add edit style * support editable * enhance accessibility & type experience * optimize IME case * support copy * add locale * add secondary & disabled * add ellipsis shadow text * split to 3 components * update snapshot * update desc * change lines also need update ellipsis * skip aria when is in ellipsis * add ResizeObserver in _util * update snapshot * move TestBase into test file * update test case * update doc * fix typo * important => level * use rows * update demo cols to 1 * fix cssText not work in firefox * update doc * add miss point * support extendable * update snapshot * fix doc * copyable support string * update snapshot * update doc * update doc desc * adjust style * full test * reset after test * rename * update snapshot * fix compile * adjust style * update desc * update prefixCls * update margin * adjust * nest wrap of tag content * adjust style * update comment * rm % * one more thing * tmp of measure * merge string as children * update snapshot * update testcase * remove comment * use internal variable for configProvider passing * update snapshot * use expandable instead of extendable * less variable it * update demo * update less * adjust code & mark style * remove mark padding * update measure logic * support nest element style * use childNode.textContent to fix react 15 error * update css * popout Typography * add link style * adjust doc * use ellipsis instead of rows & expandable * update doc * update doc * update doc & style * fix typo * add css ellipsis support * client render * update snapshot * enhance copyable * support onExpand * update test case * add test of css ellipsis * fix logic in react 15 * rename onChange -> onSave * use tagName of article * fix lint
2019-02-19 11:42:05 +08:00
2022-11-13 14:33:07 +08:00
const genTypographyStyle: GenerateStyle<TypographyToken> = (token) => {
const { componentCls, titleMarginTop } = token;
return {
[componentCls]: {
color: token.colorText,
2022-11-13 14:33:07 +08:00
wordBreak: 'break-word',
lineHeight: token.lineHeight,
[`&${componentCls}-secondary`]: {
2022-08-04 16:16:50 +08:00
color: token.colorTextDescription,
},
[`&${componentCls}-success`]: {
color: token.colorSuccess,
},
[`&${componentCls}-warning`]: {
color: token.colorWarning,
},
[`&${componentCls}-danger`]: {
color: token.colorError,
'a&:active, a&:focus': {
color: token.colorErrorActive,
},
'a&:hover': {
color: token.colorErrorHover,
},
},
[`&${componentCls}-disabled`]: {
color: token.colorTextDisabled,
cursor: 'not-allowed',
userSelect: 'none',
},
[`
div&,
p
`]: {
marginBottom: '1em',
},
...getTitleStyles(token),
[`
& + h1${componentCls},
& + h2${componentCls},
& + h3${componentCls},
& + h4${componentCls},
& + h5${componentCls}
`]: {
marginTop: titleMarginTop,
},
[`
div,
ul,
li,
p,
h1,
h2,
h3,
h4,
h5`]: {
[`
+ h1,
+ h2,
+ h3,
+ h4,
+ h5
`]: {
marginTop: titleMarginTop,
},
},
...getResetStyles(token),
...getLinkStyles(token),
// Operation
[`
${componentCls}-expand,
${componentCls}-edit,
${componentCls}-copy
`]: {
...operationUnit(token),
marginInlineStart: token.marginXXS,
},
...getEditableStyles(token),
...getCopyableStyles(token),
...getEllipsisStyles(),
'&-rtl': {
direction: 'rtl',
},
},
};
};
// ============================== Export ==============================
export default genComponentStyleHook(
'Typography',
(token) => [genTypographyStyle(token)],
() => ({
titleMarginTop: '1.2em',
titleMarginBottom: '0.5em',
}),
);