|
@ -1,13 +1,13 @@ |
|
|
import classNames from 'classnames'; |
|
|
import classnames from 'classnames'; |
|
|
import CSSMotion from 'rc-motion'; |
|
|
import CSSMotion from 'rc-motion'; |
|
|
import * as React from 'react'; |
|
|
import * as React from 'react'; |
|
|
import { useMemo, useRef } from 'react'; |
|
|
import { useMemo, useRef } from 'react'; |
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
|
|
import type { PresetColorKey } from '../theme/internal'; |
|
|
|
|
|
import type { PresetStatusColorType } from '../_util/colors'; |
|
|
import type { PresetStatusColorType } from '../_util/colors'; |
|
|
import { isPresetColor } from '../_util/colors'; |
|
|
import { isPresetColor } from '../_util/colors'; |
|
|
import { cloneElement } from '../_util/reactNode'; |
|
|
import { cloneElement } from '../_util/reactNode'; |
|
|
import type { LiteralUnion } from '../_util/type'; |
|
|
import type { LiteralUnion } from '../_util/type'; |
|
|
|
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
|
|
import type { PresetColorKey } from '../theme/internal'; |
|
|
import Ribbon from './Ribbon'; |
|
|
import Ribbon from './Ribbon'; |
|
|
import ScrollNumber from './ScrollNumber'; |
|
|
import ScrollNumber from './ScrollNumber'; |
|
|
import useStyle from './style'; |
|
|
import useStyle from './style'; |
|
@ -40,6 +40,14 @@ export interface BadgeProps { |
|
|
offset?: [number | string, number | string]; |
|
|
offset?: [number | string, number | string]; |
|
|
title?: string; |
|
|
title?: string; |
|
|
children?: React.ReactNode; |
|
|
children?: React.ReactNode; |
|
|
|
|
|
classNames?: { |
|
|
|
|
|
root?: string; |
|
|
|
|
|
indicator?: string; |
|
|
|
|
|
}; |
|
|
|
|
|
styles?: { |
|
|
|
|
|
root?: React.CSSProperties; |
|
|
|
|
|
indicator?: React.CSSProperties; |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> = (props, ref) => { |
|
|
const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> = (props, ref) => { |
|
@ -59,6 +67,8 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
style, |
|
|
style, |
|
|
className, |
|
|
className, |
|
|
rootClassName, |
|
|
rootClassName, |
|
|
|
|
|
classNames, |
|
|
|
|
|
styles, |
|
|
showZero = false, |
|
|
showZero = false, |
|
|
...restProps |
|
|
...restProps |
|
|
} = props; |
|
|
} = props; |
|
@ -154,7 +164,7 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
const isInternalColor = isPresetColor(color, false); |
|
|
const isInternalColor = isPresetColor(color, false); |
|
|
|
|
|
|
|
|
// Shared styles
|
|
|
// Shared styles
|
|
|
const statusCls = classNames({ |
|
|
const statusCls = classnames(classNames?.indicator, { |
|
|
[`${prefixCls}-status-dot`]: hasStatus, |
|
|
[`${prefixCls}-status-dot`]: hasStatus, |
|
|
[`${prefixCls}-status-${status}`]: !!status, |
|
|
[`${prefixCls}-status-${status}`]: !!status, |
|
|
[`${prefixCls}-color-${color}`]: isInternalColor, |
|
|
[`${prefixCls}-color-${color}`]: isInternalColor, |
|
@ -166,7 +176,7 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
statusStyle.background = color; |
|
|
statusStyle.background = color; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const badgeClassName = classNames( |
|
|
const badgeClassName = classnames( |
|
|
prefixCls, |
|
|
prefixCls, |
|
|
{ |
|
|
{ |
|
|
[`${prefixCls}-status`]: hasStatus, |
|
|
[`${prefixCls}-status`]: hasStatus, |
|
@ -175,6 +185,7 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
}, |
|
|
}, |
|
|
className, |
|
|
className, |
|
|
rootClassName, |
|
|
rootClassName, |
|
|
|
|
|
classNames?.root, |
|
|
hashId, |
|
|
hashId, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
@ -182,8 +193,8 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
if (!children && hasStatus) { |
|
|
if (!children && hasStatus) { |
|
|
const statusTextColor = mergedStyle.color; |
|
|
const statusTextColor = mergedStyle.color; |
|
|
return wrapSSR( |
|
|
return wrapSSR( |
|
|
<span {...restProps} className={badgeClassName} style={mergedStyle}> |
|
|
<span {...restProps} className={badgeClassName} style={{ ...styles?.root, ...mergedStyle }}> |
|
|
<span className={statusCls} style={statusStyle} /> |
|
|
<span className={statusCls} style={{ ...styles?.indicator, ...statusStyle }} /> |
|
|
{text && ( |
|
|
{text && ( |
|
|
<span style={{ color: statusTextColor }} className={`${prefixCls}-status-text`}> |
|
|
<span style={{ color: statusTextColor }} className={`${prefixCls}-status-text`}> |
|
|
{text} |
|
|
{text} |
|
@ -194,7 +205,7 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return wrapSSR( |
|
|
return wrapSSR( |
|
|
<span ref={ref} {...restProps} className={badgeClassName}> |
|
|
<span ref={ref} {...restProps} className={badgeClassName} style={styles?.root}> |
|
|
{children} |
|
|
{children} |
|
|
<CSSMotion |
|
|
<CSSMotion |
|
|
visible={!isHidden} |
|
|
visible={!isHidden} |
|
@ -210,7 +221,7 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
|
|
|
|
|
|
const isDot = isDotRef.current; |
|
|
const isDot = isDotRef.current; |
|
|
|
|
|
|
|
|
const scrollNumberCls = classNames({ |
|
|
const scrollNumberCls = classnames(classNames?.indicator, { |
|
|
[`${prefixCls}-dot`]: isDot, |
|
|
[`${prefixCls}-dot`]: isDot, |
|
|
[`${prefixCls}-count`]: !isDot, |
|
|
[`${prefixCls}-count`]: !isDot, |
|
|
[`${prefixCls}-count-sm`]: size === 'small', |
|
|
[`${prefixCls}-count-sm`]: size === 'small', |
|
@ -220,7 +231,7 @@ const InternalBadge: React.ForwardRefRenderFunction<HTMLSpanElement, BadgeProps> |
|
|
[`${prefixCls}-color-${color}`]: isInternalColor, |
|
|
[`${prefixCls}-color-${color}`]: isInternalColor, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
let scrollNumberStyle: React.CSSProperties = { ...mergedStyle }; |
|
|
let scrollNumberStyle: React.CSSProperties = { ...styles?.indicator, ...mergedStyle }; |
|
|
if (color && !isInternalColor) { |
|
|
if (color && !isInternalColor) { |
|
|
scrollNumberStyle = scrollNumberStyle || {}; |
|
|
scrollNumberStyle = scrollNumberStyle || {}; |
|
|
scrollNumberStyle.background = color; |
|
|
scrollNumberStyle.background = color; |
|
|