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

129 lines
2.6 KiB
TypeScript
Raw Normal View History

import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal';
import {
getCopiableStyles,
2022-06-22 15:18:03 +08:00
getEditableStyles,
getEllipsisStyles,
2022-06-22 15:18:03 +08:00
getLinkStyles,
getResetStyles,
getTitleStyles,
} from './mixins';
import { operationUnit } from '../../style';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
sizeMarginHeadingVerticalStart: number | string;
sizeMarginHeadingVerticalEnd: 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, sizeMarginHeadingVerticalStart } = token;
return {
[componentCls]: {
color: token.colorText,
2022-11-13 14:33:07 +08:00
wordBreak: 'break-word',
lineHeight: token.lineHeight,
'&&-secondary': {
2022-08-04 16:16:50 +08:00
color: token.colorTextDescription,
},
'&&-success': {
color: token.colorSuccess,
},
'&&-warning': {
color: token.colorWarning,
},
'&&-danger': {
color: token.colorError,
'a&:active, a&:focus': {
color: token.colorErrorActive,
},
'a&:hover': {
color: token.colorErrorHover,
},
},
'&&-disabled': {
color: token.colorTextDisabled,
cursor: 'not-allowed',
userSelect: 'none',
},
[`
div&,
p
`]: {
marginBottom: '1em',
},
...getTitleStyles(token),
[`
& + h1&,
& + h2&,
& + h3&,
& + h4&,
& + h5&
`]: {
marginTop: sizeMarginHeadingVerticalStart,
},
[`
div,
ul,
li,
p,
h1,
h2,
h3,
h4,
h5`]: {
[`
+ h1,
+ h2,
+ h3,
+ h4,
+ h5
`]: {
marginTop: sizeMarginHeadingVerticalStart,
},
},
...getResetStyles(),
...getLinkStyles(token),
// Operation
[`
${componentCls}-expand,
${componentCls}-edit,
${componentCls}-copy
`]: {
...operationUnit(token),
marginInlineStart: token.marginXXS,
},
...getEditableStyles(token),
...getCopiableStyles(token),
...getEllipsisStyles(),
'&-rtl': {
direction: 'rtl',
},
},
};
};
// ============================== Export ==============================
2022-11-13 14:33:07 +08:00
export default genComponentStyleHook('Typography', (token) => [genTypographyStyle(token)], {
sizeMarginHeadingVerticalStart: '1.2em',
sizeMarginHeadingVerticalEnd: '0.5em',
});