From 20a81169b119dbd2595251f7ec1df9794cc4c5c5 Mon Sep 17 00:00:00 2001 From: oasis-cloud Date: Thu, 14 Dec 2023 13:50:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E7=B1=BB=E5=9E=8B=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BB=9F=E4=B8=80=E4=B8=BA=20types=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20fixednavitem=20=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/address/address.taro.tsx | 2 +- src/packages/address/address.tsx | 2 +- src/packages/address/{type.ts => types.ts} | 0 src/packages/animate/__tests__/animate.spec.tsx | 2 +- src/packages/animate/animate.taro.tsx | 2 +- src/packages/animate/animate.tsx | 2 +- src/packages/animate/index.taro.ts | 2 +- src/packages/animate/index.ts | 2 +- src/packages/animate/{type.ts => types.ts} | 0 src/packages/calendar/calendar.taro.tsx | 2 +- src/packages/calendar/calendar.tsx | 2 +- src/packages/calendar/{type.ts => types.ts} | 0 src/packages/calendar/utils.tsx | 2 +- src/packages/calendaritem/calendaritem.taro.tsx | 2 +- src/packages/calendaritem/calendaritem.tsx | 2 +- src/packages/checkboxgroup/checkboxgroup.taro.tsx | 2 +- src/packages/checkboxgroup/checkboxgroup.tsx | 2 +- src/packages/checkboxgroup/{type.ts => types.ts} | 0 src/packages/fixednav/fixednav.taro.tsx | 13 ++++++------- src/packages/fixednav/fixednav.tsx | 13 ++++++------- src/packages/fixednav/index.taro.ts | 8 +++----- src/packages/fixednav/index.ts | 8 +++----- src/packages/fixednav/types.ts | 14 ++++++++++++++ src/packages/radiogroup/radiogroup.taro.tsx | 2 +- src/packages/radiogroup/radiogroup.tsx | 2 +- src/packages/radiogroup/{type.ts => types.ts} | 0 src/packages/virtuallist/{type.ts => types.ts} | 0 src/packages/virtuallist/utils.ts | 2 +- src/packages/virtuallist/virtuallist.taro.tsx | 2 +- src/packages/virtuallist/virtuallist.tsx | 2 +- 30 files changed, 51 insertions(+), 43 deletions(-) rename src/packages/address/{type.ts => types.ts} (100%) rename src/packages/animate/{type.ts => types.ts} (100%) rename src/packages/calendar/{type.ts => types.ts} (100%) rename src/packages/checkboxgroup/{type.ts => types.ts} (100%) create mode 100644 src/packages/fixednav/types.ts rename src/packages/radiogroup/{type.ts => types.ts} (100%) rename src/packages/virtuallist/{type.ts => types.ts} (100%) diff --git a/src/packages/address/address.taro.tsx b/src/packages/address/address.taro.tsx index 64268abf54..52b4c862b4 100644 --- a/src/packages/address/address.taro.tsx +++ b/src/packages/address/address.taro.tsx @@ -9,7 +9,7 @@ import Popup from '@/packages/popup/index.taro' import { ExistRender } from './existRender.taro' import { CustomRender } from './customRender.taro' import { useConfig } from '@/packages/configprovider/configprovider.taro' -import { AddressList } from './type' +import { AddressList } from './types' import { CascaderOption, CascaderOptionKey, diff --git a/src/packages/address/address.tsx b/src/packages/address/address.tsx index bc075ed531..ca0a3a0ddc 100644 --- a/src/packages/address/address.tsx +++ b/src/packages/address/address.tsx @@ -9,7 +9,7 @@ import Popup from '@/packages/popup' import { CustomRender } from './customRender' import { ExistRender } from './existRender' import { useConfig } from '@/packages/configprovider' -import { AddressList } from './type' +import { AddressList } from './types' import { CascaderOption, CascaderOptionKey, diff --git a/src/packages/address/type.ts b/src/packages/address/types.ts similarity index 100% rename from src/packages/address/type.ts rename to src/packages/address/types.ts diff --git a/src/packages/animate/__tests__/animate.spec.tsx b/src/packages/animate/__tests__/animate.spec.tsx index 7db801161f..c4d1ad9568 100644 --- a/src/packages/animate/__tests__/animate.spec.tsx +++ b/src/packages/animate/__tests__/animate.spec.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { render, waitFor, fireEvent } from '@testing-library/react' import '@testing-library/jest-dom' -import { AnimateType } from '../type' +import { AnimateType } from '../types' import { Animate } from '../animate' diff --git a/src/packages/animate/animate.taro.tsx b/src/packages/animate/animate.taro.tsx index 18fdbd9c28..4065743457 100644 --- a/src/packages/animate/animate.taro.tsx +++ b/src/packages/animate/animate.taro.tsx @@ -1,6 +1,6 @@ import React, { useState, FunctionComponent } from 'react' import classNames from 'classnames' -import { AnimateType, AnimateAction } from './type' +import { AnimateType, AnimateAction } from './types' import { BasicComponent, ComponentDefaults } from '@/utils/typings' diff --git a/src/packages/animate/animate.tsx b/src/packages/animate/animate.tsx index 18fdbd9c28..4065743457 100644 --- a/src/packages/animate/animate.tsx +++ b/src/packages/animate/animate.tsx @@ -1,6 +1,6 @@ import React, { useState, FunctionComponent } from 'react' import classNames from 'classnames' -import { AnimateType, AnimateAction } from './type' +import { AnimateType, AnimateAction } from './types' import { BasicComponent, ComponentDefaults } from '@/utils/typings' diff --git a/src/packages/animate/index.taro.ts b/src/packages/animate/index.taro.ts index 4bb70c55c8..1f795fe571 100644 --- a/src/packages/animate/index.taro.ts +++ b/src/packages/animate/index.taro.ts @@ -1,5 +1,5 @@ import { Animate } from './animate.taro' -export type { AnimateType, AnimateAction } from './type' +export type { AnimateType, AnimateAction } from './types' export type { AnimateProps } from './animate.taro' export default Animate diff --git a/src/packages/animate/index.ts b/src/packages/animate/index.ts index 7ae007af19..2fec80d997 100644 --- a/src/packages/animate/index.ts +++ b/src/packages/animate/index.ts @@ -1,5 +1,5 @@ import { Animate } from './animate' -export type { AnimateType, AnimateAction } from './type' +export type { AnimateType, AnimateAction } from './types' export type { AnimateProps } from './animate' export default Animate diff --git a/src/packages/animate/type.ts b/src/packages/animate/types.ts similarity index 100% rename from src/packages/animate/type.ts rename to src/packages/animate/types.ts diff --git a/src/packages/calendar/calendar.taro.tsx b/src/packages/calendar/calendar.taro.tsx index ddf30a32c5..ec417b388a 100644 --- a/src/packages/calendar/calendar.taro.tsx +++ b/src/packages/calendar/calendar.taro.tsx @@ -3,7 +3,7 @@ import Popup from '@/packages/popup/index.taro' import CalendarItem from '@/packages/calendaritem/index.taro' import { Utils } from '@/utils/date' import { useConfig } from '@/packages/configprovider/configprovider.taro' -import { Day, SelectedType } from './type' +import { Day, SelectedType } from './types' import { ComponentDefaults } from '@/utils/typings' type CalendarRef = { diff --git a/src/packages/calendar/calendar.tsx b/src/packages/calendar/calendar.tsx index 82fd0da75f..34d1efcac1 100644 --- a/src/packages/calendar/calendar.tsx +++ b/src/packages/calendar/calendar.tsx @@ -3,7 +3,7 @@ import Popup from '@/packages/popup' import CalendarItem from '@/packages/calendaritem' import { Utils } from '@/utils/date' import { useConfig } from '@/packages/configprovider' -import { Day, SelectedType } from './type' +import { Day, SelectedType } from './types' import { ComponentDefaults } from '@/utils/typings' type CalendarRef = { diff --git a/src/packages/calendar/type.ts b/src/packages/calendar/types.ts similarity index 100% rename from src/packages/calendar/type.ts rename to src/packages/calendar/types.ts diff --git a/src/packages/calendar/utils.tsx b/src/packages/calendar/utils.tsx index 55f581d7fc..a53b0f5077 100644 --- a/src/packages/calendar/utils.tsx +++ b/src/packages/calendar/utils.tsx @@ -1,5 +1,5 @@ import { Utils } from '@/utils/date' -import { Day, MonthInfo } from './type' +import { Day, MonthInfo } from './types' export const splitDate = (date: string) => { const split = date.indexOf('-') !== -1 ? '-' : '/' diff --git a/src/packages/calendaritem/calendaritem.taro.tsx b/src/packages/calendaritem/calendaritem.taro.tsx index edf93d723a..71b84ba66d 100644 --- a/src/packages/calendaritem/calendaritem.taro.tsx +++ b/src/packages/calendaritem/calendaritem.taro.tsx @@ -22,7 +22,7 @@ import { isEnd, isStartAndEnd, } from '../calendar/utils' -import { Day, MonthInfo, InputDate, SelectedType } from '../calendar/type' +import { Day, MonthInfo, InputDate, SelectedType } from '../calendar/types' type CalendarRef = { scrollToDate: (date: string) => void diff --git a/src/packages/calendaritem/calendaritem.tsx b/src/packages/calendaritem/calendaritem.tsx index 27ce6d600c..df089efad4 100644 --- a/src/packages/calendaritem/calendaritem.tsx +++ b/src/packages/calendaritem/calendaritem.tsx @@ -21,7 +21,7 @@ import { isEnd, isStartAndEnd, } from '../calendar/utils' -import { Day, MonthInfo, InputDate, SelectedType } from '../calendar/type' +import { Day, MonthInfo, InputDate, SelectedType } from '../calendar/types' type CalendarRef = { scrollToDate: (date: string) => void diff --git a/src/packages/checkboxgroup/checkboxgroup.taro.tsx b/src/packages/checkboxgroup/checkboxgroup.taro.tsx index 36c30cb5a7..0f6dc481ad 100644 --- a/src/packages/checkboxgroup/checkboxgroup.taro.tsx +++ b/src/packages/checkboxgroup/checkboxgroup.taro.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useImperativeHandle } from 'react' import classNames from 'classnames' -import { RadioGroupOptionType } from '@/packages/radiogroup/type' +import { RadioGroupOptionType } from '@/packages/radiogroup/types' import { Checkbox } from '../checkbox/checkbox.taro' import Context from './context' import { usePropsValue } from '@/utils/use-props-value' diff --git a/src/packages/checkboxgroup/checkboxgroup.tsx b/src/packages/checkboxgroup/checkboxgroup.tsx index 6dd2dbd65d..bb06d00c90 100644 --- a/src/packages/checkboxgroup/checkboxgroup.tsx +++ b/src/packages/checkboxgroup/checkboxgroup.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useImperativeHandle } from 'react' import classNames from 'classnames' -import { RadioGroupOptionType } from '@/packages/radiogroup/type' +import { RadioGroupOptionType } from '@/packages/radiogroup/types' import { Checkbox } from '../checkbox/checkbox' import Context from './context' import { usePropsValue } from '@/utils/use-props-value' diff --git a/src/packages/checkboxgroup/type.ts b/src/packages/checkboxgroup/types.ts similarity index 100% rename from src/packages/checkboxgroup/type.ts rename to src/packages/checkboxgroup/types.ts diff --git a/src/packages/fixednav/fixednav.taro.tsx b/src/packages/fixednav/fixednav.taro.tsx index 0d5d10bbf8..d47a3cc97e 100644 --- a/src/packages/fixednav/fixednav.taro.tsx +++ b/src/packages/fixednav/fixednav.taro.tsx @@ -4,17 +4,16 @@ import { ArrowLeft } from '@nutui/icons-react-taro' import Overlay from '@/packages/overlay/index.taro' import { useConfig } from '@/packages/configprovider/configprovider.taro' import { BasicComponent, ComponentDefaults } from '@/utils/typings' - -export type FixedNavDirection = 'right' | 'left' -export type FixedNavPosition = { - top?: string - bottom?: string -} +import { + FixedNavDirection, + FixedNavItem, + FixedNavPosition, +} from '@/packages/fixednav/types' export interface FixedNavProps extends BasicComponent { visible: boolean overlay: boolean - list: Array + list: Array activeText: string inactiveText: string position: FixedNavPosition diff --git a/src/packages/fixednav/fixednav.tsx b/src/packages/fixednav/fixednav.tsx index 6514fd1634..3585bda3bd 100644 --- a/src/packages/fixednav/fixednav.tsx +++ b/src/packages/fixednav/fixednav.tsx @@ -4,17 +4,16 @@ import { ArrowLeft } from '@nutui/icons-react' import Overlay from '@/packages/overlay' import { useConfig } from '@/packages/configprovider' import { BasicComponent, ComponentDefaults } from '@/utils/typings' - -export type FixedNavDirection = 'right' | 'left' -export type FixedNavPosition = { - top?: string - bottom?: string -} +import { + FixedNavDirection, + FixedNavItem, + FixedNavPosition, +} from '@/packages/fixednav/types' export interface FixedNavProps extends BasicComponent { visible: boolean overlay: boolean - list: Array + list: Array activeText: string inactiveText: string position: FixedNavPosition diff --git a/src/packages/fixednav/index.taro.ts b/src/packages/fixednav/index.taro.ts index 47c3d015c2..e7ef92d4f6 100644 --- a/src/packages/fixednav/index.taro.ts +++ b/src/packages/fixednav/index.taro.ts @@ -1,8 +1,6 @@ import { FixedNav } from './fixednav.taro' -export type { - FixedNavProps, - FixedNavDirection, - FixedNavPosition, -} from './fixednav.taro' +export type { FixedNavDirection, FixedNavPosition, FixedNavItem } from './types' + +export type { FixedNavProps } from './fixednav.taro' export default FixedNav diff --git a/src/packages/fixednav/index.ts b/src/packages/fixednav/index.ts index 965f2c0c70..c67b7f75a8 100644 --- a/src/packages/fixednav/index.ts +++ b/src/packages/fixednav/index.ts @@ -1,8 +1,6 @@ import { FixedNav } from './fixednav' -export type { - FixedNavProps, - FixedNavDirection, - FixedNavPosition, -} from './fixednav' +export type { FixedNavDirection, FixedNavPosition, FixedNavItem } from './types' + +export type { FixedNavProps } from './fixednav' export default FixedNav diff --git a/src/packages/fixednav/types.ts b/src/packages/fixednav/types.ts new file mode 100644 index 0000000000..03f0e83120 --- /dev/null +++ b/src/packages/fixednav/types.ts @@ -0,0 +1,14 @@ +import { Key, ReactNode } from 'react' + +export type FixedNavDirection = 'right' | 'left' +export type FixedNavPosition = { + top?: string + bottom?: string +} + +export interface FixedNavItem { + id: Key + num: number + text: ReactNode + icon: ReactNode +} diff --git a/src/packages/radiogroup/radiogroup.taro.tsx b/src/packages/radiogroup/radiogroup.taro.tsx index 87f19117b6..24c57bea9c 100644 --- a/src/packages/radiogroup/radiogroup.taro.tsx +++ b/src/packages/radiogroup/radiogroup.taro.tsx @@ -1,6 +1,6 @@ import React, { useCallback } from 'react' import classNames from 'classnames' -import { RadioGroupOptionType } from './type' +import { RadioGroupOptionType } from './types' import RadioContext from './context' import Radio from '@/packages/radio/index.taro' import { usePropsValue } from '@/utils/use-props-value' diff --git a/src/packages/radiogroup/radiogroup.tsx b/src/packages/radiogroup/radiogroup.tsx index 38f2b3e98c..0a08917dad 100644 --- a/src/packages/radiogroup/radiogroup.tsx +++ b/src/packages/radiogroup/radiogroup.tsx @@ -1,6 +1,6 @@ import React, { useCallback } from 'react' import classNames from 'classnames' -import { RadioGroupOptionType } from './type' +import { RadioGroupOptionType } from './types' import RadioContext from './context' import Radio from '@/packages/radio/index' import { usePropsValue } from '@/utils/use-props-value' diff --git a/src/packages/radiogroup/type.ts b/src/packages/radiogroup/types.ts similarity index 100% rename from src/packages/radiogroup/type.ts rename to src/packages/radiogroup/types.ts diff --git a/src/packages/virtuallist/type.ts b/src/packages/virtuallist/types.ts similarity index 100% rename from src/packages/virtuallist/type.ts rename to src/packages/virtuallist/types.ts diff --git a/src/packages/virtuallist/utils.ts b/src/packages/virtuallist/utils.ts index 5fafe77ce1..70369dbcd5 100644 --- a/src/packages/virtuallist/utils.ts +++ b/src/packages/virtuallist/utils.ts @@ -1,4 +1,4 @@ -import { PositionType, Data } from './type' +import { PositionType, Data } from './types' // 缓存列表初始化信息 const initPositinoCache = (reaItemSize: number, length = 0): PositionType[] => { diff --git a/src/packages/virtuallist/virtuallist.taro.tsx b/src/packages/virtuallist/virtuallist.taro.tsx index f920c02d98..b09a8495ea 100644 --- a/src/packages/virtuallist/virtuallist.taro.tsx +++ b/src/packages/virtuallist/virtuallist.taro.tsx @@ -9,7 +9,7 @@ import React, { import { ScrollView } from '@tarojs/components' import { getSystemInfoSync } from '@tarojs/taro' import classNames from 'classnames' -import { Data, PositionType, VirtualListState } from './type' +import { Data, PositionType, VirtualListState } from './types' import { binarySearch, initPositinoCache, updateItemSize } from './utils' import { BasicComponent, ComponentDefaults } from '@/utils/typings' diff --git a/src/packages/virtuallist/virtuallist.tsx b/src/packages/virtuallist/virtuallist.tsx index 834f92d5ae..13657cadb0 100644 --- a/src/packages/virtuallist/virtuallist.tsx +++ b/src/packages/virtuallist/virtuallist.tsx @@ -7,7 +7,7 @@ import React, { useState, } from 'react' import classNames from 'classnames' -import type { Data, VirtualListState, PositionType } from './type' +import type { Data, VirtualListState, PositionType } from './types' import { initPositinoCache, getListTotalSize, From 9807eac310cc9bd4e0b9630a2ac31cdfb69be4e1 Mon Sep 17 00:00:00 2001 From: oasis-cloud Date: Fri, 15 Dec 2023 09:42:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E7=B1=BB=E5=9E=8B=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BB=9F=E4=B8=80=E4=B8=BA=20types=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20fixednavitem=20=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/address/existRender.taro.tsx | 2 +- src/packages/address/existRender.tsx | 2 +- .../__tests__/animatingnumbers.spec.tsx | 11 +++++++---- src/packages/fixednav/__tests__/fixednav.spec.tsx | 4 ++-- src/packages/fixednav/types.ts | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/packages/address/existRender.taro.tsx b/src/packages/address/existRender.taro.tsx index 5e453bf3f9..ec57e9b3d5 100644 --- a/src/packages/address/existRender.taro.tsx +++ b/src/packages/address/existRender.taro.tsx @@ -2,7 +2,7 @@ import React, { FunctionComponent, MouseEventHandler, ReactNode } from 'react' import { Check, Location } from '@nutui/icons-react-taro' import { ScrollView } from '@tarojs/components' import { useConfig } from '@/packages/configprovider/configprovider.taro' -import { AddressList } from './type' +import { AddressList } from './types' export interface ExistRenderProps { type: string diff --git a/src/packages/address/existRender.tsx b/src/packages/address/existRender.tsx index 3b91858bce..abcc0be99e 100644 --- a/src/packages/address/existRender.tsx +++ b/src/packages/address/existRender.tsx @@ -1,7 +1,7 @@ import React, { FunctionComponent, MouseEventHandler, ReactNode } from 'react' import { Check, Location } from '@nutui/icons-react' import { useConfig } from '@/packages/configprovider' -import { AddressList } from './type' +import { AddressList } from './types' export interface ExistRenderProps { type: string diff --git a/src/packages/animatingnumbers/__tests__/animatingnumbers.spec.tsx b/src/packages/animatingnumbers/__tests__/animatingnumbers.spec.tsx index 5f2831f5ac..610b7cf629 100644 --- a/src/packages/animatingnumbers/__tests__/animatingnumbers.spec.tsx +++ b/src/packages/animatingnumbers/__tests__/animatingnumbers.spec.tsx @@ -29,10 +29,13 @@ test('test aysnc value and duration props', async () => { const listNumbers = container.querySelectorAll('.nut-countup-number') expect(listNumbers.length).toBe(8) jest.advanceTimersByTime(CountUp.defaultProps?.delay ?? 0) - expect(listNumbers[0]).toHaveAttribute( - 'style', - 'transition: transform 1.2s ease-in-out; transform: translate(0, -50%); webkit-transform: translate(0, -50%);' - ) + await waitFor(() => { + expect(listNumbers[0]).toHaveAttribute( + 'style', + 'transition: transform 1.2s ease-in-out; transform: translate(0, -50%); webkit-transform: translate(0, -50%);' + ) + }) + value = `${Math.floor(Math.random() * 999999)}.${Math.floor( Math.random() * 89 + 10 )}` diff --git a/src/packages/fixednav/__tests__/fixednav.spec.tsx b/src/packages/fixednav/__tests__/fixednav.spec.tsx index 482dd63e5b..cf59f80efd 100644 --- a/src/packages/fixednav/__tests__/fixednav.spec.tsx +++ b/src/packages/fixednav/__tests__/fixednav.spec.tsx @@ -2,9 +2,9 @@ import * as React from 'react' import { render, fireEvent, screen } from '@testing-library/react' import '@testing-library/jest-dom' -import FixedNav from '../index' +import FixedNav, { FixedNavItem } from '../index' -const list = [ +const list: FixedNavItem[] = [ { id: 1, text: '首页', diff --git a/src/packages/fixednav/types.ts b/src/packages/fixednav/types.ts index 03f0e83120..61184d161f 100644 --- a/src/packages/fixednav/types.ts +++ b/src/packages/fixednav/types.ts @@ -8,7 +8,7 @@ export type FixedNavPosition = { export interface FixedNavItem { id: Key - num: number + num?: number text: ReactNode icon: ReactNode }