@hakit/components
Version:
A series of components to work with @hakit/core
49 lines • 3.25 kB
TypeScript
import { HassEntityWithService, FilterByDomain, EntityName } from '@hakit/core';
import { IconProps } from '@iconify/react';
import { CardBaseProps } from '../..';
import { FormatFunction } from './types';
type CustomFormatter = (date: Date, formatter: FormatFunction) => React.ReactNode;
type OmitProperties = "title" | "as" | "active" | "entity" | "service" | "serviceData" | "longPressCallback" | "modalProps";
export interface TimeCardProps extends Omit<CardBaseProps<"div">, OmitProperties> {
/** Optional Home Assistant sensor providing time (state string HH:MM). If omitted, component uses internal ticking clock.
* Entity value is assumed already localized by HA; we only derive optional AM/PM suffix. */
timeEntity?: FilterByDomain<EntityName, "sensor">;
/** Optional Home Assistant sensor providing date (state string YYYY-MM-DD). If omitted, component uses current date locally but
* formats via HA locale/timezone helpers. */
dateEntity?: FilterByDomain<EntityName, "sensor">;
/** Custom time format pattern or function. Providing this always ignores `timeEntity` even if present.
* Pattern uses intl-dateformat style tokens; function receives (date, haFormatter). */
timeFormat?: string | CustomFormatter;
/** Custom date format pattern or function. Providing this always ignores `dateEntity` even if present.
* Pattern uses intl-dateformat style tokens; function receives (date, haFormatter). */
dateFormat?: string | CustomFormatter;
/** Hide the date portion entirely. @default false */
hideDate?: boolean;
/** Hide the time portion entirely. @default false */
hideTime?: boolean;
/** Hide the leading icon. @default false */
hideIcon?: boolean;
/** Milliseconds throttle for internal ticker when NOT entity-driven (custom formats or missing entities). @default 1000 */
throttleTime?: number;
/** Override icon; falls back to date entity icon or mdi:calendar. */
icon?: string;
/** Additional icon props/styles. */
iconProps?: Omit<IconProps, "icon">;
/** Center align contents instead of left alignment. @default false */
center?: boolean;
/** Click handler; receives time sensor entity when entity-driven. */
onClick?: (entity: HassEntityWithService<"sensor">, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
}
/**
*
* Default behavior: Renders current clock time & date using Home Assistant locale, timezone and 12/24h preference.
* It maintains an internal ticking Date (throttled) unless both a `timeEntity` and `dateEntity` are provided
* without custom format overrides—in which case updates rely on HA websocket events. Entities are optional.
*
* Custom formats (timeFormat/dateFormat): Always override entity usage for that portion. The function versions of the formatters will receive a timezone/locale aware formatter from the home assistant instance, so output still respects user settings. Pattern strings use intl-dateformat tokens.
*
* Ordinal day suffix (1st, 2nd, 3rd...) is added locally when composing default date output.
*/
export declare function TimeCard(props: TimeCardProps): import("@emotion/react/jsx-runtime").JSX.Element;
export {};
//# sourceMappingURL=index.d.ts.map