From 0b6356d984933a1bcda3458a306baa7c9a0d77e6 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 3 Jan 2024 08:45:11 +0800 Subject: [PATCH] chore: rename file .tsx => .ts (#46759) * chore: rename file .tsx => .ts * fix: fix * test: add test case --- ...usePatchElement.tsx => usePatchElement.ts} | 0 .../hooks/{useZIndex.tsx => useZIndex.ts} | 0 components/cascader/Panel.tsx | 6 ++-- .../style/{horizontal.tsx => horizontal.ts} | 0 components/menu/style/{index.tsx => index.ts} | 0 components/menu/style/{rtl.tsx => rtl.ts} | 0 components/menu/style/{theme.tsx => theme.ts} | 0 .../menu/style/{vertical.tsx => vertical.ts} | 0 .../message/style/{index.tsx => index.ts} | 0 components/modal/{index.tsx => index.ts} | 0 components/modal/{locale.tsx => locale.ts} | 0 .../modal/style/{confirm.tsx => confirm.ts} | 0 .../modal/style/{index.tsx => index.ts} | 0 .../popconfirm/style/{index.tsx => index.ts} | 0 components/popover/PurePanel.tsx | 14 ++++---- components/popover/__tests__/demo.test.tsx | 5 ++- components/popover/__tests__/index.test.tsx | 35 +++++++++++-------- .../popover/style/{index.tsx => index.ts} | 0 components/progress/{index.tsx => index.ts} | 0 .../progress/style/{index.tsx => index.ts} | 0 .../radio/style/{index.tsx => index.ts} | 0 components/rate/style/{index.tsx => index.ts} | 0 .../result/style/{index.tsx => index.ts} | 0 components/row/{index.tsx => index.ts} | 0 components/row/style/{index.tsx => index.ts} | 0 ...cements.tsx => mergedBuiltinPlacements.ts} | 0 .../style/{dropdown.tsx => dropdown.ts} | 0 .../select/style/{index.tsx => index.ts} | 0 .../style/{multiple.tsx => multiple.ts} | 0 .../select/style/{single.tsx => single.ts} | 0 .../skeleton/style/{index.tsx => index.ts} | 0 .../slider/style/{index.tsx => index.ts} | 0 components/statistic/{index.tsx => index.ts} | 2 +- .../statistic/style/{index.tsx => index.ts} | 0 .../steps/style/{index.tsx => index.ts} | 0 components/tag/CheckableTag.tsx | 5 +-- .../timeline/{useItems.tsx => useItems.ts} | 6 ++-- .../{useRafDebounce.tsx => useRafDebounce.ts} | 0 .../{useWatermark.tsx => useWatermark.ts} | 0 .../{excludeWarning.tsx => excludeWarning.ts} | 0 40 files changed, 40 insertions(+), 33 deletions(-) rename components/_util/hooks/{usePatchElement.tsx => usePatchElement.ts} (100%) rename components/_util/hooks/{useZIndex.tsx => useZIndex.ts} (100%) rename components/menu/style/{horizontal.tsx => horizontal.ts} (100%) rename components/menu/style/{index.tsx => index.ts} (100%) rename components/menu/style/{rtl.tsx => rtl.ts} (100%) rename components/menu/style/{theme.tsx => theme.ts} (100%) rename components/menu/style/{vertical.tsx => vertical.ts} (100%) rename components/message/style/{index.tsx => index.ts} (100%) rename components/modal/{index.tsx => index.ts} (100%) rename components/modal/{locale.tsx => locale.ts} (100%) rename components/modal/style/{confirm.tsx => confirm.ts} (100%) rename components/modal/style/{index.tsx => index.ts} (100%) rename components/popconfirm/style/{index.tsx => index.ts} (100%) rename components/popover/style/{index.tsx => index.ts} (100%) rename components/progress/{index.tsx => index.ts} (100%) rename components/progress/style/{index.tsx => index.ts} (100%) rename components/radio/style/{index.tsx => index.ts} (100%) rename components/rate/style/{index.tsx => index.ts} (100%) rename components/result/style/{index.tsx => index.ts} (100%) rename components/row/{index.tsx => index.ts} (100%) rename components/row/style/{index.tsx => index.ts} (100%) rename components/select/{mergedBuiltinPlacements.tsx => mergedBuiltinPlacements.ts} (100%) rename components/select/style/{dropdown.tsx => dropdown.ts} (100%) rename components/select/style/{index.tsx => index.ts} (100%) rename components/select/style/{multiple.tsx => multiple.ts} (100%) rename components/select/style/{single.tsx => single.ts} (100%) rename components/skeleton/style/{index.tsx => index.ts} (100%) rename components/slider/style/{index.tsx => index.ts} (100%) rename components/statistic/{index.tsx => index.ts} (89%) rename components/statistic/style/{index.tsx => index.ts} (100%) rename components/steps/style/{index.tsx => index.ts} (100%) rename components/timeline/{useItems.tsx => useItems.ts} (87%) rename components/watermark/{useRafDebounce.tsx => useRafDebounce.ts} (100%) rename components/watermark/{useWatermark.tsx => useWatermark.ts} (100%) rename tests/shared/{excludeWarning.tsx => excludeWarning.ts} (100%) diff --git a/components/_util/hooks/usePatchElement.tsx b/components/_util/hooks/usePatchElement.ts similarity index 100% rename from components/_util/hooks/usePatchElement.tsx rename to components/_util/hooks/usePatchElement.ts diff --git a/components/_util/hooks/useZIndex.tsx b/components/_util/hooks/useZIndex.ts similarity index 100% rename from components/_util/hooks/useZIndex.tsx rename to components/_util/hooks/useZIndex.ts diff --git a/components/cascader/Panel.tsx b/components/cascader/Panel.tsx index 6049c4c250..7c88e085a5 100644 --- a/components/cascader/Panel.tsx +++ b/components/cascader/Panel.tsx @@ -16,7 +16,7 @@ export type PanelPickType = Exclude | 'multiple' | 'rootC export type CascaderPanelProps = Pick; -export default function CascaderPanel(props: CascaderPanelProps) { +const CascaderPanel: React.FC = (props) => { const { prefixCls: customizePrefixCls, className, @@ -63,4 +63,6 @@ export default function CascaderPanel(props: CascaderPanelProps) { loadingIcon={loadingIcon} />, ); -} +}; + +export default CascaderPanel; diff --git a/components/menu/style/horizontal.tsx b/components/menu/style/horizontal.ts similarity index 100% rename from components/menu/style/horizontal.tsx rename to components/menu/style/horizontal.ts diff --git a/components/menu/style/index.tsx b/components/menu/style/index.ts similarity index 100% rename from components/menu/style/index.tsx rename to components/menu/style/index.ts diff --git a/components/menu/style/rtl.tsx b/components/menu/style/rtl.ts similarity index 100% rename from components/menu/style/rtl.tsx rename to components/menu/style/rtl.ts diff --git a/components/menu/style/theme.tsx b/components/menu/style/theme.ts similarity index 100% rename from components/menu/style/theme.tsx rename to components/menu/style/theme.ts diff --git a/components/menu/style/vertical.tsx b/components/menu/style/vertical.ts similarity index 100% rename from components/menu/style/vertical.tsx rename to components/menu/style/vertical.ts diff --git a/components/message/style/index.tsx b/components/message/style/index.ts similarity index 100% rename from components/message/style/index.tsx rename to components/message/style/index.ts diff --git a/components/modal/index.tsx b/components/modal/index.ts similarity index 100% rename from components/modal/index.tsx rename to components/modal/index.ts diff --git a/components/modal/locale.tsx b/components/modal/locale.ts similarity index 100% rename from components/modal/locale.tsx rename to components/modal/locale.ts diff --git a/components/modal/style/confirm.tsx b/components/modal/style/confirm.ts similarity index 100% rename from components/modal/style/confirm.tsx rename to components/modal/style/confirm.ts diff --git a/components/modal/style/index.tsx b/components/modal/style/index.ts similarity index 100% rename from components/modal/style/index.tsx rename to components/modal/style/index.ts diff --git a/components/popconfirm/style/index.tsx b/components/popconfirm/style/index.ts similarity index 100% rename from components/popconfirm/style/index.tsx rename to components/popconfirm/style/index.ts diff --git a/components/popover/PurePanel.tsx b/components/popover/PurePanel.tsx index f3da1a50d5..fe76c7cf98 100644 --- a/components/popover/PurePanel.tsx +++ b/components/popover/PurePanel.tsx @@ -1,18 +1,20 @@ +import * as React from 'react'; import classNames from 'classnames'; import { Popup } from 'rc-tooltip'; -import * as React from 'react'; -import type { PopoverProps } from '.'; -import { ConfigContext } from '../config-provider'; +import type { PopoverProps } from '.'; import { getRenderPropValue } from '../_util/getRenderPropValue'; +import { ConfigContext } from '../config-provider'; import useStyle from './style'; export const getOverlay = ( - prefixCls: string, + prefixCls?: string, title?: PopoverProps['title'], content?: PopoverProps['content'], ) => { - if (!title && !content) return undefined; + if (!title && !content) { + return null; + } return ( <> {title &&
{getRenderPropValue(title)}
} @@ -54,7 +56,7 @@ export const RawPurePanel: React.FC = (props) => { >
- {children || getOverlay(prefixCls!, title, content)} + {children || getOverlay(prefixCls, title, content)}
); diff --git a/components/popover/__tests__/demo.test.tsx b/components/popover/__tests__/demo.test.tsx index b02c927e55..0bc5e27ed5 100644 --- a/components/popover/__tests__/demo.test.tsx +++ b/components/popover/__tests__/demo.test.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; + import demoTest, { rootPropsTest } from '../../../tests/shared/demoTest'; demoTest('popover', { @@ -12,7 +13,5 @@ rootPropsTest( ), - { - findRootElements: () => document.querySelector('.ant-popover')!, - }, + { findRootElements: () => document.querySelector('.ant-popover')! }, ); diff --git a/components/popover/__tests__/index.test.tsx b/components/popover/__tests__/index.test.tsx index ba40ee4409..d3bfd0d374 100644 --- a/components/popover/__tests__/index.test.tsx +++ b/components/popover/__tests__/index.test.tsx @@ -1,39 +1,38 @@ import React from 'react'; + import Popover from '..'; import mountTest from '../../../tests/shared/mountTest'; import { fireEvent, render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; +import type { TooltipRef } from '../../tooltip'; + +const { _InternalPanelDoNotUseOrYouWillBeFired: InternalPanelDoNotUseOrYouWillBeFired } = Popover; describe('Popover', () => { mountTest(Popover); it('should show overlay when trigger is clicked', () => { - const ref = React.createRef(); - - const popover = render( + const ref = React.createRef(); + const { container } = render( show me your code , ); - - expect(popover.container.querySelector('.ant-popover-inner-content')).toBeFalsy(); - fireEvent.click(popover.container.querySelector('span')!); - expect(popover.container.querySelector('.ant-popover-inner-content')).toBeTruthy(); + expect(container.querySelector('.ant-popover-inner-content')).toBeFalsy(); + fireEvent.click(container.querySelector('span')!); + expect(container.querySelector('.ant-popover-inner-content')).toBeTruthy(); }); it('shows content for render functions', () => { const renderTitle = () => 'some-title'; const renderContent = () => 'some-content'; - const ref = React.createRef(); - - const popover = render( + const ref = React.createRef(); + const { container } = render( show me your code , ); - - fireEvent.click(popover.container.querySelector('span')!); - + fireEvent.click(container.querySelector('span')!); const popup = document.querySelector('.ant-popover')!; expect(popup).not.toBe(null); expect(popup.innerHTML).toContain('some-title'); @@ -80,13 +79,19 @@ describe('Popover', () => { }); it(`should be rendered correctly in RTL direction`, () => { - const wrapper = render( + const { container } = render( show me your Rtl demo , ); - expect(Array.from(wrapper.container.children)).toMatchSnapshot(); + expect(Array.from(container.children)).toMatchSnapshot(); + }); + + it('should right work when content is null & title is null', () => { + expect(() => { + render(); + }).not.toThrow(); }); }); diff --git a/components/popover/style/index.tsx b/components/popover/style/index.ts similarity index 100% rename from components/popover/style/index.tsx rename to components/popover/style/index.ts diff --git a/components/progress/index.tsx b/components/progress/index.ts similarity index 100% rename from components/progress/index.tsx rename to components/progress/index.ts diff --git a/components/progress/style/index.tsx b/components/progress/style/index.ts similarity index 100% rename from components/progress/style/index.tsx rename to components/progress/style/index.ts diff --git a/components/radio/style/index.tsx b/components/radio/style/index.ts similarity index 100% rename from components/radio/style/index.tsx rename to components/radio/style/index.ts diff --git a/components/rate/style/index.tsx b/components/rate/style/index.ts similarity index 100% rename from components/rate/style/index.tsx rename to components/rate/style/index.ts diff --git a/components/result/style/index.tsx b/components/result/style/index.ts similarity index 100% rename from components/result/style/index.tsx rename to components/result/style/index.ts diff --git a/components/row/index.tsx b/components/row/index.ts similarity index 100% rename from components/row/index.tsx rename to components/row/index.ts diff --git a/components/row/style/index.tsx b/components/row/style/index.ts similarity index 100% rename from components/row/style/index.tsx rename to components/row/style/index.ts diff --git a/components/select/mergedBuiltinPlacements.tsx b/components/select/mergedBuiltinPlacements.ts similarity index 100% rename from components/select/mergedBuiltinPlacements.tsx rename to components/select/mergedBuiltinPlacements.ts diff --git a/components/select/style/dropdown.tsx b/components/select/style/dropdown.ts similarity index 100% rename from components/select/style/dropdown.tsx rename to components/select/style/dropdown.ts diff --git a/components/select/style/index.tsx b/components/select/style/index.ts similarity index 100% rename from components/select/style/index.tsx rename to components/select/style/index.ts diff --git a/components/select/style/multiple.tsx b/components/select/style/multiple.ts similarity index 100% rename from components/select/style/multiple.tsx rename to components/select/style/multiple.ts diff --git a/components/select/style/single.tsx b/components/select/style/single.ts similarity index 100% rename from components/select/style/single.tsx rename to components/select/style/single.ts diff --git a/components/skeleton/style/index.tsx b/components/skeleton/style/index.ts similarity index 100% rename from components/skeleton/style/index.tsx rename to components/skeleton/style/index.ts diff --git a/components/slider/style/index.tsx b/components/slider/style/index.ts similarity index 100% rename from components/slider/style/index.tsx rename to components/slider/style/index.ts diff --git a/components/statistic/index.tsx b/components/statistic/index.ts similarity index 89% rename from components/statistic/index.tsx rename to components/statistic/index.ts index dfe3cd00ac..dd83b57a86 100644 --- a/components/statistic/index.tsx +++ b/components/statistic/index.ts @@ -13,4 +13,4 @@ export type CompoundedStatistic = typeof Statistic & CompoundedComponent; (Statistic as CompoundedStatistic).Countdown = Countdown; -export default Statistic as CompoundedStatistic; +export default (Statistic as CompoundedStatistic); diff --git a/components/statistic/style/index.tsx b/components/statistic/style/index.ts similarity index 100% rename from components/statistic/style/index.tsx rename to components/statistic/style/index.ts diff --git a/components/steps/style/index.tsx b/components/steps/style/index.ts similarity index 100% rename from components/steps/style/index.tsx rename to components/steps/style/index.ts diff --git a/components/tag/CheckableTag.tsx b/components/tag/CheckableTag.tsx index 6f529386bf..a7f98fb5a6 100644 --- a/components/tag/CheckableTag.tsx +++ b/components/tag/CheckableTag.tsx @@ -56,10 +56,7 @@ const CheckableTag = React.forwardRef((props , diff --git a/components/timeline/useItems.tsx b/components/timeline/useItems.ts similarity index 87% rename from components/timeline/useItems.tsx rename to components/timeline/useItems.ts index ebe723a7bc..a450da344c 100644 --- a/components/timeline/useItems.tsx +++ b/components/timeline/useItems.ts @@ -1,10 +1,12 @@ import type * as React from 'react'; import toArray from 'rc-util/lib/Children/toArray'; + import type { TimelineItemProps } from './TimelineItem'; function useItems(items?: TimelineItemProps[], children?: React.ReactNode): TimelineItemProps[] { - if (items && Array.isArray(items)) return items; - + if (items && Array.isArray(items)) { + return items; + } return toArray(children).map((ele: React.ReactElement) => ({ children: ele?.props?.children ?? '', ...ele.props, diff --git a/components/watermark/useRafDebounce.tsx b/components/watermark/useRafDebounce.ts similarity index 100% rename from components/watermark/useRafDebounce.tsx rename to components/watermark/useRafDebounce.ts diff --git a/components/watermark/useWatermark.tsx b/components/watermark/useWatermark.ts similarity index 100% rename from components/watermark/useWatermark.tsx rename to components/watermark/useWatermark.ts diff --git a/tests/shared/excludeWarning.tsx b/tests/shared/excludeWarning.ts similarity index 100% rename from tests/shared/excludeWarning.tsx rename to tests/shared/excludeWarning.ts