mirror of https://github.com/Lissy93/dashy.git
🔀 Merge pull request #270 from Lissy93/FIX/252-collapse-state-ignored
[FIX] Don't remember collapse state, when specified in config Fixes #252
This commit is contained in:
commit
5d8748c4e1
|
@ -1,14 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="`collapsable ${checkSpanNum(cols, 'col')} ${checkSpanNum(rows, 'row')}`"
|
<div
|
||||||
|
:class="`collapsable ${checkSpanNum(cols, 'col')} ${checkSpanNum(rows, 'row')}`"
|
||||||
:style="`${color ? 'background: '+color : ''}; ${sanitizeCustomStyles(customStyles)};`"
|
:style="`${color ? 'background: '+color : ''}; ${sanitizeCustomStyles(customStyles)};`"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
:id="`collapsible-${uniqueKey}`"
|
:id="`collapsible-${uniqueKey}`"
|
||||||
class="toggle"
|
class="toggle"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
:checked="getCollapseState()"
|
:checked="getCollapseState()"
|
||||||
@change="collapseChanged"
|
@change="collapseChanged"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
>
|
>
|
||||||
<label :for="`collapsible-${uniqueKey}`" class="lbl-toggle" tabindex="-1">
|
<label :for="`collapsible-${uniqueKey}`" class="lbl-toggle" tabindex="-1">
|
||||||
<Icon v-if="icon" :icon="icon" size="small" :url="title" class="section-icon" />
|
<Icon v-if="icon" :icon="icon" size="small" :url="title" class="section-icon" />
|
||||||
|
@ -30,14 +31,14 @@ import Icon from '@/components/LinkItems/ItemIcon.vue';
|
||||||
export default {
|
export default {
|
||||||
name: 'CollapsableContainer',
|
name: 'CollapsableContainer',
|
||||||
props: {
|
props: {
|
||||||
uniqueKey: String,
|
uniqueKey: String, // Generated unique ID
|
||||||
title: String,
|
title: String, // The section title
|
||||||
icon: String,
|
icon: String, // An optional section icon
|
||||||
collapsed: Boolean,
|
collapsed: Boolean, // Optional override collapse state
|
||||||
cols: Number,
|
cols: Number, // Set section horizontal col span / width
|
||||||
rows: Number,
|
rows: Number, // Set section vertical row span / height
|
||||||
color: String,
|
color: String, // Optional color override
|
||||||
customStyles: String,
|
customStyles: String, // Optional custom stylings
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
Icon,
|
Icon,
|
||||||
|
@ -45,7 +46,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
/* Check that row & column span is valid, and not over the max */
|
/* Check that row & column span is valid, and not over the max */
|
||||||
checkSpanNum(span, classPrefix) {
|
checkSpanNum(span, classPrefix) {
|
||||||
const maxSpan = 4;
|
const maxSpan = 5;
|
||||||
let numSpan = /^\d*$/.test(span) ? parseInt(span, 10) : 1;
|
let numSpan = /^\d*$/.test(span) ? parseInt(span, 10) : 1;
|
||||||
numSpan = (numSpan > maxSpan) ? maxSpan : numSpan;
|
numSpan = (numSpan > maxSpan) ? maxSpan : numSpan;
|
||||||
return `${classPrefix}-${numSpan}`;
|
return `${classPrefix}-${numSpan}`;
|
||||||
|
@ -68,7 +69,9 @@ export default {
|
||||||
}
|
}
|
||||||
return JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
|
return JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
|
||||||
},
|
},
|
||||||
|
/* If not specified by user, get last state from local storage */
|
||||||
getCollapseState() {
|
getCollapseState() {
|
||||||
|
if (this.collapsed !== undefined) return !this.collapsed;
|
||||||
const collapseStateObject = this.initialiseStorage();
|
const collapseStateObject = this.initialiseStorage();
|
||||||
let collapseState = !this.collapsed;
|
let collapseState = !this.collapsed;
|
||||||
if (collapseStateObject[this.uniqueKey] !== undefined) {
|
if (collapseStateObject[this.uniqueKey] !== undefined) {
|
||||||
|
@ -76,6 +79,7 @@ export default {
|
||||||
}
|
}
|
||||||
return collapseState;
|
return collapseState;
|
||||||
},
|
},
|
||||||
|
/* When section collapsed, update local storage, to remember for next time */
|
||||||
setCollapseState(id, newState) {
|
setCollapseState(id, newState) {
|
||||||
// Get the current localstorage collapse state object
|
// Get the current localstorage collapse state object
|
||||||
const collapseState = JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
|
const collapseState = JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
|
||||||
|
@ -84,9 +88,12 @@ export default {
|
||||||
// Stringify, and set the new object into local storage
|
// Stringify, and set the new object into local storage
|
||||||
localStorage.setItem(localStorageKeys.COLLAPSE_STATE, JSON.stringify(collapseState));
|
localStorage.setItem(localStorageKeys.COLLAPSE_STATE, JSON.stringify(collapseState));
|
||||||
},
|
},
|
||||||
|
/* Called when collapse state changes, trigger local storage update if needed */
|
||||||
collapseChanged(whatChanged) {
|
collapseChanged(whatChanged) {
|
||||||
this.initialiseStorage();
|
if (this.collapseState === undefined) { // Only run, if user hasn't manually set prop
|
||||||
this.setCollapseState(this.uniqueKey.toString(), whatChanged.srcElement.checked);
|
this.initialiseStorage();
|
||||||
|
this.setCollapseState(this.uniqueKey.toString(), whatChanged.srcElement.checked);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -110,22 +117,26 @@ export default {
|
||||||
&.row-2 { grid-row-start: span 2; }
|
&.row-2 { grid-row-start: span 2; }
|
||||||
&.row-3 { grid-row-start: span 3; }
|
&.row-3 { grid-row-start: span 3; }
|
||||||
&.row-4 { grid-row-start: span 4; }
|
&.row-4 { grid-row-start: span 4; }
|
||||||
|
&.row-5 { grid-row-start: span 5; }
|
||||||
|
|
||||||
grid-column-start: span 1;
|
grid-column-start: span 1;
|
||||||
@include tablet-up {
|
@include tablet-up {
|
||||||
&.col-2 { grid-column-start: span 2; }
|
&.col-2 { grid-column-start: span 2; }
|
||||||
&.col-3 { grid-column-start: span 2; }
|
&.col-3 { grid-column-start: span 2; }
|
||||||
&.col-4 { grid-column-start: span 2; }
|
&.col-4 { grid-column-start: span 2; }
|
||||||
|
&.col-5 { grid-column-start: span 2; }
|
||||||
}
|
}
|
||||||
@include laptop-up {
|
@include laptop-up {
|
||||||
&.col-2 { grid-column-start: span 2; }
|
&.col-2 { grid-column-start: span 2; }
|
||||||
&.col-3 { grid-column-start: span 3; }
|
&.col-3 { grid-column-start: span 3; }
|
||||||
&.col-4 { grid-column-start: span 3; }
|
&.col-4 { grid-column-start: span 3; }
|
||||||
|
&.col-5 { grid-column-start: span 3; }
|
||||||
}
|
}
|
||||||
@include monitor-up {
|
@include monitor-up {
|
||||||
&.col-2 { grid-column-start: span 2; }
|
&.col-2 { grid-column-start: span 2; }
|
||||||
&.col-3 { grid-column-start: span 3; }
|
&.col-3 { grid-column-start: span 3; }
|
||||||
&.col-4 { grid-column-start: span 4; }
|
&.col-4 { grid-column-start: span 4; }
|
||||||
|
&.col-5 { grid-column-start: span 5; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrap-collabsible {
|
.wrap-collabsible {
|
||||||
|
@ -144,7 +155,7 @@ export default {
|
||||||
border-radius: var(--curve-factor);
|
border-radius: var(--curve-factor);
|
||||||
transition: all 0.25s ease-out;
|
transition: all 0.25s ease-out;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: var(--item-group-heading-text-color); //var(--item-group-background);
|
color: var(--item-group-heading-text-color);
|
||||||
h3 {
|
h3 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
Loading…
Reference in New Issue