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: 类型规范化 #3034

Open
wants to merge 12 commits into
base: feat_v3.x
Choose a base branch
from
  •  
  •  
  •  
20 changes: 5 additions & 15 deletions src/packages/actionsheet/actionsheet.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import React, { FunctionComponent, ReactNode } from 'react'
import React, { FunctionComponent } from 'react'
import { View } from '@tarojs/components'
import Popup, { PopupProps } from '@/packages/popup/index.taro'
import Popup from '@/packages/popup/index.taro'
import { ComponentDefaults } from '@/utils/typings'
import { mergeProps } from '@/utils/merge-props'
import { ActionSheetOption, TaroActionSheetProps } from '@/types'

export type ActionSheetOption<T> = { [key: string]: T }

export interface ActionSheetProps extends PopupProps {
visible: boolean
description: ReactNode
options: ActionSheetOption<string | boolean>[]
optionKey: ActionSheetOption<string>
cancelText: ReactNode
onCancel: () => void
onSelect: (item: ActionSheetOption<string | boolean>, index: number) => void
}
const defaultProps = {
...ComponentDefaults,
visible: false,
Expand All @@ -24,9 +14,9 @@ const defaultProps = {
cancelText: '',
onCancel: () => {},
onSelect: () => {},
} as unknown as ActionSheetProps
} as unknown as TaroActionSheetProps
export const ActionSheet: FunctionComponent<
Partial<ActionSheetProps> &
Partial<TaroActionSheetProps> &
Omit<React.HTMLAttributes<HTMLDivElement>, 'title' | 'onSelect' | 'onClick'>
> = (props) => {
const {
Expand Down
20 changes: 5 additions & 15 deletions src/packages/actionsheet/actionsheet.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import React, { FunctionComponent, ReactNode } from 'react'
import Popup, { PopupProps } from '@/packages/popup/index'
import React, { FunctionComponent } from 'react'
import Popup from '@/packages/popup/index'
import { ComponentDefaults } from '@/utils/typings'
import { mergeProps } from '@/utils/merge-props'
import { ActionSheetOption, WebActionSheetProps } from '@/types'

export type ActionSheetOption<T> = { [key: string]: T }

export interface ActionSheetProps extends PopupProps {
visible: boolean
description: ReactNode
options: ActionSheetOption<string | boolean>[]
optionKey: ActionSheetOption<string>
cancelText: ReactNode
onCancel: () => void
onSelect: (item: ActionSheetOption<string | boolean>, index: number) => void
}
const defaultProps = {
...ComponentDefaults,
visible: false,
Expand All @@ -23,9 +13,9 @@ const defaultProps = {
cancelText: '',
onCancel: () => {},
onSelect: () => {},
} as unknown as ActionSheetProps
} as unknown as WebActionSheetProps
export const ActionSheet: FunctionComponent<
Partial<ActionSheetProps> &
Partial<WebActionSheetProps> &
Omit<React.HTMLAttributes<HTMLDivElement>, 'title' | 'onSelect'>
> = (props) => {
const {
Expand Down
5 changes: 4 additions & 1 deletion src/packages/actionsheet/index.taro.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ActionSheet } from './actionsheet.taro'

export type { ActionSheetOption, ActionSheetProps } from './actionsheet.taro'
export type {
ActionSheetOption,
TaroActionSheetProps as ActionSheetProps,
} from '@/types'

export default ActionSheet
5 changes: 4 additions & 1 deletion src/packages/actionsheet/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ActionSheet } from './actionsheet'

export type { ActionSheetOption, ActionSheetProps } from './actionsheet'
export type {
ActionSheetOption,
WebActionSheetProps as ActionSheetProps,
} from '@/types'

export default ActionSheet
7 changes: 1 addition & 6 deletions src/packages/address/address.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Popup from '@/packages/popup/index.taro'
import { ExistRender } from './existRender.taro'
import { CustomRender } from './customRender.taro'
import { useConfig } from '@/packages/configprovider/index.taro'
import { AddressList } from './types'
import { AddressList, AddressRef } from './types'
import {
CascaderOption,
CascaderOptionKey,
Expand All @@ -20,11 +20,6 @@ import {
import { ComponentDefaults } from '@/utils/typings'
import { usePropsValue } from '@/hooks/use-props-value'

type AddressRef = {
open: () => void
close: () => void
}

export interface AddressProps extends CascaderProps {
visible: boolean
defaultVisible: boolean
Expand Down
7 changes: 1 addition & 6 deletions src/packages/address/address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 './types'
import { AddressList, AddressRef } from './types'
import {
CascaderOption,
CascaderOptionKey,
Expand All @@ -19,11 +19,6 @@ import {
import { ComponentDefaults } from '@/utils/typings'
import { usePropsValue } from '@/hooks/use-props-value'

type AddressRef = {
open: () => void
close: () => void
}

export interface AddressProps extends CascaderProps {
visible: boolean
defaultVisible: boolean
Expand Down
1 change: 1 addition & 0 deletions src/packages/address/index.taro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Address } from './address.taro'

export type { AddressProps } from './address.taro'
export type { AddressList, AddressRef } from './types'
export default Address
1 change: 1 addition & 0 deletions src/packages/address/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Address } from './address'

export type { AddressProps } from './address'
export type { AddressList, AddressRef } from './types'

export default Address
5 changes: 5 additions & 0 deletions src/packages/address/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export interface CloseCallBackData extends Regions {
addressStr: string
}

export type AddressRef = {
open: () => void
close: () => void
}

export interface ResultData {
data: CloseCallBackData | AddressList
type: string
Expand Down
29 changes: 10 additions & 19 deletions src/packages/animate/animate.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import React, { useState, FunctionComponent } from 'react'
import React, { FunctionComponent, useState } from 'react'
import classNames from 'classnames'
import { View, ITouchEvent } from '@tarojs/components'
import { AnimateType, AnimateAction } from './types'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'

export interface AnimateProps extends BasicComponent {
type: AnimateType
action: AnimateAction
loop: boolean
onClick: (event: React.MouseEvent<Element, MouseEvent> | ITouchEvent) => void
}
import { ITouchEvent, View } from '@tarojs/components'
import { ComponentDefaults } from '@/utils/typings'
import { TaroAnimateProps } from '@/types'

const defaultProps = {
...ComponentDefaults,
type: 'shake',
action: 'initial',
loop: false,
onClick: (event: React.MouseEvent<Element, MouseEvent> | ITouchEvent) => {},
} as AnimateProps
onClick: (event) => {},
} as TaroAnimateProps

const classPrefix = 'nut-animate'

export const Animate: FunctionComponent<
Partial<AnimateProps> & React.HTMLAttributes<HTMLDivElement>
> = (props) => {
export const Animate: FunctionComponent<Partial<TaroAnimateProps>> = (
props
) => {
const { className, type, action, loop, onClick, children, style } = {
...defaultProps,
...props,
Expand All @@ -40,9 +33,7 @@ export const Animate: FunctionComponent<
className
)

const handleClick = (
event: React.MouseEvent<Element, MouseEvent> | ITouchEvent
) => {
const handleClick = (event: ITouchEvent) => {
setClicked(true)
// 如果不是无限循环,清除类名
if (!loop) {
Expand Down
15 changes: 4 additions & 11 deletions src/packages/animate/animate.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import React, { useState, FunctionComponent } from 'react'
import classNames from 'classnames'
import { AnimateType, AnimateAction } from './types'
import { ComponentDefaults } from '@/utils/typings'
import { WebAnimateProps } from '@/types'

import { BasicComponent, ComponentDefaults } from '@/utils/typings'

export interface AnimateProps extends BasicComponent {
type: AnimateType
action: AnimateAction
loop: boolean
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
}
const defaultProps = {
...ComponentDefaults,
type: 'shake',
action: 'initial',
loop: false,
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {},
} as AnimateProps
} as WebAnimateProps

const classPrefix = 'nut-animate'
export const Animate: FunctionComponent<
Partial<AnimateProps> & React.HTMLAttributes<HTMLDivElement>
Partial<WebAnimateProps> & React.HTMLAttributes<HTMLDivElement>
> = (props) => {
const { className, type, action, loop, onClick, children, ...rest } = {
...defaultProps,
Expand Down
7 changes: 5 additions & 2 deletions src/packages/animate/index.taro.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Animate } from './animate.taro'

export type { AnimateType, AnimateAction } from './types'
export type { AnimateProps } from './animate.taro'
export type {
TaroAnimateProps as AnimateProps,
AnimateType,
AnimateAction,
} from '@/types'
export default Animate
7 changes: 5 additions & 2 deletions src/packages/animate/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Animate } from './animate'

export type { AnimateType, AnimateAction } from './types'
export type { AnimateProps } from './animate'
export type {
WebAnimateProps as AnimateProps,
AnimateType,
AnimateAction,
} from '@/types'
export default Animate
16 changes: 6 additions & 10 deletions src/packages/animatingnumbers/countup.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@
} from 'react'
import { View, Text } from '@tarojs/components'
import { createSelectorQuery } from '@tarojs/taro'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { ComponentDefaults } from '@/utils/typings'
import { mergeProps } from '@/utils/merge-props'
import { TaroCountUpProps } from '@/types'

export interface CountUpProps extends BasicComponent {
length: number
value: string
delay?: number
duration: number
thousands: boolean
}
const defaultProps = {
...ComponentDefaults,
length: 0,
value: '',
delay: 300,
duration: 1,
thousands: false,
} as CountUpProps
export const CountUp: FunctionComponent<Partial<CountUpProps>> = (props) => {
} as TaroCountUpProps
export const CountUp: FunctionComponent<Partial<TaroCountUpProps>> = (
props
) => {
const {
length,
value,
Expand Down Expand Up @@ -85,7 +81,7 @@
})
.exec()
}
}, [numberArr])

Check warning on line 84 in src/packages/animatingnumbers/countup.taro.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has a missing dependency: 'duration'. Either include it or remove the dependency array

useEffect(() => {
if (numberArr.length) {
Expand Down
14 changes: 4 additions & 10 deletions src/packages/animatingnumbers/countup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ import React, {
useMemo,
useRef,
} from 'react'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { ComponentDefaults } from '@/utils/typings'
import { mergeProps } from '@/utils/merge-props'
import { WebCountUpProps } from '@/types'

export interface CountUpProps extends BasicComponent {
length: number
value: string
delay?: number
duration: number
thousands: boolean
}
const defaultProps = {
...ComponentDefaults,
length: 0,
value: '',
delay: 300,
duration: 1,
thousands: false,
} as CountUpProps
export const CountUp: FunctionComponent<Partial<CountUpProps>> = (props) => {
} as WebCountUpProps
export const CountUp: FunctionComponent<Partial<WebCountUpProps>> = (props) => {
const {
length,
value,
Expand Down
2 changes: 1 addition & 1 deletion src/packages/animatingnumbers/index.taro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnimatingNumbers } from './animatingnumbers.taro'
import { CountUp } from './countup.taro'

export type { CountUpProps } from './countup.taro'
export type { TaroCountUpProps as CountUpProps } from '@/types'
AnimatingNumbers.CountUp = CountUp
export default AnimatingNumbers
2 changes: 1 addition & 1 deletion src/packages/animatingnumbers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { AnimatingNumbers } from './animatingnumbers'
import { CountUp } from './countup'

AnimatingNumbers.CountUp = CountUp
export type { CountUpProps } from './countup'
export type { WebCountUpProps as CountUpProps } from '@/types'
export default AnimatingNumbers
Loading
Loading