Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit d5e67d3

Browse files
committed
add FormRadio component
1 parent 11fae05 commit d5e67d3

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

example/src/components/FormsPage.vue

+19
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@
5151
</select>
5252
</form-group>
5353
</grid-col>
54+
<grid-col md="6" lg="4">
55+
<form-group>
56+
<form-label>Radios</form-label>
57+
<div class="custom-controls-stacked">
58+
<form-radio checked name="example-radios" :value="1" label="Option 1"/>
59+
<form-radio name="example-radios" :value="2" label="Option 2"/>
60+
<form-radio name="example-radios" :value="3" disabled label="Option Disabled"/>
61+
<form-radio name="example-radios2" checked :value="4" disabled label="Option Disabled Checked"/>
62+
</div>
63+
</form-group>
64+
<form-group>
65+
<form-label>Inline Radios</form-label>
66+
<div class="custom-controls-stacked">
67+
<form-radio checked name="example-radios" :value="1" label="Option 1" inline/>
68+
<form-radio name="example-radios" :value="2" label="Option 2" inline/>
69+
<form-radio name="example-radios" :value="3" label="Option 3" inline/>
70+
</div>
71+
</form-group>
72+
</grid-col>
5473
</grid-row>
5574
</card-body>
5675
</card>

src/components/Form/FormRadio.vue

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<label class="custom-control custom-radio" :class="{'custom-control-inline': inline}">
3+
<input class="custom-control-input" v-bind="{name, checked: isChecked, disabled, value: radioValue}" @change="onChange" type="radio">
4+
<div class="custom-control-label">{{ label }}</div>
5+
</label>
6+
</template>
7+
8+
<script>
9+
import FormInput from './FormInput'
10+
11+
export default {
12+
name: "form-radio",
13+
props: {
14+
inline: {default: false, type: Boolean},
15+
value: {},
16+
label: {},
17+
checked: {default: false, type: Boolean},
18+
disabled: {default: false, type: Boolean},
19+
name: {default: '', type: String}
20+
},
21+
22+
computed: {
23+
radioValue () {
24+
return this.$attrs.value
25+
},
26+
27+
isChecked () {
28+
return this.checked || this.radioValue === this.value
29+
}
30+
},
31+
32+
methods: {
33+
onChange () {
34+
this.$emit('input', this.radioValue)
35+
}
36+
},
37+
38+
components: {FormInput}
39+
}
40+
</script>
41+
42+
<style scoped>
43+
44+
</style>

src/components/Form/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import FormGroup from './FormGroup'
22
import FormInput from './FormInput'
33
import FormInvalidFeedback from './FormInvalidFeedback'
44
import FormLabel from './FormLabel'
5+
import FormRadio from './FormRadio'
56
import FormStaticText from './FormStaticText'
67
import FormTextarea from './FormTextarea'
78

@@ -10,6 +11,7 @@ export {
1011
FormInput,
1112
FormInvalidFeedback,
1213
FormLabel,
14+
FormRadio,
1315
FormStaticText,
1416
FormTextarea
1517
}

0 commit comments

Comments
 (0)