Refactored theme switcher and layout cosmetics

pull/310/head
cagataycivici 2020-05-07 22:13:58 +03:00
parent 6637fbf392
commit 321ad78893
5 changed files with 134 additions and 115 deletions

View File

@ -10,9 +10,9 @@
</div> </div>
</a> </a>
<app-topbar @menubutton-click="onMenuButtonClick"/> <app-topbar @menubutton-click="onMenuButtonClick" @change-theme="changeTheme" :theme="theme" />
<app-menu :active="sidebarActive" /> <app-menu :active="sidebarActive" />
<app-configurator /> <app-configurator @change-theme="changeTheme" :theme="theme" />
<div :class="['layout-mask', {'layout-mask-active': sidebarActive}]" @click="onMaskClick"></div> <div :class="['layout-mask', {'layout-mask-active': sidebarActive}]" @click="onMaskClick"></div>
<div class="layout-content"> <div class="layout-content">
<router-view/> <router-view/>
@ -35,7 +35,8 @@ export default {
data() { data() {
return { return {
sidebarActive: false, sidebarActive: false,
newsActive: false newsActive: false,
theme: 'saga-blue'
} }
}, },
watch: { watch: {
@ -62,6 +63,41 @@ export default {
}, },
hideNews() { hideNews() {
this.newsActive = false; this.newsActive = false;
},
changeTheme(event) {
let themeElement = document.getElementById('theme-link');
themeElement.setAttribute('href', themeElement.getAttribute('href').replace(this.theme, event.theme));
this.theme = event.theme;
if (event.dark) {
this.addClass(document.body, event.dark);
}
else {
this.removeClass(document.body, 'dark-theme');
this.removeClass(document.body, 'dark-theme-alt');
}
this.activeMenuIndex = null;
},
addClass(element, className) {
if (!this.hasClass(element, className)) {
if (element.classList)
element.classList.add(className);
else
element.className += ' ' + className;
}
},
removeClass(element, className) {
if (element.classList)
element.classList.remove(className);
else
element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
},
hasClass(element, className) {
if (element.classList)
return element.classList.contains(className);
else
return new RegExp('(^| )' + className + '( |$)', 'gi').test(element.className);
} }
}, },
components: { components: {

View File

@ -12,7 +12,64 @@
<div class="free-themes"> <div class="free-themes">
<h1 style="margin-top: 0">FREE THEMES</h1> <h1 style="margin-top: 0">FREE THEMES</h1>
<p>Built-in component themes created by the <a href="https://www.primefaces.org/designer/primevue">PrimeVue Theme Designer</a>.</p> <p>Built-in component themes created by the <a href="https://www.primefaces.org/designer/primevue">PrimeVue Theme Designer</a>.</p>
<div class="p-grid"> <div class="p-grid">
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-saga-blue.png" alt="Saga Blue" @click="changeTheme($event, 'saga-blue', false)"/>
<i class="pi pi-check" v-if="theme === 'saga-blue'" />
</button>
<span>Saga-Blue</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-saga-green.png" alt="Saga Green" @click="changeTheme($event, 'saga-green', false)"/>
<i class="pi pi-check" v-if="theme === 'saga-green'" />
</button>
<span>Saga-Green</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-saga-purple.png" alt="Saga Purple" @click="changeTheme($event, 'saga-purple', false)"/>
<i class="pi pi-check" v-if="theme === 'saga-purple'" />
</button>
<span>Saga-Purple</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-saga-orange.png" alt="Saga Orange" @click="changeTheme($event, 'saga-orange', false)"/>
<i class="pi pi-check" v-if="theme === 'saga-orange'" />
</button>
<span>Saga-Orange</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-vela-blue.png" alt="Vela Blue" @click="changeTheme($event, 'vela-blue', 'dark-theme-alt')"/>
<i class="pi pi-check" v-if="theme === 'vela-blue'" />
</button>
<span>Vela-Blue</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-vela-green.png" alt="Vela Green" @click="changeTheme($event, 'vela-green', 'dark-theme-alt')"/>
<i class="pi pi-check" v-if="theme === 'vela-green'" />
</button>
<span>Vela-Green</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-vela-purple.png" alt="Vela Purple" @click="changeTheme($event, 'vela-purple', 'dark-theme-alt')"/>
<i class="pi pi-check" v-if="theme === 'vela-blue'" />
</button>
<span>Vela-Purple</span>
</div>
<div class="p-col-3">
<button class="p-link">
<img src="./assets/images/layouts/themeswitcher-vela-orange.png" alt="Vela Orange" @click="changeTheme($event, 'vela-orange', 'dark-theme-alt')"/>
<i class="pi pi-check" v-if="theme === 'vela-orange'" />
</button>
<span>Vela-Orange</span>
</div>
<div class="p-col-3"> <div class="p-col-3">
<button class="p-link"> <button class="p-link">
<img src="./assets/images/layouts/themeswitcher-nova-light.png" alt="Nova Light" @click="changeTheme($event, 'nova-light', false)"/> <img src="./assets/images/layouts/themeswitcher-nova-light.png" alt="Nova Light" @click="changeTheme($event, 'nova-light', false)"/>
@ -43,28 +100,28 @@
</div> </div>
<div class="p-col-3"> <div class="p-col-3">
<button class="p-link"> <button class="p-link">
<img src="./assets/images/layouts/themeswitcher-luna-blue.png" alt="Luna Blue" @click="changeTheme($event, 'luna-blue', false)"/> <img src="./assets/images/layouts/themeswitcher-luna-blue.png" alt="Luna Blue" @click="changeTheme($event, 'luna-blue', 'dark-theme')"/>
<i class="pi pi-check" v-if="theme === 'luna-blue'" /> <i class="pi pi-check" v-if="theme === 'luna-blue'" />
</button> </button>
<span>Luna-Blue</span> <span>Luna-Blue</span>
</div> </div>
<div class="p-col-3"> <div class="p-col-3">
<button class="p-link"> <button class="p-link">
<img src="./assets/images/layouts/themeswitcher-luna-green.png" alt="Luna Green" @click="changeTheme($event, 'luna-green', false)"/> <img src="./assets/images/layouts/themeswitcher-luna-green.png" alt="Luna Green" @click="changeTheme($event, 'luna-green', 'dark-theme')"/>
<i class="pi pi-check" v-if="theme === 'luna-green'" /> <i class="pi pi-check" v-if="theme === 'luna-green'" />
</button> </button>
<span>Luna-Green</span> <span>Luna-Green</span>
</div> </div>
<div class="p-col-3"> <div class="p-col-3">
<button class="p-link"> <button class="p-link">
<img src="./assets/images/layouts/themeswitcher-luna-amber.png" alt="Luna Amber" @click="changeTheme($event, 'luna-amber', false)" target="_blank"/> <img src="./assets/images/layouts/themeswitcher-luna-amber.png" alt="Luna Amber" @click="changeTheme($event, 'luna-amber', 'dark-theme')" target="_blank"/>
<i class="pi pi-check" v-if="theme === 'luna-amber'" /> <i class="pi pi-check" v-if="theme === 'luna-amber'" />
</button> </button>
<span>Luna-Amber</span> <span>Luna-Amber</span>
</div> </div>
<div class="p-col-3"> <div class="p-col-3">
<button class="p-link"> <button class="p-link">
<img src="./assets/images/layouts/themeswitcher-luna-pink.png" alt="Luna Pink" @click="changeTheme($event, 'luna-pink', false)" target="_blank"/> <img src="./assets/images/layouts/themeswitcher-luna-pink.png" alt="Luna Pink" @click="changeTheme($event, 'luna-pink', 'dark-theme')" target="_blank"/>
<i class="pi pi-check" v-if="theme === 'luna-pink'" /> <i class="pi pi-check" v-if="theme === 'luna-pink'" />
</button> </button>
<span>Luna-Pink</span> <span>Luna-Pink</span>
@ -130,10 +187,12 @@
import DomHandler from './components/utils/DomHandler'; import DomHandler from './components/utils/DomHandler';
export default { export default {
props: {
theme: String
},
data() { data() {
return { return {
active: false, active: false
theme: 'nova-light'
} }
}, },
outsideClickListener: null, outsideClickListener: null,
@ -166,20 +225,7 @@ export default {
event.preventDefault(); event.preventDefault();
}, },
changeTheme(event, theme, dark) { changeTheme(event, theme, dark) {
let themeElement = document.getElementById('theme-link'); this.$emit('change-theme', {theme: theme, dark: dark});
themeElement.setAttribute('href', themeElement.getAttribute('href').replace(this.theme, theme));
this.theme = theme;
const hasBodyDarkTheme = DomHandler.hasClass(document.body, 'dark-theme');
if (dark) {
if (!hasBodyDarkTheme) {
this.addClass(document.body, 'dark-theme');
}
}
else if(hasBodyDarkTheme) {
this.removeClass(document.body, 'dark-theme');
}
event.preventDefault(); event.preventDefault();
}, },
bindOutsideClickListener() { bindOutsideClickListener() {
@ -200,7 +246,7 @@ export default {
}, },
isOutsideClicked(event) { isOutsideClicked(event) {
return !(this.$el.isSameNode(event.target) || this.$el.contains(event.target)); return !(this.$el.isSameNode(event.target) || this.$el.contains(event.target));
}, }
} }
} }
</script> </script>

View File

@ -1,9 +1,5 @@
<template> <template>
<div class="content-section layout-footer clearfix"> <div class="content-section layout-footer">
<span>PrimeVue 2.0.0</span> <span>PrimeVue 2.0.0 by </span><a href="https://www.primetek.com.tr">PrimeTek</a>
<div class="footer-links">
<a href="https://github.com/primefaces/primevue"><i class=" icon-github fa fa-github-square"></i></a>
<a href="https://twitter.com/primevue"><i class="icon-twitter fa fa-twitter-square"></i></a>
</div>
</div> </div>
</template> </template>

View File

@ -85,47 +85,14 @@ export default {
}, },
data() { data() {
return { return {
theme: 'saga-blue',
activeMenuIndex: null activeMenuIndex: null
} }
}, },
methods: { methods: {
changeTheme(event, theme, dark) { changeTheme(event, theme, dark) {
let themeElement = document.getElementById('theme-link'); this.$emit('change-theme', {theme: theme, dark: dark});
themeElement.setAttribute('href', themeElement.getAttribute('href').replace(this.theme, theme));
this.theme = theme;
if (dark) {
this.addClass(document.body, dark);
}
else {
this.removeClass(document.body, 'dark-theme');
this.removeClass(document.body, 'dark-theme-alt');
}
this.activeMenuIndex = null;
event.preventDefault(); event.preventDefault();
}, },
addClass(element, className) {
if (!this.hasClass(element, className)) {
if (element.classList)
element.classList.add(className);
else
element.className += ' ' + className;
}
},
removeClass(element, className) {
if (element.classList)
element.classList.remove(className);
else
element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
},
hasClass(element, className) {
if (element.classList)
return element.classList.contains(className);
else
return new RegExp('(^| )' + className + '( |$)', 'gi').test(element.className);
},
toggleMenu(event, index) { toggleMenu(event, index) {
this.activeMenuIndex = (this.activeMenuIndex === index) ? null : index; this.activeMenuIndex = (this.activeMenuIndex === index) ? null : index;
event.preventDefault(); event.preventDefault();

View File

@ -12,7 +12,7 @@
} }
} }
$focusBorderColor:#8dcdff; $focusBorderColor:#b6daf2;
html { html {
font-size: 14px; font-size: 14px;
@ -44,7 +44,7 @@ input[type="number"] {
a { a {
text-decoration: none; text-decoration: none;
color: #4eafe6; color: #2874A6;
} }
.layout-news { .layout-news {
@ -351,7 +351,7 @@ a {
height: calc(100% - 70px); height: calc(100% - 70px);
background-color: #ffffff; background-color: #ffffff;
overflow: auto; overflow: auto;
width: 280px; width: 250px;
box-shadow: 0 0 2px rgba(0,0,0,0.25); box-shadow: 0 0 2px rgba(0,0,0,0.25);
.layout-menu { .layout-menu {
@ -457,7 +457,7 @@ a {
} }
.layout-content { .layout-content {
margin-left: 280px; margin-left: 250px;
padding-top: 70px; padding-top: 70px;
.content-section { .content-section {
@ -628,13 +628,9 @@ a {
} }
a { a {
color: #638fb7; color: #2874A6;
font-weight: 700; font-weight: 500;
transition: color .2s; transition: color .2s;
&:hover {
color: #82a5c5;
}
} }
.btn-viewsource { .btn-viewsource {
@ -790,31 +786,10 @@ a {
.layout-footer { .layout-footer {
font-size: 14px; font-size: 14px;
color: #84939f;
span a {
margin-left: 0;
}
.footer-links {
float: right;
font-size: 24px;
}
a { a {
margin-left: 16px; color: #495057;
} font-weight: 600;
.icon-github {
width: 29.1px;
height: 29.1px;
color:#20272a
}
.icon-twitter {
width: 29.1px;
height: 29.1px;
color:#20272a
} }
} }
@ -886,13 +861,9 @@ a {
} }
a { a {
color: #638fb7; color: #2874A6;
font-weight: 700;
transition: color .2s; transition: color .2s;
font-weight: 500;
&:hover {
color: #82a5c5;
}
} }
.layout-config-content { .layout-config-content {
@ -953,8 +924,13 @@ a {
color: #495057; color: #495057;
background-color: #ffffff; background-color: #ffffff;
p { img {
color: #727272; width: 50px;
border-radius: 4px;
}
span {
font-size: 13px;
} }
} }
@ -962,13 +938,10 @@ a {
box-shadow: 0 0 0 0.2em $focusBorderColor; box-shadow: 0 0 0 0.2em $focusBorderColor;
} }
img {
width: 100%;
}
button { button {
text-align: center;
position: relative; position: relative;
display: inline-flex;
justify-content: center;
transition: box-shadow .2s; transition: box-shadow .2s;
i { i {
@ -1001,6 +974,10 @@ a {
p { p {
color: #d8d8d8; color: #d8d8d8;
} }
img {
width: 100%;
}
} }
} }
@ -1030,12 +1007,9 @@ a {
margin-bottom: 2em; margin-bottom: 2em;
} }
a { a {
color: #638fb7; color: #2E86C1;
font-weight: 500;
transition: color .2s; transition: color .2s;
&:hover {
color: #82a5c5;
}
} }
.home-button { .home-button {