Files
custum-hyprpanel/modules/menus/calendar/weather/temperature/index.ts
Jas Singh b200b6fadb Fix NerdFont icon alignments. (#143)
* WIP

* Fix nerdfont icon alignments

* Ship needed fonts

* Remove italicised fonts

* Update readme and separate OSD settings into their own category.

* Dashboard styling updates

---------

Co-authored-by: matavach <erik@matijevich.org>
2024-08-18 00:32:22 -07:00

95 lines
3.5 KiB
TypeScript

import { Weather } from "lib/types/weather";
import { Variable } from "types/variable";
import options from "options";
const { unit } = options.menus.clock.weather;
export const TodayTemperature = (theWeather: Variable<Weather>) => {
const getIcon = (fahren: number) => {
const icons = {
100: "",
75: "",
50: "",
25: "",
0: "",
};
const colors = {
100: "weather-color red",
75: "weather-color orange",
50: "weather-color lavender",
25: "weather-color blue",
0: "weather-color sky",
};
const threshold =
fahren < 0
? 0
: [100, 75, 50, 25, 0].find((threshold) => threshold <= fahren);
return {
icon: icons[threshold || 50],
color: colors[threshold || 50],
};
};
return Widget.Box({
hpack: "center",
vpack: "center",
vertical: true,
children: [
Widget.Box({
hexpand: true,
vpack: "center",
class_name: "calendar-menu-weather today temp container",
vertical: false,
children: [
Widget.Box({
hexpand: true,
hpack: "center",
children: [
Widget.Label({
class_name: "calendar-menu-weather today temp label",
label: Utils.merge(
[theWeather.bind("value"), unit.bind("value")],
(wthr, unt) => {
if (unt === "imperial") {
return `${Math.ceil(wthr.current.temp_f)}° F`;
} else {
return `${Math.ceil(wthr.current.temp_c)}° C`;
}
},
),
}),
Widget.Label({
class_name: theWeather
.bind("value")
.as(
(v) =>
`calendar-menu-weather today temp label icon txt-icon ${getIcon(Math.ceil(v.current.temp_f)).color}`,
),
label: theWeather
.bind("value")
.as((v) => getIcon(Math.ceil(v.current.temp_f)).icon),
}),
],
}),
],
}),
Widget.Box({
hpack: "center",
child: Widget.Label({
max_width_chars: 17,
truncate: "end",
lines: 2,
class_name: theWeather
.bind("value")
.as(
(v) =>
`calendar-menu-weather today condition label ${getIcon(Math.ceil(v.current.temp_f)).color}`,
),
label: theWeather.bind("value").as((v) => v.current.condition.text),
}),
}),
],
});
};