Skip to content

Commit 17baaf2

Browse files
committed
feat: bnav components
Some are not fully finished, and does not include the full list of nav components
1 parent 2b36ee1 commit 17baaf2

File tree

6 files changed

+133
-33
lines changed

6 files changed

+133
-33
lines changed

packages/bootstrap-vue-3/src/BootstrapVue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import BNav from './components/BNav/BNav.vue'
7373
import BNavbar from './components/BNav/BNavbar.vue'
7474
import BNavbarBrand from './components/BNav/BNavbarBrand.vue'
7575
import BNavbarNav from './components/BNav/BNavbarNav.vue'
76-
import BNavbarToggle from './components/BNav/BNavbarToggle.vue'
76+
// import BNavbarToggle from './components/BNav/BNavbarToggle.vue'
7777
import BNavItem from './components/BNav/BNavItem.vue'
7878
import BNavItemDropdown from './components/BNav/BNavItemDropdown.vue'
7979
import BOffcanvas from './components/BOffcanvas.vue'
@@ -188,7 +188,7 @@ export {
188188
BNavbar,
189189
BNavbarBrand,
190190
BNavbarNav,
191-
BNavbarToggle,
191+
// BNavbarToggle,
192192
BNavItem,
193193
BNavItemDropdown,
194194
BOffcanvas,
@@ -315,7 +315,7 @@ declare module '@vue/runtime-core' {
315315
BNavbar: typeof BNavbar
316316
BNavbarBrand: typeof BNavbarBrand
317317
BNavbarNav: typeof BNavbarNav
318-
BNavbarToggle: typeof BNavbarToggle
318+
// BNavbarToggle: typeof BNavbarToggle
319319
BNavItem: typeof BNavItem
320320
BNavItemDropdown: typeof BNavItemDropdown
321321
BOffcanvas: typeof BOffcanvas
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
<ul class="nav" :class="classes">
2+
<component :is="tag" class="nav" :class="classes">
33
<slot />
4-
</ul>
4+
</component>
55
</template>
66

77
<script setup lang="ts">
@@ -10,27 +10,36 @@ import {computed} from 'vue'
1010
1111
interface BNavProps {
1212
align?: string
13+
cardHeader?: boolean
1314
fill?: boolean
1415
justified?: boolean
1516
pills?: boolean
17+
small?: boolean
1618
tabs?: boolean
19+
tag?: string
1720
vertical?: boolean
1821
}
1922
2023
const props = withDefaults(defineProps<BNavProps>(), {
24+
cardHeader: false,
2125
fill: false,
2226
justified: false,
2327
pills: false,
28+
small: false,
2429
tabs: false,
30+
tag: 'ul',
2531
vertical: false,
2632
})
2733
2834
const classes = computed(() => ({
29-
'flex-column': props.vertical,
30-
[`justify-content-${props.align}`]: props.align,
3135
'nav-tabs': props.tabs,
32-
'nav-pills': props.pills,
36+
'nav-pills': props.pills && !props.tabs,
37+
'card-header-tabs': !props.vertical && props.cardHeader && props.tabs,
38+
'card-header-pills': !props.vertical && props.cardHeader && !props.tabs,
39+
'flex-column': props.vertical,
3340
'nav-fill': props.fill,
3441
'nav-justified': props.justified,
42+
[`justify-content-${props.align}`]: props.align,
43+
'small': props.small,
3544
}))
3645
</script>

packages/bootstrap-vue-3/src/components/BNav/BNavbar.vue

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,45 @@
66

77
<script setup lang="ts">
88
import {computed} from 'vue'
9-
import type {ColorVariant, NavbarBreakpoint} from '../../types'
9+
import type {ColorVariant} from '../../types'
1010
1111
interface Props {
12-
variant?: ColorVariant
13-
toggleable?: NavbarBreakpoint
12+
fixed?: string
13+
print?: boolean
14+
sticky?: boolean
1415
tag?: string
16+
toggleable?: false | 'sm' | 'md' | 'lg' | 'xl' // Type Omit<Breakpoint, 'xxl'>
17+
type?: string
18+
variant?: ColorVariant
1519
}
1620
1721
const props = withDefaults(defineProps<Props>(), {
18-
variant: 'light',
19-
toggleable: false, // navbar never collapses
22+
print: false,
23+
sticky: false,
2024
tag: 'nav',
25+
toggleable: false, // navbar never collapses
26+
type: 'light',
2127
})
2228
2329
const computedRole = computed<undefined | 'navigation'>(() =>
2430
props.tag === 'nav' ? undefined : 'navigation'
2531
)
2632
33+
const computedNavbarExpand = computed<undefined | string>(() =>
34+
props.toggleable && typeof props.toggleable === 'string'
35+
? `navbar-expand-${props.toggleable}`
36+
: props.toggleable === false
37+
? 'navbar-expand'
38+
: undefined
39+
)
40+
2741
const classes = computed(() => ({
28-
'navbar-light': props.variant === 'light',
29-
'navbar-dark': props.variant !== 'light',
30-
'navbar-expand': props.toggleable === false, // for navbars that never collapse
42+
'd-print': props.print,
43+
'sticky-top': props.sticky,
44+
[`navbar-${props.type}`]: props.type,
3145
[`bg-${props.variant}`]: props.variant,
32-
[`navbar-expand-${props.toggleable}`]: typeof props.toggleable === 'string',
46+
[`fixed-${props.fixed}`]: props.fixed,
47+
'navbar-expand': props.toggleable === false, // for navbars that never collapse
48+
[computedNavbarExpand.value as string]: computedNavbarExpand.value !== undefined,
3349
}))
3450
</script>

packages/bootstrap-vue-3/src/components/BNav/BNavbarBrand.vue

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,40 @@
55
</template>
66

77
<script setup lang="ts">
8+
// TODO refactor this to use old setup containing BLINKPROPS and pluckprops utility
9+
import type {LinkTarget} from '../../types'
810
import {computed} from 'vue'
911
import type {RouteLocationRaw} from 'vue-router'
1012
1113
interface Props {
12-
tag?: string
14+
active?: boolean
15+
activeClass?: string
16+
append?: boolean
17+
disabled?: boolean
18+
exact?: boolean
19+
exactActiveClass?: string
20+
exactPath?: boolean
21+
exactPathActiveClass?: string
1322
href?: string
23+
noPrefetch?: boolean
24+
prefetch?: boolean
25+
rel?: string
26+
replace?: boolean
27+
routerComponentName?: string
28+
tag?: string
29+
target?: LinkTarget
1430
to?: RouteLocationRaw
1531
}
1632
1733
const props = withDefaults(defineProps<Props>(), {
34+
active: false,
35+
append: false,
36+
disabled: false,
37+
exact: false,
38+
exactPath: false,
39+
noPrefetch: false,
40+
replace: false,
41+
target: '_self',
1842
tag: 'div',
1943
})
2044
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
<template>
2-
<ul class="navbar-nav">
2+
<ul class="navbar-nav" :class="classes">
33
<slot></slot>
44
</ul>
55
</template>
6+
7+
<script setup lang="ts">
8+
import {computed} from 'vue'
9+
10+
interface Props {
11+
align?: string
12+
fill?: boolean
13+
justified?: boolean
14+
small?: boolean
15+
tag?: string
16+
}
17+
18+
const props = withDefaults(defineProps<Props>(), {
19+
fill: false,
20+
justified: false,
21+
small: false,
22+
tag: 'ul',
23+
})
24+
25+
const comptuedJustifyContent = computed(() => {
26+
const value = props.align === 'left' ? 'start' : props.align === 'right' ? 'end' : props.align
27+
return `justify-content-${value}`
28+
})
29+
30+
const classes = computed(() => ({
31+
'nav-fill': props.fill,
32+
'nav-justified': props.justified,
33+
[comptuedJustifyContent.value]: props.align !== undefined,
34+
'small': props.small,
35+
}))
36+
</script>
Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
<template>
2-
<button :class="classes" type="button" @click="onButtonClicked">
3-
<span class="navbar-toggler-icon"></span>
2+
<button
3+
v-b-toggle=""
4+
class="navbar-toggler"
5+
:class="classes"
6+
type=""
7+
v-bind="attrs"
8+
@click="onClick"
9+
>
10+
<span class="navbar-toggler-icon" />
411
</button>
512
</template>
613

714
<script setup lang="ts">
8-
import {ref} from 'vue'
15+
import {BToggle as vBToggle} from '../../directives/index'
16+
import {computed} from 'vue'
17+
import {ButtonType} from '../../types'
918
1019
interface Props {
11-
target?: string
1220
disabled?: boolean // TODO ensure that if the button is disabled that it doesn't collapse
21+
label?: string
22+
target?: string // TODO target should be required, ignoring the other rules about possibly undefined? It is in B-V
1323
}
1424
1525
const props = withDefaults(defineProps<Props>(), {
26+
label: 'Toggle navigation',
1627
disabled: false,
1728
})
1829
@@ -22,17 +33,26 @@ interface Emits {
2233
2334
const emit = defineEmits<Emits>()
2435
25-
const classes = ref({
36+
const attrs = computed(() => ({
37+
'type': 'button' as ButtonType,
38+
'disabled': props.disabled,
39+
'aria-label': props.label,
40+
}))
41+
42+
const classes = computed(() => ({
2643
'navbar-toggler': true,
2744
'collapsed': true,
28-
})
29-
30-
const onButtonClicked = () => {
31-
emit('click')
32-
33-
classes.value.collapsed = !classes.value.collapsed
34-
35-
const el = document.getElementById(props.target) // Handle this
36-
el?.classList.toggle('show')
45+
}))
46+
47+
const onClick = (): void => {
48+
if (!props.disabled) {
49+
emit('click')
50+
51+
classes.value.collapsed = !classes.value.collapsed
52+
if (props.target !== undefined) {
53+
const el = document.getElementById(props.target)
54+
el?.classList.toggle('show')
55+
}
56+
}
3757
}
3858
</script>

0 commit comments

Comments
 (0)