The .file element is a simple interactive label that wraps an <input type="file">. It comprises several sub-elements:
.file the main container
.file-label the actual interactive and clickable part of the element
.file-input the native file input, hidden for styling purposes
.file-cta the upload call-to-action
.file-icon an optional upload icon
.file-label the "Choose a file…" text
.file-name a container for the chosen file name
{% include elements/snippet.html content=file %}
{% include elements/anchor.html name="Modifiers" %}
With the .has-name modifier combined with the .file-name element, you can add a placeholder for the selected file name.
{{ file_name }}
{% highlight html %}{{ file_name }}{% endhighlight %}
You can move the CTA to the right side with the .is-right modifier.
{{ file_name_right }}
{% highlight html %}{{ file_name_right }}{% endhighlight %}
You can also expand the name to fill up the space with the .is-fullwidth modifier.
{{ file_name_fullwidth }}
{% highlight html %}{{ file_name_fullwidth }}{% endhighlight %}
You can have a boxed block with the .is-boxed modifier.
{{ file_boxed }}
{% highlight html %}{{ file_boxed }}{% endhighlight %}
You can combine.has-name and .is-boxed.
{{ file_boxed_name }}
{% highlight html %}{{ file_boxed_name }}{% endhighlight %}
{% include elements/anchor.html name="Colors" %}
You can style the file element by appending one of the {{ site.data.colors.derived | size }} color modifiers:
{% for color in site.data.colors.derived %}
is-{{ color.id }}
{% endfor %}
{% include elements/snippet.html content=file_colors clipped=true %}
{% include elements/anchor.html name="Sizes" %}
You can append one of 3 additional sizes:
.is-small
.is-medium
.is-large
{% include elements/snippet.html content=file_sizes clipped=true %}
{% include elements/snippet.html content=file_sizes_name clipped=true %}
{% include elements/snippet.html content=file_sizes_boxed clipped=true %}
{% include elements/snippet.html content=file_sizes_boxed_name clipped=true %}
{% include elements/anchor.html name="Alignment" %}
You can align the file input:
to the center with the is-centered modifier
to the right with the is-right modifier
{% include elements/snippet.html content=file_centered %}
{% include elements/snippet.html content=file_right %}
{% include elements/anchor.html name="JavaScript" %}
A file upload input requires JavaScript to retrieve the selected file name.
Here is an example of how this could be done:
{% include elements/snippet.html content=file_javascript %}
{% include elements/variables.html
type='element'
variables_keys=page.variables_keys
folder='elements'
file='form'
%}