bulma/docs/documentation/form/file.html

453 lines
13 KiB
HTML
Raw Normal View History

2017-07-29 22:16:31 +00:00
---
title: File upload
2024-03-21 16:11:54 +00:00
layout: docs
theme: library
2017-07-29 22:16:31 +00:00
doc-tab: form
2017-07-29 22:46:27 +00:00
doc-subtab: file
2018-04-09 15:15:58 +00:00
breadcrumb:
2024-03-21 16:11:54 +00:00
- home
- documentation
- form
- form-file
2017-07-29 22:16:31 +00:00
file_name: "Screen Shot 2017-07-29 at 15.54.25.png"
variables_keys:
2024-03-21 16:11:54 +00:00
- $file-border-color
- $file-radius
- $file-cta-background-color
- $file-cta-color
- $file-cta-hover-color
- $file-cta-active-color
- $file-name-border-color
- $file-name-border-style
- $file-name-border-width
- $file-name-max-width
2018-04-09 15:15:58 +00:00
meta:
experimental: true
colors: true
sizes: true
variables: true
2017-07-29 22:16:31 +00:00
---
{% capture file %}
<div class="file">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
2017-07-29 22:16:31 +00:00
<span class="file-cta">
<span class="file-icon">
2018-01-10 16:30:23 +00:00
<i class="fas fa-upload"></i>
2017-07-29 22:16:31 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
2017-07-29 22:16:31 +00:00
</span>
</label>
</div>
{% endcapture %}
2017-07-29 22:46:27 +00:00
{% capture file_name %}
<div class="file has-name">
2017-07-29 22:16:31 +00:00
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
2017-07-29 22:16:31 +00:00
<span class="file-cta">
<span class="file-icon">
2018-01-10 16:30:23 +00:00
<i class="fas fa-upload"></i>
2017-07-29 22:16:31 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
2017-07-29 22:16:31 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
2017-07-29 22:16:31 +00:00
</label>
</div>
{% endcapture %}
2017-07-29 23:22:26 +00:00
{% capture file_name_right %}
<div class="file has-name is-right">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
2017-07-29 23:22:26 +00:00
<span class="file-cta">
<span class="file-icon">
2018-01-10 16:30:23 +00:00
<i class="fas fa-upload"></i>
2017-07-29 23:22:26 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
2017-07-29 23:22:26 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
2017-07-29 23:22:26 +00:00
</label>
</div>
{% endcapture %}
{% capture file_name_fullwidth %}
<div class="file has-name is-fullwidth">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
2017-07-29 23:22:26 +00:00
<span class="file-cta">
<span class="file-icon">
2018-01-10 16:30:23 +00:00
<i class="fas fa-upload"></i>
2017-07-29 23:22:26 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
2017-07-29 23:22:26 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
2017-07-29 23:22:26 +00:00
</label>
</div>
{% endcapture %}
2017-08-07 18:49:24 +00:00
{% capture file_boxed %}
<div class="file is-boxed">
2017-07-29 22:16:31 +00:00
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
2017-07-29 22:16:31 +00:00
<span class="file-cta">
<span class="file-icon">
2018-01-10 16:30:23 +00:00
<i class="fas fa-upload"></i>
2017-07-29 22:16:31 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
2017-07-29 22:16:31 +00:00
</span>
</label>
</div>
{% endcapture %}
2017-08-07 18:49:24 +00:00
{% capture file_boxed_name %}
<div class="file has-name is-boxed">
2017-07-29 22:16:31 +00:00
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
2017-07-29 22:16:31 +00:00
<span class="file-cta">
<span class="file-icon">
2018-01-10 16:30:23 +00:00
<i class="fas fa-upload"></i>
2017-07-29 22:16:31 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
2017-07-29 22:16:31 +00:00
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
2017-07-29 22:16:31 +00:00
</label>
</div>
{% endcapture %}
{% capture file_colors_a %}
<div class="file is-primary">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Primary file… </span>
</span>
</label>
2017-07-29 23:06:32 +00:00
</div>
{% endcapture %}
{% capture file_colors_b %}
<div class="file is-info has-name">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Info file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
</label>
2017-07-29 22:16:31 +00:00
</div>
{% endcapture %}
{% capture file_colors_c %}
<div class="file is-warning is-boxed">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-cloud-upload-alt"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Warning file… </span>
</span>
</label>
2017-07-29 22:16:31 +00:00
</div>
{% endcapture %}
{% capture file_colors_d %}
<div class="file is-danger has-name is-boxed">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-cloud-upload-alt"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Danger file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
</label>
2017-07-29 22:16:31 +00:00
</div>
{% endcapture %}
2017-08-07 18:49:24 +00:00
{% capture file_centered %}
<div class="file is-centered is-boxed is-success has-name">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Centered file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
</label>
2017-08-07 18:49:24 +00:00
</div>
{% endcapture %}
{% capture file_right %}
<div class="file is-right is-info">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Right file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
</label>
2017-08-07 18:49:24 +00:00
</div>
{% endcapture %}
{% capture file_javascript %}
<div id="file-js-example" class="file has-name">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> Choose a file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> No file uploaded </span>
</label>
</div>
<script>
2024-03-21 16:11:54 +00:00
const fileInput = document.querySelector("#file-js-example input[type=file]");
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
2024-03-21 16:11:54 +00:00
const fileName = document.querySelector("#file-js-example .file-name");
fileName.textContent = fileInput.files[0].name;
}
2024-03-21 16:11:54 +00:00
};
</script>
{% endcapture %}
<!-- -->
2017-07-29 22:16:31 +00:00
2018-04-09 15:15:58 +00:00
<div class="content">
<p>
2024-03-21 16:11:54 +00:00
The <code>file</code> element is a simple <strong>interactive label</strong> that wraps an
<code>&lt;input type="file"&gt;</code>. It comprises several sub-elements:
2018-04-09 15:15:58 +00:00
</p>
<ul>
<li>
2019-10-13 19:06:56 +00:00
<code>file</code> the main <strong>container</strong>
2017-07-29 22:46:27 +00:00
<ul>
<li>
2019-10-13 19:06:56 +00:00
<code>file-label</code> the actual <strong>interactive</strong> and clickable part of the element
2017-07-29 22:46:27 +00:00
<ul>
2024-03-21 16:11:54 +00:00
<li><code>file-input</code> the <strong>native</strong> file input, hidden for styling purposes</li>
2018-04-09 15:15:58 +00:00
<li>
2019-10-13 19:06:56 +00:00
<code>file-cta</code> the upload <strong>call-to-action</strong>
2017-07-29 22:46:27 +00:00
<ul>
2024-03-21 16:11:54 +00:00
<li><code>file-icon</code> an optional <strong>upload</strong> icon</li>
<li><code>file-label</code> the "Choose a file…" text</li>
2017-07-29 22:46:27 +00:00
</ul>
</li>
2024-03-21 16:11:54 +00:00
<li><code>file-name</code> a container for the <strong>chosen file</strong> name</li>
2017-07-29 22:46:27 +00:00
</ul>
</li>
</ul>
2018-04-09 15:15:58 +00:00
</li>
</ul>
</div>
2017-07-29 22:16:31 +00:00
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=file %}
{% include docs/elements/anchor.html name="Modifiers" %}
2017-07-29 23:22:26 +00:00
2018-04-09 15:15:58 +00:00
<div class="columns">
<div class="column is-6">
2018-04-09 15:15:58 +00:00
<div class="content">
<p>
2024-03-21 16:11:54 +00:00
With the <code>has-name</code> modifier combined with the <code>file-name</code> element, you can add a
<strong>placeholder</strong> for the selected file name.
2018-04-09 15:15:58 +00:00
</p>
2017-07-29 23:22:26 +00:00
</div>
2024-03-21 16:11:54 +00:00
<div class="bd-example">{{ file_name }}</div>
2018-04-09 15:15:58 +00:00
</div>
<div class="column is-6 bd-highlight-full">
2024-03-21 16:11:54 +00:00
{% highlight html -%}
{{- file_name -}}
{%- endhighlight %}
2018-04-09 15:15:58 +00:00
</div>
</div>
2017-07-29 22:16:31 +00:00
2018-04-09 15:15:58 +00:00
<div class="columns">
<div class="column is-6">
2018-04-09 15:15:58 +00:00
<div class="content">
2024-03-21 16:11:54 +00:00
<p>You can move the CTA to the <strong>right side</strong> with the <code>is-right</code> modifier.</p>
2018-04-09 15:15:58 +00:00
</div>
2024-03-21 16:11:54 +00:00
<div class="bd-example">{{ file_name_right }}</div>
2018-04-09 15:15:58 +00:00
</div>
<div class="column is-6 bd-highlight-full">
2024-03-21 16:11:54 +00:00
{% highlight html -%}
{{- file_name_right -}}
{%- endhighlight %}
2018-04-09 15:15:58 +00:00
</div>
</div>
2017-07-29 23:06:32 +00:00
2018-04-09 15:15:58 +00:00
<div class="columns">
<div class="column is-6">
2017-08-30 21:21:30 +00:00
<div class="content">
<p>
2019-10-13 19:06:56 +00:00
You can also <strong>expand</strong> the name to fill up the space with the <code>is-fullwidth</code> modifier.
2017-08-30 21:21:30 +00:00
</p>
2017-07-29 23:06:32 +00:00
</div>
2024-03-21 16:11:54 +00:00
<div class="bd-example">{{ file_name_fullwidth }}</div>
2018-04-09 15:15:58 +00:00
</div>
<div class="column is-6 bd-highlight-full">
2024-03-21 16:11:54 +00:00
{% highlight html -%}
{{- file_name_fullwidth -}}
{%- endhighlight %}
2018-04-09 15:15:58 +00:00
</div>
</div>
2017-07-29 22:16:31 +00:00
2018-04-09 15:15:58 +00:00
<div class="columns">
<div class="column is-6">
2018-04-09 15:15:58 +00:00
<div class="content">
2024-03-21 16:11:54 +00:00
<p>You can have a <strong>boxed block</strong> with the <code>is-boxed</code> modifier.</p>
2018-04-09 15:15:58 +00:00
</div>
2024-03-21 16:11:54 +00:00
<div class="bd-example">{{ file_boxed }}</div>
2018-04-09 15:15:58 +00:00
</div>
<div class="column is-6 bd-highlight-full">
2024-03-21 16:11:54 +00:00
{% highlight html -%}
{{- file_boxed -}}
{%- endhighlight %}
2018-04-09 15:15:58 +00:00
</div>
</div>
2017-07-29 22:16:31 +00:00
2018-04-09 15:15:58 +00:00
<div class="columns">
<div class="column is-6">
2017-07-29 22:46:27 +00:00
<div class="content">
2024-03-21 16:11:54 +00:00
<p>You can <strong>combine</strong> <code>has-name</code> and <code>is-boxed</code>.</p>
2018-04-09 15:15:58 +00:00
</div>
2024-03-21 16:11:54 +00:00
<div class="bd-example">{{ file_boxed_name }}</div>
2018-04-09 15:15:58 +00:00
</div>
<div class="column is-6 bd-highlight-full">
2024-03-21 16:11:54 +00:00
{% highlight html -%}
{{- file_boxed_name -}}
{%- endhighlight %}
2018-04-09 15:15:58 +00:00
</div>
</div>
2017-07-29 22:46:27 +00:00
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor.html name="Colors" %}
2018-04-09 15:15:58 +00:00
<div class="content">
<p>
2024-03-21 16:11:54 +00:00
You can style the file element by appending one of the
<strong>{{ site.data.colors.derived | size }} color modifiers</strong>:
2018-04-09 15:15:58 +00:00
</p>
<ul>
{% for color in site.data.colors.derived %}
<li>
<code>is-{{ color.id }}</code>
</li>
{% endfor %}
</ul>
</div>
2017-07-29 22:16:31 +00:00
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=file_colors_a %}
{% include docs/elements/snippet.html content=file_colors_b %}
{% include docs/elements/snippet.html content=file_colors_c %}
{% include docs/elements/snippet.html content=file_colors_d %}
{% include docs/elements/anchor.html name="Sizes" %}
2018-04-09 15:15:58 +00:00
<div class="content">
2024-03-21 16:11:54 +00:00
<p>You can append one of the <strong>4 available sizes</strong>:</p>
2018-04-09 15:15:58 +00:00
<ul>
<li>
2019-10-13 19:06:56 +00:00
<code>is-small</code>
2018-04-09 15:15:58 +00:00
</li>
2024-03-21 16:11:54 +00:00
<li><code>is-normal</code> (default)</li>
2018-04-09 15:15:58 +00:00
<li>
2019-10-13 19:06:56 +00:00
<code>is-medium</code>
2018-04-09 15:15:58 +00:00
</li>
<li>
2019-10-13 19:06:56 +00:00
<code>is-large</code>
2018-04-09 15:15:58 +00:00
</li>
</ul>
</div>
2017-07-29 22:16:31 +00:00
{% for size in site.data.sizes %}
2024-03-21 16:11:54 +00:00
{% capture foobar %}
<div class="file is-{{ size }}">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> {{ size | capitalize }} file… </span>
</span>
</label>
</div>
{% endcapture %}
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=foobar %}
{% endfor %}
{% for size in site.data.sizes %}
2024-03-21 16:11:54 +00:00
{% capture foobar %}
<div class="file is-{{ size }} has-name">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> {{ size | capitalize }} file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
</label>
</div>
{% endcapture %}
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=foobar %}
{% endfor %}
{% for size in site.data.sizes %}
2024-03-21 16:11:54 +00:00
{% capture foobar %}
<div class="file is-{{ size }} is-boxed">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> {{ size | capitalize }} file… </span>
</span>
</label>
</div>
{% endcapture %}
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=foobar %}
{% endfor %}
{% for size in site.data.sizes %}
2024-03-21 16:11:54 +00:00
{% capture foobar %}
<div class="file is-{{ size }} is-boxed has-name">
<label class="file-label">
2024-03-21 16:11:54 +00:00
<input class="file-input" type="file" name="resume" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-label"> {{ size | capitalize }} file… </span>
</span>
2024-03-21 16:11:54 +00:00
<span class="file-name"> {{ page.file_name }} </span>
</label>
</div>
{% endcapture %}
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=foobar %}
{% endfor %}
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor.html name="Alignment" %}
2017-07-29 22:16:31 +00:00
2018-04-09 15:15:58 +00:00
<div class="content">
2024-03-21 16:11:54 +00:00
<p>You can <strong>align</strong> the file input:</p>
2018-04-09 15:15:58 +00:00
<ul>
2024-03-21 16:11:54 +00:00
<li>to the <strong>center</strong> with the <code>is-centered</code> modifier</li>
<li>to the <strong>right</strong> with the <code>is-right</code> modifier</li>
2018-04-09 15:15:58 +00:00
</ul>
</div>
2017-07-29 22:46:27 +00:00
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html content=file_centered %}
{% include docs/elements/snippet.html content=file_right %}
{% include docs/elements/anchor.html name="JavaScript" %}
2018-04-09 15:15:58 +00:00
<div class="content">
<p>
2024-03-21 16:11:54 +00:00
A file upload input requires JavaScript to <strong>retrieve</strong> the <strong>selected file name</strong>. Here
is an example of how this could be done:
2018-04-09 15:15:58 +00:00
</p>
</div>
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet.html horizontal=true content=file_javascript %}