17 lines
642 B
TypeScript
17 lines
642 B
TypeScript
import { Binding } from "astal";
|
|
|
|
type Substitution = { charging?: string, idle?: string }
|
|
|
|
export const getBatteryIcon = (percentage: number, charging: Binding<boolean>) => {
|
|
const levels = Array.from({ length: 10 }, (_, i) => (i + 1) * 10);
|
|
const level = levels.find((level) => percentage <= level)!;
|
|
|
|
const substitutions: Record<number, Substitution> = {
|
|
100: { charging: "battery-level-100-charged-symbolic" }
|
|
};
|
|
|
|
return charging.as(c => c
|
|
? substitutions[level]?.charging || `battery-level-${level}-charging-symbolic`
|
|
: substitutions[level]?.idle || `battery-level-${level}-symbolic`
|
|
);
|
|
}; |