For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/en/components/time-range-picker.md.
  • English
  • TimeRangePicker

    Choose a start and end time.

    Basic usage

    09:00 ~ 18:00
    basic.tsx
    import { Space, Text, TimeRangePicker } from '@ifhover/leaf-ui';
    
    import { useState } from 'react';
    
    export function TimeRangePickerBasic() {
      const [value, setValue] = useState<import('@ifhover/leaf-ui').TimeRange | null>([
        '09:00',
        '18:00',
      ]);
      return (
        <Space direction="vertical" align="stretch">
          <TimeRangePicker value={value} onChange={setValue} />
          <output>
            <Text tone="muted">{value?.join(' ~ ') || '—'}</Text>
          </output>
        </Space>
      );
    }
    

    More examples

    12-hour clock with seconds
    Allow an overnight range
    advanced.tsx
    import { Space, Text, TimeRangePicker } from '@ifhover/leaf-ui';
    
    export function TimeRangePickerOptions() {
      return (
        <Space direction="vertical" align="stretch">
          <Text tone="muted">12-hour clock with seconds</Text>
          <TimeRangePicker use12Hours showSeconds defaultValue={['09:30:00', '17:45:00']} />
          <Text tone="muted">Allow an overnight range</Text>
          <TimeRangePicker allowOvernight defaultValue={['22:00', '06:00']} />
        </Space>
      );
    }
    

    Usage

    Confirm to submit the draft. Type 09:00 ~ 18:00 and press Enter. allowOvernight allows an earlier end time to represent the following day.

    Types

    Import these types for data, callbacks and refs.

    import type { TimeRangePickerProps, TimeRange, TimeParts } from '@ifhover/leaf-ui';

    The exported TimeRange type is readonly [string, string], using 24-hour time strings.

    Restrict available times

    Business hours for both endpoints
    capabilities.tsx
    import { Space, Text, TimeRangePicker } from '@ifhover/leaf-ui';
    
    export function Capabilities() {
      return (
        <Space direction="vertical" align="stretch">
          <Text>{'Business hours for both endpoints'}</Text>
          <TimeRangePicker
            defaultValue={['09:00', '17:30']}
            disabledTime={(time) => time.hour < 9 || time.hour > 18}
            use12Hours
            minuteStep={15}
          />
        </Space>
      );
    }
    

    TimeRangePickerProps API

    PropertyTypeDefaultDescription
    popupPlacement'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end'—Placement relative to the trigger.
    popupClassNamestring—Custom class for the popup.
    popupStyleCSSProperties—Custom popup styles.
    popupRender(content: React.ReactNode) => React.ReactNode—Wrap or extend popup content; retain the supplied content to preserve interaction.
    getPopupContainer() => Element | DocumentFragment—Return a popup container, including a ShadowRoot.
    size'sm' | 'md' | 'lg''md'Size or spacing preset
    status'error' | 'warning'—Display state
    allowClearbooleantrueShow the clear button
    inputReadOnlyboolean—Disable typing while retaining panel selection.
    openboolean—Control whether the panel is open.
    defaultOpenboolean—Initial open state.
    valuereadonly [string, string] | null—Controlled value
    defaultValuereadonly [string, string] | nullnullInitial value, restored by uncontrolled form resets
    onChange(value: readonly [string, string] | null) => void—Value change callback
    onOpenChange(open: boolean) => void—Open state changes
    showSecondsbooleanfalseShow seconds
    use12Hoursbooleanfalse12-hour display
    minuteStepnumber5Minute interval
    secondStepnumber1Second interval
    allowOvernightbooleanfalseAllow overnight ranges
    disabledTime(parts: TimeParts, position: 'start' | 'end') => boolean—Restrict start and end times

    TimeParts API

    PropertyTypeDefaultDescription
    hournumberRequiredHour, 0–23
    minutenumberRequiredMinute, 0–59
    secondnumberRequiredSet second