Skip to content

SInputRadios

<SInputRadios> is a radio button input component.

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

Item 001

Item 002

Item 003

Usage

Import <SInputRadios> component and pass in options and value props.

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

const input = ref(1)

const options = [
  { label: 'Item 001', value: 1 },
  { label: 'Item 002', value: 2 },
  { label: 'Item 003', value: 3 }
]
</script>

<template>
  <SInputRadios :options="options" v-model="input" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import SInputRadios from '@globalbrain/sefirot/lib/components/SInputRadios.vue'

const input = ref(1)

const options = [
  { label: 'Item 001', value: 1 },
  { label: 'Item 002', value: 2 },
  { label: 'Item 003', value: 3 }
]
</script>

<template>
  <SInputRadios :options="options" 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
<SInputRadios
  size="small"
  :options="[...]"
  v-model="..."
/>
<SInputRadios
  size="small"
  :options="[...]"
  v-model="..."
/>

:label

Defines the label text of the input.

ts
interface Props {
  label?: string
}
interface Props {
  label?: string
}
template
<SInputRadios
  label="Name"
  :options="[...]"
  v-model="..."
/>
<SInputRadios
  label="Name"
  :options="[...]"
  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
<SInputRadios
  label="Domain"
  info="Some helpful information."
  v-model="..."
/>
<SInputRadios
  label="Domain"
  info="Some helpful information."
  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
<SInputRadios
  label="Company URL"
  note="Optional"
  :options="[...]"
  v-model="..."
/>
<SInputRadios
  label="Company URL"
  note="Optional"
  :options="[...]"
  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
<SInputRadios :check-icon="IconCheckCircle" />
<SInputRadios :check-icon="IconCheckCircle" />

:check-text

Text to display alongside check-icon.

ts
interface Props {
  checkText?: string
}
interface Props {
  checkText?: string
}
template
<SInputRadios :check-text="Saved" />
<SInputRadios :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
<SInputRadios
  :check-icon="IconCheckCircle"
  check-text="Uploaded"
  check-color="success"
/>
<SInputRadios
  :check-icon="IconCheckCircle"
  check-text="Uploaded"
  check-color="success"
/>

:options

The list of selectable options for the input.

ts
interface Props {
  options?: Option[]
}

export interface Option {
  label: string
  value: string | number | boolean
  disabled?: boolean
}
interface Props {
  options?: Option[]
}

export interface Option {
  label: string
  value: string | number | boolean
  disabled?: boolean
}
template
<SInputRadios
  :options="[
    { label: 'Item 001', value: 1 },
    { label: 'Item 002', value: 2 },
    { label: 'Item 003', value: 3 }
  ]"
  v-model="..."
/>
<SInputRadios
  :options="[
    { label: 'Item 001', value: 1 },
    { label: 'Item 002', value: 2 },
    { label: 'Item 003', value: 3 }
  ]"
  v-model="..."
/>

:nullable

Enables the user to deselect options. The default is false.

ts
interface Props {
  nullable?: boolean
}
interface Props {
  nullable?: boolean
}
template
<SInputRadios
  :options="[...]"
  nullable
  v-model="..."
/>
<SInputRadios
  :options="[...]"
  nullable
  v-model="..."
/>

:disabled

Mark input as disabled. When this prop is set, users may not be able to focus the element not trigger any events.

ts
interface Props {
  disabled?: boolean
}
interface Props {
  disabled?: boolean
}
template
<SInputRadios
  :options="[...]"
  disabled
  v-model="..."
/>
<SInputRadios
  :options="[...]"
  disabled
  v-model="..."
/>

: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?: string | number | boolean | null
}
interface Props {
  value?: string | number | boolean | null
}
template
<SInputRadios
  :options="[...]"
  :value="1"
/>
<SInputRadios
  :options="[...]"
  :value="1"
/>

:model-value

The v-model binding for the input.

ts
interface Props {
  modelValue?: string | number | boolean | null
}
interface Props {
  modelValue?: string | number | boolean | null
}
template
<SInputRadios
  :options="[...]"
  v-model="1"
/>
<SInputRadios
  :options="[...]"
  v-model="1"
/>

: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
<SInputRadios
  :options="[...]"
  v-model="1"
  :validation="validation"
/>
<SInputRadios
  :options="[...]"
  v-model="1"
  :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
<SInputRadios
  :options="[...]"
  v-model="1"
  :validation="validation"
  hide-error
/>
<SInputRadios
  :options="[...]"
  v-model="1"
  :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
<SInputRadios label="Domain" v-model="...">
  <template #info>
    Learn more about this field <SLink href="...">here</SLink>.
  </template>
</SInputRadios>
<SInputRadios label="Domain" v-model="...">
  <template #info>
    Learn more about this field <SLink href="...">here</SLink>.
  </template>
</SInputRadios>

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: Value): void
}

type Value = string | number | boolean | null
interface Emits {
  (e: 'update:model-value', value: Value): void
}

type Value = string | number | boolean | null

@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: Value): void
}

type Value = string | number | boolean | null
interface Emits {
  (e: 'change', value: Value): void
}

type Value = string | number | boolean | null

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.