lijianan
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
21 additions and
2 deletions
-
components/avatar/avatar.tsx
-
components/config-provider/__tests__/style.test.tsx
-
components/config-provider/context.ts
-
components/config-provider/index.en-US.md
-
components/config-provider/index.tsx
-
components/config-provider/index.zh-CN.md
|
|
@ -54,7 +54,7 @@ const InternalAvatar: React.ForwardRefRenderFunction<HTMLSpanElement, AvatarProp |
|
|
|
const avatarChildrenRef = React.useRef<HTMLSpanElement>(null); |
|
|
|
const avatarNodeMergeRef = composeRef<HTMLSpanElement>(ref, avatarNodeRef); |
|
|
|
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext); |
|
|
|
const { getPrefixCls, avatar } = React.useContext(ConfigContext); |
|
|
|
|
|
|
|
const setScaleParam = () => { |
|
|
|
if (!avatarChildrenRef.current || !avatarNodeRef.current) { |
|
|
@ -149,6 +149,7 @@ const InternalAvatar: React.ForwardRefRenderFunction<HTMLSpanElement, AvatarProp |
|
|
|
const classString = classNames( |
|
|
|
prefixCls, |
|
|
|
sizeCls, |
|
|
|
avatar?.className, |
|
|
|
{ |
|
|
|
[`${prefixCls}-${shape}`]: !!shape, |
|
|
|
[`${prefixCls}-image`]: hasImageElement || (src && isImgExist), |
|
|
@ -227,7 +228,7 @@ const InternalAvatar: React.ForwardRefRenderFunction<HTMLSpanElement, AvatarProp |
|
|
|
return wrapSSR( |
|
|
|
<span |
|
|
|
{...others} |
|
|
|
style={{ ...sizeStyle, ...responsiveSizeStyle, ...others.style }} |
|
|
|
style={{ ...sizeStyle, ...responsiveSizeStyle, ...avatar?.style, ...others.style }} |
|
|
|
className={classString} |
|
|
|
ref={avatarNodeMergeRef} |
|
|
|
> |
|
|
|
|
|
@ -2,6 +2,7 @@ import React from 'react'; |
|
|
|
import ConfigProvider from '..'; |
|
|
|
import { render } from '../../../tests/utils'; |
|
|
|
import Anchor from '../../anchor'; |
|
|
|
import Avatar from '../../avatar'; |
|
|
|
import Badge from '../../badge'; |
|
|
|
import Breadcrumb from '../../breadcrumb'; |
|
|
|
import Card from '../../card'; |
|
|
@ -609,6 +610,17 @@ describe('ConfigProvider support style and className props', () => { |
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'blue' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should Avatar className & style works', () => { |
|
|
|
const { container } = render( |
|
|
|
<ConfigProvider avatar={{ className: 'cp-avatar', style: { backgroundColor: 'blue' } }}> |
|
|
|
<Avatar /> |
|
|
|
</ConfigProvider>, |
|
|
|
); |
|
|
|
const element = container.querySelector<HTMLSpanElement>('.ant-avatar'); |
|
|
|
expect(element).toHaveClass('cp-avatar'); |
|
|
|
expect(element).toHaveStyle({ backgroundColor: 'blue' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should Tag className & style works', () => { |
|
|
|
const { container } = render( |
|
|
|
<ConfigProvider tag={{ className: 'cp-tag', style: { backgroundColor: 'blue' } }}> |
|
|
|
|
|
@ -116,6 +116,7 @@ export interface ConfigConsumerProps { |
|
|
|
radio?: ComponentStyleConfig; |
|
|
|
rate?: ComponentStyleConfig; |
|
|
|
switch?: ComponentStyleConfig; |
|
|
|
avatar?: ComponentStyleConfig; |
|
|
|
tag?: ComponentStyleConfig; |
|
|
|
table?: ComponentStyleConfig; |
|
|
|
card?: ComponentStyleConfig; |
|
|
|
|
|
@ -102,6 +102,7 @@ const { |
|
|
|
| Property | Description | Type | Default | Version | |
|
|
|
| --- | --- | --- | --- | --- | |
|
|
|
| anchor | Set Anchor common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | |
|
|
|
| avatar | Set Avatar common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | |
|
|
|
| badge | Set Badge common props | { className?: string, style?: React.CSSProperties, classNames?: { count?: string, indicator?: string }, styles?: { count?: React.CSSProperties, indicator?: React.CSSProperties } } | - | 5.7.0 | |
|
|
|
| breadcrumb | Set Breadcrumb common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | |
|
|
|
| button | Set Button common props | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties } } | - | 5.6.0 | |
|
|
|
|
|
@ -160,6 +160,7 @@ export interface ConfigProviderProps { |
|
|
|
radio?: ComponentStyleConfig; |
|
|
|
rate?: ComponentStyleConfig; |
|
|
|
switch?: ComponentStyleConfig; |
|
|
|
avatar?: ComponentStyleConfig; |
|
|
|
tag?: ComponentStyleConfig; |
|
|
|
table?: ComponentStyleConfig; |
|
|
|
card?: ComponentStyleConfig; |
|
|
@ -275,6 +276,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => { |
|
|
|
radio, |
|
|
|
rate, |
|
|
|
switch: SWITCH, |
|
|
|
avatar, |
|
|
|
tag, |
|
|
|
table, |
|
|
|
card, |
|
|
@ -352,6 +354,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => { |
|
|
|
radio, |
|
|
|
rate, |
|
|
|
switch: SWITCH, |
|
|
|
avatar, |
|
|
|
tag, |
|
|
|
table, |
|
|
|
card, |
|
|
|
|
|
@ -104,6 +104,7 @@ const { |
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 | |
|
|
|
| --- | --- | --- | --- | --- | |
|
|
|
| anchor | 设置 Anchor 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | |
|
|
|
| avatar | 设置 Avatar 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | |
|
|
|
| badge | 设置 Badge 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { count?: string, indicator?: string }, styles?: { count?: React.CSSProperties, indicator?: React.CSSProperties } } | - | 5.7.0 | |
|
|
|
| breadcrumb | 设置 Breadcrumb 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | |
|
|
|
| button | 设置 Button 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties } } | - | 5.6.0 | |
|
|
|