-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `Menu` migrates to Vue 3. Changes sufficient to render the documentation page of `Menu` are made. - A new concept "menu item container" that abstracts a container of `MenuItem`s is introduced, and it is provided as `BMenuItemContainer` defined in a new file `src/components/menu/MenuItemContainerMixin.js`. `Menu` and `MenuItem` are a `BMenuItemContainer`. `MenuItem` used to depend on `$children` of its parent to list its siblings, but Vue 3 no longer provides `$children`. Thus, the concept "menu item container" is introduced. A `MenuItem` actively registers itself to the immediate parent "menu item container" when it is mounted. A `MenuItem` reads parent's "menu items" to access its siblings. - In `src/components/menu/Menu.vue`, - `MenuItemContainerMixin` (see above) is mixed in. - In `src/components/menu/MenuItem.vue`, - `MenuItemContainerMixin` (see above) is mixed in. - `MenuItem` `inject`s `BMenuItemContainer` as `parent`. - `MenuItem` reads `parent`'s `menuItems` instead of `$children` to access its siblings. Note that `parent` is not equivalent to `$parent`. For instance, when a `MenuItem` is wrapped inside a `transition` its `$parent` is neither a `Menu` nor `MenuItem` but a `Transition`. - `MenuItem` appends itself to its parent when it is mounted. And it removes itself from its parent when it is about to be umounted. - Events to be emitted are listed in `emits`. - Binding of `$listeners` is removed because Vue 3 no longer provides `$listeners`. Listeners are included in `$attrs`. - In `src/components/menu/MenuList.vue`, - `MenuList` becomes a new functional component conforms to Vue 3. - Resolves the `b-icon` component with `resolveComponent`. - Common, - Automatic ESLinst fix is applied.
- Loading branch information
Showing
4 changed files
with
92 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export default { | ||
provide() { | ||
return { | ||
BMenuItemContainer: this | ||
} | ||
}, | ||
data() { | ||
return { | ||
menuItems: [] | ||
} | ||
}, | ||
methods: { | ||
appendMenuItem(item) { | ||
this.menuItems.push(item) | ||
}, | ||
removeMenuItem(item) { | ||
const index = this.menuItems.indexOf(item) | ||
if (index !== -1) { | ||
this.menuItems.splice(index, 1) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
<script> | ||
export default { | ||
name: 'BMenuList', | ||
functional: true, | ||
props: { | ||
label: String, | ||
icon: String, | ||
iconPack: String, | ||
ariaRole: { | ||
type: String, | ||
default: '' | ||
import { h as createElement, resolveComponent } from 'vue' | ||
const BMenuList = (props, context) => { | ||
let vlabel = null | ||
const slots = context.slots | ||
if (props.label || slots.label) { | ||
vlabel = createElement( | ||
'p', | ||
{ class: 'menu-label' }, | ||
props.label | ||
? props.icon | ||
? [ | ||
createElement(resolveComponent('b-icon'), { | ||
icon: props.icon, | ||
pack: props.iconPack, | ||
size: props.size | ||
}), | ||
createElement('span', {}, props.label) | ||
] | ||
: props.label | ||
: slots.label() | ||
) | ||
} | ||
const vnode = createElement( | ||
'ul', | ||
{ | ||
class: 'menu-list', | ||
role: props.ariaRole === 'menu' ? props.ariaRole : null | ||
}, | ||
size: { | ||
type: String, | ||
default: 'is-small' | ||
} | ||
slots.default() | ||
) | ||
return vlabel ? [vlabel, vnode] : vnode | ||
} | ||
BMenuList.props = { | ||
label: String, | ||
icon: String, | ||
iconPack: String, | ||
ariaRole: { | ||
type: String, | ||
default: '' | ||
}, | ||
render(createElement, context) { | ||
let vlabel = null | ||
const slots = context.slots() | ||
if (context.props.label || slots.label) { | ||
vlabel = createElement('p', { attrs: { 'class': 'menu-label' } }, | ||
context.props.label | ||
? context.props.icon | ||
? [ | ||
createElement('b-icon', { | ||
props: { | ||
'icon': context.props.icon, | ||
'pack': context.props.iconPack, | ||
'size': context.props.size | ||
} | ||
}), | ||
createElement('span', {}, context.props.label) | ||
] : context.props.label | ||
: slots.label) | ||
} | ||
const vnode = createElement('ul', { attrs: { 'class': 'menu-list', 'role': context.props.ariaRole === 'menu' ? context.props.ariaRole : null } }, slots.default) | ||
return vlabel ? [ vlabel, vnode ] : vnode | ||
size: { | ||
type: String, | ||
default: 'is-small' | ||
} | ||
} | ||
export default BMenuList | ||
</script> |