Files
homarr/packages/widgets/src/stocks/index.ts
T
Bergasha 7150cdbbab Add a "Show details" toggle to the stock widget's compact view
The compact view auto-reveals name/change/range as the widget gets
bigger, which can overlap badly depending on how the widget's actual
proportions land relative to those breakpoints. Add a switch (on by
default, matching current behavior) to force the minimal symbol+price
look regardless of size. Scoped to the compact layout only - the
Shift-triggered advanced view is untouched.
2026-08-20 12:32:42 +10:00

51 lines
1.7 KiB
TypeScript

import { IconBuildingBank } from "@tabler/icons-react";
import { createWidgetDefinition, widgetQueryInputMatches } from "../definition";
import { optionsBuilder } from "../options";
export const stockPriceTimeFrames = {
range: ["1d", "5d", "1mo", "3mo", "6mo", "ytd", "1y", "2y", "5y", "10y", "max"] as const,
interval: ["5m", "15m", "30m", "1h", "1d", "5d", "1wk", "1mo"] as const,
};
const timeRangeOptions = stockPriceTimeFrames.range;
const timeIntervalOptions = stockPriceTimeFrames.interval;
export const { definition, componentLoader } = createWidgetDefinition("stockPrice", {
supportsAdvancedFocus: true,
icon: IconBuildingBank,
queryKey: [["widget", "stockPrice", "getPriceHistory"]],
queryMatcher: ({ input }, scope) =>
widgetQueryInputMatches(input, {
stock: scope.options.stock,
timeRange: scope.options.timeRange,
timeInterval: scope.options.timeInterval,
}),
refetchInterval: null,
createOptions() {
return optionsBuilder.from((factory) => ({
stock: factory.text({
defaultValue: "AAPL",
}),
timeRange: factory.select({
defaultValue: "1mo",
options: timeRangeOptions.map((value) => ({
value,
label: (t) => t(`widget.stockPrice.option.timeRange.option.${value}.label`),
})),
}),
timeInterval: factory.select({
defaultValue: "1d",
options: timeIntervalOptions.map((value) => ({
value,
label: (t) => t(`widget.stockPrice.option.timeInterval.option.${value}.label`),
})),
}),
showDetails: factory.switch({
defaultValue: true,
withDescription: true,
}),
}));
},
}).withDynamicImport(() => import("./component"));