Skip to content

SInputFile

<SInputFile> is a file select input component.

@globalbrain/sefirot/lib/components/SInputFile.vue

No file choosen

Usage

Import <SInputFile> and pass in the value prop.

vue
<script setup lang="ts">
import { ref } from 'vue'
import SInputFile from '@globalbrain/sefirot/lib/components/SInputFile.vue'

const input = ref<File | File[] | null>(null)
</script>

<template>
  <SInputFile placeholder="No file choosen" v-model="input" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import SInputFile from '@globalbrain/sefirot/lib/components/SInputFile.vue'

const input = ref<File | File[] | null>(null)
</script>

<template>
  <SInputFile placeholder="No file choosen" v-model="input" />
</template>

Props

Here are the list of props you may pass to the component.

:size

Defines the size of the input. The default is small.

ts
interface Props {
  size?: 'mini' | 'small' | 'medium'
}
interface Props {
  size?: 'mini' | 'small' | 'medium'
}
template
<SInputFile size="small" v-model="..." />
<SInputFile size="small" v-model="..." />

:label

Defines the label text of the input.

ts
interface Props {
  label?: string
}
interface Props {
  label?: string
}
template
<SInputFile label="Upload file" v-model="..." />
<SInputFile label="Upload file" v-model="..." />

:info

Shows help icon after the label and shows info in a tooltip when the user hovers the label.

ts
interface Props {
  info?: string
}
interface Props {
  info?: string
}
template
<SInputFile
  label="Upload image"
  info="This will be used as your avatar."
  v-model="..."
/>
<SInputFile
  label="Upload image"
  info="This will be used as your avatar."
  v-model="..."
/>

:note

Adds small help text after the label. Best used along with label prop.

ts
interface Props {
  note?: string
}
interface Props {
  note?: string
}
template
<SInputFile
  label="Upload file"
  note="Optional"
  v-model="..."
/>
<SInputFile
  label="Upload file"
  note="Optional"
  v-model="..."
/>

:help

Adds small help text to the bottom of the input.

ts
interface Props {
  help?: string
}
interface Props {
  help?: string
}
template
<SInputFile
  label="Upload file"
  help="Accepts only JPG and PNG."
  v-model="..."
/>
<SInputFile
  label="Upload file"
  help="Accepts only JPG and PNG."
  v-model="..."
/>

:text

Defines the text of the button. Defaults to 'Choose File'.

ts
interface Props {
  text?: string
}
interface Props {
  text?: string
}
template
<SInputFile text="Select File" v-model="..." />
<SInputFile text="Select File" v-model="..." />

:placeholder

Defines the placeholder text to show when the value is empty.

ts
interface Props {
  placeholder?: string
}
interface Props {
  placeholder?: string
}
template
<SInputFile placeholder="No file choosen" v-model="..." />
<SInputFile placeholder="No file choosen" v-model="..." />

:accept

Defines the file types to accept.

ts
interface Props {
  accept?: string
}
interface Props {
  accept?: string
}
template
<SInputFile accept="image/*" v-model="..." />
<SInputFile accept="image/*" v-model="..." />

:multiple

Defines whether to accept multiple files.

ts
interface Props {
  multiple?: boolean
}
interface Props {
  multiple?: boolean
}
template
<SInputFile multiple v-model="..." />
<SInputFile multiple v-model="..." />

:check-icon

Icon to display at corner right of label. Useful to show the status of a particular input.

ts
import { IconifyIcon } from '@iconify/vue/dist/offline'
import { DefineComponent } from 'vue'

interface Props {
  checkIcon?: IconifyIcon | DefineComponent
}
import { IconifyIcon } from '@iconify/vue/dist/offline'
import { DefineComponent } from 'vue'

interface Props {
  checkIcon?: IconifyIcon | DefineComponent
}
template
<SInputFile :check-icon="IconCheckCircle" />
<SInputFile :check-icon="IconCheckCircle" />

:check-text

Text to display alongside check-icon.

ts
interface Props {
  checkText?: string
}
interface Props {
  checkText?: string
}
template
<SInputFile :check-text="Saved" />
<SInputFile :check-text="Saved" />

:check-color

Defines the color of check-icon and check-text. The default is neutral.

ts
interface Props {
  checkColor?: Color
}

type Color =
  | 'neutral' 
  | 'mute' 
  | 'info' 
  | 'success' 
  | 'warning' 
  | 'danger'
interface Props {
  checkColor?: Color
}

type Color =
  | 'neutral' 
  | 'mute' 
  | 'info' 
  | 'success' 
  | 'warning' 
  | 'danger'
template
<SInputFile
  :check-icon="IconCheckCircle"
  check-text="Uploaded"
  check-color="success"
/>
<SInputFile
  :check-icon="IconCheckCircle"
  check-text="Uploaded"
  check-color="success"
/>

:value

Sets the input value. When model-value prop is set (e.g. via v-model directive), this prop gets ignored.

ts
interface Props {
  value?: File | File[] | null
}
interface Props {
  value?: File | File[] | null
}
template
<SInputFile :value="file" />
<SInputFile :value="file" />

:model-value

The v-model binding for the input.

ts
interface Props {
  modelValue?: File | File[] | null
}
interface Props {
  modelValue?: File | File[] | null
}
template
<SInputFile v-model="file" />
<SInputFile v-model="file" />

:validation

The validation object for the input. It accepts Vuelidate like validation object and displays error if there're any.

ts
import { Ref } from 'vue'

interface Props {
  validation?: Validatable
}

export interface Validatable {
  readonly $dirty: boolean
  readonly $invalid: boolean
  readonly $errors: ValidatableError[]
  readonly $touch: () => void
}

export interface ValidatableError {
  readonly $message: string | Ref<string>
}
import { Ref } from 'vue'

interface Props {
  validation?: Validatable
}

export interface Validatable {
  readonly $dirty: boolean
  readonly $invalid: boolean
  readonly $errors: ValidatableError[]
  readonly $touch: () => void
}

export interface ValidatableError {
  readonly $message: string | Ref<string>
}
template
<SInputFile
  v-model="file"
  :validation="validation"
/>
<SInputFile
  v-model="file"
  :validation="validation"
/>

:hide-error

Stop showing validation error message even when there are errors. This prop will not prevent the error color from appearing.

ts
interface Props {
  hideError?: boolean
}
interface Props {
  hideError?: boolean
}
template
<SInputFile
  v-model="file"
  :validation="validation"
  hide-error
/>
<SInputFile
  v-model="file"
  :validation="validation"
  hide-error
/>

Slots

Here are the list of slots you may define within the component.

#info

Same as info prop. When info prop and this slot are defined at the same time, this slot will take precedence.

template
<SInputFile label="Upload image" v-model="...">
  <template #info>
    Learn more about this field <SLink href="...">here</SLink>.
  </template>
</SInputFile>
<SInputFile label="Upload image" v-model="...">
  <template #info>
    Learn more about this field <SLink href="...">here</SLink>.
  </template>
</SInputFile>

Events

Here are the list of events the component may emit.

@update:model-value

Emits when the user selects the item. This event is always emitted together with change event.

ts
interface Emits {
  (e: 'update:model-value', value: File | File[] | null): void
}
interface Emits {
  (e: 'update:model-value', value: File | File[] | null): void
}

@change

Emits when the user selects the item. This event is always emitted together with update:model-value event.

ts
interface Emits {
  (e: 'change', value: File | File[] | null): void
}
interface Emits {
  (e: 'change', value: File | File[] | null): void
}

Styles

You may customize the styles by overriding --input prefixed CSS variables.

Global input styles

You may customize the various styles of the component via global input related CSS variables. Please refer to Styles: Input Styles page.