Skip to content

Commit

Permalink
Enhancements for better wrapping of Status Area icons
Browse files Browse the repository at this point in the history
- Add code and CSS for toggling single/multiline display of indicators.
- Add code to detect overflow state of indicators.
  • Loading branch information
charlesh88 committed Sep 18, 2024
1 parent b8a933e commit f06b629
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/ui/layout/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
:class="{
'l-shell__head--expanded': headExpanded,
'l-shell__head--minify-indicators': !headExpanded,
'l-shell__head--can-wrap': headCanWrap
'l-shell__head--indicators-single-line': !indicatorsMultiline
}"
>
<CreateButton class="l-shell__create-button" />
<GrandSearch ref="grand-search" />
<StatusIndicators />
<button
class="l-shell__head__button c-icon-button"
:class="headCanWrap ? 'icon-multiline' : 'icon-singleline'"
:aria-label="`Display as ${headCanWrap ? 'multiple lines' : 'single line'}`"
:title="`Display as ${headCanWrap ? 'multiple lines' : 'single line'}`"
@click="toggleHeadWrapping"
:class="indicatorsMultiline ? 'icon-singleline' : 'icon-multiline'"
:aria-label="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`"
:title="`Display as ${indicatorsMultiline ? 'single line' : 'multiple lines'}`"
@click="toggleIndicatorsMultiline"
></button>
<button
class="l-shell__head__collapse-button c-icon-button"
Expand Down Expand Up @@ -205,10 +205,10 @@ export default {
data: function () {
let storedHeadProps = window.localStorage.getItem('openmct-shell-head');
let headExpanded = true;
let headCanWrap = false;
let indicatorsMultiline = false;
if (storedHeadProps) {
headExpanded = JSON.parse(storedHeadProps).expanded;
headCanWrap = JSON.parse(storedHeadProps).wrapping;
indicatorsMultiline = JSON.parse(storedHeadProps).multiline;
}
return {
Expand All @@ -220,7 +220,7 @@ export default {
triggerSync: false,
triggerReset: false,
headExpanded,
headCanWrap,
indicatorsMultiline,
isResizing: false,
disableClearButton: false
};
Expand Down Expand Up @@ -278,13 +278,13 @@ export default {
})
);
},
toggleHeadWrapping() {
this.headCanWrap = !this.headCanWrap;
toggleIndicatorsMultiline() {
this.indicatorsMultiline = !this.indicatorsMultiline;
window.localStorage.setItem(
'openmct-shell-head',
JSON.stringify({
wrapping: this.headCanWrap
multiline: this.indicatorsMultiline
})
);
},
Expand Down
18 changes: 11 additions & 7 deletions src/ui/layout/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,22 @@
}

&__indicators {
// Style as multiline by default
display: flex;
flex-wrap: wrap;
font-size: 11px;
min-height: 24px;
justify-content: flex-end;

.l-shell__head--expanded & {
}

.l-shell__head--can-wrap & {
// Force elements to wrap down when width constrained
background: rgba(deeppink, 0.4);
height: 24px;
.l-shell__head--indicators-single-line & {
flex-wrap: nowrap;
justify-content: flex-start; // Overflow detection doesn't work with flex-end.
max-height: 24px;
overflow: hidden;

> *:first-child {
margin-left: auto; // Mimics justify-content: flex-end when in single line mode.
}
}
}

Expand Down
19 changes: 17 additions & 2 deletions src/ui/layout/status-bar/StatusIndicators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
at runtime from the About dialog for additional information.
-->
<template>
<div class="l-shell__head-section l-shell__indicators">
<div ref="indicators" class="l-shell__head-section l-shell__indicators">
<component
:is="indicator.value.vueComponent"
v-for="indicator in sortedIndicators"
Expand All @@ -33,7 +33,8 @@ export default {
inject: ['openmct'],
data() {
return {
indicators: this.openmct.indicators.getIndicatorObjectsByPriority().map(shallowRef)
indicators: this.openmct.indicators.getIndicatorObjectsByPriority().map(shallowRef),
indicatorsOverflowing: false
};
},
computed: {
Expand All @@ -45,15 +46,29 @@ export default {
return [...this.indicators].sort((a, b) => b.value.priority - a.value.priority);
}
},
mounted() {
this.checkOverflow();
window.addEventListener('resize', this.checkOverflow);
},
beforeUnmount() {
this.openmct.indicators.off('addIndicator', this.addIndicator);
window.removeEventListener('resize', this.checkOverflow);
},
created() {
this.openmct.indicators.on('addIndicator', this.addIndicator);
},
methods: {
addIndicator(indicator) {
this.indicators.push(shallowRef(indicator));
},
checkOverflow() {
const element = this.$refs.indicators;
const sizes = {
spaceNeeded: element.scrollWidth,
spaceAvail: element.clientWidth
};
this.indicatorsOverflowing = sizes.spaceNeeded > sizes.spaceAvail;
console.log('checkOverflow', this.indicatorsOverflowing, sizes.spaceNeeded, sizes.spaceAvail);
}
}
};
Expand Down

0 comments on commit f06b629

Please sign in to comment.