Skip to content

Commit 5f2a1a2

Browse files
authored
docs: added describe props api, styles, react-uploader-api via ref (#14)
* docs: added describe props api, styles, react-uploader-api via ref * feat: added className for wrapper * docs: added describe summary and Quick Features * feat: added userAgentIntegration
1 parent 45752f1 commit 5f2a1a2

File tree

6 files changed

+127
-38
lines changed

6 files changed

+127
-38
lines changed

packages/react-uploader/README.md

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,120 @@
66
alt="">
77
</a>
88

9-
Uploadcare React Uploader. Allows you to use Uploader in React applications according to React canons.
10-
9+
Welcome to the Uploadcare React Uploader documentation!
10+
This library allows you to seamlessly integrate Uploadcare file uploader into your React applications while adhering to
11+
React principles.
1112

1213
[![Build Status][badge-build]][build-url]
1314
[![NPM version][npm-img]][npm-url]
1415
[![GitHub release][badge-release-img]][badge-release-url]
1516
[![Uploadcare stack on StackShare][badge-stack-img]][badge-stack-url]
1617

18+
* [Summary about project](#summary-about-project)
19+
* [Quick Features](#quick-features)
20+
* [Install](#install)
21+
* [Common](#common)
22+
* [Usage](#usage)
23+
* [Regular](#regular)
24+
* [Inline](#inline)
25+
* [Minimal](#minimal)
26+
* [Props API](#props-api)
27+
* [Styles](#styles)
28+
* [File Uploader API](#file-uploader-api)
29+
* [Events](#events)
30+
* [Security issues](#security-issues)
31+
* [Feedback](#feedback)
32+
33+
## Summary about project
34+
35+
This documentation provides guidance on how to use the Uploadcare React Uploader in your projects, along with details
36+
about its features, installation process, usage examples, customization options, event handling, and security
37+
considerations.
38+
39+
## Quick Features
40+
41+
- Seamless integration with React applications
42+
- Three different upload options: Regular, Inline, and Minimal
43+
- Customizable styles
44+
- Access to File Uploader API
45+
- Comprehensive event handling
1746

1847
## Install
1948

20-
```
49+
```bash
2150
npm i @uploadcare/react-uploader
2251
```
2352

2453
## Usage
2554

55+
The Uploadcare React Uploader offers three main components for integration.
56+
Each component serves specific use cases and can be easily implemented into your project.
57+
58+
### Regular
59+
2660
```jsx
27-
import { FileUploaderRegular } from "@uploadcare/react-uploader";
61+
import {FileUploaderRegular} from "@uploadcare/react-uploader";
2862

2963
<FileUploaderRegular pubkey="YOUR_PUBLIC_KEY"/>;
3064
```
3165

66+
### Inline
67+
68+
```jsx
69+
import {FileUploaderInline} from "@uploadcare/react-uploader";
70+
71+
<FileUploaderInline pubkey="YOUR_PUBLIC_KEY"/>;
72+
```
73+
74+
### Minimal
75+
76+
```jsx
77+
import {FileUploaderMinimal} from "@uploadcare/react-uploader";
78+
79+
<FileUploaderMinimal pubkey="YOUR_PUBLIC_KEY"/>;
80+
```
81+
82+
## Props API
83+
84+
An easy way to connect React-Uploader to your project and utilize the available API props.
85+
We provide a full set of props that are used in blocks. For review we suggest you to look at
86+
the [documentation](uc-docs-file-uploader-options).
87+
88+
## Styles
89+
90+
You can customize the appearance of the React uploader using the className prop, which allows you to add custom CSS
91+
classes to the uploader `FileUploader[Regular | Minimal | Inline]` wrapper.
92+
93+
```jsx
94+
import {FileUploaderRegular} from "@uploadcare/react-uploader";
95+
96+
<FileUploaderRegular className="fileUploaderWrapper" pubkey="YOUR_PUBLIC_KEY"/>;
97+
```
98+
99+
```css
100+
.fileUploaderWrapper lr-file-uploader-regular {
101+
}
102+
```
103+
32104
## File Uploader API
33105

34-
It is possible to get ref on UploadCtxProvider via `ref`. In this way it is possible to additional uploader management
35-
methods.
106+
For convenience, we provide the ability to access the File Uploader API using `refUploadCtxProvider`.
107+
You can see what methods are available in `refUploadCtxProvider` in the [documentation][uc-docs-file-uploader-api].
108+
It is important to note that we now pass all InstanceType from UploadCtxProvider.
36109

37110
```jsx
38-
import React, { useRef } from "react";
111+
import React, {useRef, useEffect} from "react";
39112
import {
40113
FileUploaderRegular,
41114
UploadCtxProvider
42115
} from "@uploadcare/react-uploader";
43116

44-
const uploaderRef = useRef<InstanceType<UploadCtxProvider> | null>(null);
117+
const Example = () => {
118+
const uploaderRef = useRef < InstanceType < UploadCtxProvider > | null > (null);
45119

46-
<FileUploaderRegular refUploadCtxProvider={uploaderRef} pubkey="YOUR_PUBLIC_KEY"/>;
120+
121+
<FileUploaderRegular refUploadCtxProvider={uploaderRef} pubkey="YOUR_PUBLIC_KEY"/>;
122+
}
47123
```
48124

49125
## Events
@@ -57,7 +133,7 @@ The principle of converting events from blocks to React Uploader:
57133
Example:
58134

59135
```jsx
60-
import { FileUploaderRegular } from "@uploadcare/react-uploader";
136+
import {FileUploaderRegular} from "@uploadcare/react-uploader";
61137

62138
<FileUploaderRegular
63139
pubkey="YOUR_PUBLIC_KEY"
@@ -109,12 +185,23 @@ request at [[email protected]][uc-email-hello].
109185
[uc-email-hello]: mailto:[email protected]
110186

111187
[badge-stack-img]: https://img.shields.io/badge/tech-stack-0690fa.svg?style=flat
188+
112189
[badge-stack-url]: https://stackshare.io/uploadcare/stacks/
190+
113191
[badge-release-img]: https://img.shields.io/github/release/uploadcare/react-components.svg
192+
114193
[badge-release-url]: https://github.com/uploadcare/react-components/releases
194+
115195
[npm-img]: http://img.shields.io/npm/v/@uploadcare/react-uploader.svg
196+
116197
[npm-url]: https://www.npmjs.com/package/@uploadcare/react-uploader
198+
117199
[badge-build]: https://github.com/uploadcare/react-components/actions/workflows/checks.yml/badge.svg
200+
118201
[build-url]: https://github.com/uploadcare/react-components/actions/workflows/checks.yml
119202

120203
[uc-docs-events]: https://uploadcare.com/docs/file-uploader/events/
204+
205+
[uc-docs-file-uploader-api]: https://uploadcare.com/docs/file-uploader/api
206+
207+
[uc-docs-file-uploader-options]: https://uploadcare.com/docs/file-uploader/options/

packages/react-uploader/src/Uploader/Inline/FileUploaderInline.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, { FC, useMemo } from "react";
1+
import React, { type FC, useMemo } from "react";
22
import * as LR from "@uploadcare/blocks";
33
import { customElementToReactComponent } from "@uploadcare/react-adapter";
44
import { AdapterConfig } from "../core/AdapterConfig";
55
import { AdapterUploadCtxProvider } from "../core/AdapterUploadCtxProvider";
66
import type { TProps } from "../types";
77
import { getStyleSource } from "../default";
88
import { getCalcPropertyOfProps } from "../../utils/getCalcPropertyOfProps";
9+
import { getUserAgentIntegration } from "../../utils/getUserAgentIntegration";
910

1011
LR.registerBlocks(LR);
1112

@@ -22,19 +23,17 @@ export const FileUploaderInline: FC<TProps> = ({
2223
refUploadCtxProvider,
2324
...props
2425
}) => {
25-
const CTX_NAME = useMemo(
26-
() => ctxName ?? LR.UID.generate(),
27-
[ctxName, LR.UID.generate],
28-
);
26+
const CTX_NAME = useMemo(() => ctxName ?? LR.UID.generate(), [ctxName]);
2927

3028
const { eventHandlers, config } = useMemo(
3129
() => getCalcPropertyOfProps<TProps>(props),
3230
[props],
3331
);
3432

3533
return (
36-
<React.Fragment>
37-
<AdapterConfig ctx-name={CTX_NAME} {...config} />
34+
<div className={className}>
35+
{/* @ts-ignore */}
36+
<AdapterConfig userAgentIntegration={getUserAgentIntegration(config.pubkey)} ctx-name={CTX_NAME} {...config} />
3837
{/* @ts-ignore */}
3938
<AdapterUploadCtxProvider
4039
ref={refUploadCtxProvider}
@@ -43,6 +42,6 @@ export const FileUploaderInline: FC<TProps> = ({
4342
/>
4443

4544
<AdapterFileUploaderInline ctx-name={CTX_NAME} css-src={CSS_SRC_INLINE} />
46-
</React.Fragment>
45+
</div>
4746
);
4847
};

packages/react-uploader/src/Uploader/Minimal/FileUploaderMinimal.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, { FC, useMemo } from "react";
1+
import React, { type FC, useMemo } from "react";
22
import * as LR from "@uploadcare/blocks";
33
import { customElementToReactComponent } from "@uploadcare/react-adapter";
44
import { AdapterConfig } from "../core/AdapterConfig";
55
import { AdapterUploadCtxProvider } from "../core/AdapterUploadCtxProvider";
66
import type { TProps } from "../types";
77
import { getStyleSource } from "../default";
88
import { getCalcPropertyOfProps } from "../../utils/getCalcPropertyOfProps";
9+
import { getUserAgentIntegration } from "../../utils/getUserAgentIntegration";
910

1011
LR.registerBlocks(LR);
1112

@@ -23,19 +24,17 @@ export const FileUploaderMinimal: FC<TProps> = ({
2324
refUploadCtxProvider,
2425
...props
2526
}) => {
26-
const CTX_NAME = useMemo(
27-
() => ctxName ?? LR.UID.generate(),
28-
[ctxName, LR.UID.generate],
29-
);
27+
const CTX_NAME = useMemo(() => ctxName ?? LR.UID.generate(), [ctxName]);
3028

3129
const { eventHandlers, config } = useMemo(
3230
() => getCalcPropertyOfProps<TProps>(props),
3331
[props],
3432
);
3533

3634
return (
37-
<React.Fragment>
38-
<AdapterConfig ctx-name={CTX_NAME} {...config} />
35+
<div className={className}>
36+
{/* @ts-ignore */}
37+
<AdapterConfig userAgentIntegration={getUserAgentIntegration(config.pubkey)} ctx-name={CTX_NAME} {...config} />
3938
{/* @ts-ignore */}
4039
<AdapterUploadCtxProvider
4140
ref={refUploadCtxProvider}
@@ -46,6 +45,6 @@ export const FileUploaderMinimal: FC<TProps> = ({
4645
ctx-name={CTX_NAME}
4746
css-src={CSS_SRC_MINIMAL}
4847
/>
49-
</React.Fragment>
48+
</div>
5049
);
5150
};

packages/react-uploader/src/Uploader/Regular/FileUploaderRegular.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, useMemo } from "react";
1+
import React, { type FC, useMemo } from "react";
22
import * as LR from "@uploadcare/blocks";
33
import { customElementToReactComponent } from "@uploadcare/react-adapter";
44
import { AdapterConfig } from "../core/AdapterConfig";
@@ -7,6 +7,7 @@ import { getStyleSource } from "../default";
77
import type { TProps } from "../types";
88

99
import { getCalcPropertyOfProps } from "../../utils/getCalcPropertyOfProps";
10+
import { getUserAgentIntegration } from "../../utils/getUserAgentIntegration";
1011

1112
LR.registerBlocks(LR);
1213

@@ -24,19 +25,17 @@ export const FileUploaderRegular: FC<TProps> = ({
2425
refUploadCtxProvider,
2526
...props
2627
}) => {
27-
const CTX_NAME = useMemo(
28-
() => ctxName ?? LR.UID.generate(),
29-
[ctxName, LR.UID.generate],
30-
);
28+
const CTX_NAME = useMemo(() => ctxName ?? LR.UID.generate(), [ctxName]);
3129

3230
const { eventHandlers, config } = useMemo(
3331
() => getCalcPropertyOfProps<TProps>(props),
3432
[props],
3533
);
3634

3735
return (
38-
<React.Fragment>
39-
<AdapterConfig ctx-name={CTX_NAME} {...config} />
36+
<div className={className}>
37+
{/* @ts-ignore */}
38+
<AdapterConfig userAgentIntegration={getUserAgentIntegration(config.pubkey)} ctx-name={CTX_NAME} {...config}/>
4039
{/* @ts-ignore */}
4140
<AdapterUploadCtxProvider
4241
ref={refUploadCtxProvider}
@@ -47,6 +46,6 @@ export const FileUploaderRegular: FC<TProps> = ({
4746
ctx-name={CTX_NAME}
4847
css-src={CSS_SRC_REGULAR}
4948
/>
50-
</React.Fragment>
49+
</div>
5150
);
5251
};

packages/react-uploader/src/Uploader/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from "react";
2-
import {
3-
type ConfigType,
1+
import type { Ref } from "react";
2+
import type {
3+
ConfigType,
44
UploadCtxProvider,
55
EventMap,
66
} from "@uploadcare/blocks";
@@ -18,7 +18,7 @@ export type TEventsSchema = {
1818
};
1919

2020
type TRefUploadCtxProvider = {
21-
refUploadCtxProvider?: React.Ref<InstanceType<UploadCtxProvider>>;
21+
refUploadCtxProvider?: Ref<InstanceType<UploadCtxProvider>>;
2222
};
2323

2424
type TPropsWithEvents = Partial<TEventsSchema>;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { version, name } from "../../package.json";
2+
3+
export const getUserAgentIntegration = (pubkey: string) => {
4+
return `${name}/${version}/${pubkey} (JavaScript; React;)`;
5+
};

0 commit comments

Comments
 (0)