Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CP support Drawer closeIcon #46894

Merged
merged 13 commits into from
Jan 26, 2024
5 changes: 4 additions & 1 deletion components/config-provider/__tests__/style.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,21 @@ describe('ConfigProvider support style and className props', () => {
expect(container.querySelector('.ant-divider'))?.toHaveStyle({ color: 'red', height: '80px' });
});

it('Should Drawer className works', () => {
it('Should Drawer className & closeIcon works', () => {
render(
<ConfigProvider
drawer={{
className: 'test-class',
closeIcon: <span className="cp-test-close-icon">close</span>,
}}
>
<Drawer title="Test Drawer" open />
</ConfigProvider>,
);

const selectors = '.ant-drawer-content .ant-drawer-close .cp-test-close-icon';
expect(document.querySelector('.ant-drawer-content')).toHaveClass('test-class');
expect(document.querySelector<HTMLSpanElement>(selectors)).toBeTruthy();
});

it('Should Drawer style works', () => {
Expand Down
6 changes: 2 additions & 4 deletions components/config-provider/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ export interface ButtonConfig extends ComponentStyleConfig {
styles?: ButtonProps['styles'];
}

export interface DrawerConfig extends ComponentStyleConfig {
classNames?: DrawerProps['classNames'];
styles?: DrawerProps['styles'];
}
export type DrawerConfig = ComponentStyleConfig &
Pick<DrawerProps, 'classNames' | 'styles' | 'closeIcon'>;

export interface FlexConfig extends ComponentStyleConfig {
vertical?: FlexProps['vertical'];
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 @@ -118,7 +118,7 @@ const {
| rangePicker | Set rangePicker common props | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
| descriptions | Set Descriptions common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| divider | Set Divider common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| drawer | Set Drawer common props | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api) } | - | 5.7.0, `classNames` and `styles`: 5.10.0 |
| drawer | Set Drawer common props | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api), closeIcon?: ReactNode } | - | 5.7.0, `classNames` and `styles`: 5.10.0, `closeIcon`: 5.14.0 |
| dropdown | Set Dropdown common props | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
| empty | Set Empty common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| flex | Set Flex common props | { className?: string, style?: React.CSSProperties, vertical?: boolean } | - | 5.10.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 @@ -8,7 +8,8 @@ import useMemo from 'rc-util/lib/hooks/useMemo';
import { merge } from 'rc-util/lib/utils/set';
import type { Options } from 'scroll-into-view-if-needed';

import warning, { WarningContext, type WarningContextProps } from '../_util/warning';
import warning, { WarningContext } from '../_util/warning';
import type { WarningContextProps } from '../_util/warning';
import type { RequiredMark } from '../form/Form';
import ValidateMessagesContext from '../form/validateMessagesContext';
import type { InputProps } from '../input';
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 @@ -120,7 +120,7 @@ const {
| rangePicker | 设置 RangePicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
| descriptions | 设置 Descriptions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| divider | 设置 Divider 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| drawer | 设置 Drawer 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api) } | - | 5.7.0, `classNames` 和 `styles`: 5.10.0 |
| drawer | 设置 Drawer 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api), closeIcon?: ReactNode } | - | 5.7.0, `classNames` 和 `styles`: 5.10.0, `closeIcon`: 5.14.0 |
| dropdown | 设置 Dropdown 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
| empty | 设置 Empty 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| flex | 设置 Flex 组件的通用属性 | { className?: string, style?: React.CSSProperties, vertical?: boolean } | - | 5.10.0 |
Expand Down
3 changes: 2 additions & 1 deletion components/drawer/DrawerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ const DrawerPanel: React.FC<DrawerPanelProps> = (props) => {
),
[onClose],
);

const [mergedClosable, mergedCloseIcon] = useClosable(
closable,
closeIcon,
typeof closeIcon !== 'undefined' ? closeIcon : drawerContext?.closeIcon,
customCloseIconRender,
undefined,
true,
Expand Down