--- title: File Picker layout: nested-component.html ---

File Picker

Pretty input fields for files. Creates thumbnail previews for images, and shows common filetype icons for other files.

Usage

Add the class file-picker to a form-group to initialize this plugin without writing any Javascript. Alternatively you can instantiate the plugin like this: $('.some-element').filePicker();. Options can be defined as data-attributes, or as an object when instantiating in Javascript.

Options

Option Default Description
disablePreview false Disables the image/file drag and drop zone.
filePatterns
'CODE': {
    icon: 'fa-file-code-o',
    match: /\.(php|js|css|html|json)$/i
}
A list of file types and an associated regex test for the supported file extensions. You can see the default supported tests & icons here

Initialize with a predefined file

To instantiate the file-picker with a predefined file, you need to use either of the following data-attributes (but not both :-) )

Attribute Description
data-image Will set the preview-image's src to the string defined in the data-attribute
data-file Will set the preview-icon to a an icon matching a regex in the filePatterns object, or a fallback icon

Basic Example

Drop your file here
Browse

Loading...

NYI

Without a preview / drop zone

Drop your file here
Browse

Loading...

NYI

With a predefined image

Drop your file here
Browse

Loading...

NYI

With a predefined file

Drop your file here
Browse

Loading...

NYI

Direction

You can control the direction in which elements are rendered both vertically and horizontally by adding any combination of the following modifier classes.

Class name Description
.file-picker--reverse Reverses the direction of the drop zone and the input field
.file-picker--vertical Arranges the drop-zone and input in vertical
Drop your file here
Browse

Loading...

NYI
Drop your file here
Browse

Loading...

NYI
Drop your file here
Browse

Loading...

NYI

Dropzone sizing

Controlling the size of the drop zone is as easy as adding an inline style to the .file-picker__zone.

Keep in mind that inline styling always wins. If you set the width of the drop-zone higher than its parent container, you will introduce scrolling.

Drop your file here
Browse

Loading...

NYI