-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from jbouder/thumbnails
Update UI for Thumbnails
- Loading branch information
Showing
11 changed files
with
209 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import { FileInput } from './file-input'; | ||
|
||
describe('FileInput', () => { | ||
test('renders a default file input successfully', () => { | ||
const { baseElement } = render(<FileInput id="input" name="input" />); | ||
const input = baseElement.querySelector('input'); | ||
|
||
expect(input).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders a file input with multiple files allowed', () => { | ||
const { baseElement } = render(<FileInput id="input" allowMultiple />); | ||
const input = baseElement.querySelector('input'); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(input).toHaveAttribute('multiple'); | ||
}); | ||
|
||
test('renders a file input with allowed file types', () => { | ||
const { baseElement } = render( | ||
<FileInput id="input" allowedFileTypes="image/png" />, | ||
); | ||
const input = baseElement.querySelector('input'); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(input).toHaveAttribute('accept', 'image/png'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import classnames from 'classnames'; | ||
import React from 'react'; | ||
|
||
export interface FileInputProps { | ||
/** | ||
* The unique identifier for this component | ||
*/ | ||
id: string; | ||
/** | ||
* The name for the file input field | ||
*/ | ||
name?: string; | ||
/** | ||
* Whether or not to allow multiple files to be uploaded | ||
*/ | ||
allowMultiple?: boolean; | ||
/** | ||
* The types of files that are allowed to be uploaded | ||
*/ | ||
allowedFileTypes?: string; | ||
} | ||
|
||
/** | ||
* File input allows users to attach one or multiple files. | ||
*/ | ||
export const FileInput = ({ | ||
id, | ||
name, | ||
className, | ||
allowMultiple = undefined, | ||
allowedFileTypes = 'image/png, image/jpeg', | ||
...props | ||
}: FileInputProps & JSX.IntrinsicElements['input']): React.ReactElement => { | ||
const classes = classnames('file-input', className); | ||
return ( | ||
<input | ||
id={id} | ||
name={name} | ||
className={classes} | ||
type="file" | ||
multiple={allowMultiple} | ||
accept={allowedFileTypes} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default FileInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters