Browse Source

feat: CP support Avatar className and style (#43315)

pull/43319/head
lijianan 1 year ago
committed by GitHub
parent
commit
5190e6f677
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      components/avatar/avatar.tsx
  2. 12
      components/config-provider/__tests__/style.test.tsx
  3. 1
      components/config-provider/context.ts
  4. 1
      components/config-provider/index.en-US.md
  5. 3
      components/config-provider/index.tsx
  6. 1
      components/config-provider/index.zh-CN.md

5
components/avatar/avatar.tsx

@ -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}
>

12
components/config-provider/__tests__/style.test.tsx

@ -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' } }}>

1
components/config-provider/context.ts

@ -116,6 +116,7 @@ export interface ConfigConsumerProps {
radio?: ComponentStyleConfig;
rate?: ComponentStyleConfig;
switch?: ComponentStyleConfig;
avatar?: ComponentStyleConfig;
tag?: ComponentStyleConfig;
table?: ComponentStyleConfig;
card?: ComponentStyleConfig;

1
components/config-provider/index.en-US.md

@ -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 |

3
components/config-provider/index.tsx

@ -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,

1
components/config-provider/index.zh-CN.md

@ -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 |

Loading…
Cancel
Save