Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dumirc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'path';

export default defineConfig({
alias: {
'rc-upload$': path.resolve('src'),
'rc-upload/es': path.resolve('src'),
'@rc-component/upload$': path.resolve('src'),
'@rc-component/upload/es': path.resolve('src'),
},
mfsu: false,
favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'],
Expand Down
100 changes: 46 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# rc-upload
# @rc-component/upload

React Upload

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![build status][github-actions-image]][github-actions-url]
[![Codecov][codecov-image]][codecov-url]
[![bundle size][bundlephobia-image]][bundlephobia-url]
[![dumi][dumi-image]][dumi-url]
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] [![dumi][dumi-image]][dumi-url]

[npm-image]: http://img.shields.io/npm/v/rc-upload.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-upload
[npm-image]: http://img.shields.io/npm/v/@rc-component/upload.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/upload
[travis-image]: https://img.shields.io/travis/react-component/upload/master?style=flat-square
[travis-url]: https://travis-ci.com/react-component/upload
[github-actions-image]: https://github.com/react-component/upload/workflows/CI/badge.svg
Expand All @@ -21,10 +16,10 @@ React Upload
[david-image]: https://david-dm.org/react-component/upload/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/upload?type=dev
[david-dev-image]: https://david-dm.org/react-component/upload/dev-status.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/rc-upload.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-upload
[bundlephobia-url]: https://bundlephobia.com/package/rc-upload
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-upload
[download-image]: https://img.shields.io/npm/dm/@rc-component/upload.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/upload
[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/upload
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/upload
[dumi-url]: https://github.com/umijs/dumi
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square

Expand All @@ -43,16 +38,16 @@ online example: https://upload.react-component.vercel.app/

## Feature

* support IE11+, Chrome, Firefox, Safari
- support IE11+, Chrome, Firefox, Safari

## install

[![rc-upload](https://nodei.co/npm/rc-upload.png)](https://npmjs.org/package/rc-upload)
[![@rc-component/upload](https://nodei.co/npm/@rc-component/upload.png)](https://npmjs.org/package/@rc-component/upload)

## Usage

```js
var Upload = require('rc-upload');
var Upload = require('@rc-component/upload');
var React = require('react');
React.render(<Upload />, container);
```
Expand All @@ -61,30 +56,30 @@ React.render(<Upload />, container);

### props

|name|type|default| description|
|-----|---|--------|----|
|name | string | file| file param post to server |
|style | object | {}| root component inline style |
|className | string | - | root component className |
|disabled | boolean | false | whether disabled |
|component | "div"|"span" | "span"| wrap component name |
|action| string &#124; function(file): string &#124; Promise&lt;string&gt; | | form action url |
|method | string | post | request method |
|directory| boolean | false | support upload whole directory |
|data| object/function(file) | | other data object to post or a function which returns a data object(a promise object which resolve a data object) |
|headers| object | {} | http headers to post, available in modern browsers |
|accept | string | | input accept attribute |
|capture | string | | input capture attribute |
|multiple | boolean | false | only support ie10+|
|onStart | function| | start upload file |
|onError| function| | error callback |
|onSuccess | function | | success callback |
|onProgress | function || progress callback, only for modern browsers|
|beforeUpload| function |null| before upload check, return false or a rejected Promise will stop upload, only for modern browsers|
|customRequest | function | null | provide an override for the default xhr behavior for additional customization|
|withCredentials | boolean | false | ajax upload with cookie send |
|openFileDialogOnClick | boolean | true | useful for drag only upload as it does not trigger on enter key or click event |
|pastable | boolean | false | support paste upload |
| name | type | default | description |
| --- | --- | --- | --- |
| name | string | file | file param post to server |
| style | object | {} | root component inline style |
| className | string | - | root component className |
| disabled | boolean | false | whether disabled |
| component | "div" \| "span" | "span" | wrap component name |
| action | string &#124; function(file): string &#124; Promise&lt;string&gt; | | form action url |
| method | string | post | request method |
| directory | boolean | false | support upload whole directory |
| data | object/function(file) | | other data object to post or a function which returns a data object(a promise object which resolve a data object) |
| headers | object | {} | http headers to post, available in modern browsers |
| accept | string | | input accept attribute |
| capture | string | | input capture attribute |
| multiple | boolean | false | only support ie10+ |
| onStart | function | | start upload file |
| onError | function | | error callback |
| onSuccess | function | | success callback |
| onProgress | function | | progress callback, only for modern browsers |
| beforeUpload | function | null | before upload check, return false or a rejected Promise will stop upload, only for modern browsers |
| customRequest | function | null | provide an override for the default xhr behavior for additional customization |
| withCredentials | boolean | false | ajax upload with cookie send |
| openFileDialogOnClick | boolean | true | useful for drag only upload as it does not trigger on enter key or click event |
| pastable | boolean | false | support paste upload |

#### onError arguments

Expand All @@ -96,31 +91,28 @@ React.render(<Upload />, container);

1. `result`: response body
2. `file`: upload file
3. `xhr`: xhr header, only for modern browsers which support AJAX upload. since
2.4.0

3. `xhr`: xhr header, only for modern browsers which support AJAX upload. since 2.4.0

### customRequest

Allows for advanced customization by overriding default behavior in AjaxUploader. Provide your own XMLHttpRequest calls to interface with custom backend processes or interact with AWS S3 service through the aws-sdk-js package.

customRequest callback is passed an object with:

* `onProgress: (event: { percent: number }): void`
* `onError: (event: Error, body?: Object): void`
* `onSuccess: (body: Object): void`
* `data: Object`
* `filename: String`
* `file: File`
* `withCredentials: Boolean`
* `action: String`
* `headers: Object`

- `onProgress: (event: { percent: number }): void`
- `onError: (event: Error, body?: Object): void`
- `onSuccess: (body: Object): void`
- `data: Object`
- `filename: String`
- `file: File`
- `withCredentials: Boolean`
- `action: String`
- `headers: Object`

### methods

abort(file?: File) => void: abort the uploading file

## License

rc-upload is released under the MIT license.
@rc-component/upload is released under the MIT license.
2 changes: 1 addition & 1 deletion docs/examples/asyncAction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console:0 */
import React from 'react';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const props = {
action: () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/beforeUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-console:0 */

import type { Action, RcFile } from '@/interface';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const props = {
action: '/upload.do' as Action,
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/customRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-console:0 */
import React from 'react';
import axios from 'axios';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';
import { UploadRequestOption } from '@/interface';

const uploadProps = {
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/directoryUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-console:0 */

import React from 'react';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const Test = () => {
const uploaderProps = {
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/drag.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console:0 */
import React from 'react';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const props = {
action: '/upload.do',
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/dragDirectory.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console:0 */
import React from 'react';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const props = {
action: '/upload.do',
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/paste.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console:0 */
import React from 'react';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const props = {
action: '/upload.do',
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/pasteDirectory.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console:0 */
import React from 'react';
import Upload from 'rc-upload';
import Upload from '@rc-component/upload';

const props = {
action: '/upload.do',
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console:0 */

import Upload, { type UploadProps } from 'rc-upload';
import Upload, { type UploadProps } from '@rc-component/upload';
import React from 'react';

const style = `
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: rc-upload
title: @rc-component/upload
---

<embed src="../README.md"></embed>
11 changes: 0 additions & 11 deletions now.json

This file was deleted.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-upload",
"version": "4.11.0",
"name": "@rc-component/upload",
"version": "1.0.0",
"description": "upload ui component for react",
"keywords": [
"react",
Expand Down Expand Up @@ -30,19 +30,19 @@
"docs:deploy": "npm run docs:build && gh-pages -d dist",
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
"now-build": "npm run docs:build",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"prepublishOnly": "npm run compile && rc-np",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
"postpublish": "npm run docs:deploy",
"start": "dumi dev",
"test": "rc-test"
},
"dependencies": {
"@babel/runtime": "^7.18.3",
"classnames": "^2.2.5",
"rc-util": "^5.2.0"
"@rc-component/util": "^1.3.0",
"classnames": "^2.2.5"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
"@rc-component/father-plugin": "^2.0.2",
"@rc-component/np": "^1.0.4",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^16.2.0",
"@types/jest": "^30.0.0",
Expand All @@ -58,7 +58,6 @@
"father": "^4.0.0",
"fs-extra": "^11.2.0",
"gh-pages": "^6.1.1",
"np": "^10.0.7",
"raf": "^3.4.0",
"rc-test": "^7.0.13",
"react": "^18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint react/no-is-mounted:0,react/sort-comp:0,react/prop-types:0 */
import clsx from 'classnames';
import pickAttrs from 'rc-util/lib/pickAttrs';
import pickAttrs from '@rc-component/util/lib/pickAttrs';
import React, { Component } from 'react';
import attrAccept from './attr-accept';
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/attr-accept.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import warning from 'rc-util/lib/warning';
import { warning } from '@rc-component/util';
import type { RcFile } from './interface';

export default (file: RcFile, acceptedFiles: string | string[]) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent, render } from '@testing-library/react';
import { resetWarned } from 'rc-util/lib/warning';
import { resetWarned } from '@rc-component/util/lib/warning';
import React from 'react';
import sinon from 'sinon';
import { format } from 'util';
Expand Down
21 changes: 5 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@
"skipLibCheck": true,
"esModuleInterop": true,
"paths": {
"@/*": [
"src/*"
],
"@@/*": [
"src/.umi/*"
],
"rc-upload": [
"src/index.ts"
]
"@/*": ["src/*"],
"@@/*": ["src/.umi/*"],
"@rc-component/upload": ["src/index.ts"]
}
},
"include": [
".dumirc.ts",
"./src/**/*.ts",
"./src/**/*.tsx",
"./docs/**/*.tsx"
]
}
"include": [".dumirc.ts", "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx"]
}