nixos-configs/modules/ags/config/ts/bar/items/battery.ts

31 lines
766 B
TypeScript
Raw Normal View History

const Battery = await Service.import('battery');
const { Label, Icon, Box } = Widget;
import Separator from '../../misc/separator.ts';
2023-09-11 19:57:21 -04:00
const LOW_BATT = 20;
2023-12-18 18:00:30 -05:00
const SPACING = 5;
2023-12-18 18:00:30 -05:00
export default () => Box({
class_name: 'toggle-off battery',
2023-12-18 18:00:30 -05:00
children: [
Icon({
class_name: 'battery-indicator',
icon: Battery.bind('icon_name'),
}).hook(Battery, (self) => {
self.toggleClassName('charging', Battery.charging);
self.toggleClassName('charged', Battery.charged);
self.toggleClassName('low', Battery.percent < LOW_BATT);
2023-12-18 18:00:30 -05:00
}),
Separator(SPACING),
2023-12-18 18:00:30 -05:00
Label({
label: Battery.bind('percent')
.transform((v) => `${v}%`),
}),
],
});