-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6319421
commit c5811f8
Showing
6 changed files
with
152 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 Primary = Template.bind({}); |
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,127 @@ | ||
<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() { | ||
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