Skip to content

Commit e8f06b5

Browse files
author
issayah
committed
BForm's script setup conversion and improvements
1 parent f4ef16a commit e8f06b5

File tree

7 files changed

+124
-128
lines changed

7 files changed

+124
-128
lines changed

src/components/BDropdown/BDropdownItem.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ const componentAttrs = computed(() => ({
6262
...(attrs.to ? {activeClass: 'active', ...attrs} : {}),
6363
}))
6464
65-
const clicked = (e: MouseEvent): void => {
66-
emit('click', e)
67-
}
65+
const clicked = (e: MouseEvent): void => emit('click', e)
6866
</script>
6967

7068
<script lang="ts">

src/components/BDropdown/BDropdownItemButton.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ const attrs = computed(() => ({
4444
disabled: props.disabled,
4545
}))
4646
47-
const clicked = (e: MouseEvent): void => {
48-
emit('click', e)
49-
}
47+
const clicked = (e: MouseEvent): void => emit('click', e)
5048
</script>
5149

5250
<script lang="ts">

src/components/BForm/BForm.vue

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
<template>
2-
<form
3-
:id="id"
4-
:novalidate="novalidate"
5-
:class="classes"
6-
@submit.prevent="$emit('submit', $event)"
7-
>
2+
<form :id="id" :novalidate="novalidate" :class="classes" @submit.prevent="submitted">
83
<slot />
94
</form>
105
</template>
116

12-
<script lang="ts">
13-
import {computed, defineComponent} from 'vue'
7+
<script setup lang="ts">
8+
// import type {BFormEmits, BFormProps} from '@/types/components'
9+
import {computed} from 'vue'
1410
15-
export default defineComponent({
16-
name: 'BForm',
17-
props: {
18-
id: {type: String, required: false},
19-
floating: {type: Boolean, default: false},
20-
novalidate: {type: Boolean, default: false},
21-
validated: {type: Boolean, default: false},
22-
},
23-
emits: ['submit'],
24-
setup(props) {
25-
const classes = computed(() => ({
26-
'form-floating': props.floating,
27-
'was-validated': props.validated,
28-
}))
11+
interface BFormProps {
12+
id?: string
13+
floating?: boolean
14+
novalidate?: boolean
15+
validated?: boolean
16+
}
2917
30-
return {
31-
classes,
32-
}
33-
},
18+
const props = withDefaults(defineProps<BFormProps>(), {
19+
floating: false,
20+
novalidate: false,
21+
validated: false,
3422
})
23+
24+
interface BFormEmits {
25+
(e: 'submit', value: Event): void
26+
}
27+
28+
const emit = defineEmits<BFormEmits>()
29+
30+
const classes = computed(() => ({
31+
'form-floating': props.floating,
32+
'was-validated': props.validated,
33+
}))
34+
35+
const submitted = (e: Event): void => emit('submit', e)
3536
</script>

src/components/BForm/BFormInvalidFeedback.vue

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
</component>
55
</template>
66

7-
<script lang="ts">
8-
import {computed, defineComponent} from 'vue'
7+
<script setup lang="ts">
8+
// import type {BFormInvalidFeedbackProps} from '@/types/components'
9+
import {computed} from 'vue'
910
10-
export default defineComponent({
11-
name: 'BFormInvalidFeedback',
12-
props: {
13-
ariaLive: {type: String, required: false},
14-
forceShow: {type: Boolean, default: false},
15-
id: {type: String, required: false},
16-
role: {type: String, required: false},
17-
state: {type: Boolean, default: undefined},
18-
tag: {type: String, default: 'div'},
19-
tooltip: {type: Boolean, default: false},
20-
},
21-
setup(props) {
22-
const computedShow = computed(() => props.forceShow === true || props.state === false)
23-
const classes = computed(() => ({
24-
'd-block': computedShow.value,
25-
'invalid-feedback': !props.tooltip,
26-
'invalid-tooltip': props.tooltip,
27-
}))
28-
const attrs = computed(() => ({
29-
'id': props.id || null,
30-
'role': props.role || null,
31-
'aria-live': props.ariaLive || null,
32-
'aria-atomic': props.ariaLive ? 'true' : null,
33-
}))
11+
interface BFormInvalidFeedbackProps {
12+
ariaLive?: string
13+
forceShow?: boolean
14+
id?: string
15+
role?: string
16+
state?: boolean
17+
tag?: string
18+
tooltip?: boolean
19+
}
3420
35-
return {
36-
attrs,
37-
classes,
38-
computedShow,
39-
}
40-
},
21+
const props = withDefaults(defineProps<BFormInvalidFeedbackProps>(), {
22+
forceShow: false,
23+
state: undefined,
24+
tag: 'div',
25+
tooltip: false,
4126
})
27+
28+
const computedShow = computed<boolean>(() => props.forceShow === true || props.state === false)
29+
30+
const classes = computed(() => ({
31+
'd-block': computedShow.value,
32+
'invalid-feedback': !props.tooltip,
33+
'invalid-tooltip': props.tooltip,
34+
}))
35+
36+
const attrs = computed(() => ({
37+
'id': props.id || null,
38+
'role': props.role || null,
39+
'aria-live': props.ariaLive || null,
40+
'aria-atomic': props.ariaLive ? 'true' : null,
41+
}))
4242
</script>

src/components/BForm/BFormRow.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
</component>
55
</template>
66

7-
<script lang="ts">
8-
import {defineComponent} from 'vue'
7+
<script setup lang="ts">
8+
// import type {BFormRowProps} from '@/types/components'
99
10-
export default defineComponent({
11-
name: 'BFormRow',
12-
props: {
13-
tag: {type: String, default: 'div'},
14-
},
10+
interface BFormRowProps {
11+
tag?: string
12+
}
13+
14+
withDefaults(defineProps<BFormRowProps>(), {
15+
tag: 'div',
1516
})
1617
</script>

src/components/BForm/BFormText.vue

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@
44
</component>
55
</template>
66

7-
<script lang="ts">
8-
import {computed, defineComponent, PropType} from 'vue'
9-
import {TextColorVariant} from '../../types'
7+
<script setup lang="ts">
8+
// import type {BFormTextProps} from '@/types/components'
9+
import {computed} from 'vue'
10+
import type {TextColorVariant} from '@/types'
1011
11-
export default defineComponent({
12-
name: 'BFormText',
13-
props: {
14-
id: {type: String, required: false},
15-
inline: {type: Boolean, default: false},
16-
tag: {type: String, default: 'small'},
17-
textVariant: {type: String as PropType<TextColorVariant>, default: 'muted'},
18-
},
19-
setup(props) {
20-
const classes = computed(() => ({
21-
'form-text': !props.inline,
22-
[`text-${props.textVariant}`]: props.textVariant,
23-
}))
12+
interface BFormTextProps {
13+
id?: string
14+
inline?: boolean
15+
tag?: string
16+
textVariant?: TextColorVariant
17+
}
2418
25-
const attrs = computed(() => ({
26-
id: props.id || null,
27-
}))
28-
29-
return {
30-
attrs,
31-
classes,
32-
}
33-
},
19+
const props = withDefaults(defineProps<BFormTextProps>(), {
20+
inline: false,
21+
tag: 'small',
22+
textVariant: 'muted',
3423
})
24+
25+
const classes = computed(() => ({
26+
'form-text': !props.inline,
27+
[`text-${props.textVariant}`]: props.textVariant,
28+
}))
29+
30+
const attrs = computed(() => ({
31+
id: props.id || null,
32+
}))
3533
</script>

src/components/BForm/BFormValidFeedback.vue

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
</component>
55
</template>
66

7-
<script lang="ts">
8-
import {computed, defineComponent} from 'vue'
7+
<script setup lang="ts">
8+
// import type {BFormValidFeedbackProps} from '@/types/components'
9+
import {computed} from 'vue'
910
10-
export default defineComponent({
11-
name: 'BFormValidFeedback',
12-
props: {
13-
ariaLive: {type: String, required: false},
14-
forceShow: {type: Boolean, default: false},
15-
id: {type: String, required: false},
16-
role: {type: String, required: false},
17-
state: {type: Boolean, default: undefined},
18-
tag: {type: String, default: 'div'},
19-
tooltip: {type: Boolean, default: false},
20-
},
21-
setup(props) {
22-
const computedShow = computed(() => props.forceShow === true || props.state === true)
23-
const classes = computed(() => ({
24-
'd-block': computedShow.value,
25-
'valid-feedback': !props.tooltip,
26-
'valid-tooltip': props.tooltip,
27-
}))
28-
const attrs = computed(() => ({
29-
'id': props.id || null,
30-
'role': props.role || null,
31-
'aria-live': props.ariaLive || null,
32-
'aria-atomic': props.ariaLive ? 'true' : null,
33-
}))
11+
interface BFormValidFeedbackProps {
12+
ariaLive?: string
13+
forceShow?: boolean
14+
id?: string
15+
role?: string
16+
state?: boolean
17+
tag?: string
18+
tooltip?: boolean
19+
}
3420
35-
return {
36-
attrs,
37-
classes,
38-
computedShow,
39-
}
40-
},
21+
const props = withDefaults(defineProps<BFormValidFeedbackProps>(), {
22+
forceShow: false,
23+
state: undefined,
24+
tag: 'div',
25+
tooltip: false,
4126
})
27+
28+
const computedShow = computed<boolean>(() => props.forceShow === true || props.state === true)
29+
30+
const classes = computed(() => ({
31+
'd-block': computedShow.value,
32+
'valid-feedback': !props.tooltip,
33+
'valid-tooltip': props.tooltip,
34+
}))
35+
36+
const attrs = computed(() => ({
37+
'id': props.id || null,
38+
'role': props.role || null,
39+
'aria-live': props.ariaLive || null,
40+
'aria-atomic': props.ariaLive ? 'true' : null,
41+
}))
4242
</script>

0 commit comments

Comments
 (0)