@tangible/ui 0.0.21 → 0.2.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/components/Button/Button.js +6 -8
- package/components/Button/types.d.ts +5 -7
- package/components/Chip/Chip.d.ts +28 -0
- package/components/Chip/Chip.js +19 -3
- package/components/Combobox/Combobox.d.ts +1 -1
- package/components/Combobox/Combobox.js +2 -2
- package/components/Combobox/types.d.ts +13 -0
- package/components/DatePicker/Calendar.d.ts +12 -0
- package/components/DatePicker/Calendar.js +145 -0
- package/components/DatePicker/DatePicker.d.ts +23 -0
- package/components/DatePicker/DatePicker.js +123 -0
- package/components/DatePicker/DateRangePicker.d.ts +16 -0
- package/components/DatePicker/DateRangePicker.js +114 -0
- package/components/DatePicker/date-utils.d.ts +51 -0
- package/components/DatePicker/date-utils.js +228 -0
- package/components/DatePicker/index.d.ts +8 -0
- package/components/DatePicker/index.js +6 -0
- package/components/DatePicker/presets.d.ts +3 -0
- package/components/DatePicker/presets.js +37 -0
- package/components/DatePicker/types.d.ts +138 -0
- package/components/DatePicker/types.js +39 -0
- package/components/IconButton/types.d.ts +2 -2
- package/components/MultiCombobox/MultiCombobox.d.ts +33 -0
- package/components/MultiCombobox/MultiCombobox.js +595 -0
- package/components/MultiCombobox/MultiComboboxContext.d.ts +8 -0
- package/components/MultiCombobox/MultiComboboxContext.js +36 -0
- package/components/MultiCombobox/index.d.ts +3 -0
- package/components/MultiCombobox/index.js +2 -0
- package/components/MultiCombobox/types.d.ts +244 -0
- package/components/MultiCombobox/types.js +7 -0
- package/components/MultiSelect/MultiSelect.js +22 -2
- package/components/Popover/Popover.js +16 -2
- package/components/SegmentedControl/types.d.ts +2 -2
- package/components/Select/Select.js +14 -0
- package/components/Slider/Slider.d.ts +2 -0
- package/components/Slider/Slider.js +29 -0
- package/components/Slider/index.d.ts +2 -0
- package/components/Slider/index.js +1 -0
- package/components/Slider/types.d.ts +39 -0
- package/components/Slider/types.js +1 -0
- package/components/index.d.ts +4 -0
- package/components/index.js +3 -0
- package/package.json +13 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +1181 -187
- package/styles/all.expanded.unlayered.css +1181 -187
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +6 -0
- package/styles/components/button.scss +59 -43
- package/styles/components/card.scss +1 -1
- package/styles/components/chip.scss +84 -10
- package/styles/components/combobox.scss +16 -2
- package/styles/components/date-picker.scss +400 -0
- package/styles/components/icon-button.scss +36 -30
- package/styles/components/input/index.scss +1 -2
- package/styles/components/multi-combobox.scss +457 -0
- package/styles/components/multi-select.scss +34 -18
- package/styles/components/notice.scss +15 -6
- package/styles/components/pager.scss +4 -2
- package/styles/components/popover.scss +6 -0
- package/styles/components/progress.scss +23 -6
- package/styles/components/segmented-control.scss +53 -15
- package/styles/components/select.scss +19 -3
- package/styles/components/slider.scss +184 -0
- package/styles/components/switch.scss +1 -1
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/system/_control.scss +9 -8
- package/styles/system/_tokens.scss +16 -0
- package/tui-manifest.json +311 -14
- package/utils/portal.d.ts +0 -4
- package/utils/portal.js +38 -5
|
@@ -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,
|
|
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
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IconName } from '../../icons/registry';
|
|
2
|
-
import type { Size, ThemeIntent } from '../../types';
|
|
2
|
+
import type { Size, ThemeIntent, ThemeStatus } from '../../types';
|
|
3
3
|
export type { Size };
|
|
4
4
|
/**
|
|
5
5
|
* Semantic color themes.
|
|
@@ -9,8 +9,11 @@ export type { Size };
|
|
|
9
9
|
* - `'destructive'`: Alias for `'danger'` — mapped internally before
|
|
10
10
|
* class generation. Provided for readability in consumer code where
|
|
11
11
|
* "destructive" better describes the intent (e.g. `theme="destructive"`).
|
|
12
|
+
* - `'success'` / `'warning'` / `'info'`: Status-coloured actions for
|
|
13
|
+
* surfaces where the action carries the status semantics (approve,
|
|
14
|
+
* proceed-with-caution, learn-more).
|
|
12
15
|
*/
|
|
13
|
-
export type Theme = ThemeIntent | 'destructive';
|
|
16
|
+
export type Theme = ThemeIntent | ThemeStatus | 'destructive';
|
|
14
17
|
/**
|
|
15
18
|
* Visual style variants.
|
|
16
19
|
* - `'solid'`: Filled background (default)
|
|
@@ -110,11 +113,6 @@ type CommonProps = {
|
|
|
110
113
|
* Custom right icon element. Overrides rightIconName.
|
|
111
114
|
*/
|
|
112
115
|
rightIcon?: React.ReactNode;
|
|
113
|
-
/**
|
|
114
|
-
* Size of icons.
|
|
115
|
-
* @default 'sm'
|
|
116
|
-
*/
|
|
117
|
-
iconSize?: Size;
|
|
118
116
|
/**
|
|
119
117
|
* Additional CSS class names.
|
|
120
118
|
* Note: Use sparingly. Prefer component API tokens for customization.
|
|
@@ -29,6 +29,20 @@ export type ChipProps = {
|
|
|
29
29
|
leftIcon?: React.ReactNode;
|
|
30
30
|
rightIcon?: React.ReactNode;
|
|
31
31
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
32
|
+
/**
|
|
33
|
+
* When provided, renders a trailing remove (×) button after the content.
|
|
34
|
+
* The button is a real `<button>` — the only focusable target in the chip —
|
|
35
|
+
* so the chip body stays non-interactive. Intended for token/tag patterns
|
|
36
|
+
* (MultiSelect, MultiCombobox). Combining `onRemove` with an interactive
|
|
37
|
+
* chip (`onClick` or ChipGroup) nests interactive elements and warns in dev.
|
|
38
|
+
*/
|
|
39
|
+
onRemove?: React.MouseEventHandler<HTMLButtonElement>;
|
|
40
|
+
/**
|
|
41
|
+
* Accessible label for the remove button. Pass a specific label like
|
|
42
|
+
* `Remove Alice` for context.
|
|
43
|
+
* @default 'Remove'
|
|
44
|
+
*/
|
|
45
|
+
removeLabel?: string;
|
|
32
46
|
/** When inside ChipGroup, identifies this chip for selection tracking */
|
|
33
47
|
value?: OptionValue;
|
|
34
48
|
} & Omit<React.HTMLAttributes<HTMLSpanElement>, 'onClick'>;
|
|
@@ -57,6 +71,20 @@ export declare const Chip: React.ForwardRefExoticComponent<{
|
|
|
57
71
|
leftIcon?: React.ReactNode;
|
|
58
72
|
rightIcon?: React.ReactNode;
|
|
59
73
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
74
|
+
/**
|
|
75
|
+
* When provided, renders a trailing remove (×) button after the content.
|
|
76
|
+
* The button is a real `<button>` — the only focusable target in the chip —
|
|
77
|
+
* so the chip body stays non-interactive. Intended for token/tag patterns
|
|
78
|
+
* (MultiSelect, MultiCombobox). Combining `onRemove` with an interactive
|
|
79
|
+
* chip (`onClick` or ChipGroup) nests interactive elements and warns in dev.
|
|
80
|
+
*/
|
|
81
|
+
onRemove?: React.MouseEventHandler<HTMLButtonElement>;
|
|
82
|
+
/**
|
|
83
|
+
* Accessible label for the remove button. Pass a specific label like
|
|
84
|
+
* `Remove Alice` for context.
|
|
85
|
+
* @default 'Remove'
|
|
86
|
+
*/
|
|
87
|
+
removeLabel?: string;
|
|
60
88
|
/** When inside ChipGroup, identifies this chip for selection tracking */
|
|
61
89
|
value?: OptionValue;
|
|
62
90
|
} & Omit<React.HTMLAttributes<HTMLSpanElement>, "onClick"> & React.RefAttributes<HTMLElement>>;
|
package/components/Chip/Chip.js
CHANGED
|
@@ -5,7 +5,8 @@ import { cx } from '../../utils/cx.js';
|
|
|
5
5
|
import { toKey } from '../../utils/value-key.js';
|
|
6
6
|
import { isDev } from '../../utils/is-dev.js';
|
|
7
7
|
import { useChipGroupContext } from '../ChipGroup/ChipGroupContext.js';
|
|
8
|
-
|
|
8
|
+
import { Icon } from '../Icon/index.js';
|
|
9
|
+
export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, children, size = 'md', theme = 'secondary', variant = 'default', selected: selectedProp, disabled: disabledProp, interactive, className, leftIcon, rightIcon, onClick: onClickProp, onRemove, removeLabel = 'Remove', value, ...rest }, ref) {
|
|
9
10
|
const groupContext = useChipGroupContext();
|
|
10
11
|
// Dev warning: inside ChipGroup without value
|
|
11
12
|
useEffect(() => {
|
|
@@ -13,6 +14,13 @@ export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, c
|
|
|
13
14
|
console.warn('Chip: Inside a ChipGroup but missing `value` prop. This chip will not be managed by the group.');
|
|
14
15
|
}
|
|
15
16
|
}, [groupContext, value]);
|
|
17
|
+
// Dev warning: onRemove nests a <button> — the chip body must not also be
|
|
18
|
+
// interactive, or we produce nested interactive elements (invalid a11y).
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (isDev() && onRemove && (onClickProp || groupContext)) {
|
|
21
|
+
console.warn('Chip: `onRemove` renders a nested <button>; do not combine it with an interactive chip (`onClick` or ChipGroup). Use a display-only chip with `onRemove` for token/tag patterns.');
|
|
22
|
+
}
|
|
23
|
+
}, [onRemove, onClickProp, groupContext]);
|
|
16
24
|
// Derive from group context when applicable
|
|
17
25
|
const isManaged = groupContext !== null && value !== undefined;
|
|
18
26
|
const selected = isManaged ? groupContext.selectedValues.has(toKey(value)) : selectedProp;
|
|
@@ -35,7 +43,7 @@ export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, c
|
|
|
35
43
|
onClick(e);
|
|
36
44
|
}
|
|
37
45
|
}, [isClickable, onClick]);
|
|
38
|
-
const classes = cx('tui-chip', size && `is-size-${size}`, theme && `is-theme-${theme}`, variant !== 'default' && `is-style-${variant}`, selected && 'is-selected', (interactive || isManaged) && 'is-interactive', className);
|
|
46
|
+
const classes = cx('tui-chip', size && `is-size-${size}`, theme && `is-theme-${theme}`, variant !== 'default' && `is-style-${variant}`, selected && 'is-selected', (interactive || isManaged) && 'is-interactive', onRemove && 'has-remove', className);
|
|
39
47
|
const anchorProps = as === 'a'
|
|
40
48
|
? {
|
|
41
49
|
href: disabled || isManaged ? undefined : href ?? '#',
|
|
@@ -60,5 +68,13 @@ export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, c
|
|
|
60
68
|
'aria-disabled': disabled || undefined,
|
|
61
69
|
}
|
|
62
70
|
: {};
|
|
63
|
-
return (_jsxs(Tag, { ref: ref, className: classes, ...anchorProps, ...buttonProps, onClick: disabled ? undefined : onClick, ...rest, children: [leftIcon && leftIcon, children != null && children !== '' && (_jsx("span", { className: "tui-chip__text", children: children })), rightIcon && rightIcon
|
|
71
|
+
return (_jsxs(Tag, { ref: ref, className: classes, ...anchorProps, ...buttonProps, onClick: disabled ? undefined : onClick, ...rest, children: [leftIcon && leftIcon, children != null && children !== '' && (_jsx("span", { className: "tui-chip__text", children: children })), rightIcon && rightIcon, onRemove && (_jsx("button", { type: "button", className: "tui-chip__remove", "aria-label": removeLabel, disabled: disabled, tabIndex: disabled ? -1 : undefined,
|
|
72
|
+
// Stop propagation so removing doesn't trigger any ancestor click
|
|
73
|
+
// (e.g. a token-field wrapper that focuses the input).
|
|
74
|
+
onClick: (e) => {
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
onRemove(e);
|
|
77
|
+
},
|
|
78
|
+
// Keep pointerdown from stealing focus/opening a parent listbox.
|
|
79
|
+
onPointerDown: (e) => e.stopPropagation(), children: _jsx(Icon, { name: "system/close", "aria-hidden": "true" }) }))] }));
|
|
64
80
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComboboxProps, ComboboxContentProps, ComboboxOptionProps, ComboboxGroupProps, ComboboxLabelProps } from './types';
|
|
2
|
-
declare function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, openOnFocus, filterMode, onQueryChange, clearable, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, inputClassName, labels: labelsProp, children, }: ComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, openOnFocus, filterMode, onQueryChange, clearable, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputClassName, labels: labelsProp, children, }: ComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace ComboboxRoot {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
|
@@ -13,7 +13,7 @@ import { defaultComboboxLabels } from './types.js';
|
|
|
13
13
|
// =============================================================================
|
|
14
14
|
// Combobox Root
|
|
15
15
|
// =============================================================================
|
|
16
|
-
function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', openOnFocus = true, filterMode = 'always', onQueryChange, clearable = true, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, inputClassName, labels: labelsProp, children, }) {
|
|
16
|
+
function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', openOnFocus = true, filterMode = 'always', onQueryChange, clearable = true, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputClassName, labels: labelsProp, children, }) {
|
|
17
17
|
const labels = { ...defaultComboboxLabels, ...labelsProp };
|
|
18
18
|
// Controlled/uncontrolled value (initialize from defaultValue)
|
|
19
19
|
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
@@ -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" }) })), _jsx("span", { className: "tui-combobox__icon", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down" }) })] }), 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, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, 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
|
// =============================================================================
|
|
@@ -91,6 +91,19 @@ export type ComboboxProps = {
|
|
|
91
91
|
* ID of element that labels this combobox.
|
|
92
92
|
*/
|
|
93
93
|
'aria-labelledby'?: string;
|
|
94
|
+
/**
|
|
95
|
+
* ID(s) of element(s) that describe this combobox (helper text, error).
|
|
96
|
+
* Forwarded to the input — Field.Control injects this.
|
|
97
|
+
*/
|
|
98
|
+
'aria-describedby'?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Invalid state, forwarded to the input. Field.Control injects this.
|
|
101
|
+
*/
|
|
102
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
103
|
+
/**
|
|
104
|
+
* Required state, forwarded to the input. Field.Control injects this.
|
|
105
|
+
*/
|
|
106
|
+
'aria-required'?: boolean | 'true' | 'false';
|
|
94
107
|
/**
|
|
95
108
|
* Whether to show the clear button when a value is present.
|
|
96
109
|
* @default true
|
|
@@ -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>>;
|