Skip to content

Commit

Permalink
feat: adding format file by props to upload input
Browse files Browse the repository at this point in the history
  • Loading branch information
santosluiz000 committed Mar 23, 2021
1 parent 46b0900 commit 8ef259c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ In the example below, the form block is contained in a Flex Layout row:
| `pointer` | `string` | ![https://img.shields.io/badge/-Mandatory-red](https://img.shields.io/badge/-Mandatory-red) JSON schema pointer i.e. the JSON schema path (for example: #/properties/address) in which the form block inputs should be validated against. Note that since you are configuring a `form-field-group` block, the path must not include a schema's sub-property, only a schema's property. | `undefined` |
| `uiSchema` | `object` | Redefines how the `form-field-groups` block should render each sub-properties declared in the JSON schema path defined in `pointer`. As said previously, the `form-field-groups` already does that by itself, but you can overwrite the sub-properties types through a schema and so redefine how each form block will be rendered. | `undefined` |

### `form-input.upload` props

| Prop name | Type | Description | Default Value |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `pointer` | `string` | ![https://img.shields.io/badge/-Mandatory-red](https://img.shields.io/badge/-Mandatory-red) JSON schema pointer i.e. the JSON schema path (for example: #/properties/address) in which the form block inputs should be validated against. Note that since you are configuring a `form-field-group` block, the path must not include a schema's sub-property, only a schema's property. | `undefined` |
| `typeAceppt` | `string` | ![https://img.shields.io/badge/-optional-yellow](https://img.shields.io/badge/-optional-yellow) By default the upload input just accept image and pdf format files. If you want to customize it, you can pass the format type that you want following this pattern: `*.TYPEFILE`. You can also pass multiple format types if you want: `*.TYPEFILE1, *.TYPEFILE2`

- **`uiSchema` object:**

```js
Expand Down
4 changes: 2 additions & 2 deletions react/components/Upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const InputUpload = (props: FormRawInputProps) => {
const [imageUrl, setImageUrl] = React.useState<string | undefined>()
const [error, setError] = React.useState<string | null>()

const { inputType = InputTypes.input, pointer, ...rest } = props
const { inputType = InputTypes.input, typeAccept, pointer, ...rest } = props

const onDropImage = async (files: File[]) => {
setError(null)
Expand Down Expand Up @@ -95,7 +95,7 @@ const InputUpload = (props: FormRawInputProps) => {
}

const { getInputProps, getRootProps } = useDropzone({
accept: '.pdf, image/*',
accept: typeAccept ?? '.pdf, image/*',
maxSize: MAX_SIZE,
multiple: false,
onDrop: onDropImage,
Expand Down
1 change: 1 addition & 0 deletions react/typings/InputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export enum InputTypes {
export interface FormRawInputProps extends BaseInputProps {
inputType?: InputTypes
value?: string
typeAccept?: string
}

0 comments on commit 8ef259c

Please sign in to comment.