canny-ui-react 1.0.0 → 2.0.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.
- package/dist/components/Alert/Alert.types.d.ts +8 -0
- package/dist/components/CommandPalette/CommandPalette.d.ts +31 -0
- package/dist/components/CommandPalette/CommandPalette.types.d.ts +71 -0
- package/dist/components/CommandPalette/index.d.ts +2 -0
- package/dist/components/DatePicker/DatePicker.d.ts +2 -0
- package/dist/components/DatePicker/DatePicker.types.d.ts +83 -0
- package/dist/components/DatePicker/dateUtils.d.ts +28 -0
- package/dist/components/DatePicker/index.d.ts +2 -0
- package/dist/components/Toast/Toast.d.ts +15 -0
- package/dist/components/Toast/Toast.types.d.ts +57 -0
- package/dist/components/Toast/index.d.ts +2 -0
- package/dist/index.cjs +84 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5115 -3779
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
|
@@ -5,4 +5,12 @@ export interface AlertProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'
|
|
|
5
5
|
solid?: boolean;
|
|
6
6
|
title?: ReactNode;
|
|
7
7
|
children?: ReactNode;
|
|
8
|
+
/** Custom icon node. Pass `false` to hide the default icon. */
|
|
9
|
+
icon?: ReactNode | false;
|
|
10
|
+
/** Inline action slot — a button or link rendered on the right. */
|
|
11
|
+
action?: ReactNode;
|
|
12
|
+
/** When provided, renders a close button that invokes this callback. */
|
|
13
|
+
onDismiss?: () => void;
|
|
14
|
+
/** Accessible label for the dismiss button. */
|
|
15
|
+
dismissLabel?: string;
|
|
8
16
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CommandPaletteProps, CommandPaletteTriggerProps, UseCommandPaletteOptions, UseCommandPaletteReturn } from './CommandPalette.types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that manages open state and binds the ⌘K / Ctrl+K hotkey.
|
|
4
|
+
* Pass `{ hotkey: false }` to opt out and wire your own toggle.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useCommandPalette({ hotkey }?: UseCommandPaletteOptions): UseCommandPaletteReturn;
|
|
7
|
+
/**
|
|
8
|
+
* Command palette — keyboard-driven search overlay built on cmdk + Radix Dialog.
|
|
9
|
+
* Render once near the root of your app; use `useCommandPalette()` (or your own
|
|
10
|
+
* state) to control `open`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { open, setOpen } = useCommandPalette();
|
|
14
|
+
* <CommandPalette
|
|
15
|
+
* open={open}
|
|
16
|
+
* onOpenChange={setOpen}
|
|
17
|
+
* sections={[
|
|
18
|
+
* { title: 'Pages', items: [{ id: '/', label: 'Home', href: '/' }] },
|
|
19
|
+
* ]}
|
|
20
|
+
* onItemSelect={(item) => item.href && router.push(item.href)}
|
|
21
|
+
* />
|
|
22
|
+
*/
|
|
23
|
+
export declare function CommandPalette({ open, onOpenChange, sections, placeholder, title, description, emptyText, footer, onItemSelect, contentClassName, }: CommandPaletteProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
/**
|
|
25
|
+
* Pill-shaped trigger button for the command palette. Use in a Navbar or
|
|
26
|
+
* anywhere you want a visible search affordance.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* <CommandPaletteTrigger onClick={() => setOpen(true)} />
|
|
30
|
+
*/
|
|
31
|
+
export declare function CommandPaletteTrigger({ onClick, label, shortcut, className, }: CommandPaletteTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface CommandPaletteItem {
|
|
3
|
+
/** Stable identifier — used as React key. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Visible label. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** When provided, selecting the item navigates to this href via `onItemSelect` (consumer wires the router). */
|
|
8
|
+
href?: string;
|
|
9
|
+
/** Custom select handler — overrides default href navigation. */
|
|
10
|
+
onSelect?: () => void;
|
|
11
|
+
/** Additional searchable terms beyond the label. */
|
|
12
|
+
keywords?: string[];
|
|
13
|
+
/** Right-aligned badge (e.g. "new"). */
|
|
14
|
+
badge?: ReactNode;
|
|
15
|
+
/** Leading icon. Defaults to a section-derived icon if not provided. */
|
|
16
|
+
icon?: ReactNode;
|
|
17
|
+
/** Right-aligned hint text (e.g. a path). */
|
|
18
|
+
hint?: ReactNode;
|
|
19
|
+
/** Disable selection. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface CommandPaletteSection {
|
|
23
|
+
/** Group heading rendered above items. */
|
|
24
|
+
title: string;
|
|
25
|
+
/** Items in this group. */
|
|
26
|
+
items: CommandPaletteItem[];
|
|
27
|
+
}
|
|
28
|
+
export interface CommandPaletteProps {
|
|
29
|
+
/** Controlled open state. */
|
|
30
|
+
open: boolean;
|
|
31
|
+
/** Open-state setter. */
|
|
32
|
+
onOpenChange: (open: boolean) => void;
|
|
33
|
+
/** Grouped item sections. */
|
|
34
|
+
sections: CommandPaletteSection[];
|
|
35
|
+
/** Search input placeholder. */
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
/** Title for assistive tech (visually hidden). */
|
|
38
|
+
title?: string;
|
|
39
|
+
/** Description for assistive tech (visually hidden). */
|
|
40
|
+
description?: string;
|
|
41
|
+
/** Empty-state content. */
|
|
42
|
+
emptyText?: ReactNode;
|
|
43
|
+
/** Footer content. Defaults to keyboard hints. Pass `false` to hide. */
|
|
44
|
+
footer?: ReactNode | false;
|
|
45
|
+
/**
|
|
46
|
+
* Fires when the user selects an item. Use this to navigate via your router.
|
|
47
|
+
* If the item has its own `onSelect`, that runs first.
|
|
48
|
+
*/
|
|
49
|
+
onItemSelect?: (item: CommandPaletteItem) => void;
|
|
50
|
+
/** Extra className on the dialog content. */
|
|
51
|
+
contentClassName?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface CommandPaletteTriggerProps {
|
|
54
|
+
/** Click handler — usually `() => setOpen(true)`. */
|
|
55
|
+
onClick: () => void;
|
|
56
|
+
/** Visible label. */
|
|
57
|
+
label?: string;
|
|
58
|
+
/** Keyboard shortcut hint. Defaults to "⌘K". */
|
|
59
|
+
shortcut?: string;
|
|
60
|
+
/** Extra className. */
|
|
61
|
+
className?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface UseCommandPaletteOptions {
|
|
64
|
+
/** Bind the ⌘K / Ctrl+K hotkey. Default: true. */
|
|
65
|
+
hotkey?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface UseCommandPaletteReturn {
|
|
68
|
+
open: boolean;
|
|
69
|
+
setOpen: (open: boolean) => void;
|
|
70
|
+
toggle: () => void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { CommandPalette, CommandPaletteTrigger, useCommandPalette } from './CommandPalette';
|
|
2
|
+
export type { CommandPaletteItem, CommandPaletteSection, CommandPaletteProps, CommandPaletteTriggerProps, UseCommandPaletteOptions, UseCommandPaletteReturn, } from './CommandPalette.types';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import type { WeekDay } from './dateUtils';
|
|
3
|
+
export type DatePickerSize = 'sm' | 'md' | 'lg';
|
|
4
|
+
export type DatePickerColor = 'primary' | 'danger' | 'warning' | 'success';
|
|
5
|
+
export type DatePickerMode = 'date' | 'month' | 'year' | 'time' | 'datetime';
|
|
6
|
+
/**
|
|
7
|
+
* Declarative date-window constraint.
|
|
8
|
+
* - `'any'` (default): no restriction
|
|
9
|
+
* - `'future'`: today and later
|
|
10
|
+
* - `'past'`: today and earlier
|
|
11
|
+
* - `'current'`: today only
|
|
12
|
+
*
|
|
13
|
+
* Combines with explicit `min` / `max` — the stricter of the two always wins.
|
|
14
|
+
*/
|
|
15
|
+
export type DatePickerAllow = 'any' | 'future' | 'past' | 'current';
|
|
16
|
+
export interface DatePickerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children'> {
|
|
17
|
+
/** Which picker to show. */
|
|
18
|
+
mode?: DatePickerMode;
|
|
19
|
+
/** Controlled value. `null` means cleared. */
|
|
20
|
+
value?: Date | string | null;
|
|
21
|
+
/** Uncontrolled initial value. */
|
|
22
|
+
defaultValue?: Date | string;
|
|
23
|
+
/** Fires on selection and clear. */
|
|
24
|
+
onChange?: (date: Date | null) => void;
|
|
25
|
+
/** Earliest selectable date (inclusive). */
|
|
26
|
+
min?: Date | string;
|
|
27
|
+
/** Latest selectable date (inclusive). */
|
|
28
|
+
max?: Date | string;
|
|
29
|
+
/** Declarative date-window constraint. Combines with `min`/`max` (stricter wins). */
|
|
30
|
+
allow?: DatePickerAllow;
|
|
31
|
+
/** Predicate to disable arbitrary dates (ignored for time-only mode). */
|
|
32
|
+
disabledDate?: (date: Date) => boolean;
|
|
33
|
+
/** Predicate to disable specific times (hour/minute/second combos). */
|
|
34
|
+
disabledTime?: (date: Date) => boolean;
|
|
35
|
+
/** Text shown when empty. */
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
/** Trigger size. */
|
|
38
|
+
size?: DatePickerSize;
|
|
39
|
+
/** Validation color on the trigger. Auto-flips to `'danger'` on validation errors. */
|
|
40
|
+
color?: DatePickerColor;
|
|
41
|
+
/** Disable the trigger. */
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
/** Show a clear button when a value is selected. */
|
|
44
|
+
clearable?: boolean;
|
|
45
|
+
/** BCP-47 locale tag. Defaults to the browser's. */
|
|
46
|
+
locale?: string;
|
|
47
|
+
/** 0 = Sunday, 1 = Monday, …, 6 = Saturday. Defaults to 0. */
|
|
48
|
+
weekStartsOn?: WeekDay;
|
|
49
|
+
/** Use 12-hour clock with AM/PM for time / datetime. Default: inferred from locale. */
|
|
50
|
+
hour12?: boolean;
|
|
51
|
+
/** Show a seconds column in time / datetime. */
|
|
52
|
+
showSeconds?: boolean;
|
|
53
|
+
/** Minute granularity (1–30). Default 1. */
|
|
54
|
+
minuteStep?: number;
|
|
55
|
+
/** Second granularity (1–30). Default 1. */
|
|
56
|
+
secondStep?: number;
|
|
57
|
+
/** Custom display formatter for the selected value. */
|
|
58
|
+
format?: (date: Date, mode: DatePickerMode) => string;
|
|
59
|
+
/** Replace the trigger icon. */
|
|
60
|
+
icon?: ReactNode;
|
|
61
|
+
/** Required — empty value is treated as invalid. */
|
|
62
|
+
required?: boolean;
|
|
63
|
+
/** Custom validator. Returns an error message or null/undefined if valid. */
|
|
64
|
+
validate?: (date: Date | null) => string | null | undefined;
|
|
65
|
+
/** Explicit error message. When set, forces danger state and renders below the trigger. */
|
|
66
|
+
error?: ReactNode;
|
|
67
|
+
/** Fires whenever the internal validation state changes. */
|
|
68
|
+
onValidate?: (error: string | null) => void;
|
|
69
|
+
/** id forwarded to the trigger (for Field integration). */
|
|
70
|
+
id?: string;
|
|
71
|
+
/** aria-invalid forwarded to the trigger. */
|
|
72
|
+
'aria-invalid'?: boolean;
|
|
73
|
+
/** aria-describedby forwarded to the trigger. */
|
|
74
|
+
'aria-describedby'?: string;
|
|
75
|
+
/** Accessible label for the dialog. */
|
|
76
|
+
dialogLabel?: string;
|
|
77
|
+
/** Name for form submission. */
|
|
78
|
+
name?: string;
|
|
79
|
+
/** Controlled open state. */
|
|
80
|
+
open?: boolean;
|
|
81
|
+
/** Called when open state changes. */
|
|
82
|
+
onOpenChange?: (open: boolean) => void;
|
|
83
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
2
|
+
export declare function startOfDay(d: Date): Date;
|
|
3
|
+
export declare function endOfDay(d: Date): Date;
|
|
4
|
+
export declare function isSameDay(a: Date | null | undefined, b: Date | null | undefined): boolean;
|
|
5
|
+
export declare function isSameMonth(a: Date, b: Date): boolean;
|
|
6
|
+
export declare function isSameYear(a: Date, b: Date): boolean;
|
|
7
|
+
export declare function startOfMonth(d: Date): Date;
|
|
8
|
+
export declare function startOfYear(d: Date): Date;
|
|
9
|
+
export declare function startOfDecade(d: Date): Date;
|
|
10
|
+
export declare function addMonths(d: Date, n: number): Date;
|
|
11
|
+
export declare function addDays(d: Date, n: number): Date;
|
|
12
|
+
export declare function addYears(d: Date, n: number): Date;
|
|
13
|
+
export declare function withTime(d: Date, h: number, m: number, s?: number): Date;
|
|
14
|
+
export declare function clamp(d: Date, min?: Date | null, max?: Date | null): Date;
|
|
15
|
+
/** 6×7 grid (42 cells) starting on `weekStartsOn`. */
|
|
16
|
+
export declare function buildMonthGrid(viewDate: Date, weekStartsOn: WeekDay): Date[];
|
|
17
|
+
export declare function weekdayLabels(locale: string, weekStartsOn: WeekDay): string[];
|
|
18
|
+
export declare function monthLabels(locale: string, style?: 'short' | 'long'): string[];
|
|
19
|
+
export declare function formatMonthYear(d: Date, locale: string): string;
|
|
20
|
+
export declare function formatYearOnly(d: Date, locale: string): string;
|
|
21
|
+
export declare function formatMonthOnly(d: Date, locale: string): string;
|
|
22
|
+
export declare function formatMedium(d: Date, locale: string): string;
|
|
23
|
+
export declare function formatTime(d: Date, locale: string, hour12: boolean, showSeconds: boolean): string;
|
|
24
|
+
export declare function formatDateTime(d: Date, locale: string, hour12: boolean, showSeconds: boolean): string;
|
|
25
|
+
export declare function parseDate(input: Date | string | null | undefined): Date | null;
|
|
26
|
+
export declare function isBefore(a: Date, b: Date): boolean;
|
|
27
|
+
export declare function isAfter(a: Date, b: Date): boolean;
|
|
28
|
+
export declare function pad2(n: number): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToastApi, ToastProviderProps } from './Toast.types';
|
|
2
|
+
/**
|
|
3
|
+
* Wrap your app to enable `useToast()`. Renders a portaled viewport at the
|
|
4
|
+
* chosen `position`. Multiple providers will simply create separate viewports.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ToastProvider({ children, position, defaultDuration, maxToasts, offset, }: ToastProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
/**
|
|
8
|
+
* Imperative toast API. Must be called inside a `<ToastProvider>` tree.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const { toast } = useToast();
|
|
12
|
+
* toast.success('Saved');
|
|
13
|
+
* toast({ title: 'Custom', description: 'Anything.', action: <button>Undo</button> });
|
|
14
|
+
*/
|
|
15
|
+
export declare function useToast(): ToastApi;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type ToastVariant = 'default' | 'success' | 'info' | 'warning' | 'danger' | 'loading';
|
|
3
|
+
export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
4
|
+
export interface ToastOptions {
|
|
5
|
+
/** Visible title. Required unless `description` is supplied. */
|
|
6
|
+
title?: ReactNode;
|
|
7
|
+
/** Optional secondary line under the title. */
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** Right-side action node — typically a Button. */
|
|
10
|
+
action?: ReactNode;
|
|
11
|
+
/** Override the default icon. Pass `false` to hide the icon. */
|
|
12
|
+
icon?: ReactNode | false;
|
|
13
|
+
/** Variant — drives color, icon, and ARIA role. */
|
|
14
|
+
variant?: ToastVariant;
|
|
15
|
+
/** ms before auto-dismiss. Pass `Infinity` (or a negative number) to keep open until dismissed. */
|
|
16
|
+
duration?: number;
|
|
17
|
+
/** Fires when the toast disappears (auto or manual). */
|
|
18
|
+
onDismiss?: () => void;
|
|
19
|
+
/** Stable identifier — supply when calling `update(id, …)`. */
|
|
20
|
+
id?: string;
|
|
21
|
+
/** Hide the close button. */
|
|
22
|
+
dismissible?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface ToastInstance extends Required<Pick<ToastOptions, 'variant' | 'duration' | 'dismissible'>> {
|
|
25
|
+
id: string;
|
|
26
|
+
title?: ReactNode;
|
|
27
|
+
description?: ReactNode;
|
|
28
|
+
action?: ReactNode;
|
|
29
|
+
icon?: ReactNode | false;
|
|
30
|
+
onDismiss?: () => void;
|
|
31
|
+
/** Internal — flips to true when entering exit animation. */
|
|
32
|
+
exiting?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ToastFunction {
|
|
35
|
+
(opts: ToastOptions | string): string;
|
|
36
|
+
success: (title: ReactNode, opts?: Omit<ToastOptions, 'variant' | 'title'>) => string;
|
|
37
|
+
info: (title: ReactNode, opts?: Omit<ToastOptions, 'variant' | 'title'>) => string;
|
|
38
|
+
warning: (title: ReactNode, opts?: Omit<ToastOptions, 'variant' | 'title'>) => string;
|
|
39
|
+
error: (title: ReactNode, opts?: Omit<ToastOptions, 'variant' | 'title'>) => string;
|
|
40
|
+
loading: (title: ReactNode, opts?: Omit<ToastOptions, 'variant' | 'title'>) => string;
|
|
41
|
+
}
|
|
42
|
+
export interface ToastApi {
|
|
43
|
+
toast: ToastFunction;
|
|
44
|
+
dismiss: (id?: string) => void;
|
|
45
|
+
update: (id: string, opts: Partial<ToastOptions>) => void;
|
|
46
|
+
}
|
|
47
|
+
export interface ToastProviderProps {
|
|
48
|
+
children: ReactNode;
|
|
49
|
+
/** Where the toast viewport renders. Default `bottom-right`. */
|
|
50
|
+
position?: ToastPosition;
|
|
51
|
+
/** Default duration (ms) when individual toasts don't specify one. Default 5000. */
|
|
52
|
+
defaultDuration?: number;
|
|
53
|
+
/** Max number of toasts visible at once; older ones drop off. Default 5. */
|
|
54
|
+
maxToasts?: number;
|
|
55
|
+
/** Distance from the viewport edges. Default `1rem`. */
|
|
56
|
+
offset?: string;
|
|
57
|
+
}
|