UNPKG

@gfazioli/mantine-clock

Version:

React Clock components and hooks for Mantine with timezone support, countdown timers, customization options, and real-time updates.

73 lines (72 loc) 2.59 kB
/** * Options for configuring the `useClock` hook. */ export interface UseClockOptions { /** Whether the clock is active and updating. */ enabled?: boolean; /** The timezone to use for the clock. */ timezone?: string; /** The frequency (in milliseconds) at which the clock updates. */ updateFrequency?: number; /** Whether to use 24-hour format or 12-hour format. */ use24Hours?: boolean; /** Whether to pad single-digit seconds with a leading zero. */ padSeconds?: boolean; /** Whether to pad single-digit minutes with a leading zero. */ padMinutes?: boolean; /** Whether to pad single-digit hours with a leading zero. */ padHours?: boolean; } /** * Data returned by the `useClock` hook. */ export interface ClockData { /** The current year. */ year: number; /** The current month (1-12). */ month: number; /** The current day of the month. */ day: number; /** The current week of the year. */ week: number; /** Whether the current year is a leap year. */ isLeap: boolean; /** The current hour (adjusted for 12/24-hour format). */ hours: number | string; /** The current minute. */ minutes: number | string; /** The current second. */ seconds: number | string; /** The current millisecond. */ milliseconds: number; /** Whether the time is AM or PM (only relevant if use24Hours is false). */ amPm?: 'AM' | 'PM'; /** Whether the clock is currently running and updating. */ isRunning: boolean; /** Function to start the clock. */ start: () => void; /** Function to pause the clock. */ pause: () => void; /** Function to resume the clock. */ resume: () => void; /** Function to reset the clock to its initial state. */ reset: () => void; } /** * `useClock` is a React hook that provides real-time clock data. * * This hook allows you to track the current time with options for timezone, * update frequency, and 12/24-hour format. It returns an object containing * detailed time information such as year, month, day, week, and more. * * @param {UseClockOptions} options - Configuration options for the clock. * @returns {ClockData} An object containing the current time data. * * @example * const { year, month, day, hours, minutes, seconds } = useClock({ * timezone: 'America/New_York', * updateFrequency: 1000, * use24Hours: false, * }); */ export declare function useClock({ enabled, timezone, updateFrequency, use24Hours, padSeconds, padMinutes, padHours, }: UseClockOptions): ClockData;