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: adding format file by props to upload input #33

Merged
merged 7 commits into from
Mar 25, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- New prop `accept` to `form-input.upload`.

## [0.5.1] - 2021-03-17
### Fixed
- Change `form-input.upload` to render only on client since it breaks SSR.
Expand Down
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` |
| `accept` | `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 [read more about the `accept` field](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept).

- **`uiSchema` object:**

```js
Expand Down
6 changes: 3 additions & 3 deletions react/components/Upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const messages = defineMessages({
},
})

const InputUpload = (props: FormRawInputProps) => {
const InputUpload = (props: FormRawInputProps & { accept?: string }) => {
const intl = useIntl()
const [uploadFile] = useMutation<MutationData>(UploadFileMutation)
const ref = React.useRef<HTMLDivElement>(null)
Expand All @@ -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, accept, 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: accept ?? '.pdf, image/*',
maxSize: MAX_SIZE,
multiple: false,
onDrop: onDropImage,
Expand Down