@dinofront/design_system 1.19.9 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,10 +42,19 @@ export interface SelectV2BaseProps extends BaseProps, Partial<SelectV2ReactSelec
42
42
  /** Label for the "create" row, e.g. `(v) => `Add "${v}"``. Defaults to
43
43
  * react-select's own `Create "..."` wording. */
44
44
  formatCreateLabel?: (inputValue: string) => ReactNode;
45
+ /** With `creatable`: decides whether the typed text offers a "create" row.
46
+ * Defaults to react-select's rule (non-empty and not matching an existing
47
+ * option's label). */
48
+ isValidNewOption?: (inputValue: string) => boolean;
49
+ /** With `creatable`: where the "create" row sits in the list. Default `'last'`. */
50
+ createOptionPosition?: 'first' | 'last';
45
51
  placeholder?: string;
46
52
  label?: ReactNode;
47
53
  /** Content rendered on the label row, right of the label text — e.g. an info tooltip trigger. */
48
54
  labelAddons?: ReactNode;
55
+ /** Replaces the chevron at the end of the control, e.g. a clock icon for a
56
+ * time field. Unlike the chevron, it doesn't flip when the menu opens. */
57
+ dropdownIcon?: ReactNode;
49
58
  helperText?: ReactNode;
50
59
  errorText?: ReactNode;
51
60
  error?: boolean;
@@ -94,7 +103,9 @@ export interface SelectV2BaseProps extends BaseProps, Partial<SelectV2ReactSelec
94
103
  }
95
104
  export type SelectV2Props = (SelectV2BaseProps & {
96
105
  isMulti?: false;
97
- value?: OptionValue;
106
+ /** `undefined` leaves the select uncontrolled; `null` keeps it
107
+ * controlled with nothing selected. */
108
+ value?: OptionValue | null;
98
109
  defaultValue?: OptionValue;
99
110
  onChange?: (value: OptionValue | undefined) => void;
100
111
  }) | (SelectV2BaseProps & {
@@ -0,0 +1,15 @@
1
+ import { TimePickerProps } from './TimePicker.types';
2
+ /**
3
+ * A 24-hour time-of-day picker. Never `<input type="time">`, whose 12h/24h
4
+ * display follows the user's OS locale and can't be controlled.
5
+ *
6
+ * - Desktop: a SelectV2 (react-select) dropdown of suggested times every
7
+ * `step` minutes. Users can type a time too — partial input filters the
8
+ * suggestions, a complete time that isn't suggested gets its own row.
9
+ * - Mobile (≤ 768px, or `mobile`): a trigger that opens a dialog with hour
10
+ * and minute wheels, confirmed with Apply (as in the previous library).
11
+ *
12
+ * This file owns the value (controlled or not) and the constraints; the two
13
+ * UIs only render them.
14
+ */
15
+ export declare const TimePicker: import('react').ForwardRefExoticComponent<TimePickerProps & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,47 @@
1
+ import { ReactNode } from 'react';
2
+ import { BaseProps } from '../../types';
3
+ import { SelectV2BaseProps, SelectV2Size } from '../SelectV2/SelectV2.types';
4
+ export type TimePickerSize = SelectV2Size;
5
+ /** react-select's `menuPlacement` union, same as SelectV2/DatePicker. */
6
+ export type TimePickerMenuPlacement = NonNullable<SelectV2BaseProps['menuPlacement']>;
7
+ /** Field props TimePicker shares with SelectV2. Inherited rather than
8
+ * redeclared, so their types and docs live in one place. */
9
+ type SelectV2SharedProps = Pick<SelectV2BaseProps, 'label' | 'helperText' | 'error' | 'errorText' | 'size' | 'disabled' | 'required' | 'placeholder' | 'clearable' | 'searchable' | 'menuPlacement' | 'id' | 'className' | 'wrapperClassName'>;
10
+ /**
11
+ * Props for TimePicker. The shared field props come from SelectV2, but a few
12
+ * defaults differ: `required` defaults to `false` (SelectV2: `true`),
13
+ * `searchable` to `true` (typing a time — `"930"`, `"0930"`, `"09:30"`), and
14
+ * `placeholder` to `'Select time'`. On mobile, `menuPlacement` has no effect.
15
+ */
16
+ export interface TimePickerProps extends BaseProps, SelectV2SharedProps {
17
+ /** Selected time as a 24-hour `"HH:mm"` string. `null` = controlled with no
18
+ * selection; leave `undefined` (optionally with `defaultValue`) to let the
19
+ * picker manage its own state. */
20
+ value?: string | null;
21
+ /** Initial time (`"HH:mm"`) when uncontrolled. Declared here rather than
22
+ * inherited: react-select's `defaultValue` takes an option object. */
23
+ defaultValue?: string | null;
24
+ /** Fires with the picked or typed `"HH:mm"` time, or `null` when cleared. */
25
+ onChange?: (value: string | null) => void;
26
+ /** Minutes between suggested times, starting at 00:00. Default `15`. Typed
27
+ * times aren't limited to the grid. */
28
+ step?: number;
29
+ /** Earliest allowed time (`"HH:mm"`), inclusive. Earlier suggestions render disabled and can't be typed. */
30
+ minTime?: string;
31
+ /** Latest allowed time (`"HH:mm"`), inclusive. Later suggestions render disabled and can't be typed. */
32
+ maxTime?: string;
33
+ /** Individual times (`"HH:mm"`) that can't be picked or typed. Suggestions stay in the list, disabled. */
34
+ excludeTimes?: string[];
35
+ /** Arbitrary per-time predicate, evaluated alongside `minTime`/`maxTime`/`excludeTimes`. Times it rejects are disabled. */
36
+ filterTime?: (time: string) => boolean;
37
+ /** Fill the parent's width instead of the intrinsic min-width, like DatePicker. */
38
+ fullWidth?: boolean;
39
+ /** Force the mobile UI (`true`, a dialog with hour/minute wheels) or the
40
+ * desktop dropdown (`false`). Default: mobile at viewports ≤ 768px (`useIsMobile`). */
41
+ mobile?: boolean;
42
+ /** Mobile dialog title. Defaults to `label`, then `'Select time'`. */
43
+ mobileTitle?: ReactNode;
44
+ /** Mobile dialog confirm button text. Default `'Apply'`. */
45
+ mobileApplyText?: string;
46
+ }
47
+ export {};
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Pure helpers behind TimePicker. Times are always 24-hour `"HH:mm"` strings
3
+ * (zero-padded), so plain string comparison orders them chronologically.
4
+ */
5
+ export declare const pad2: (n: number) => string;
6
+ /** Minutes since midnight → `"HH:mm"`. */
7
+ export declare function minutesToTime(minutes: number): string;
8
+ /** `"HH:mm"` (or `"H:mm"`) → minutes since midnight, or `null` if it isn't a valid 24h time. */
9
+ export declare function timeToMinutes(time: string): number | null;
10
+ /** Normalizes `"9:05"` → `"09:05"`; `null` for anything that isn't a valid 24h time. */
11
+ export declare function normalizeTime(time: string | null | undefined): string | null;
12
+ /** Clamps `step` to a whole number of minutes in 1–1440; invalid values fall back to 15. */
13
+ export declare function safeStep(step: number | undefined): number;
14
+ /** Every `step` minutes from 00:00 up to (not past) 23:59. */
15
+ export declare function generateTimes(step?: number): string[];
16
+ export interface TimeConstraints {
17
+ minTime?: string;
18
+ maxTime?: string;
19
+ excludeTimes?: string[];
20
+ filterTime?: (time: string) => boolean;
21
+ }
22
+ /** Builds the "is this time unavailable?" predicate from TimePicker's constraint props. */
23
+ export declare function createTimeDisabler({ minTime, maxTime, excludeTimes, filterTime, }: TimeConstraints): (time: string) => boolean;
24
+ /**
25
+ * A *complete* time typed by the user, normalized to `"HH:mm"`, or `null` if
26
+ * the text is partial or invalid. Accepts `"930"` / `"0930"` (digits only;
27
+ * 3 digits read as H:MM), `"9:30"` / `"09:30"`, and `"9.30"`.
28
+ */
29
+ export declare function parseTypedTime(input: string): string | null;
30
+ /**
31
+ * The prefix of `"HH:mm"` options that match partially typed text:
32
+ * `"9"` → `"09"`, `"1"` → `"1"` (01, 10–19), `"14"` → `"14:"`, `"93"` → `"09:3"`,
33
+ * `"9:3"` → `"09:3"`, `"175"` → `"17:5"`. `null` when the text can't be a time.
34
+ */
35
+ export declare function typedTimePrefix(input: string): string | null;
36
+ /**
37
+ * Whether a suggested option should stay visible for the typed text. A
38
+ * complete time that is itself a suggestion narrows the list to just it (so
39
+ * Enter picks it); one that isn't (e.g. "09:07" with a 15-minute step) keeps
40
+ * that hour's suggestions visible next to the typed time's own row.
41
+ */
42
+ export declare function matchesTypedTime(option: string, input: string, isSuggested: (time: string) => boolean): boolean;
43
+ /**
44
+ * Applies an `"HH:mm"` time to a date: a new `Date` on `base`'s calendar day
45
+ * (default: today) at that local time, seconds zeroed. Throws on an invalid time.
46
+ */
47
+ export declare function timeToDate(time: string, base?: Date): Date;
48
+ /** A `Date`'s local time as a 24-hour `"HH:mm"` string. */
49
+ export declare function dateToTime(date: Date): string;
@@ -0,0 +1,13 @@
1
+ import { TimePickerProps } from './TimePicker.types';
2
+ export type TimePickerViewProps = Omit<TimePickerProps, 'value' | 'defaultValue' | 'onChange' | 'step' | 'minTime' | 'maxTime' | 'excludeTimes' | 'filterTime' | 'mobile' | 'fullWidth' | 'wrapperClassName'> & {
3
+ value: string | null;
4
+ onCommit: (value: string | null) => void;
5
+ /** Suggested times (`"HH:mm"`), every `step` minutes. */
6
+ times: string[];
7
+ isDisabled: (time: string) => boolean;
8
+ };
9
+ /**
10
+ * Desktop UI: SelectV2 single-select in react-select's creatable mode, so a
11
+ * typed time that isn't one of the suggestions can still be picked.
12
+ */
13
+ export declare function TimePickerDesktop({ value, onCommit, times, isDisabled, clearable, searchable, size, label, required, helperText, placeholder, disabled, menuPlacement, error, errorText, id, className, dataTestId, }: TimePickerViewProps): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { TimePickerViewProps } from './TimePickerDesktop';
2
+ /**
3
+ * Mobile UI, matching the previous library's TimePicker: a select-like
4
+ * trigger that opens a dialog with infinite hour (00–23) and minute (00–59)
5
+ * wheels (`@ncdai/react-wheel-picker`), confirmed with Apply. Unavailable
6
+ * times (`minTime`, `maxTime`, `excludeTimes`, `filterTime`) are greyed out
7
+ * on the wheels and can't be applied.
8
+ */
9
+ export declare function TimePickerMobile({ value, onCommit, times, isDisabled, clearable, size, label, required, helperText, placeholder, disabled, error, errorText, mobileTitle, mobileApplyText, id, className, dataTestId, }: TimePickerViewProps): import("react").JSX.Element;
@@ -0,0 +1,3 @@
1
+ export { TimePicker } from './TimePicker';
2
+ export { timeToDate, dateToTime } from './TimePicker.utils';
3
+ export type { TimePickerProps, TimePickerSize, TimePickerMenuPlacement } from './TimePicker.types';
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export * from './components/Tabs';
44
44
  export * from './components/Text';
45
45
  export * from './components/TextArea';
46
46
  export * from './components/ThemeSwitch';
47
+ export * from './components/TimePicker';
47
48
  export * from './components/Tooltip';
48
49
  export * from './components/UnderConstruction';
49
50
  export * from './components/Upload';