-
-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert battery icon to vue component (#2726)
* feat: use vue battery icon * Add battery icon stories * feat: use battery state if available
- Loading branch information
1 parent
1301f97
commit e0209c6
Showing
9 changed files
with
213 additions
and
87 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,32 @@ | ||
import BatteryIcon from "./BatteryIcon.vue"; | ||
|
||
// More on default export: https://storybook.js.org/docs/vue/writing-stories/introduction#default-export | ||
export default { | ||
title: "Battery Icon", | ||
component: BatteryIcon, | ||
}; | ||
|
||
// More on component templates: https://storybook.js.org/docs/vue/writing-stories/introduction#using-args | ||
const Template = (_args, { argTypes }) => ({ | ||
props: Object.keys(argTypes), | ||
components: { BatteryIcon }, | ||
template: '<battery-icon v-bind="$props" />', | ||
}); | ||
|
||
export const OK = Template.bind({}); | ||
OK.args = { | ||
voltage: 16, | ||
vbatmincellvoltage: 3.7, | ||
vbatmaxcellvoltage: 4.2, | ||
vbatwarningcellvoltage: 3.8, | ||
}; | ||
export const Warning = Template.bind({}); | ||
Warning.args = { | ||
...OK.args, | ||
voltage: 15.1, | ||
}; | ||
export const Empty = Template.bind({}); | ||
Empty.args = { | ||
...OK.args, | ||
voltage: 14, | ||
}; |
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,136 @@ | ||
<template> | ||
<div class="battery-icon"> | ||
<div class="quad-status-contents"> | ||
<div | ||
class="battery-status" | ||
:class="classes" | ||
:style="{ width: batteryWidth + '%' }" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8; // Maybe is better to add a call to MSP_BATTERY_STATE but is not available for all versions | ||
export default { | ||
props: { | ||
voltage: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
vbatmincellvoltage: { | ||
type: Number, | ||
default: 1, | ||
}, | ||
vbatmaxcellvoltage: { | ||
type: Number, | ||
default: 1, | ||
}, | ||
vbatwarningcellvoltage: { | ||
type: Number, | ||
default: 1, | ||
}, | ||
}, | ||
computed: { | ||
nbCells() { | ||
let nbCells = Math.floor(this.voltage / this.vbatmaxcellvoltage) + 1; | ||
if (this.voltage === 0) { | ||
nbCells = 1; | ||
} | ||
return nbCells; | ||
}, | ||
min() { | ||
return this.vbatmincellvoltage * this.nbCells; | ||
}, | ||
max() { | ||
return this.vbatmaxcellvoltage * this.nbCells; | ||
}, | ||
warn() { | ||
return this.vbatwarningcellvoltage * this.nbCells; | ||
}, | ||
isEmpty() { | ||
return ( | ||
this.voltage < this.min && this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM | ||
); | ||
}, | ||
classes() { | ||
if (this.batteryState) { | ||
return { | ||
"state-ok": this.batteryState === 0, | ||
"state-warning": this.batteryState === 1, | ||
"state-empty": this.batteryState === 2, | ||
// TODO: BATTERY_NOT_PRESENT | ||
// TODO: BATTERY_INIT | ||
}; | ||
} | ||
const isWarning = this.voltage < this.warn; | ||
return { | ||
"state-empty": this.isEmpty, | ||
"state-warning": isWarning, | ||
"state-ok": !this.isEmpty && !isWarning, | ||
}; | ||
}, | ||
batteryWidth() { | ||
return this.isEmpty | ||
? 100 | ||
: ((this.voltage - this.min) / (this.max - this.min)) * 100; | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style> | ||
.quad-status-contents { | ||
display: inline-block; | ||
margin-top: 10px; | ||
margin-left: 14px; | ||
height: 10px; | ||
width: 31px; | ||
} | ||
.quad-status-contents progress::-webkit-progress-bar { | ||
height: 12px; | ||
background-color: #eee; | ||
} | ||
.quad-status-contents progress::-webkit-progress-value { | ||
background-color: #bcf; | ||
} | ||
.battery-icon { | ||
background-image: url(../../images/icons/cf_icon_bat_grey.svg); | ||
background-size: contain; | ||
background-position: center; | ||
display: inline-block; | ||
height: 30px; | ||
width: 60px; | ||
transition: none; | ||
margin-top: 4px; | ||
margin-left: -4px; | ||
background-repeat: no-repeat; | ||
} | ||
.battery-status { | ||
height: 11px; | ||
} | ||
@keyframes error-blinker { | ||
0% { | ||
background-color: transparent; | ||
} | ||
50% { | ||
background-color: var(--error); | ||
} | ||
} | ||
.battery-status.state-ok { | ||
background-color: #59aa29; | ||
} | ||
.battery-status.state-warning { | ||
background-color: var(--error); | ||
} | ||
.battery-status.state-empty { | ||
animation: error-blinker 1s linear infinite; | ||
} | ||
</style> |
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,29 @@ | ||
/** | ||
* Main theme colors | ||
* This file is left as css on purpose to make it easier to work without | ||
* the need to compile the less files and still can be use in storybook | ||
*/ | ||
:root { | ||
--accent: #ffbb00; | ||
--error: red; | ||
--subtleAccent: silver; | ||
--quietText: #ffffff; | ||
--quietHeader: #828885; | ||
--defaultText: #000000; | ||
--subtleText: #c0c0c0; | ||
--mutedText: #616161; | ||
--linkText: #2e2ebb; | ||
--boxBackground: #ffffff; | ||
--alternativeBackground: #f9f9f9; | ||
--sideBackground: #ffffff; | ||
--ledAccent: #adadad; | ||
--ledBackground: #e9e9e9; | ||
--gimbalBackground: #eee; | ||
--gimbalCrosshair: var(--subtleAccent); | ||
--switcherysecond: #c4c4c4; | ||
--pushedButton-background: #c4c4c4; | ||
--pushedButton-fontColor: #000000; | ||
--hoverButton-background: #ffcc3e; | ||
--superSubtleAccent: #cccccc; | ||
--accentBorder: #ffbb00; | ||
} |
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