@gfazioli/mantine-clock

中文文档
4.0.20发布于 2026/11/09MITTypeScriptESM + CJS零依赖近 30 天下载 2598

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

原始使用文档
文档目录10 节
  1. Overview
  2. Installation
  3. Usage
  4. Clock Component
  5. useClock Hook
  6. useClockCountDown Hook
  7. Styling and Theming
  8. Advanced Examples
  9. Features
  10. Sponsor

Mantine Clock Component

Mantine Clock

mantine-clock at a glance, refreshed daily: commits, releases, stars, issues and pull requests, a year of commit activity, the weekly rhythm, languages, latest commits and releases, contributors
Made with glancecard · refreshed daily

Overview

This component is created on top of the Mantine library. It requires Mantine 9.x and React 19.

Mantine Clock delivers both an analog Clock component and time-management hooks tailored for React applications.

The Clock supports live ticking or static display via a value prop, multiple second-hand behaviors (smooth, tick, half‑tick), and rich styling through classNames and the Styles API—including control over ticks, numbers, hands, center dot, and themed appearances like a “Neon Cyber Clock.” It further enables visual sector arcs that dynamically align to current seconds, minutes, and hours hand positions, with precise start rules, direction, colors, and opacity.

[!note]

→ Demo and Documentation → Youtube Video → More Mantine Components

Installation

npm install @gfazioli/mantine-clock dayjs

or

yarn add @gfazioli/mantine-clock dayjs

dayjs is a peer dependency: the clocks read and convert the time with it (its utc and timezone plugins), so install it alongside if your app does not have it yet.

After installation import package styles at the root of your application:

import '@gfazioli/mantine-clock/styles.css';

Usage

The Mantine Clock library provides powerful components and hooks for time management and visualization in React applications using Mantine.

Clock Component

Create analog clocks with real-time updates or static time display:

import { Clock } from '@gfazioli/mantine-clock';

// Real-time clock
function LiveClock() {
  return <Clock />;
}

// Static clock showing specific time
function StaticClock() {
  return <Clock value={new Date('2023-12-25T15:30:00')} running={false} />;
}

// Customized clock with timezone
function WorldClock() {
  return (
    <Clock 
      timezone="America/New_York"
      size={200}
      hourHandColor="blue"
      minuteHandColor="cyan"
      secondHandColor="red"
    />
  );
}

useClock Hook

Get real-time time data with flexible formatting:

import { useClock } from '@gfazioli/mantine-clock';

function DigitalClock() {
  const { hours, minutes, seconds, amPm, isRunning } = useClock({
    timezone: 'UTC',
    use24Hours: false,
    padHours: true,
    padMinutes: true,
    padSeconds: true
  });

  return (
    <div>
      {hours}:{minutes}:{seconds} {amPm}
    </div>
  );
}

useClockCountDown Hook

Create countdown timers with target dates or durations:

import { useClockCountDown } from '@gfazioli/mantine-clock';

// Countdown to specific date
function EventCountdown() {
  const { day, hours, minutes, seconds } = useClockCountDown({
    targetDate: new Date('2024-12-31T23:59:59'),
    onCountDownCompleted: () => alert('Happy New Year!')
  });

  return (
    <div>
      Time remaining: {day}d {hours}h {minutes}m {seconds}s
    </div>
  );
}

// Countdown from duration
function TimerCountdown() {
  const { minutes, seconds, isRunning } = useClockCountDown({
    minutes: 25, // 25-minute Pomodoro timer
    onCountDownCompleted: () => console.log('Break time!')
  });

  return (
    <div>
      Pomodoro: {minutes}:{seconds}
    </div>
  );
}

Styling and Theming

The library integrates seamlessly with Mantine's theming system:

import '@gfazioli/mantine-clock/styles.css';
// or with CSS layers
import '@gfazioli/mantine-clock/styles.layer.css';

// Custom styled clock with available CSS variables
function ThemedClock() {
  return (
    <Clock 
      style={{
        '--clock-color': 'var(--mantine-color-blue-1)',
        '--clock-hour-ticks-color': 'var(--mantine-color-blue-6)',
        '--clock-minute-ticks-color': 'var(--mantine-color-blue-4)',
        '--clock-primary-numbers-color': 'var(--mantine-color-blue-9)',
        '--clock-secondary-numbers-color': 'var(--mantine-color-blue-7)',
        '--clock-hour-hand-color': 'var(--mantine-color-blue-8)',
        '--clock-minute-hand-color': 'var(--mantine-color-blue-6)',
        '--clock-second-hand-color': 'var(--mantine-color-red-6)'
      }}
      className="my-custom-clock"
    />
  );
}

Advanced Examples

// Multi-timezone dashboard
function WorldClockDashboard() {
  const timezones = [
    { name: 'New York', tz: 'America/New_York' },
    { name: 'London', tz: 'Europe/London' },
    { name: 'Tokyo', tz: 'Asia/Tokyo' }
  ];

  return (
    <div style={{ display: 'flex', gap: '2rem' }}>
      {timezones.map(({ name, tz }) => (
        <div key={tz}>
          <h3>{name}</h3>
          <Clock timezone={tz} size={150} />
        </div>
      ))}
    </div>
  );
}

// Clock with custom number visibility and styling
function CustomNumbersClock() {
  return (
    <Clock 
      primaryNumbersOpacity={1}
      secondaryNumbersOpacity={0.5}
      primaryNumbersColor="blue"
      secondaryNumbersColor="gray"
      size={200}
    />
  );
}

// Countdown with controls
function ControllableCountdown() {
  const countdown = useClockCountDown({
    minutes: 10,
    enabled: false
  });

  return (
    <div>
      <div>{countdown.minutes}:{countdown.seconds}</div>
      <button onClick={countdown.start}>Start</button>
      <button onClick={countdown.pause}>Pause</button>
      <button onClick={countdown.resume}>Resume</button>
      <button onClick={countdown.reset}>Reset</button>
    </div>
  );
}

Features

  • Real-time Updates: Automatic time synchronization with configurable frequency
  • Timezone Support: Global timezone compatibility with IANA timezone database
  • Clock.Digital: Compound component for digital clock display with AM/PM, date, and custom separators
  • Responsive Size: Breakpoint-based responsive sizing ({ base: "sm", md: "lg" }) using Mantine's native CSS media queries
  • Clock Shapes: Circle and rounded-rectangle (Apple Watch style) with configurable aspect ratio
  • Sector Arcs: Visual arcs aligned to seconds, minutes, and hours hands
  • Custom Hand Rendering: Full control via render props for hour, minute, and second hands
  • Mount Animation: Entrance animation from 12:00 to current time
  • Countdown Timer: useClockCountDown hook with target dates, durations, and completion callbacks
  • Customizable Styling: Full control over appearance via Styles API and CSS variables
  • TypeScript Support: Complete type definitions for better developer experience
  • Accessibility: Built with WCAG compliance and screen reader support

Sponsor

Your support helps me:

  • Keep the project actively maintained with timely bug fixes and security updates
  • Add new features, improve performance, and refine the developer experience
  • Expand test coverage and documentation for smoother adoption
  • Ensure long‑term sustainability without relying on ad hoc free time
  • Prioritize community requests and roadmap items that matter most

Open source thrives when those who benefit can give back—even a small monthly contribution makes a real difference. Sponsorships help cover maintenance time, infrastructure, and the countless invisible tasks that keep a project healthy.

Your help truly matters.

💚 Become a sponsor today and help me keep this project reliable, up‑to‑date, and growing for everyone.


https://github.com/user-attachments/assets/727a8634-28ee-4279-80b1-dcf2cb7f5961

版本与发布记录

@gfazioli/mantine-clock 共发布 48 个版本,首次发布于 2025/08/02;过去 12 个月发布了 35 个版本。

版本发布日期距今
4.0.20latest2026/11/096 天前
4.0.192026/11/069 天前
4.0.182026/10/2621 天前
4.0.172026/10/2224 天前
4.0.162026/10/131 个月前
4.0.152026/10/101 个月前

关于 @gfazioli/mantine-clock 的常见问题

@gfazioli/mantine-clock 是什么?

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

如何安装 @gfazioli/mantine-clock?

在项目目录运行 npm install @gfazioli/mantine-clock,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:dayjs(^1.11.13)、react(^18.x || ^19.x)、react-dom(^18.x || ^19.x)、@mantine/core(>=9.0.0)、@mantine/hooks(>=9.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gfazioli/mantine-clock 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gfazioli/mantine-clock 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gfazioli/mantine-clock 可以商用吗?

@gfazioli/mantine-clock 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gfazioli/mantine-clock 的下载量有多少?

根据 npm 官方下载统计,@gfazioli/mantine-clock 在 2026/10/17 – 2026/11/15 这 30 天内被下载 2,598 次,日均约 87 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gfazioli/mantine-clock 还在维护吗?

最新版本 4.0.20 发布于 2026/11/09(6 天前);至今共发布 48 个版本,其中过去 12 个月发布了 35 个;首次发布于 2025/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。