31 lines
949 B
TypeScript
Raw Normal View History

2025-03-26 22:11:26 +03:00
import { bind } from "astal";
import Battery from "gi://AstalBattery";
import accent from "../../accent.css";
2024-12-27 15:42:51 +03:00
export default function BatteryLevel() {
2025-03-26 22:11:26 +03:00
const bat = Battery.get_default();
const percent = bind(bat, "percentage").as(p => Math.floor(p * 100));
2024-12-27 15:42:51 +03:00
2025-03-26 22:11:26 +03:00
return (
<box
className="Battery"
visible={bind(bat, "isPresent")}
css={percent.as(p => `
background-image: linear-gradient(
to right,
${accent} 0%,
${accent} ${p}%,
transparent ${p}%,
transparent 100%
);
background-size: 100% 3px;
background-repeat: no-repeat;
background-position: bottom;
`)}
>
<icon icon={bind(bat, "batteryIconName")} />
<label label={percent.as(p => `${p}%`)} />
</box>
);
2024-12-27 15:42:51 +03:00
}