import { Machine, EventObject, Service } from '@zag-js/core'; import { PropTypes, RequiredBy, CommonProperties } from '@zag-js/types'; interface Time { days: T; hours: T; minutes: T; seconds: T; milliseconds: T; } type TimePart = keyof Time; type TimerAction = "start" | "pause" | "resume" | "reset" | "restart"; type ElementIds = Partial<{ root: string; area: string; }>; interface TickDetails { value: number; time: Time; formattedTime: Time; } interface TimerProps extends CommonProperties { /** * The ids of the timer parts */ ids?: ElementIds | undefined; /** * Whether the timer should countdown, decrementing the timer on each tick. */ countdown?: boolean | undefined; /** * The total duration of the timer in milliseconds. */ startMs?: number | undefined; /** * The minimum count of the timer in milliseconds. */ targetMs?: number | undefined; /** * Whether the timer should start automatically */ autoStart?: boolean | undefined; /** * The interval in milliseconds to update the timer count. * @default 1000 */ interval?: number | undefined; /** * Function invoked when the timer ticks */ onTick?: ((details: TickDetails) => void) | undefined; /** * Function invoked when the timer is completed */ onComplete?: (() => void) | undefined; } type PropsWithDefault = "interval" | "startMs"; interface Context { /** * The timer count in milliseconds. */ currentMs: number; } interface Computed { /** * The time parts of the timer count. */ time: Time; /** * The formatted time parts of the timer count. */ formattedTime: Time; /** * The progress percentage of the timer. */ progressPercent: number; } interface TimerSchema { state: "idle" | "running" | "paused" | "running:temp"; props: RequiredBy; context: Context; computed: Computed; event: EventObject; action: string; effect: string; guard: string; } type TimerService = Service; type TimerMachine = Machine; interface ItemProps { type: TimePart; } interface ActionTriggerProps { action: TimerAction; } interface TimerApi { /** * Whether the timer is running. */ running: boolean; /** * Whether the timer is paused. */ paused: boolean; /** * The formatted timer count value. */ time: Time; /** * The formatted time parts of the timer count. */ formattedTime: Time; /** * Function to start the timer. */ start: VoidFunction; /** * Function to pause the timer. */ pause: VoidFunction; /** * Function to resume the timer. */ resume: VoidFunction; /** * Function to reset the timer. */ reset: VoidFunction; /** * Function to restart the timer. */ restart: VoidFunction; /** * The progress percentage of the timer. */ progressPercent: number; getRootProps: () => T["element"]; getAreaProps: () => T["element"]; getControlProps: () => T["element"]; getItemProps: (props: ItemProps) => T["element"]; getItemValueProps: (props: ItemProps) => T["element"]; getItemLabelProps: (props: ItemProps) => T["element"]; getSeparatorProps: () => T["element"]; getActionTriggerProps: (props: ActionTriggerProps) => T["button"]; } export type { ActionTriggerProps, ElementIds, ItemProps, TickDetails, Time, TimePart, TimerAction, TimerApi, TimerMachine, TimerProps, TimerSchema, TimerService };