nb-radio
This is a radio button group component for Vue.js 3+.
Loading component...
Installation
Yarn
yarn add @vlalg-nimbus/nb-inputs
Usage
Vue 3
import { createApp } from 'vue'
import App from './App.vue'
import NbInputComponents from '@vlalg-nimbus/nb-inputs'
import "@vlalg-nimbus/nb-inputs/dist/style.css";
const app = createApp(App)
app.use(NbInputComponents)
app.mount('#app')
To use, simply call the component, in this case it will be NbRadio or nb-radio.
Mode 1
<template>
<NbRadio />
</template>
Preview & Playground
Select the component you want to edit/test
Loading Sandbox...
Props
Items with an (*) mean they are required
| name | Value type | Default | Description |
|---|---|---|---|
| nbId (*) | String | Sets the id attribute to differentiate from other components | |
| display | String | 'b' | Defines the display type. Accepts ib and b. |
| tabIndex | Number, Array | 0 | Defines the tab index. Can be a number (applied to all items) or an array (one value per item). Set this property to make the radio buttons focusable by the keyboard. |
| hasTabIndexEnter | Boolean | true | Enables the radio buttons to be activated with the Enter key when focused. |
| hasTabIndexSpace | Boolean | true | Enables the radio buttons to be activated with the Space key when focused. |
| ariaLabel | String | 'Alternate Text Button' | Defines the aria-label attribute for screen readers. |
| ariaAttrs | Object | {} | Allows passing custom aria attributes as an object. Keys will automatically receive the aria- prefix. Example: { 'describedby': 'help-id', 'required': 'true' } |
| disabled | Boolean | false | Defines if the radio is disabled |
| groupName | String | '' | Defines radio group name |
| options | Array | Defines the list of values. It is an array of objects { value: 'Value', text: 'Text' } | |
| currentOption | String | '' | Defines the selected value. The value must exist in the list options, in the key field |
| valueType | String | 'boolean' | Defines values type. Accepts boolean, string and number |
| theme | String | 'light' | Defines the theme. Accepts dark and light. When theme is set, uses theme-specific color props. |
| hoverEffect | Boolean | false | Defines whether the hover effect exists when passing over the radio without it being selected. |
| activeHoverEffect | Boolean | false | Defines whether the hover effect exists when passing over the radio while it is selected. |
| itemGap | Number | 15 | Defines the space between radio options. |
| internalGap | Number | 6 | Defines the space between the radio and the text. |
| scale | Number | 1 | Defines component scale (size). |
| fontFamily | String | "'Lato', sans-serif" | Defines the font-family |
| fontSize | String | '1.6em' | Defines the font-size |
| fontWeight | Number | 400 | Defines the font-weight |
| lightTextColor | String | '#333333' | Defines the text color for light theme. Accepts Color name and Hex |
| lightColor | String | '#cccccc' | Defines the radio color for light theme. Accepts Hex color only |
| lightColorHover | String | '#bbbbbb' | Defines the radio hover color for light theme. Accepts Hex color only |
| darkTextColor | String | '#e0e0e0' | Defines the text color for dark theme. Accepts Color name and Hex |
| darkColor | String | '#555555' | Defines the radio color for dark theme. Accepts Hex color only |
| darkColorHover | String | '#666666' | Defines the radio hover color for dark theme. Accepts Hex color only |
Events
| name | Return type | Description |
|---|---|---|
| current-value | value | Fired when an update to the selected value is made, returns selected value. |
| changed | value | Fired when an update to the selected value is made, returns selected value. |
| clicked | nothing | Fired when a radio button is clicked, returns nothing. |
Example
Light Theme (default)
<template>
<NbRadio
nb-id="radio-light"
display="b"
group-name="radio-group-light"
theme="light"
:options="radioOptions"
:current-option="currentRadioValue"
light-text-color="#1e40af"
light-color="#3b82f6"
light-color-hover="#60a5fa"
:hover-effect="true"
:active-hover-effect="true"
value-type="string"
@current-value="handleRadioChange($event)"
@changed="handleRadioChange($event)"
@clicked="logEvent()"
/>
</template>
<script setup>
import { ref } from 'vue';
defineOptions({
name: 'CompRadio',
});
const radioOptions = [
{ value: 'option1', text: 'Option 1' },
{ value: 'option2', text: 'Option 2' },
{ value: 'option3', text: 'Option 3' }
];
const currentRadioValue = ref('option1');
const handleRadioChange = (value) => {
currentRadioValue.value = value;
console.log('Radio changed:', value);
};
const logEvent = () => {
console.log('clicked');
};
</script>
Dark Theme
<template>
<NbRadio
nb-id="radio-dark"
display="b"
group-name="radio-group-dark"
theme="dark"
:options="radioOptions"
:current-option="currentRadioValue"
dark-text-color="#a78bfa"
dark-color="#8b5cf6"
dark-color-hover="#7c3aed"
:hover-effect="true"
:active-hover-effect="true"
value-type="string"
@current-value="handleRadioChange($event)"
@changed="handleRadioChange($event)"
@clicked="logEvent()"
/>
</template>
<script setup>
import { ref } from 'vue';
defineOptions({
name: 'CompRadioDark',
});
const radioOptions = [
{ value: 'option1', text: 'Option 1' },
{ value: 'option2', text: 'Option 2' },
{ value: 'option3', text: 'Option 3' }
];
const currentRadioValue = ref('option2');
const handleRadioChange = (value) => {
currentRadioValue.value = value;
console.log('Radio changed:', value);
};
const logEvent = () => {
console.log('clicked');
};
</script>
