Skip to content

Commit

Permalink
feat: CP support collapse expandIcon (ant-design#47473)
Browse files Browse the repository at this point in the history
* feat: CP support Avatar icon

* fix: fix

* fix: fix

* test: fix test case

* fix: fix

* fix: fix type

* Update avatar.tsx

Signed-off-by: lijianan <574980606@qq.com>

* Update avatar.tsx

Signed-off-by: lijianan <574980606@qq.com>

---------

Signed-off-by: lijianan <574980606@qq.com>
  • Loading branch information
li-jia-nan authored and tanzhenyun committed Mar 29, 2024
1 parent 571d81f commit 45d1322
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
13 changes: 7 additions & 6 deletions components/_util/reactNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';

import type { AnyObject } from './type';

export const { isValidElement } = React;
Expand All @@ -9,20 +10,20 @@ export function isFragment(child: any): boolean {

type RenderProps = AnyObject | ((originProps: AnyObject) => AnyObject | void);

export function replaceElement(
export function replaceElement<P>(
element: React.ReactNode,
replacement: React.ReactNode,
props?: RenderProps,
): React.ReactNode {
if (!isValidElement(element)) {
) {
if (!isValidElement<P>(element)) {
return replacement;
}
return React.cloneElement(
return React.cloneElement<P>(
element,
typeof props === 'function' ? props(element.props || {}) : props,
);
}

export function cloneElement(element: React.ReactNode, props?: RenderProps): React.ReactElement {
return replaceElement(element, element, props) as React.ReactElement;
export function cloneElement<P>(element: React.ReactNode, props?: RenderProps) {
return replaceElement<P>(element, element, props) as React.ReactElement;
}
5 changes: 3 additions & 2 deletions components/config-provider/__tests__/style.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('ConfigProvider support style and className props', () => {
expect(element).toHaveStyle({ backgroundColor: 'red' });
});

it('Should Collapse className works', () => {
it('Should Collapse className & expandIcon works', () => {
const items = [
{
key: '1',
Expand All @@ -285,13 +285,14 @@ describe('ConfigProvider support style and className props', () => {
<ConfigProvider
collapse={{
className: 'test-class',
expandIcon: (props) => <span className="cp-test-icon">{props.isActive}</span>,
}}
>
<Collapse items={items} />
</ConfigProvider>,
);

expect(container.querySelector('.ant-collapse')).toHaveClass('test-class');
expect(container.querySelector<HTMLSpanElement>('.cp-test-icon')).toBeTruthy();
});

it('Should Collapse style works', () => {
Expand Down
5 changes: 4 additions & 1 deletion components/config-provider/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { AlertProps } from '../alert';
import type { BadgeProps } from '../badge';
import type { ButtonProps } from '../button';
import type { CardProps } from '../card';
import type { CollapseProps } from '../collapse';
import type { DrawerProps } from '../drawer';
import type { FlexProps } from '../flex/interface';
import type { FormProps } from '../form/Form';
Expand Down Expand Up @@ -82,6 +83,8 @@ export interface ImageConfig extends ComponentStyleConfig {
preview?: Partial<Record<'closeIcon', React.ReactNode>>;
}

export type CollapseConfig = ComponentStyleConfig & Pick<CollapseProps, 'expandIcon'>;

export type TourConfig = Pick<TourProps, 'closeIcon'>;

export type ModalConfig = ComponentStyleConfig &
Expand Down Expand Up @@ -148,7 +151,7 @@ export interface ConfigConsumerProps {
calendar?: ComponentStyleConfig;
carousel?: ComponentStyleConfig;
cascader?: ComponentStyleConfig;
collapse?: ComponentStyleConfig;
collapse?: CollapseConfig;
typography?: ComponentStyleConfig;
skeleton?: ComponentStyleConfig;
spin?: ComponentStyleConfig;
Expand Down
2 changes: 1 addition & 1 deletion components/config-provider/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const {
| carousel | Set Carousel common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| cascader | Set Cascader common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| checkbox | Set Checkbox common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| collapse | Set Collapse common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| collapse | Set Collapse common props | { className?: string, style?: React.CSSProperties, expandIcon?: (props) => ReactNode } | - | 5.7.0, expandIcon: 5.15.0 |
| colorPicker | Set ColorPicker common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| datePicker | Set datePicker common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| rangePicker | Set rangePicker common props | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
Expand Down
3 changes: 2 additions & 1 deletion components/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
BadgeConfig,
ButtonConfig,
CardConfig,
CollapseConfig,
ComponentStyleConfig,
ConfigConsumerProps,
CSPConfig,
Expand Down Expand Up @@ -142,7 +143,7 @@ export interface ConfigProviderProps {
calendar?: ComponentStyleConfig;
carousel?: ComponentStyleConfig;
cascader?: ComponentStyleConfig;
collapse?: ComponentStyleConfig;
collapse?: CollapseConfig;
divider?: ComponentStyleConfig;
drawer?: DrawerConfig;
typography?: ComponentStyleConfig;
Expand Down
2 changes: 1 addition & 1 deletion components/config-provider/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const {
| carousel | 设置 Carousel 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| cascader | 设置 Cascader 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| checkbox | 设置 Checkbox 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| collapse | 设置 Collapse 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| collapse | 设置 Collapse 组件的通用属性 | { className?: string, style?: React.CSSProperties, expandIcon?: (props) => ReactNode } | - | 5.7.0, expandIcon: 5.15.0 |
| colorPicker | 设置 ColorPicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| datePicker | 设置 DatePicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| rangePicker | 设置 RangePicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
Expand Down

0 comments on commit 45d1322

Please sign in to comment.