Skip to content

Commit

Permalink
fix(antd/next): fix upload typings (#2856)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Feb 24, 2022
1 parent de85f9f commit 5b78f97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions packages/antd/src/upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import { isArr, toArr } from '@formily/shared'
import { UPLOAD_PLACEHOLDER } from './placeholder'
import { usePrefixCls } from '../__builtins__'

export type UploadProps = Omit<AntdUploadProps, 'onChange'> & {
export type IUploadProps = Omit<AntdUploadProps, 'onChange'> & {
textContent?: React.ReactNode
onChange?: (fileList: UploadFile[]) => void
serviceErrorMessage?: string
}

export type DraggerProps = Omit<AntdDraggerProps, 'onChange'> & {
export type IDraggerUploadProps = Omit<AntdDraggerProps, 'onChange'> & {
textContent?: React.ReactNode
onChange?: (fileList: UploadFile[]) => void
serviceErrorMessage?: string
}

type ComposedUpload = React.FC<UploadProps> & {
Dragger?: React.FC<DraggerProps>
type ComposedUpload = React.FC<IUploadProps> & {
Dragger?: React.FC<IDraggerUploadProps>
}

type IUploadProps = {
type IExtendsUploadProps = {
fileList?: any[]
serviceErrorMessage?: string
onChange?: (...args: any) => void
Expand Down Expand Up @@ -148,7 +148,7 @@ const useUploadValidator = (serviceErrorMessage = 'Upload Service Error') => {
})
}

function useUploadProps<T extends IUploadProps = UploadProps>({
function useUploadProps<T extends IExtendsUploadProps = IUploadProps>({
serviceErrorMessage,
...props
}: T) {
Expand All @@ -163,7 +163,7 @@ function useUploadProps<T extends IUploadProps = UploadProps>({
}
}

const getPlaceholder = (props: UploadProps) => {
const getPlaceholder = (props: IUploadProps) => {
if (props.listType !== 'picture-card') {
return (
<Button>
Expand All @@ -176,7 +176,7 @@ const getPlaceholder = (props: UploadProps) => {
}

export const Upload: ComposedUpload = connect(
(props: React.PropsWithChildren<UploadProps>) => {
(props: React.PropsWithChildren<IUploadProps>) => {
return (
<AntdUpload {...useUploadProps(props)}>
{props.children || getPlaceholder(props)}
Expand All @@ -189,7 +189,7 @@ export const Upload: ComposedUpload = connect(
)

const Dragger = connect(
(props: React.PropsWithChildren<DraggerProps>) => {
(props: React.PropsWithChildren<IDraggerUploadProps>) => {
return (
<div className={usePrefixCls('upload-dragger')}>
<AntdUpload.Dragger {...useUploadProps(props)}>
Expand Down
26 changes: 13 additions & 13 deletions packages/next/src/upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import {
import { isArr, toArr } from '@formily/shared'
import { UPLOAD_PLACEHOLDER } from './placeholder'

type UploadProps = NextUploadProps & {
type ExtendsUploadProps = NextUploadProps & {
textContent?: React.ReactNode
serviceErrorMessage?: string
}

type FileList = Parameters<UploadProps['onChange']>[0]
type FileList = Parameters<ExtendsUploadProps['onChange']>[0]

type ExtendUploadProps = UploadProps & { serviceErrorMessage?: string }

type ExtendCardProps = CardProps & { serviceErrorMessage?: string }

type ComposedUpload = React.FC<ExtendUploadProps> & {
Card?: React.FC<ExtendCardProps>
Dragger?: React.FC<ExtendUploadProps>
type ComposedUpload = React.FC<IUploadProps> & {
Card?: React.FC<ICardUploadProps>
Dragger?: React.FC<IUploadProps>
}

type IUploadProps = {
type IExtendsUploadProps = {
value?: any[]
serviceErrorMessage?: string
onChange?: (...args: any) => void
formatter?: (...args: any) => any
}

export type IUploadProps = ExtendsUploadProps & { serviceErrorMessage?: string }

export type ICardUploadProps = CardProps & { serviceErrorMessage?: string }

const testOpts = (
ext: RegExp,
options: { exclude?: string[]; include?: string[] }
Expand Down Expand Up @@ -101,7 +101,7 @@ const getState = (target: any) => {
return target?.state || target?.status
}

const normalizeFileList = (fileList: UploadProps['value']) => {
const normalizeFileList = (fileList: IUploadProps['value']) => {
if (fileList && fileList.length) {
return fileList.map(({ ...file }, index) => {
delete file['originFileObj']
Expand Down Expand Up @@ -157,7 +157,7 @@ const useUploadValidator = (serviceErrorMessage = 'Upload Service Error') => {
})
}

function useUploadProps<T extends IUploadProps = ExtendUploadProps>({
function useUploadProps<T extends IExtendsUploadProps = IUploadProps>({
serviceErrorMessage,
...props
}: T) {
Expand All @@ -182,7 +182,7 @@ function useUploadProps<T extends IUploadProps = ExtendUploadProps>({
}
}

const getPlaceholder = (props: UploadProps) => {
const getPlaceholder = (props: IUploadProps) => {
if (props.shape !== 'card') {
return (
<Button>
Expand Down

0 comments on commit 5b78f97

Please sign in to comment.