BorderedLoader receives theme as a parameter but was creating DynamicBorder() without passing it, causing DynamicBorder to fall back to the global theme variable which is undefined when loaded via jiti (separate module cache). Added doc comment to DynamicBorder explaining the jiti issue.
26 lines
774 B
TypeScript
26 lines
774 B
TypeScript
import type { Component } from "@mariozechner/pi-tui";
|
|
import { theme } from "../theme/theme.js";
|
|
|
|
/**
|
|
* Dynamic border component that adjusts to viewport width.
|
|
*
|
|
* Note: When used from hooks loaded via jiti, the global `theme` may be undefined
|
|
* because jiti creates a separate module cache. Always pass an explicit color
|
|
* function when using DynamicBorder in components exported for hook use.
|
|
*/
|
|
export class DynamicBorder implements Component {
|
|
private color: (str: string) => string;
|
|
|
|
constructor(color: (str: string) => string = (str) => theme.fg("border", str)) {
|
|
this.color = color;
|
|
}
|
|
|
|
invalidate(): void {
|
|
// No cached state to invalidate currently
|
|
}
|
|
|
|
render(width: number): string[] {
|
|
return [this.color("─".repeat(Math.max(1, width)))];
|
|
}
|
|
}
|