Skip to content

Commit 6401fbe

Browse files
committed
feat(CFormFeedback): add new component
1 parent 6e42bf5 commit 6401fbe

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/components/form/CFormFeedback.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { defineComponent, h } from 'vue'
2+
3+
const CFormFeedback = defineComponent({
4+
name: 'CFormFeedback',
5+
props: {
6+
/**
7+
* Component used for the root node. Either a string to use a HTML element or a component.
8+
*
9+
* @default 'div'
10+
*/
11+
component: {
12+
type: String,
13+
required: false,
14+
default: 'div',
15+
},
16+
/**
17+
* Method called immediately after the `value` prop changes.
18+
*/
19+
invalid: Boolean,
20+
/**
21+
* If your form layout allows it, you can display validation feedback in a styled tooltip.
22+
*/
23+
tooltip: Boolean,
24+
/**
25+
* Set component validation state to valid.
26+
*/
27+
valid: Boolean,
28+
},
29+
setup(props, { slots }) {
30+
return () =>
31+
h(
32+
props.component,
33+
{
34+
class: [
35+
{
36+
[`invalid-${props.tooltip ? 'tooltip' : 'feedback'}`]: props.invalid,
37+
[`valid-${props.tooltip ? 'tooltip' : 'feedback'}`]: props.valid,
38+
},
39+
],
40+
},
41+
slots.default && slots.default(),
42+
)
43+
},
44+
})
45+
46+
export { CFormFeedback }

src/components/form/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { App } from 'vue'
22
import { CForm } from './CForm'
33
import { CFormCheck } from './CFormCheck'
44
import { CFormControl } from './CFormControl'
5+
import { CFormFeedback } from './CFormFeedback'
56
import { CFormFloating } from './CFormFloating'
67
import { CFormInput } from './CFormInput'
78
import { CFormLabel } from './CFormLabel'
@@ -18,6 +19,7 @@ const CFormPlugin = {
1819
app.component(CForm.name, CForm)
1920
app.component(CFormCheck.name, CFormCheck)
2021
app.component(CFormControl.name, CFormControl)
22+
app.component(CFormFeedback.name, CFormFeedback)
2123
app.component(CFormFloating.name, CFormFloating)
2224
app.component(CFormInput.name, CFormInput)
2325
app.component(CFormLabel.name, CFormLabel)
@@ -36,6 +38,7 @@ export {
3638
CForm,
3739
CFormCheck,
3840
CFormControl,
41+
CFormFeedback,
3942
CFormFloating,
4043
CFormInput,
4144
CFormLabel,

0 commit comments

Comments
 (0)