Skip to content

Commit 6f88a26

Browse files
committed
refactor: update shared components
1 parent cac84bd commit 6f88a26

File tree

5 files changed

+109
-33
lines changed

5 files changed

+109
-33
lines changed

src/components/AppHeaderDropdownAccnt.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<CDropdown variant="nav-item">
33
<CDropdownToggle placement="bottom-end" class="py-0" :caret="false">
4-
<CAvatar :src="avatar" size="md"/>
4+
<CAvatar :src="avatar" size="md" />
55
</CDropdownToggle>
6-
<CDropdownMenu>
7-
<CDropdownHeader tag="div" class="text-center" color="light">
8-
<strong>Account</strong>
6+
<CDropdownMenu class="pt-0">
7+
<CDropdownHeader component="h6" class="bg-light fw-semibold py-2">
8+
Account
99
</CDropdownHeader>
1010
<CDropdownItem>
1111
<CIcon icon="cil-bell" /> Updates
@@ -23,7 +23,7 @@
2323
<CIcon icon="cil-comment-square" /> Comments
2424
<CBadge color="warning" class="ms-auto">{{ itemsCount }}</CBadge>
2525
</CDropdownItem>
26-
<CDropdownHeader tag="div" class="text-center" color="light">
26+
<CDropdownHeader component="h6" class="bg-light fw-semibold py-2">
2727
<strong>Settings</strong>
2828
</CDropdownHeader>
2929
<CDropdownItem> <CIcon icon="cil-user" /> Profile </CDropdownItem>
@@ -48,12 +48,12 @@
4848
<script>
4949
import avatar from './../assets/images/avatars/8.jpg'
5050
export default {
51-
name: "AppHeaderDropdownAccnt",
51+
name: 'AppHeaderDropdownAccnt',
5252
data() {
5353
return {
5454
avatar: avatar,
5555
itemsCount: 42,
56-
};
56+
}
5757
},
58-
};
58+
}
5959
</script>

src/components/AppSidebar.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<template>
2-
<CSidebar position="fixed" selfHiding="md" :unfoldable="sidebarUnfoldable" :visible="sidebarVisible">
2+
<CSidebar
3+
position="fixed"
4+
selfHiding="md"
5+
:unfoldable="sidebarUnfoldable"
6+
:visible="sidebarVisible"
7+
@visible-change="
8+
(event) =>
9+
$store.commit({
10+
type: 'updateSidebarVisible',
11+
value: event,
12+
})
13+
"
14+
>
315
<CSidebarBrand>
416
<CIcon
517
customClassName="sidebar-brand-full"

src/components/AppSidebarNav.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent, h, resolveComponent } from 'vue'
2-
import { RouterLink } from 'vue-router'
2+
import { RouterLink, useRoute } from 'vue-router'
33

44
import { CSidebarNav, CNavItem, CNavGroup, CNavTitle } from '@coreui/vue'
55
import nav from '@/_nav.js'
@@ -12,33 +12,56 @@ const AppSidebarNav = defineComponent({
1212
CNavTitle,
1313
},
1414
setup() {
15+
const normalizePath = (path) =>
16+
decodeURI(path)
17+
.replace(/#.*$/, '')
18+
.replace(/(index)?\.(html)$/, '')
19+
20+
const isActiveLink = (route, link) => {
21+
if (link === undefined) {
22+
return false
23+
}
24+
25+
if (route.hash === link) {
26+
return true
27+
}
28+
29+
const currentPath = normalizePath(route.path)
30+
const targetPath = normalizePath(link)
31+
32+
return currentPath === targetPath
33+
}
34+
35+
const isActiveItem = (route, item) => {
36+
if (isActiveLink(route, item.to)) {
37+
return true
38+
}
39+
40+
if (item.children) {
41+
return item.children.some((child) => isActiveItem(route, child))
42+
}
43+
44+
return false
45+
}
46+
1547
const renderItem = (item) => {
48+
const route = useRoute()
49+
1650
if (item.children) {
1751
return h(
18-
RouterLink,
52+
resolveComponent('CNavGroup'),
1953
{
20-
to: item.route,
21-
custom: true,
54+
visible: item.children.some((child) => isActiveItem(route, child)),
2255
},
2356
{
24-
default: (props) =>
25-
h(
26-
resolveComponent('CNavGroup'),
27-
{
28-
visible: props.isActive,
29-
},
30-
{
31-
togglerContent: () => [
32-
h(resolveComponent('CIcon'), {
33-
customClassName: 'nav-icon',
34-
name: item.icon,
35-
}),
36-
item.name,
37-
],
38-
default: () =>
39-
item.children.map((child) => renderItem(child)),
40-
},
41-
),
57+
togglerContent: () => [
58+
h(resolveComponent('CIcon'), {
59+
customClassName: 'nav-icon',
60+
name: item.icon,
61+
}),
62+
item.name,
63+
],
64+
default: () => item.children.map((child) => renderItem(child)),
4265
},
4366
)
4467
}
@@ -76,7 +99,7 @@ const AppSidebarNav = defineComponent({
7699
},
77100
{
78101
default: () => item.badge.text,
79-
}
102+
},
80103
),
81104
],
82105
},

src/components/DocsCallout.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<CCallout color="info" class="bg-white">
3+
A Vue {{name}} component {{plural ? 'have' : 'has'}} been created as a native
4+
Vue.js version of Bootstrap {{name}}. {{name}} {{plural ? 'are' : 'is'}}
5+
delivered with some new features, variants, and unique design that matches
6+
CoreUI Design System requirements.
7+
<br />
8+
<br />
9+
For more information please visit our official
10+
<CLink :href="href" target="_blank">
11+
documentation of CoreUI Components Library for Vue.js
12+
</CLink>
13+
.
14+
</CCallout>
15+
</template>
16+
17+
<script>
18+
import packageJson from '../../package.json'
19+
export default {
20+
name: 'DocsCallout',
21+
props: {
22+
href: {
23+
type: String,
24+
default: undefined,
25+
required: false,
26+
},
27+
name: {
28+
type: String,
29+
default: undefined,
30+
required: false,
31+
},
32+
},
33+
setup(props) {
34+
const href = `https://coreui.io/vue/docs/${packageJson.config.coreui_library_short_version}/${props.href}`
35+
36+
return {
37+
href,
38+
}
39+
},
40+
}
41+
</script>

src/components/Example.vue renamed to src/components/DocsExample.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<script>
2525
import packageJson from "../../package.json";
2626
export default {
27-
name: "Example",
27+
name: "DocsExample",
2828
props: {
2929
href: {
3030
type: String,

0 commit comments

Comments
 (0)