@tangible/ui 0.0.20 → 0.1.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.
Files changed (61) hide show
  1. package/components/Accordion/Accordion.js +1 -1
  2. package/components/Button/Button.js +6 -8
  3. package/components/Button/types.d.ts +0 -5
  4. package/components/Combobox/Combobox.js +2 -2
  5. package/components/DatePicker/Calendar.d.ts +12 -0
  6. package/components/DatePicker/Calendar.js +145 -0
  7. package/components/DatePicker/DatePicker.d.ts +23 -0
  8. package/components/DatePicker/DatePicker.js +123 -0
  9. package/components/DatePicker/DateRangePicker.d.ts +16 -0
  10. package/components/DatePicker/DateRangePicker.js +114 -0
  11. package/components/DatePicker/date-utils.d.ts +51 -0
  12. package/components/DatePicker/date-utils.js +228 -0
  13. package/components/DatePicker/index.d.ts +8 -0
  14. package/components/DatePicker/index.js +6 -0
  15. package/components/DatePicker/presets.d.ts +3 -0
  16. package/components/DatePicker/presets.js +37 -0
  17. package/components/DatePicker/types.d.ts +138 -0
  18. package/components/DatePicker/types.js +39 -0
  19. package/components/MultiSelect/MultiSelect.js +1 -1
  20. package/components/Notice/Notice.d.ts +2 -2
  21. package/components/Popover/Popover.js +16 -2
  22. package/components/SegmentedControl/types.d.ts +2 -2
  23. package/components/Select/Select.js +2 -2
  24. package/components/Tabs/Tabs.js +1 -1
  25. package/components/index.d.ts +1 -0
  26. package/components/index.js +1 -0
  27. package/icons/icons.svg +6 -2
  28. package/icons/lms/index.js +1 -1
  29. package/icons/manifest.json +32 -0
  30. package/icons/registry.d.ts +8 -0
  31. package/icons/registry.js +4 -0
  32. package/icons/system/index.d.ts +8 -0
  33. package/icons/system/index.js +45 -1
  34. package/package.json +5 -1
  35. package/styles/all.css +1 -1
  36. package/styles/all.expanded.css +429 -64
  37. package/styles/all.expanded.unlayered.css +429 -64
  38. package/styles/all.unlayered.css +1 -1
  39. package/styles/components/_bundle.scss +2 -0
  40. package/styles/components/accordion.scss +4 -1
  41. package/styles/components/button.scss +23 -10
  42. package/styles/components/card.scss +1 -1
  43. package/styles/components/chip.scss +36 -11
  44. package/styles/components/combobox.scss +3 -1
  45. package/styles/components/date-picker.scss +400 -0
  46. package/styles/components/icon-button.scss +4 -4
  47. package/styles/components/icon.scss +14 -3
  48. package/styles/components/multi-select.scss +5 -2
  49. package/styles/components/notice.scss +43 -10
  50. package/styles/components/popover.scss +6 -0
  51. package/styles/components/progress.scss +22 -5
  52. package/styles/components/segmented-control.scss +13 -1
  53. package/styles/components/select.scss +11 -2
  54. package/styles/components/text-input.scss +5 -1
  55. package/styles/core.css +1 -1
  56. package/styles/core.unlayered.css +1 -1
  57. package/styles/system/_control.scss +9 -8
  58. package/styles/system/_tokens.scss +3 -0
  59. package/tui-manifest.json +107 -13
  60. package/utils/portal.d.ts +0 -4
  61. package/utils/portal.js +38 -5
@@ -233,7 +233,7 @@ function AccordionTrigger({ asChild = false, 'aria-label': ariaLabel, children,
233
233
  return element;
234
234
  }
235
235
  // Default: render as button with built-in chevron indicator
236
- const button = (_jsxs("button", { ref: triggerRef, type: "button", id: triggerId, className: cx('tui-accordion__trigger', className), "aria-expanded": isOpen, "aria-controls": panelId, "aria-label": ariaLabel, disabled: disabled, "data-state": state, "data-disabled": disabled || undefined, onClick: handleClick, onKeyDown: handleKeyDown, children: [children && _jsx("span", { className: "tui-accordion__trigger-content", children: children }), _jsx(Icon, { name: "system/chevron-down", size: "lg", className: "tui-accordion__indicator", "aria-hidden": "true" })] }));
236
+ const button = (_jsxs("button", { ref: triggerRef, type: "button", id: triggerId, className: cx('tui-accordion__trigger', className), "aria-expanded": isOpen, "aria-controls": panelId, "aria-label": ariaLabel, disabled: disabled, "data-state": state, "data-disabled": disabled || undefined, onClick: handleClick, onKeyDown: handleKeyDown, children: [children && _jsx("span", { className: "tui-accordion__trigger-content", children: children }), _jsx(Icon, { name: "system/chevron-down", className: "tui-accordion__indicator", "aria-hidden": "true" })] }));
237
237
  // Wrap in heading if headingLevel is specified
238
238
  if (headingLevel) {
239
239
  const Heading = `h${headingLevel}`;
@@ -4,13 +4,10 @@ import { cx } from '../../utils/cx.js';
4
4
  import { Icon } from '../Icon/index.js';
5
5
  import { getSafeRel } from '../../utils/polymorphic.js';
6
6
  import { defaultButtonLabels } from './types.js';
7
- export const Button = forwardRef(({ label, children, size = 'md', theme = 'primary', variant = 'solid', fullWidth, disabled = false, loading = false, loadingLabel: loadingLabelProp, labels: labelsProp, leftIconName, rightIconName, leftIcon, rightIcon, iconSize: iconSizeProp, className, target, rel, onClick, style, ...rest }, ref) => {
7
+ export const Button = forwardRef(({ label, children, size = 'md', theme = 'primary', variant = 'solid', fullWidth, disabled = false, loading = false, loadingLabel: loadingLabelProp, labels: labelsProp, leftIconName, rightIconName, leftIcon, rightIcon, className, target, rel, onClick, style, ...rest }, ref) => {
8
8
  const isLink = typeof rest.href === 'string';
9
9
  const isDisabled = disabled || loading;
10
10
  const labels = { ...defaultButtonLabels, ...labelsProp };
11
- // Auto-scale icon size with button size when not explicitly set
12
- const iconSizeMap = { xs: 'xs', sm: 'xs', md: 'sm', lg: 'md' };
13
- const iconSize = iconSizeProp ?? iconSizeMap[size];
14
11
  // Compose loading state into aria-label for screen readers
15
12
  const loadingLabel = loading
16
13
  ? (loadingLabelProp ?? (typeof label === 'string' ? `${label}, loading` : undefined))
@@ -18,10 +15,11 @@ export const Button = forwardRef(({ label, children, size = 'md', theme = 'prima
18
15
  // Normalize destructive → danger for CSS class
19
16
  const themeClass = theme === 'destructive' ? 'danger' : theme;
20
17
  const classes = cx('tui-button', `is-size-${size}`, `is-theme-${themeClass}`, variant !== 'solid' && `is-style-${variant}`, fullWidth && 'is-width-full', isDisabled && 'is-disabled', className);
21
- // Icon size: pass string sizes to Icon component
22
- const iconSizeForIcon = typeof iconSize === 'string' ? iconSize : undefined;
23
- const Left = leftIcon ?? (leftIconName ? _jsx(Icon, { name: leftIconName, size: iconSizeForIcon }) : null);
24
- const Right = rightIcon ?? (rightIconName ? _jsx(Icon, { name: rightIconName, size: iconSizeForIcon }) : null);
18
+ // Icons are sizeless: they track the label via the button's icon rule
19
+ // (see --tui-button-icon-scale) — presentation sizes are neutralised in
20
+ // buttons, so a size prop here would be a lie.
21
+ const Left = leftIcon ?? (leftIconName ? _jsx(Icon, { name: leftIconName }) : null);
22
+ const Right = rightIcon ?? (rightIconName ? _jsx(Icon, { name: rightIconName }) : null);
25
23
  const content = label != null ? (_jsxs(_Fragment, { children: [Left, _jsx("span", { children: label }), Right] })) : (_jsxs(_Fragment, { children: [Left, children, Right] }));
26
24
  if (isLink) {
27
25
  const { href, tabIndex, ...anchorRest } = rest;
@@ -110,11 +110,6 @@ type CommonProps = {
110
110
  * Custom right icon element. Overrides rightIconName.
111
111
  */
112
112
  rightIcon?: React.ReactNode;
113
- /**
114
- * Size of icons.
115
- * @default 'sm'
116
- */
117
- iconSize?: Size;
118
113
  /**
119
114
  * Additional CSS class names.
120
115
  * Note: Use sparingly. Prefer component API tokens for customization.
@@ -386,7 +386,7 @@ function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inp
386
386
  return (_jsx(ComboboxActionsContext.Provider, { value: actionsValue, children: _jsx(ComboboxStateContext.Provider, { value: stateValue, children: _jsxs("div", { className: "tui-combobox", children: [_jsxs("div", { className: "tui-combobox__input-wrapper", children: [_jsx("input", { ref: (node) => {
387
387
  inputRef.current = node;
388
388
  refs.setReference(node);
389
- }, type: "text", id: inputId, className: cx('tui-combobox__input', size !== 'md' && `is-size-${size}`, inputClassName), role: "combobox", "aria-expanded": open, "aria-controls": open ? listboxId : undefined, "aria-autocomplete": "list", "aria-activedescendant": activeOptionId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, disabled: disabled, placeholder: placeholder, value: inputValue, autoComplete: "off", ...referenceProps, onChange: handleInputChange }), clearable && inputValue && !disabled && (_jsx("button", { type: "button", className: "tui-combobox__clear", onClick: handleClear, onMouseDown: (e) => e.preventDefault(), "aria-label": labels.clear, tabIndex: -1, children: _jsx(Icon, { name: "system/close", size: "sm" }) })), _jsx("span", { className: "tui-combobox__icon", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down", size: "sm" }) })] }), children] }) }) }));
389
+ }, type: "text", id: inputId, className: cx('tui-combobox__input', size !== 'md' && `is-size-${size}`, inputClassName), role: "combobox", "aria-expanded": open, "aria-controls": open ? listboxId : undefined, "aria-autocomplete": "list", "aria-activedescendant": activeOptionId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, disabled: disabled, placeholder: placeholder, value: inputValue, autoComplete: "off", ...referenceProps, onChange: handleInputChange }), clearable && inputValue && !disabled && (_jsx("button", { type: "button", className: "tui-combobox__clear", onClick: handleClear, onMouseDown: (e) => e.preventDefault(), "aria-label": labels.clear, tabIndex: -1, children: _jsx(Icon, { name: "system/close" }) })), _jsx("span", { className: "tui-combobox__icon", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down" }) })] }), children] }) }) }));
390
390
  }
391
391
  ComboboxRoot.displayName = 'Combobox';
392
392
  // =============================================================================
@@ -461,7 +461,7 @@ function ComboboxOptionComponent({ value: optionValue, disabled = false, textVal
461
461
  const itemProps = getItemProps({
462
462
  onClick: handleClick,
463
463
  });
464
- return (_jsxs("div", { ref: ref, id: optionId, role: "option", className: cx('tui-combobox__option', className), "aria-selected": isSelected, "aria-disabled": disabled || undefined, "data-highlighted": isHighlighted || undefined, "data-disabled": disabled || undefined, ...itemProps, onPointerDown: composeEventHandlers(handlePointerDown, itemProps.onPointerDown), children: [_jsx("span", { className: "tui-combobox__option-content", children: children }), isSelected && (_jsx(Icon, { name: "system/check", size: "sm", className: "tui-combobox__option-check", "aria-hidden": "true" }))] }));
464
+ return (_jsxs("div", { ref: ref, id: optionId, role: "option", className: cx('tui-combobox__option', className), "aria-selected": isSelected, "aria-disabled": disabled || undefined, "data-highlighted": isHighlighted || undefined, "data-disabled": disabled || undefined, ...itemProps, onPointerDown: composeEventHandlers(handlePointerDown, itemProps.onPointerDown), children: [_jsx("span", { className: "tui-combobox__option-content", children: children }), isSelected && (_jsx(Icon, { name: "system/check", className: "tui-combobox__option-check", "aria-hidden": "true" }))] }));
465
465
  }
466
466
  ComboboxOptionComponent.displayName = 'Combobox.Option';
467
467
  // =============================================================================
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ export declare const Calendar: React.ForwardRefExoticComponent<import("./types").CalendarBaseProps & {
3
+ value?: Date | null;
4
+ onChange?: (day: Date) => void;
5
+ month?: Date;
6
+ defaultMonth?: Date;
7
+ onMonthChange?: (month: Date) => void;
8
+ range?: import("./date-utils").DateRange | null;
9
+ labels?: import("./types").CalendarLabels;
10
+ 'aria-label'?: string;
11
+ className?: string;
12
+ } & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,145 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { cx } from '../../utils/cx.js';
4
+ import { useControllableState } from '../../utils/use-controllable-state.js';
5
+ import { IconButton } from '../IconButton/index.js';
6
+ import { addDays, addMonths, addYears, getMonthGrid, getMonthNames, getWeekdayLabels, isAfterDay, isBeforeDay, isSameDay, isSameMonth, isWithinDays, startOfMonth, } from './date-utils.js';
7
+ import { resolveLocale } from './date-utils.js';
8
+ import { defaultCalendarLabels } from './types.js';
9
+ // =============================================================================
10
+ // Calendar
11
+ // =============================================================================
12
+ //
13
+ // A single month grid following the APG date-grid pattern: a real table with
14
+ // role="grid", roving tabindex on the day buttons, arrows ±1/±7 days,
15
+ // Home/End to week bounds, PageUp/PageDown ±1 month (with Shift, ±1 year).
16
+ // Clicking the caption opens the standard month/year drill-down (a Jan–Dec
17
+ // grid with year navigation); choosing a month returns to the day view.
18
+ //
19
+ // Behavioural reference: WAI-ARIA APG "Date Picker Dialog" example and
20
+ // React Aria's useCalendar (read, not imported — see the imitate-don't-
21
+ // import decision in TIMELINE, Jul 27).
22
+ //
23
+ // =============================================================================
24
+ function dayKey(d) {
25
+ return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
26
+ }
27
+ export const Calendar = React.forwardRef(function Calendar({ value, onChange, month: monthProp, defaultMonth, onMonthChange, range, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, labels: labelsProp, 'aria-label': ariaLabel, className, }, ref) {
28
+ const labels = { ...defaultCalendarLabels, ...labelsProp };
29
+ const locale = resolveLocale(localeProp);
30
+ const [visibleMonthState, setVisibleMonth] = useControllableState({
31
+ value: monthProp,
32
+ defaultValue: defaultMonth ?? value ?? new Date(),
33
+ onChange: onMonthChange,
34
+ });
35
+ // defaultValue is always supplied, so the state is never actually
36
+ // undefined — coalesce once (memoised so hook deps stay stable).
37
+ const fallbackMonth = React.useRef(new Date());
38
+ const visibleMonth = visibleMonthState ?? fallbackMonth.current;
39
+ const [view, setView] = React.useState('days');
40
+ const [focusedDay, setFocusedDay] = React.useState(() => value ?? new Date());
41
+ const gridRef = React.useRef(null);
42
+ const pendingFocus = React.useRef(false);
43
+ const captionId = React.useId();
44
+ const monthNames = getMonthNames(locale);
45
+ const weekdays = getWeekdayLabels(locale, weekStartsOn);
46
+ const caption = `${monthNames[visibleMonth.getMonth()]} ${visibleMonth.getFullYear()}`;
47
+ const dayFormatter = React.useMemo(() => new Intl.DateTimeFormat(locale, { dateStyle: 'full' }), [locale]);
48
+ const isDisabled = React.useCallback((day) => {
49
+ if (min && isBeforeDay(day, min))
50
+ return true;
51
+ if (max && isAfterDay(day, max))
52
+ return true;
53
+ return isDayDisabled ? isDayDisabled(day) : false;
54
+ }, [min, max, isDayDisabled]);
55
+ // Move the roving focus target, shifting the visible month when the target
56
+ // leaves it. Actual DOM focus happens after render (the button may not
57
+ // exist until the new month paints).
58
+ const moveFocus = React.useCallback((day) => {
59
+ setFocusedDay(day);
60
+ if (!isSameMonth(day, visibleMonth))
61
+ setVisibleMonth(startOfMonth(day));
62
+ pendingFocus.current = true;
63
+ }, [visibleMonth, setVisibleMonth]);
64
+ React.useEffect(() => {
65
+ if (!pendingFocus.current)
66
+ return;
67
+ pendingFocus.current = false;
68
+ const btn = gridRef.current?.querySelector(`[data-day="${dayKey(focusedDay)}"]`);
69
+ btn?.focus();
70
+ });
71
+ // Keep the roving target inside the visible month when navigation happens
72
+ // via the caption arrows rather than the keyboard.
73
+ React.useEffect(() => {
74
+ if (!isSameMonth(focusedDay, visibleMonth)) {
75
+ const clamped = new Date(visibleMonth);
76
+ clamped.setDate(Math.min(focusedDay.getDate(), new Date(visibleMonth.getFullYear(), visibleMonth.getMonth() + 1, 0).getDate()));
77
+ setFocusedDay(clamped);
78
+ }
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- clamp only when the month moves
80
+ }, [visibleMonth]);
81
+ const handleDayKeyDown = (event, day) => {
82
+ const jump = {
83
+ ArrowLeft: () => addDays(day, -1),
84
+ ArrowRight: () => addDays(day, 1),
85
+ ArrowUp: () => addDays(day, -7),
86
+ ArrowDown: () => addDays(day, 7),
87
+ Home: () => addDays(day, -((day.getDay() - weekStartsOn + 7) % 7)),
88
+ End: () => addDays(day, 6 - ((day.getDay() - weekStartsOn + 7) % 7)),
89
+ PageUp: () => (event.shiftKey ? addYears(day, -1) : addMonths(day, -1)),
90
+ PageDown: () => (event.shiftKey ? addYears(day, 1) : addMonths(day, 1)),
91
+ };
92
+ const move = jump[event.key];
93
+ if (move) {
94
+ event.preventDefault();
95
+ moveFocus(move());
96
+ }
97
+ };
98
+ const selectDay = (day) => {
99
+ if (isDisabled(day))
100
+ return;
101
+ moveFocus(day);
102
+ onChange?.(day);
103
+ };
104
+ // ---------------------------------------------------------------------------
105
+ // Month/year drill-down view
106
+ // ---------------------------------------------------------------------------
107
+ if (view === 'months') {
108
+ return (_jsxs("div", { ref: ref, className: cx('tui-calendar', 'is-view-months', className), "aria-label": ariaLabel, children: [_jsxs("div", { className: "tui-calendar__nav", children: [_jsx(IconButton, { className: "tui-calendar__prev", icon: "system/arrow-left", label: labels.prevYear, variant: "ghost", size: "sm", onClick: () => setVisibleMonth(addYears(visibleMonth, -1)) }), _jsx("button", { type: "button", className: "tui-calendar__caption", "aria-live": "polite", onClick: () => setView('days'), children: visibleMonth.getFullYear() }), _jsx(IconButton, { className: "tui-calendar__next", icon: "system/arrow-right", label: labels.nextYear, variant: "ghost", size: "sm", onClick: () => setVisibleMonth(addYears(visibleMonth, 1)) })] }), _jsx("div", { className: "tui-calendar__months", role: "listbox", "aria-label": caption, children: getMonthNames(locale, 'short').map((name, m) => {
109
+ const current = m === visibleMonth.getMonth();
110
+ return (_jsx("button", { type: "button", role: "option", "aria-selected": current, className: cx('tui-calendar__month', current && 'is-selected'), onClick: () => {
111
+ const next = new Date(visibleMonth);
112
+ next.setDate(1);
113
+ next.setMonth(m);
114
+ setVisibleMonth(next);
115
+ setView('days');
116
+ }, children: name }, name));
117
+ }) })] }));
118
+ }
119
+ // ---------------------------------------------------------------------------
120
+ // Day grid view
121
+ // ---------------------------------------------------------------------------
122
+ const weeks = getMonthGrid(visibleMonth, weekStartsOn);
123
+ const today = new Date();
124
+ const hasFocusTarget = weeks.some((row) => row.some((d) => isSameDay(d, focusedDay)));
125
+ return (_jsxs("div", { ref: ref, className: cx('tui-calendar', className), "aria-label": ariaLabel, children: [_jsxs("div", { className: "tui-calendar__nav", children: [_jsx(IconButton, { className: "tui-calendar__prev", icon: "system/arrow-left", label: labels.prevMonth, variant: "ghost", size: "sm", onClick: () => setVisibleMonth(addMonths(visibleMonth, -1)) }), _jsxs("button", { type: "button", id: captionId, className: "tui-calendar__caption", "aria-live": "polite", "aria-label": labels.openMonthPicker(caption), onClick: () => setView('months'), children: [_jsx("span", { className: "tui-calendar__caption-month", children: monthNames[visibleMonth.getMonth()] }), ' ', _jsx("span", { className: "tui-calendar__caption-year", children: visibleMonth.getFullYear() })] }), _jsx(IconButton, { className: "tui-calendar__next", icon: "system/arrow-right", label: labels.nextMonth, variant: "ghost", size: "sm", onClick: () => setVisibleMonth(addMonths(visibleMonth, 1)) })] }), _jsxs("table", { ref: gridRef, role: "grid", className: "tui-calendar__grid", "aria-labelledby": captionId, children: [_jsx("thead", { children: _jsx("tr", { children: weekdays.map((w) => (_jsx("th", { scope: "col", className: "tui-calendar__weekday", "aria-label": w.long, children: w.narrow }, w.long))) }) }), _jsx("tbody", { children: weeks.map((row) => (_jsx("tr", { children: row.map((day) => {
126
+ const outside = !isSameMonth(day, visibleMonth);
127
+ const selected = isSameDay(day, value);
128
+ const isToday = isSameDay(day, today);
129
+ const disabled = isDisabled(day);
130
+ const rangeStart = range?.from ? isSameDay(day, range.from) : false;
131
+ const rangeEnd = range?.to ? isSameDay(day, range.to) : false;
132
+ const inRange = range?.from && range?.to ? isWithinDays(day, range.from, range.to) : false;
133
+ const isFocusTarget = hasFocusTarget
134
+ ? isSameDay(day, focusedDay)
135
+ : day.getDate() === 1 && !outside;
136
+ const description = [
137
+ isToday ? labels.today : null,
138
+ selected || rangeStart || rangeEnd ? labels.selected : null,
139
+ ]
140
+ .filter(Boolean)
141
+ .join(', ');
142
+ return (_jsx("td", { className: cx('tui-calendar__cell', outside && 'is-outside', selected && 'is-selected', isToday && 'is-today', inRange && 'is-in-range', rangeStart && 'is-range-start', rangeEnd && 'is-range-end'), "aria-selected": selected || rangeStart || rangeEnd || undefined, children: _jsx("button", { type: "button", className: "tui-calendar__day", "data-day": dayKey(day), tabIndex: isFocusTarget ? 0 : -1, "aria-disabled": disabled || undefined, "aria-current": isToday ? 'date' : undefined, "aria-label": labels.day(dayFormatter.format(day)) + (description ? ` (${description})` : ''), onClick: () => selectDay(day), onKeyDown: (e) => handleDayKeyDown(e, day), onFocus: () => setFocusedDay(day), children: day.getDate() }) }, dayKey(day)));
143
+ }) }, dayKey(row[0])))) })] })] }));
144
+ });
145
+ Calendar.displayName = 'Calendar';
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ /** Internal time editor: [HH : MM] [AM|PM] zoneLabel. */
3
+ export declare function TimeField({ value, onChange, hour12, zoneLabel, labels, }: {
4
+ value: Date;
5
+ onChange: (next: Date) => void;
6
+ hour12: boolean;
7
+ zoneLabel?: React.ReactNode;
8
+ labels: Required<import('./types').DatePickerLabels>;
9
+ }): import("react/jsx-runtime").JSX.Element;
10
+ export declare const DatePicker: React.ForwardRefExoticComponent<import("./types").CalendarBaseProps & {
11
+ value?: Date | null;
12
+ defaultValue?: Date | null;
13
+ onChange?: (value: Date) => void;
14
+ withTime?: boolean;
15
+ hour12?: boolean;
16
+ zoneLabel?: React.ReactNode;
17
+ disabled?: boolean;
18
+ labels?: import("./types").DatePickerLabels;
19
+ calendarLabels?: import("./types").CalendarLabels;
20
+ 'aria-label'?: string;
21
+ className?: string;
22
+ id?: string;
23
+ } & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,123 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { cx } from '../../utils/cx.js';
4
+ import { useControllableState } from '../../utils/use-controllable-state.js';
5
+ import { Button } from '../Button/index.js';
6
+ import { Icon } from '../Icon/index.js';
7
+ import { IconButton } from '../IconButton/index.js';
8
+ import { Popover, PopoverContent, PopoverTrigger } from '../Popover/index.js';
9
+ import { SegmentedControl } from '../SegmentedControl/index.js';
10
+ import { Select } from '../Select/index.js';
11
+ import { Calendar } from './Calendar.js';
12
+ import { clampDay, daysInMonth, formatDay, formatDayTime, getMonthNames, withDay, resolveLocale, } from './date-utils.js';
13
+ import { defaultDatePickerLabels } from './types.js';
14
+ // =============================================================================
15
+ // DatePicker
16
+ // =============================================================================
17
+ //
18
+ // Trigger (input-group anatomy, readonly) opening a popover dialog:
19
+ // [ Pick a Date and Time Now × ]
20
+ // [ [02 : 05] [AM|PM] UTC+0 ] (withTime)
21
+ // [ [August v] [8] [2024] ]
22
+ // [ calendar ]
23
+ //
24
+ // Commit model: every interaction commits immediately onto the current value
25
+ // (or "today at 00:00" when empty) — there is no staged draft; the range
26
+ // picker owns Apply/Cancel semantics.
27
+ //
28
+ // =============================================================================
29
+ /** Two-digit numeric segment with arrow-key stepping and select-on-focus. */
30
+ function NumberSegment({ value, min, max, onCommit, label, className, pad = true, }) {
31
+ const [text, setText] = React.useState(null);
32
+ const shown = text ?? (pad ? String(value).padStart(2, '0') : String(value));
33
+ const commit = (raw) => {
34
+ setText(null);
35
+ const n = Number(raw);
36
+ if (raw === '' || Number.isNaN(n))
37
+ return;
38
+ onCommit(Math.max(min, Math.min(max, Math.trunc(n))));
39
+ };
40
+ return (_jsx("input", { className: cx('tui-input', className), inputMode: "numeric", value: shown, "aria-label": label, onFocus: (e) => e.currentTarget.select(), onChange: (e) => setText(e.target.value.replace(/\D/g, '').slice(0, 4)), onBlur: (e) => commit(e.target.value), onKeyDown: (e) => {
41
+ if (e.key === 'Enter')
42
+ commit(e.currentTarget.value);
43
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
44
+ e.preventDefault();
45
+ const step = e.key === 'ArrowUp' ? 1 : -1;
46
+ const next = value + step;
47
+ onCommit(next > max ? min : next < min ? max : next);
48
+ setText(null);
49
+ }
50
+ } }));
51
+ }
52
+ /** Internal time editor: [HH : MM] [AM|PM] zoneLabel. */
53
+ export function TimeField({ value, onChange, hour12, zoneLabel, labels, }) {
54
+ const hours = value.getHours();
55
+ const meridiem = hours >= 12 ? 'pm' : 'am';
56
+ const displayHour = hour12 ? hours % 12 || 12 : hours;
57
+ const setHours = (h) => {
58
+ const next = new Date(value);
59
+ next.setHours(h, value.getMinutes(), 0, 0);
60
+ onChange(next);
61
+ };
62
+ return (_jsxs("div", { className: "tui-date-picker__time", children: [_jsxs("div", { className: "tui-date-picker__time-field", role: "group", "aria-label": labels.timeSection, children: [_jsx(NumberSegment, { className: "tui-date-picker__time-segment", value: displayHour, min: hour12 ? 1 : 0, max: hour12 ? 12 : 23, label: labels.hour, onCommit: (h) => {
63
+ if (!hour12)
64
+ return setHours(h);
65
+ const base = h % 12;
66
+ setHours(meridiem === 'pm' ? base + 12 : base);
67
+ } }), _jsx("span", { className: "tui-date-picker__time-colon", "aria-hidden": "true", children: ":" }), _jsx(NumberSegment, { className: "tui-date-picker__time-segment", value: value.getMinutes(), min: 0, max: 59, label: labels.minute, onCommit: (m) => {
68
+ const next = new Date(value);
69
+ next.setMinutes(m, 0, 0);
70
+ onChange(next);
71
+ } })] }), hour12 && (_jsxs(SegmentedControl, { className: "tui-date-picker__meridiem", "aria-label": labels.meridiem, size: "xs", value: meridiem, onValueChange: (next) => {
72
+ const base = hours % 12;
73
+ setHours(next === 'pm' ? base + 12 : base);
74
+ }, children: [_jsx(SegmentedControl.Item, { value: "am", children: labels.am }), _jsx(SegmentedControl.Item, { value: "pm", children: labels.pm })] })), zoneLabel != null && _jsx("span", { className: "tui-date-picker__zone", children: zoneLabel })] }));
75
+ }
76
+ export const DatePicker = React.forwardRef(function DatePicker({ value: valueProp, defaultValue, onChange, withTime = false, hour12 = true, zoneLabel, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, className, id, }, ref) {
77
+ const labels = { ...defaultDatePickerLabels, ...labelsProp };
78
+ const locale = resolveLocale(localeProp);
79
+ const [open, setOpen] = React.useState(false);
80
+ const [value, setValue] = useControllableState({
81
+ value: valueProp,
82
+ defaultValue: defaultValue ?? null,
83
+ onChange: onChange,
84
+ });
85
+ // Interactions commit onto the current value, or a fresh midnight-today.
86
+ const base = React.useMemo(() => {
87
+ if (value)
88
+ return value;
89
+ const seed = new Date();
90
+ seed.setHours(0, 0, 0, 0);
91
+ return clampDay(seed, min, max);
92
+ }, [value, min, max]);
93
+ // The visible calendar month is view state, not value state — arrow
94
+ // navigation must not commit dates the user never chose. It re-anchors to
95
+ // the value whenever one is committed.
96
+ const [viewMonth, setViewMonth] = React.useState(base);
97
+ const commit = (next) => {
98
+ setValue(next);
99
+ setViewMonth(next);
100
+ };
101
+ const title = withTime ? labels.titleWithTime : labels.title;
102
+ const formatted = value
103
+ ? withTime
104
+ ? formatDayTime(value, locale)
105
+ : formatDay(value, locale)
106
+ : null;
107
+ const monthNames = getMonthNames(locale);
108
+ return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, className: cx('tui-input-group', 'tui-date-picker__trigger', disabled && 'is-disabled', className), "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": ariaLabel ?? (formatted ? labels.trigger(formatted) : labels.triggerEmpty), children: [_jsx("span", { className: cx('tui-date-picker__trigger-value', !formatted && 'is-placeholder'), children: formatted ?? labels.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-picker", "aria-label": title, children: [_jsxs("div", { className: "tui-date-picker__head", children: [_jsx("span", { className: "tui-date-picker__title", children: title }), _jsx(Button, { className: "tui-date-picker__now", variant: "ghost", theme: "primary", size: "sm", label: labels.now, onClick: () => commit(clampDay(new Date(), min, max)) }), _jsx(IconButton, { className: "tui-date-picker__close", icon: "system/close", label: labels.close, variant: "ghost", size: "sm", onClick: () => setOpen(false) })] }), withTime && (_jsx(TimeField, { value: base, onChange: commit, hour12: hour12, zoneLabel: zoneLabel, labels: labels })), _jsxs("div", { className: "tui-date-picker__fields", role: "group", "aria-label": labels.dateSection, children: [_jsx("div", { className: "tui-date-picker__month", children: _jsxs(Select, { value: String(base.getMonth()), onValueChange: (m) => {
109
+ const next = new Date(base);
110
+ next.setDate(Math.min(next.getDate(), daysInMonth(new Date(next.getFullYear(), Number(m), 1))));
111
+ next.setMonth(Number(m));
112
+ commit(next);
113
+ }, "aria-label": labels.month, children: [_jsx(Select.Trigger, {}), _jsx(Select.Content, { children: monthNames.map((name, m) => (_jsx(Select.Option, { value: String(m), children: name }, name))) })] }) }), _jsx(NumberSegment, { className: "tui-date-picker__day-field", value: base.getDate(), min: 1, max: daysInMonth(base), pad: false, label: labels.dayOfMonth, onCommit: (d) => {
114
+ const next = new Date(base);
115
+ next.setDate(d);
116
+ commit(next);
117
+ } }), _jsx(NumberSegment, { className: "tui-date-picker__year-field", value: base.getFullYear(), min: 1, max: 9999, pad: false, label: labels.year, onCommit: (y) => {
118
+ const next = new Date(base);
119
+ next.setFullYear(y);
120
+ commit(next);
121
+ } })] }), _jsx(Calendar, { value: value, month: viewMonth, onMonthChange: setViewMonth, onChange: (day) => commit(withDay(value, day)), min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels })] })] }));
122
+ });
123
+ DatePicker.displayName = 'DatePicker';
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import type { DateRange } from './date-utils';
3
+ import type { DateRangePreset } from './types';
4
+ export declare const DateRangePicker: React.ForwardRefExoticComponent<import("./types").CalendarBaseProps & {
5
+ value?: DateRange | null;
6
+ defaultValue?: DateRange | null;
7
+ onChange?: (range: DateRange) => void;
8
+ withTime?: boolean;
9
+ presets?: DateRangePreset[] | false;
10
+ disabled?: boolean;
11
+ labels?: import("./types").DateRangePickerLabels;
12
+ calendarLabels?: import("./types").CalendarLabels;
13
+ 'aria-label'?: string;
14
+ className?: string;
15
+ id?: string;
16
+ } & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,114 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { cx } from '../../utils/cx.js';
4
+ import { useControllableState } from '../../utils/use-controllable-state.js';
5
+ import { Button } from '../Button/index.js';
6
+ import { Icon } from '../Icon/index.js';
7
+ import { Popover, PopoverContent, PopoverTrigger } from '../Popover/index.js';
8
+ import { TextInput } from '../TextInput/index.js';
9
+ import { Calendar } from './Calendar.js';
10
+ import { addMonths, formatDay, formatDayTime, formatNumeric, isBeforeDay, isSameMonth, parseNumeric, startOfMonth, resolveLocale, } from './date-utils.js';
11
+ import { defaultDateRangePresets } from './presets.js';
12
+ import { defaultDateRangePickerLabels } from './types.js';
13
+ // =============================================================================
14
+ // DateRangePicker
15
+ // =============================================================================
16
+ //
17
+ // Trigger opening a popover dialog with a quick-range rail, editable From/To
18
+ // fields, and two linked month calendars. Selection is staged: day clicks
19
+ // build a draft (first click sets From, second sets To, swapping if needed),
20
+ // and only Apply commits it — Cancel or dismissal discards the draft.
21
+ //
22
+ // =============================================================================
23
+ const EMPTY_RANGE = { from: null, to: null };
24
+ export const DateRangePicker = React.forwardRef(function DateRangePicker({ value: valueProp, defaultValue, onChange, withTime = false, presets = defaultDateRangePresets, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, className, id, }, ref) {
25
+ const labels = { ...defaultDateRangePickerLabels, ...labelsProp };
26
+ const locale = resolveLocale(localeProp);
27
+ const [open, setOpen] = React.useState(false);
28
+ const [value, setValue] = useControllableState({
29
+ value: valueProp,
30
+ defaultValue: defaultValue ?? null,
31
+ onChange: onChange,
32
+ });
33
+ const [draft, setDraft] = React.useState(value ?? EMPTY_RANGE);
34
+ const [viewMonth, setViewMonth] = React.useState(() => value?.from ?? new Date());
35
+ // (Re)open seeds the draft and view from the committed value.
36
+ const handleOpenChange = (next) => {
37
+ if (next) {
38
+ setDraft(value ?? EMPTY_RANGE);
39
+ setViewMonth(startOfMonth(value?.from ?? new Date()));
40
+ }
41
+ setOpen(next);
42
+ };
43
+ const apply = () => {
44
+ if (!draft.from || !draft.to)
45
+ return;
46
+ setValue(draft);
47
+ setOpen(false);
48
+ };
49
+ const pickDay = (day) => {
50
+ setDraft((prev) => {
51
+ if (!prev.from || (prev.from && prev.to)) {
52
+ // Start a new range; keep the previous From time-of-day if any.
53
+ const from = new Date(day);
54
+ if (prev.from)
55
+ from.setHours(prev.from.getHours(), prev.from.getMinutes(), 0, 0);
56
+ else
57
+ from.setHours(0, 0, 0, 0);
58
+ return { from, to: null };
59
+ }
60
+ const to = new Date(day);
61
+ to.setHours(prev.to?.getHours() ?? 0, prev.to?.getMinutes() ?? 0, 0, 0);
62
+ if (isBeforeDay(to, prev.from)) {
63
+ return { from: to, to: prev.from };
64
+ }
65
+ return { from: prev.from, to };
66
+ });
67
+ };
68
+ const applyPreset = (preset) => {
69
+ const range = preset.getRange(new Date());
70
+ setDraft(range);
71
+ if (range.from)
72
+ setViewMonth(startOfMonth(range.from));
73
+ };
74
+ const format = (d) => withTime ? formatDayTime(d, locale) : formatDay(d, locale);
75
+ const formatted = value?.from && value?.to ? `${format(value.from)} - ${format(value.to)}` : null;
76
+ const fieldText = (d) => (d ? formatNumeric(d, locale, withTime) : '');
77
+ const rightMonth = addMonths(viewMonth, 1);
78
+ // Second calendar stays one month ahead; hide nav overlap by letting the
79
+ // left calendar own "previous" and the right own "next".
80
+ const showPresets = presets !== false && presets.length > 0;
81
+ return (_jsxs(Popover, { open: open, onOpenChange: handleOpenChange, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, className: cx('tui-input-group', 'tui-date-range-picker__trigger', disabled && 'is-disabled', className), "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": ariaLabel ?? (formatted ? labels.trigger(formatted) : labels.triggerEmpty), children: [_jsx("span", { className: cx('tui-date-range-picker__trigger-value', !formatted && 'is-placeholder'), children: formatted ?? labels.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-range-picker", "aria-label": labels.triggerEmpty, children: [_jsxs("div", { className: "tui-date-range-picker__body", children: [showPresets && (_jsx("div", { className: "tui-date-range-picker__presets", role: "group", "aria-label": labels.presets, children: presets.map((preset) => (_jsx(Button, { className: "tui-date-range-picker__preset", variant: "ghost", theme: "primary", size: "sm", label: preset.label, onClick: () => applyPreset(preset) }, preset.label))) })), _jsxs("div", { className: "tui-date-range-picker__main", children: [_jsxs("div", { className: "tui-date-range-picker__fields", children: [_jsx(RangeField, { label: labels.from, value: fieldText(draft.from), locale: locale, onCommit: (d) => {
82
+ setDraft((prev) => {
83
+ const next = { ...prev, from: d };
84
+ if (next.to && isBeforeDay(next.to, d))
85
+ next.to = null;
86
+ return next;
87
+ });
88
+ setViewMonth(startOfMonth(d));
89
+ } }), _jsx("span", { className: "tui-date-range-picker__fields-dash", "aria-hidden": "true", children: "-" }), _jsx(RangeField, { label: labels.to, value: fieldText(draft.to), locale: locale, onCommit: (d) => {
90
+ setDraft((prev) => prev.from && isBeforeDay(d, prev.from)
91
+ ? { from: d, to: prev.from }
92
+ : { ...prev, to: d });
93
+ } })] }), _jsxs("div", { className: "tui-date-range-picker__calendars", children: [_jsx(Calendar, { className: "tui-date-range-picker__calendar", month: viewMonth, onMonthChange: (m) => {
94
+ // Keep the pair adjacent whichever side navigated.
95
+ setViewMonth(isSameMonth(m, rightMonth) ? addMonths(viewMonth, 1) : m);
96
+ }, onChange: pickDay, range: draft, min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels }), _jsx(Calendar, { className: "tui-date-range-picker__calendar", month: rightMonth, onMonthChange: (m) => {
97
+ setViewMonth(addMonths(m, -1));
98
+ }, onChange: pickDay, range: draft, min: min, max: max, isDayDisabled: isDayDisabled, weekStartsOn: weekStartsOn, locale: locale, labels: calendarLabels })] })] })] }), _jsxs("div", { className: "tui-date-range-picker__foot", children: [_jsx(Button, { className: "tui-date-range-picker__cancel", variant: "outline", theme: "primary", label: labels.cancel, onClick: () => setOpen(false) }), _jsx(Button, { className: "tui-date-range-picker__apply", theme: "primary", label: labels.apply, disabled: !draft.from || !draft.to, onClick: apply })] })] })] }));
99
+ });
100
+ DateRangePicker.displayName = 'DateRangePicker';
101
+ /** Editable From/To text field: shows the formatted value, parses on commit. */
102
+ function RangeField({ label, value, locale, onCommit, }) {
103
+ const [text, setText] = React.useState(null);
104
+ const commit = (raw) => {
105
+ setText(null);
106
+ const parsed = parseNumeric(raw, locale);
107
+ if (parsed)
108
+ onCommit(parsed);
109
+ };
110
+ return (_jsxs("label", { className: "tui-date-range-picker__field", children: [_jsx("span", { className: "tui-date-range-picker__field-label", children: label }), _jsx(TextInput, { value: text ?? value, onChange: (e) => setText(e.target.value), onBlur: (e) => commit(e.target.value), onKeyDown: (e) => {
111
+ if (e.key === 'Enter')
112
+ commit(e.currentTarget.value);
113
+ } })] }));
114
+ }
@@ -0,0 +1,51 @@
1
+ export type DateRange = {
2
+ from: Date | null;
3
+ to: Date | null;
4
+ };
5
+ /** 0 = Sunday … 6 = Saturday, matching Date#getDay(). */
6
+ export type WeekStart = 0 | 1 | 2 | 3 | 4 | 5 | 6;
7
+ export declare function isSameDay(a: Date | null | undefined, b: Date | null | undefined): boolean;
8
+ export declare function isSameMonth(a: Date, b: Date): boolean;
9
+ /** Strictly before, comparing calendar days (time-of-day ignored). */
10
+ export declare function isBeforeDay(a: Date, b: Date): boolean;
11
+ export declare function isAfterDay(a: Date, b: Date): boolean;
12
+ /** Day is within [from, to] inclusive, comparing calendar days. */
13
+ export declare function isWithinDays(day: Date, from: Date, to: Date): boolean;
14
+ /** New Date shifted by n days; preserves time-of-day. */
15
+ export declare function addDays(date: Date, n: number): Date;
16
+ /**
17
+ * New Date shifted by n months; clamps the day-of-month so Jan 31 + 1 month
18
+ * lands on Feb 28/29 rather than overflowing into March.
19
+ */
20
+ export declare function addMonths(date: Date, n: number): Date;
21
+ export declare function addYears(date: Date, n: number): Date;
22
+ export declare function daysInMonth(date: Date): number;
23
+ export declare function startOfMonth(date: Date): Date;
24
+ export declare function startOfWeek(date: Date, weekStartsOn: WeekStart): Date;
25
+ /**
26
+ * The visible day grid for a month: always 6 rows of 7 (42 days), starting
27
+ * on the locale's week start, so the popover height never jumps between
28
+ * months. Time-of-day on the returned dates is noon — callers merge their
29
+ * own time when committing a selection.
30
+ */
31
+ export declare function getMonthGrid(month: Date, weekStartsOn: WeekStart): Date[][];
32
+ /** New Date with the given calendar day but this date's time-of-day. */
33
+ export declare function withDay(time: Date | null | undefined, day: Date): Date;
34
+ export declare function clampDay(date: Date, min?: Date, max?: Date): Date;
35
+ export declare function getMonthNames(locale: string, width?: 'long' | 'short'): string[];
36
+ /** Weekday labels in grid order for the given week start. */
37
+ export declare function getWeekdayLabels(locale: string, weekStartsOn: WeekStart): {
38
+ narrow: string;
39
+ long: string;
40
+ }[];
41
+ export declare function formatDay(date: Date, locale: string): string;
42
+ export declare function formatDayTime(date: Date, locale: string): string;
43
+ /** Numeric form for text fields, e.g. "08/08/2024" or "08/08/2024, 00:00". */
44
+ export declare function formatNumeric(date: Date, locale: string, withTime: boolean): string;
45
+ /**
46
+ * Parse a numeric date string ("08/08/2024", "8.8.2024, 14:30") using the
47
+ * locale's part order. Returns null on anything that doesn't resolve to a
48
+ * real calendar day. Two-digit years are rejected rather than guessed.
49
+ */
50
+ export declare function parseNumeric(text: string, locale: string): Date | null;
51
+ export declare function resolveLocale(locale?: string): string;