|
@@ -17,6 +17,7 @@ import type { Ellipsis, EllipsisPos, ShowTooltip, TypographyBaseSize, Typography
|
|
import { CopyableConfig, LinkType } from './title';
|
|
import { CopyableConfig, LinkType } from './title';
|
|
import { BaseProps } from '../_base/baseComponent';
|
|
import { BaseProps } from '../_base/baseComponent';
|
|
import { isSemiIcon, runAfterTicks } from '../_utils';
|
|
import { isSemiIcon, runAfterTicks } from '../_utils';
|
|
|
|
+import SizeContext from './context';
|
|
import ResizeObserver, { ObserverProperty, ResizeEntry } from '../resizeObserver';
|
|
import ResizeObserver, { ObserverProperty, ResizeEntry } from '../resizeObserver';
|
|
|
|
|
|
export interface BaseTypographyProps extends BaseProps {
|
|
export interface BaseTypographyProps extends BaseProps {
|
|
@@ -165,6 +166,9 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
|
|
className: '',
|
|
className: '',
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ static contextType = SizeContext;
|
|
|
|
+
|
|
|
|
+ context: TypographyBaseSize;
|
|
wrapperRef: React.RefObject<any>;
|
|
wrapperRef: React.RefObject<any>;
|
|
expandRef: React.RefObject<any>;
|
|
expandRef: React.RefObject<any>;
|
|
copyRef: React.RefObject<any>;
|
|
copyRef: React.RefObject<any>;
|
|
@@ -615,13 +619,14 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
|
|
|
|
|
|
renderIcon() {
|
|
renderIcon() {
|
|
const { icon, size } = this.props;
|
|
const { icon, size } = this.props;
|
|
|
|
+ const realSize = size === 'inherit' ? this.context : size;
|
|
if (!icon) {
|
|
if (!icon) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- const iconSize: Size = size === 'small' ? 'small' : 'default';
|
|
|
|
|
|
+ const iconSize: Size = realSize === 'small' ? 'small' : 'default';
|
|
return (
|
|
return (
|
|
<span className={`${prefixCls}-icon`} x-semi-prop="icon">
|
|
<span className={`${prefixCls}-icon`} x-semi-prop="icon">
|
|
- {isSemiIcon(icon) ? React.cloneElement((icon as React.ReactElement), { size: iconSize }) : icon}
|
|
|
|
|
|
+ {isSemiIcon(icon) ? React.cloneElement((icon as React.ReactElement), { realSize: iconSize }) : icon}
|
|
</span>
|
|
</span>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -653,6 +658,7 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
|
|
// 'link',
|
|
// 'link',
|
|
'delete',
|
|
'delete',
|
|
]);
|
|
]);
|
|
|
|
+ const realSize = size === 'inherit' ? this.context : size;
|
|
const iconNode = this.renderIcon();
|
|
const iconNode = this.renderIcon();
|
|
const ellipsisOpt = this.getEllipsisOpt();
|
|
const ellipsisOpt = this.getEllipsisOpt();
|
|
const { ellipsisCls, ellipsisStyle } = this.getEllipsisStyle();
|
|
const { ellipsisCls, ellipsisStyle } = this.getEllipsisStyle();
|
|
@@ -673,7 +679,7 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
|
|
const wrapperCls = cls(className, ellipsisCls, {
|
|
const wrapperCls = cls(className, ellipsisCls, {
|
|
// [`${prefixCls}-primary`]: !type || type === 'primary',
|
|
// [`${prefixCls}-primary`]: !type || type === 'primary',
|
|
[`${prefixCls}-${type}`]: type && !link,
|
|
[`${prefixCls}-${type}`]: type && !link,
|
|
- [`${prefixCls}-${size}`]: size,
|
|
|
|
|
|
+ [`${prefixCls}-${realSize}`]: realSize,
|
|
[`${prefixCls}-link`]: link,
|
|
[`${prefixCls}-link`]: link,
|
|
[`${prefixCls}-disabled`]: disabled,
|
|
[`${prefixCls}-disabled`]: disabled,
|
|
[`${prefixCls}-${spacing}`]: spacing,
|
|
[`${prefixCls}-${spacing}`]: spacing,
|
|
@@ -728,14 +734,18 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
|
|
}
|
|
}
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
|
+ const { size } = this.props;
|
|
|
|
+ const realSize = size === 'inherit' ? this.context : size;
|
|
const content = (
|
|
const content = (
|
|
- <LocaleConsumer componentName="Typography">
|
|
|
|
- {(locale: Locale['Typography']) => {
|
|
|
|
- this.expandStr = locale.expand;
|
|
|
|
- this.collapseStr = locale.collapse;
|
|
|
|
- return this.renderTipWrapper();
|
|
|
|
- }}
|
|
|
|
- </LocaleConsumer>
|
|
|
|
|
|
+ <SizeContext.Provider value={realSize}>
|
|
|
|
+ <LocaleConsumer componentName="Typography">
|
|
|
|
+ {(locale: Locale['Typography']) => {
|
|
|
|
+ this.expandStr = locale.expand;
|
|
|
|
+ this.collapseStr = locale.collapse;
|
|
|
|
+ return this.renderTipWrapper();
|
|
|
|
+ }}
|
|
|
|
+ </LocaleConsumer>
|
|
|
|
+ </SizeContext.Provider>
|
|
);
|
|
);
|
|
if (this.props.ellipsis) {
|
|
if (this.props.ellipsis) {
|
|
return (
|
|
return (
|