@lt-ui/uikit 0.0.2 → 0.0.3
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/_internal/floating/use-floating.d.ts +1 -1
- package/_internal/floating/use-floating.js +6 -2
- package/cjs/_internal/floating/use-floating.js +6 -2
- package/cjs/image/image-viewer.js +3 -13
- package/cjs/image/image.js +4 -27
- package/cjs/image/use-image-preview.js +32 -0
- package/cjs/image/use-image-viewer.js +21 -0
- package/cjs/modal/modal.js +4 -10
- package/cjs/modal/styles/_animations.css +2 -2
- package/cjs/modal/styles/modal.module.css +7 -2
- package/cjs/modal/use-modal.js +15 -1
- package/cjs/navigation/navigation-compact.js +2 -30
- package/cjs/navigation/navigation-row.js +5 -65
- package/cjs/navigation/navigation-views.js +3 -57
- package/cjs/navigation/styles/navigation.module.css +2 -0
- package/cjs/navigation/use-navigation-flyout.js +39 -0
- package/cjs/navigation/use-navigation-panel-stages.js +23 -0
- package/cjs/navigation/use-navigation-row.js +39 -0
- package/cjs/select/components/select-multiselect-panel.js +9 -67
- package/cjs/select/components/select-option-row.js +7 -53
- package/cjs/select/hooks/use-select-multiselect-panel-layout.js +53 -0
- package/cjs/select/hooks/use-select-option-row.js +23 -0
- package/cjs/select/views/select-view.js +2 -2
- package/cjs/snackbar/snack-view.js +9 -42
- package/cjs/snackbar/use-snack-view.js +16 -0
- package/cjs/tabs/tab-list.js +2 -20
- package/cjs/tabs/tab-panel.js +4 -39
- package/cjs/tabs/use-tab-list-navigation.js +27 -0
- package/cjs/tabs/use-tab-panel.js +12 -0
- package/cjs/time-picker/time-panel.js +2 -47
- package/cjs/time-picker/use-time-column-list.js +48 -0
- package/cjs/tooltip/tooltip.js +1 -1
- package/cjs/tree/tree-row.js +13 -73
- package/cjs/tree/use-tree-row.js +102 -0
- package/cjs/utils/class-names.js +3 -1
- package/image/image-viewer.js +3 -13
- package/image/image.js +5 -28
- package/image/use-image-preview.d.ts +10 -0
- package/image/use-image-preview.js +29 -0
- package/image/use-image-viewer.d.ts +8 -0
- package/image/use-image-viewer.js +18 -0
- package/input/fields/use-text-field.d.ts +2 -0
- package/masked-input/use-mask.d.ts +2 -0
- package/modal/modal.d.ts +1 -0
- package/modal/modal.js +4 -10
- package/modal/styles/_animations.css +2 -2
- package/modal/styles/modal.module.css +7 -2
- package/modal/types.d.ts +5 -0
- package/modal/use-modal.d.ts +3 -1
- package/modal/use-modal.js +17 -3
- package/navigation/navigation-compact.d.ts +1 -2
- package/navigation/navigation-compact.js +3 -31
- package/navigation/navigation-row.d.ts +1 -2
- package/navigation/navigation-row.js +6 -33
- package/navigation/navigation-views.js +3 -24
- package/navigation/styles/navigation.module.css +2 -0
- package/navigation/types.d.ts +1 -0
- package/navigation/use-navigation-flyout.d.ts +9 -0
- package/navigation/use-navigation-flyout.js +36 -0
- package/navigation/use-navigation-panel-stages.d.ts +5 -0
- package/navigation/use-navigation-panel-stages.js +20 -0
- package/navigation/use-navigation-row.d.ts +16 -0
- package/navigation/use-navigation-row.js +36 -0
- package/number-input/use-number-input.d.ts +2 -0
- package/package.json +1 -1
- package/popover/types.d.ts +2 -2
- package/select/components/select-multiselect-panel.d.ts +3 -1
- package/select/components/select-multiselect-panel.js +8 -66
- package/select/components/select-option-row.js +7 -20
- package/select/hooks/use-select-multiselect-panel-layout.d.ts +14 -0
- package/select/hooks/use-select-multiselect-panel-layout.js +49 -0
- package/select/hooks/use-select-option-row.d.ts +13 -0
- package/select/hooks/use-select-option-row.js +20 -0
- package/select/hooks/use-select-view-model.d.ts +1 -1
- package/select/select.d.ts +1 -1
- package/select/types.d.ts +3 -2
- package/select/views/select-view.js +2 -2
- package/snackbar/snack-view.js +7 -7
- package/snackbar/use-snack-view.d.ts +8 -0
- package/snackbar/use-snack-view.js +13 -0
- package/tabs/tab-list.js +4 -22
- package/tabs/tab-panel.js +4 -6
- package/tabs/use-tab-list-navigation.d.ts +2 -0
- package/tabs/use-tab-list-navigation.js +24 -0
- package/tabs/use-tab-panel.d.ts +6 -0
- package/tabs/use-tab-panel.js +9 -0
- package/time-picker/time-panel.js +2 -47
- package/time-picker/use-time-column-list.d.ts +7 -0
- package/time-picker/use-time-column-list.js +45 -0
- package/tooltip/tooltip.js +1 -1
- package/tree/tree-row.js +15 -75
- package/tree/use-tree-row.d.ts +331 -0
- package/tree/use-tree-row.js +99 -0
- package/utils/class-names.d.ts +1 -1
- package/utils/class-names.js +3 -1
|
@@ -1,94 +1,36 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import React, {
|
|
4
|
+
import React, { useMemo, useRef } from 'react';
|
|
5
5
|
import { CHIPS_NAV_ATTR, useChipsNav } from '../../_internal/hooks';
|
|
6
6
|
import { Button } from '../../button';
|
|
7
|
-
import { useIsomorphicLayoutEffect } from '../../hooks/use-isomorphic-layout-effect';
|
|
8
7
|
import { Icon } from '../../icon';
|
|
9
8
|
import { ArrowIcon, DelIcon } from '../../icons';
|
|
10
9
|
import { useLocale } from '../../locale/use-locale';
|
|
10
|
+
import { Typography } from '../../typography';
|
|
11
11
|
import { useAutoScrollToBottom } from '../hooks/use-auto-scroll-to-bottom';
|
|
12
12
|
import { useChipsLayout } from '../hooks/use-chips-row-count';
|
|
13
13
|
import { useSelectVirtual } from '../hooks/use-select-virtual';
|
|
14
|
+
import { useAutoDecideChipsOverflow, useContentAreaHeight, } from '../hooks/use-select-multiselect-panel-layout';
|
|
14
15
|
import styles from '../styles/select.module.css';
|
|
15
16
|
import { getOptionText } from '../utils/filter-options';
|
|
16
17
|
import { getStatusContent } from '../utils/get-status-content';
|
|
17
18
|
import { retainComboboxFocusOnMouseDown } from '../utils/retain-combobox-focus';
|
|
18
19
|
import { SelectOptionList } from './select-option-list';
|
|
19
20
|
import { SelectPanelStatus } from './select-panel-status';
|
|
20
|
-
/**
|
|
21
|
-
* `chipsExpandedMode="auto"`: панель открывается развёрнутой, чтобы измерить реальное число строк
|
|
22
|
-
* (см. `useSelectMultiselectPanelState`), и здесь по факту overflow решает — оставить развёрнутой
|
|
23
|
-
* или свернуть. Решение принимается один раз за сессию открытия, дальше чипсы можно переключать вручную.
|
|
24
|
-
*/
|
|
25
|
-
function useAutoDecideChipsOverflow({ open, chipsExpandedMode, showChipsArea, chipsFullMode, chipsRowCount, chipsNumericMaxRows, onChipsOverflow, }) {
|
|
26
|
-
const autoDecidedRef = useRef(false);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!open) {
|
|
29
|
-
autoDecidedRef.current = false;
|
|
30
|
-
}
|
|
31
|
-
}, [open]);
|
|
32
|
-
useIsomorphicLayoutEffect(() => {
|
|
33
|
-
if (!open || chipsExpandedMode !== 'auto' || autoDecidedRef.current || !showChipsArea) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (chipsFullMode) {
|
|
37
|
-
autoDecidedRef.current = true;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (chipsRowCount === 0) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
autoDecidedRef.current = true;
|
|
44
|
-
if (chipsNumericMaxRows !== undefined && chipsRowCount > chipsNumericMaxRows) {
|
|
45
|
-
onChipsOverflow === null || onChipsOverflow === void 0 ? void 0 : onChipsOverflow();
|
|
46
|
-
}
|
|
47
|
-
}, [
|
|
48
|
-
open,
|
|
49
|
-
chipsExpandedMode,
|
|
50
|
-
showChipsArea,
|
|
51
|
-
chipsFullMode,
|
|
52
|
-
chipsRowCount,
|
|
53
|
-
chipsNumericMaxRows,
|
|
54
|
-
onChipsOverflow,
|
|
55
|
-
]);
|
|
56
|
-
}
|
|
57
|
-
/** Высота области содержимого панели: нужна, чтобы блок чипсов в режиме `'full'` занял всё доступное место */
|
|
58
|
-
function useContentAreaHeight(ref, enabled, remeasureKey) {
|
|
59
|
-
const [height, setHeight] = useState(0);
|
|
60
|
-
useIsomorphicLayoutEffect(() => {
|
|
61
|
-
const contentArea = ref.current;
|
|
62
|
-
if (!enabled || !contentArea) {
|
|
63
|
-
setHeight(0);
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
const measure = () => {
|
|
67
|
-
setHeight(contentArea.clientHeight);
|
|
68
|
-
};
|
|
69
|
-
measure();
|
|
70
|
-
if (typeof ResizeObserver === 'undefined') {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
const observer = new ResizeObserver(measure);
|
|
74
|
-
observer.observe(contentArea);
|
|
75
|
-
return () => observer.disconnect();
|
|
76
|
-
}, [ref, enabled, remeasureKey]);
|
|
77
|
-
return height;
|
|
78
|
-
}
|
|
79
21
|
/** Какие части шапки панели показывать: заголовок с выбранным, блок чипсов или подпись «ничего не выбрано» */
|
|
80
|
-
function getHeaderVisibility(showPanelHeaderEnabled, hasSelection, chipsExpanded) {
|
|
22
|
+
function getHeaderVisibility(showPanelHeaderEnabled, hasSelection, chipsExpanded, chipsEnabled) {
|
|
81
23
|
const showSelectionHeader = showPanelHeaderEnabled && hasSelection;
|
|
82
24
|
return {
|
|
83
25
|
showPanelHeaderEnabled,
|
|
84
26
|
showSelectionHeader,
|
|
85
|
-
showChipsArea: showSelectionHeader && chipsExpanded,
|
|
27
|
+
showChipsArea: showSelectionHeader && chipsExpanded && chipsEnabled,
|
|
86
28
|
showEmptyLabel: showPanelHeaderEnabled && !hasSelection,
|
|
87
29
|
};
|
|
88
30
|
}
|
|
89
31
|
/** Padding-bottom `.chipsArea` (сверху паддинга нет — см. стили) — учитывается в max-height блока чипсов */
|
|
90
32
|
const CHIPS_AREA_VERTICAL_PADDING = 16;
|
|
91
|
-
export function SelectMultiselectPanel({ id, options, chipOptions, value: selectedValues, onUpdate: onSelect, onRemoveChip, onClear, showPanelHeader = true, chipsExpanded, chipsExpandedMode = 'auto', onToggleChips, onChipsOverflow, emptySelectionLabel: emptySelectionLabelProp, selectedCountLabel: selectedCountLabelProp, collapseLabel: collapseLabelProp, clearLabel: clearLabelProp, size = 'l', className, children, open = true, showLoader, showNotFound, showMinCharsHint, notFoundContent, minCharsContent, loadingContent, activeValue, onOptionMouseMove, onListMouseMove, keyboardNavActive, restoreComboboxFocus, maxHeight = 376, chipsMaxRows = 3, mobile = false, searchActive = false, virtualized, }) {
|
|
33
|
+
export function SelectMultiselectPanel({ id, options, chipOptions, value: selectedValues, onUpdate: onSelect, onRemoveChip, onClear, showPanelHeader = true, chipsEnabled = true, chipsExpanded, chipsExpandedMode = 'auto', onToggleChips, onChipsOverflow, emptySelectionLabel: emptySelectionLabelProp, selectedCountLabel: selectedCountLabelProp, collapseLabel: collapseLabelProp, clearLabel: clearLabelProp, size = 'l', className, children, open = true, showLoader, showNotFound, showMinCharsHint, notFoundContent, minCharsContent, loadingContent, activeValue, onOptionMouseMove, onListMouseMove, keyboardNavActive, restoreComboboxFocus, maxHeight = 376, chipsMaxRows = 3, mobile = false, searchActive = false, virtualized, }) {
|
|
92
34
|
const { t } = useLocale();
|
|
93
35
|
const emptySelectionLabel = emptySelectionLabelProp !== null && emptySelectionLabelProp !== void 0 ? emptySelectionLabelProp : t('select.emptySelection');
|
|
94
36
|
const selectedCountLabel = selectedCountLabelProp !== null && selectedCountLabelProp !== void 0 ? selectedCountLabelProp : ((count) => t('select.selectedCount', { count }));
|
|
@@ -120,7 +62,7 @@ export function SelectMultiselectPanel({ id, options, chipOptions, value: select
|
|
|
120
62
|
const onPanelMouseDownCapture = (event) => {
|
|
121
63
|
retainComboboxFocusOnMouseDown(event);
|
|
122
64
|
};
|
|
123
|
-
const { showPanelHeaderEnabled, showSelectionHeader, showChipsArea, showEmptyLabel } = getHeaderVisibility(showPanelHeader !== false, selectedOptions.length > 0, chipsExpanded);
|
|
65
|
+
const { showPanelHeaderEnabled, showSelectionHeader, showChipsArea, showEmptyLabel } = getHeaderVisibility(showPanelHeader !== false, selectedOptions.length > 0, chipsExpanded, chipsEnabled);
|
|
124
66
|
const showStatus = showLoader || showNotFound || showMinCharsHint;
|
|
125
67
|
const statusContent = getStatusContent({
|
|
126
68
|
loading: showLoader,
|
|
@@ -159,5 +101,5 @@ export function SelectMultiselectPanel({ id, options, chipOptions, value: select
|
|
|
159
101
|
return (_jsxs("div", { id: id, ref: panelRef, className: clsx(styles.panel, mobile && styles.panelMobile, !showPanelHeaderEnabled && styles.panelFit, className),
|
|
160
102
|
// С шапкой и чипсами высота фиксирована: при сворачивании чипсов панель не должна прыгать. Без шапки
|
|
161
103
|
// (`chipsVariant="none"`) панель по высоте списка — без пустого места под вариантами
|
|
162
|
-
style: showPanelHeaderEnabled ? { height: maxHeight } : { maxHeight }, onKeyDown: onChipsKeyDown, onMouseDownCapture: onPanelMouseDownCapture, onClickCapture: onPanelClickCapture, children: [showSelectionHeader && (_jsxs("div", { className: clsx(styles.panelHeader, showHeaderDivider && styles.panelHeaderDivider), children: [_jsx(Button, { type: "button", size: "m", variant: "link-secondary", iconRight: _jsx(ArrowIcon, { direction: headerCollapsed ? 'bottom' : 'top' }), tabIndex: -1, [CHIPS_NAV_ATTR]: '', onClick: onToggleChips, children: headerLabel }), _jsx(Button, { type: "button", size: "m", variant: "link-secondary", iconLeft: _jsx(DelIcon, {}), tabIndex: -1, [CHIPS_NAV_ATTR]: '', onClick: onClear, children: clearLabel })] })), _jsxs("div", { ref: contentAreaRef, className: styles.contentArea, children: [showChipsArea && (_jsx("div", { ref: chipsScrollRef, className: clsx(styles.chipsArea, !chipsFullMode && styles.chipsAreaFixed, chipsFullMode && styles.chipsAreaFull, chipsOverflows && styles.chipsAreaScrollable, showChipsDivider && styles.chipsAreaDivider), style: chipsAreaMaxHeight !== undefined ? { maxHeight: chipsAreaMaxHeight } : undefined, children: _jsx("div", { ref: chipsAreaRef, className: styles.chipsRow, children: selectedOptions.map(option => (_jsxs("span", { className: styles.panelChip, children: [_jsx("span", { className: styles.panelChipText, children: getOptionText(option) }), _jsx("button", { type: "button", className: styles.panelChipRemove, tabIndex: -1, [CHIPS_NAV_ATTR]: '', "aria-label": t('select.remove', { label: getOptionText(option) }), onClick: () => onRemoveChip(option.value), children: _jsx(Icon, { size: 16, color: "text-invert", children: _jsx(DelIcon, {}) }) })] }, String(option.value)))) }) })), showEmptyLabel && !showStatus && !searchActive && (_jsx("div", { className: styles.emptySelection, children: emptySelectionLabel })), _jsxs("div", { className: styles.listSection, children: [!showChipsArea && _jsx("div", { className: styles.listPaddingTop }), _jsx("div", { ref: virtual.enabled ? virtual.scrollRef : undefined, className: styles.listWrapFill, children: listContent }), _jsx("div", { className: styles.listPaddingBottom })] })] })] }));
|
|
104
|
+
style: showPanelHeaderEnabled ? { height: maxHeight } : { maxHeight }, onKeyDown: onChipsKeyDown, onMouseDownCapture: onPanelMouseDownCapture, onClickCapture: onPanelClickCapture, children: [showSelectionHeader && (_jsxs("div", { className: clsx(styles.panelHeader, showHeaderDivider && styles.panelHeaderDivider), children: [chipsEnabled ? (_jsx(Button, { type: "button", size: "m", variant: "link-secondary", iconRight: _jsx(ArrowIcon, { direction: headerCollapsed ? 'bottom' : 'top' }), tabIndex: -1, [CHIPS_NAV_ATTR]: '', onClick: onToggleChips, children: headerLabel })) : (_jsx(Typography, { variant: "body-s-compact", color: "text-secondary", children: selectedCountLabel(selectedOptions.length) })), _jsx(Button, { type: "button", size: "m", variant: "link-secondary", iconLeft: _jsx(DelIcon, {}), tabIndex: -1, [CHIPS_NAV_ATTR]: '', onClick: onClear, children: clearLabel })] })), _jsxs("div", { ref: contentAreaRef, className: styles.contentArea, children: [showChipsArea && (_jsx("div", { ref: chipsScrollRef, className: clsx(styles.chipsArea, !chipsFullMode && styles.chipsAreaFixed, chipsFullMode && styles.chipsAreaFull, chipsOverflows && styles.chipsAreaScrollable, showChipsDivider && styles.chipsAreaDivider), style: chipsAreaMaxHeight !== undefined ? { maxHeight: chipsAreaMaxHeight } : undefined, children: _jsx("div", { ref: chipsAreaRef, className: styles.chipsRow, children: selectedOptions.map(option => (_jsxs("span", { className: styles.panelChip, children: [_jsx("span", { className: styles.panelChipText, children: getOptionText(option) }), _jsx("button", { type: "button", className: styles.panelChipRemove, tabIndex: -1, [CHIPS_NAV_ATTR]: '', "aria-label": t('select.remove', { label: getOptionText(option) }), onClick: () => onRemoveChip(option.value), children: _jsx(Icon, { size: 16, color: "text-invert", children: _jsx(DelIcon, {}) }) })] }, String(option.value)))) }) })), showEmptyLabel && !showStatus && !searchActive && (_jsx("div", { className: styles.emptySelection, children: emptySelectionLabel })), _jsxs("div", { className: styles.listSection, children: [!showChipsArea && _jsx("div", { className: styles.listPaddingTop }), _jsx("div", { ref: virtual.enabled ? virtual.scrollRef : undefined, className: styles.listWrapFill, children: listContent }), _jsx("div", { className: styles.listPaddingBottom })] })] })] }));
|
|
163
105
|
}
|
|
@@ -1,37 +1,24 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import React
|
|
4
|
+
import React from 'react';
|
|
5
5
|
import { Icon } from '../../icon';
|
|
6
6
|
import { ListIcon } from '../../list/list-item/list-icon';
|
|
7
7
|
import { Typography } from '../../typography';
|
|
8
8
|
import { useSelectClassNames } from '../class-names-context';
|
|
9
9
|
import styles from '../styles/select.module.css';
|
|
10
10
|
import { getSelectOptionElementId } from '../utils/select-option-id';
|
|
11
|
+
import { useSelectOptionRow } from '../hooks/use-select-option-row';
|
|
11
12
|
export function SelectOptionRow({ value, text, description, selected = false, active = false, disabled = false, showSelectionIcon = true, size = 'l', setSize, posInSet, onSelect, onMouseMove, }) {
|
|
12
13
|
const classNames = useSelectClassNames();
|
|
13
14
|
const iconSize = size === 'm' ? 20 : 24;
|
|
14
15
|
const textVariant = size === 'l' ? 'body-m' : 'body-s';
|
|
15
16
|
const descriptionVariant = size === 'l' ? 'body-m-compact' : 'body-s-compact';
|
|
16
|
-
const onClick =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const onKeyDown = useCallback((event) => {
|
|
22
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
23
|
-
event.preventDefault();
|
|
24
|
-
onClick();
|
|
25
|
-
}
|
|
26
|
-
}, [onClick]);
|
|
27
|
-
const onOptionMouseDown = useCallback((event) => {
|
|
28
|
-
event.preventDefault();
|
|
29
|
-
}, []);
|
|
30
|
-
const onOptionMouseMove = useCallback(() => {
|
|
31
|
-
if (!disabled) {
|
|
32
|
-
onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove();
|
|
33
|
-
}
|
|
34
|
-
}, [disabled, onMouseMove]);
|
|
17
|
+
const { onClick, onKeyDown, onOptionMouseDown, onOptionMouseMove } = useSelectOptionRow({
|
|
18
|
+
disabled,
|
|
19
|
+
onSelect,
|
|
20
|
+
onMouseMove,
|
|
21
|
+
});
|
|
35
22
|
return (_jsxs("li", { "data-lt-ui": "select-option", id: getSelectOptionElementId(value), role: "option", tabIndex: -1, "aria-selected": selected, "aria-disabled": disabled, "aria-setsize": setSize, "aria-posinset": posInSet, className: clsx(styles.optionRow, styles[`optionRow_${size}`], {
|
|
36
23
|
[styles.optionRowDisabled]: disabled,
|
|
37
24
|
[styles.optionRowActive]: active,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { ChipsExpandedMode } from './use-select-multiselect-panel-state';
|
|
3
|
+
type AutoDecideParams = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
chipsExpandedMode: ChipsExpandedMode;
|
|
6
|
+
showChipsArea: boolean;
|
|
7
|
+
chipsFullMode: boolean;
|
|
8
|
+
chipsRowCount: number;
|
|
9
|
+
chipsNumericMaxRows?: number;
|
|
10
|
+
onChipsOverflow?: () => void;
|
|
11
|
+
};
|
|
12
|
+
export declare function useAutoDecideChipsOverflow({ open, chipsExpandedMode, showChipsArea, chipsFullMode, chipsRowCount, chipsNumericMaxRows, onChipsOverflow, }: AutoDecideParams): void;
|
|
13
|
+
export declare function useContentAreaHeight(ref: RefObject<HTMLDivElement | null>, enabled: boolean, remeasureKey: string): number;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useIsomorphicLayoutEffect } from '../../hooks/use-isomorphic-layout-effect';
|
|
4
|
+
export function useAutoDecideChipsOverflow({ open, chipsExpandedMode, showChipsArea, chipsFullMode, chipsRowCount, chipsNumericMaxRows, onChipsOverflow, }) {
|
|
5
|
+
const autoDecidedRef = useRef(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!open)
|
|
8
|
+
autoDecidedRef.current = false;
|
|
9
|
+
}, [open]);
|
|
10
|
+
useIsomorphicLayoutEffect(() => {
|
|
11
|
+
if (!open || chipsExpandedMode !== 'auto' || autoDecidedRef.current || !showChipsArea)
|
|
12
|
+
return;
|
|
13
|
+
if (chipsFullMode) {
|
|
14
|
+
autoDecidedRef.current = true;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (chipsRowCount === 0)
|
|
18
|
+
return;
|
|
19
|
+
autoDecidedRef.current = true;
|
|
20
|
+
if (chipsNumericMaxRows !== undefined && chipsRowCount > chipsNumericMaxRows)
|
|
21
|
+
onChipsOverflow === null || onChipsOverflow === void 0 ? void 0 : onChipsOverflow();
|
|
22
|
+
}, [
|
|
23
|
+
open,
|
|
24
|
+
chipsExpandedMode,
|
|
25
|
+
showChipsArea,
|
|
26
|
+
chipsFullMode,
|
|
27
|
+
chipsRowCount,
|
|
28
|
+
chipsNumericMaxRows,
|
|
29
|
+
onChipsOverflow,
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
export function useContentAreaHeight(ref, enabled, remeasureKey) {
|
|
33
|
+
const [height, setHeight] = useState(0);
|
|
34
|
+
useIsomorphicLayoutEffect(() => {
|
|
35
|
+
const contentArea = ref.current;
|
|
36
|
+
if (!enabled || !contentArea) {
|
|
37
|
+
setHeight(0);
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const measure = () => setHeight(contentArea.clientHeight);
|
|
41
|
+
measure();
|
|
42
|
+
if (typeof ResizeObserver === 'undefined')
|
|
43
|
+
return undefined;
|
|
44
|
+
const observer = new ResizeObserver(measure);
|
|
45
|
+
observer.observe(contentArea);
|
|
46
|
+
return () => observer.disconnect();
|
|
47
|
+
}, [ref, enabled, remeasureKey]);
|
|
48
|
+
return height;
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { KeyboardEvent, MouseEvent } from 'react';
|
|
2
|
+
type Params = {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
onSelect?: () => void;
|
|
5
|
+
onMouseMove?: () => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function useSelectOptionRow({ disabled, onSelect, onMouseMove }: Params): {
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
onKeyDown: (event: KeyboardEvent<HTMLLIElement>) => void;
|
|
10
|
+
onOptionMouseDown: (event: MouseEvent<HTMLLIElement>) => void;
|
|
11
|
+
onOptionMouseMove: () => void;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
export function useSelectOptionRow({ disabled, onSelect, onMouseMove }) {
|
|
4
|
+
const onClick = useCallback(() => {
|
|
5
|
+
if (!disabled)
|
|
6
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect();
|
|
7
|
+
}, [disabled, onSelect]);
|
|
8
|
+
const onKeyDown = useCallback((event) => {
|
|
9
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
10
|
+
return;
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
onClick();
|
|
13
|
+
}, [onClick]);
|
|
14
|
+
const onOptionMouseDown = useCallback((event) => event.preventDefault(), []);
|
|
15
|
+
const onOptionMouseMove = useCallback(() => {
|
|
16
|
+
if (!disabled)
|
|
17
|
+
onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove();
|
|
18
|
+
}, [disabled, onMouseMove]);
|
|
19
|
+
return { onClick, onKeyDown, onOptionMouseDown, onOptionMouseMove };
|
|
20
|
+
}
|
|
@@ -22,7 +22,7 @@ export declare function useSelectViewModel(props: SelectProps, ref: React.Ref<Se
|
|
|
22
22
|
readonly selectedValueText: string | undefined;
|
|
23
23
|
readonly hasValue: boolean;
|
|
24
24
|
readonly popoverClassName: string | undefined;
|
|
25
|
-
readonly dropdownWidth: "content" | "field";
|
|
25
|
+
readonly dropdownWidth: number | "content" | "field";
|
|
26
26
|
readonly placement: import("../..").PopoverPlacement;
|
|
27
27
|
readonly container: import("../..").PortalContainer | undefined;
|
|
28
28
|
readonly children: import("react").ReactNode;
|
package/select/select.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const Select: React.ForwardRefExoticComponent<import("..").DataAt
|
|
|
18
18
|
size?: import("./components/select-field").SelectFieldSize;
|
|
19
19
|
popoverClassName?: string;
|
|
20
20
|
classNames?: import("..").ComponentClassNames<"Select">;
|
|
21
|
-
dropdownWidth?: "field" | "content";
|
|
21
|
+
dropdownWidth?: "field" | "content" | number;
|
|
22
22
|
placement?: import("..").PopoverPlacement;
|
|
23
23
|
children?: React.ReactNode;
|
|
24
24
|
'data-testid'?: string;
|
package/select/types.d.ts
CHANGED
|
@@ -348,10 +348,11 @@ export type SelectProps<T extends ItemValue = ItemValue> = DataAttributes & (Use
|
|
|
348
348
|
/** Свои классы для частей компонента (список — в таблице «Классы» на странице документации) */
|
|
349
349
|
classNames?: ComponentClassNames<'Select'>;
|
|
350
350
|
/**
|
|
351
|
-
* Ширина выпадающей панели: `field` — как у поля, `content` — не уже поля, по самому длинному варианту без
|
|
351
|
+
* Ширина выпадающей панели: `field` — как у поля, `content` — не уже поля, по самому длинному варианту без переноса;
|
|
352
|
+
* число задаёт фиксированную ширину в пикселях (на узком экране панель ограничивается шириной окна).
|
|
352
353
|
* @default 'field'
|
|
353
354
|
*/
|
|
354
|
-
dropdownWidth?: 'field' | 'content';
|
|
355
|
+
dropdownWidth?: 'field' | 'content' | number;
|
|
355
356
|
/**
|
|
356
357
|
* Позиционирование выпадающей панели относительно поля
|
|
357
358
|
* @default 'bottom-start'
|
|
@@ -42,7 +42,7 @@ export function SelectView({ vm }) {
|
|
|
42
42
|
const field = (_jsx(SelectField, { ref: activatorRef, label: label, "aria-label": ariaLabel, startAdornment: startAdornment, placeholder: placeholder, displayValue: fieldDisplayValue, mode: select.mode, multiselectLabels: select.multiselectDisplayLabels, chipsVariant: chipsVariant, open: select.open, disabled: disabled, status: status, theme: theme, filled: hasValue, size: size, variant: variant, fullWidth: fullWidth,
|
|
43
43
|
// В шторке поле только открывает её: запрос вводят в строке поиска шторки, иначе клавиатура закрыла бы список
|
|
44
44
|
showSearch: select.showSearch && !sheet, searchValue: select.searchValue, selectedValueText: selectedValueText, onSearchChange: onSearchChange, onOpen: onOpen, onToggle: onToggle, overflowSelectedLabel: overflowSelectedLabel, allowClear: select.allowClear, onClear: onClear, caption: caption, className: className, listboxId: select.listboxId, controlRef: select.inputRef, activeDescendantId: select.activeOptionId, onComboboxKeyDown: select.onComboboxKeyDown }));
|
|
45
|
-
const panel = isMultiple ? (_jsx(SelectMultiselectPanel, { id: select.listboxId, options: select.listOptions, chipOptions: select.options, searchActive: !!select.searchValue, value: selectedArray, onUpdate: select.handleSelect, onRemoveChip: onRemoveChip, onClear: onClear, showPanelHeader: showPanelHeader, chipsExpanded: multiselectPanel.chipsExpanded, chipsExpandedMode: multiselectPanel.mode, onToggleChips: onToggleChips, onChipsOverflow: onChipsOverflow, emptySelectionLabel: emptySelectionLabel, selectedCountLabel: selectedCountLabel, collapseLabel: collapseLabel, clearLabel: clearLabel, virtualized: virtualized, chipsMaxRows: multiselectChipsMaxRows, size: listSize, open: select.open, showLoader: select.showLoader, showNotFound: select.showNotFound, showMinCharsHint: select.showMinCharsHint, notFoundContent: select.notFoundContent, minCharsContent: select.minCharsContent, loadingContent: select.loadingContent, className: panelClassName, activeValue: select.activeOptionValue, onOptionMouseMove: select.onOptionMouseMove, onListMouseMove: select.onListMouseMove, keyboardNavActive: select.keyboardNavActive, restoreComboboxFocus: select.restoreComboboxFocus, maxHeight: sheet ? SHEET_MULTISELECT_HEIGHT : dropdownMaxHeight, mobile: sheet, children: children })) : (_jsx(SelectSinglePanel, { id: select.listboxId, selectionMode: "single", value: select.selectedValues, onUpdate: select.handleSelect, options: select.listOptions, size: listSize, open: select.open, showNotFound: select.showNotFound, showMinCharsHint: select.showMinCharsHint, notFoundContent: select.notFoundContent, minCharsContent: select.minCharsContent, loadingContent: select.loadingContent, loading: select.loading, fetching: fetching, maxHeight: sheet ? 'none' : dropdownMaxHeight, virtualized: virtualized, onListScroll: onListScroll, activeValue: select.activeOptionValue, onOptionMouseMove: select.onOptionMouseMove, onListMouseMove: select.onListMouseMove, keyboardNavActive: select.keyboardNavActive, className: panelClassName, mobile: sheet, children: children }));
|
|
45
|
+
const panel = isMultiple ? (_jsx(SelectMultiselectPanel, { id: select.listboxId, options: select.listOptions, chipOptions: select.options, searchActive: !!select.searchValue, value: selectedArray, onUpdate: select.handleSelect, onRemoveChip: onRemoveChip, onClear: onClear, showPanelHeader: showPanelHeader, chipsEnabled: chipsVariant === 'inside', chipsExpanded: multiselectPanel.chipsExpanded, chipsExpandedMode: multiselectPanel.mode, onToggleChips: onToggleChips, onChipsOverflow: onChipsOverflow, emptySelectionLabel: emptySelectionLabel, selectedCountLabel: selectedCountLabel, collapseLabel: collapseLabel, clearLabel: clearLabel, virtualized: virtualized, chipsMaxRows: multiselectChipsMaxRows, size: listSize, open: select.open, showLoader: select.showLoader, showNotFound: select.showNotFound, showMinCharsHint: select.showMinCharsHint, notFoundContent: select.notFoundContent, minCharsContent: select.minCharsContent, loadingContent: select.loadingContent, className: panelClassName, activeValue: select.activeOptionValue, onOptionMouseMove: select.onOptionMouseMove, onListMouseMove: select.onListMouseMove, keyboardNavActive: select.keyboardNavActive, restoreComboboxFocus: select.restoreComboboxFocus, maxHeight: sheet ? SHEET_MULTISELECT_HEIGHT : dropdownMaxHeight, mobile: sheet, children: children })) : (_jsx(SelectSinglePanel, { id: select.listboxId, selectionMode: "single", value: select.selectedValues, onUpdate: select.handleSelect, options: select.listOptions, size: listSize, open: select.open, showNotFound: select.showNotFound, showMinCharsHint: select.showMinCharsHint, notFoundContent: select.notFoundContent, minCharsContent: select.minCharsContent, loadingContent: select.loadingContent, loading: select.loading, fetching: fetching, maxHeight: sheet ? 'none' : dropdownMaxHeight, virtualized: virtualized, onListScroll: onListScroll, activeValue: select.activeOptionValue, onOptionMouseMove: select.onOptionMouseMove, onListMouseMove: select.onListMouseMove, keyboardNavActive: select.keyboardNavActive, className: panelClassName, mobile: sheet, children: children }));
|
|
46
46
|
// Нет ни вариантов, ни статуса (загрузка, «ничего не найдено», подсказка): пустую панель не показываем
|
|
47
47
|
const hasNoPanelContent = !isMultiple &&
|
|
48
48
|
select.listOptions.length === 0 &&
|
|
@@ -60,5 +60,5 @@ export function SelectView({ vm }) {
|
|
|
60
60
|
return (_jsx("div", { ref: select.containerRef, ...vm.dataProps, "data-testid": testId, "data-lt-ui": "select", className: clsx(viewStyles.root, fullWidth && viewStyles.rootFullWidth), children: _jsx(Popover, { "data-testid": getRelatedTestId(testId, 'popup'), anchor: field, open: select.open && !hasNoPanelContent, onOpenChange: open => {
|
|
61
61
|
if (!open)
|
|
62
62
|
onPopoverClose();
|
|
63
|
-
}, trigger: "manual", layer: false, returnFocus: false, arrow: false, matchWidth: dropdownWidth === 'content' ? 'min' : true, placement: placement, offset: 4, container: container, className: viewStyles.selectPopover, children: _jsx("div", { ref: popupRef, role: "presentation", children: panel }) }) }));
|
|
63
|
+
}, trigger: "manual", layer: false, returnFocus: false, arrow: false, matchWidth: dropdownWidth === 'content' ? 'min' : dropdownWidth === 'field' ? true : dropdownWidth, placement: placement, offset: 4, container: container, className: viewStyles.selectPopover, children: _jsx("div", { ref: popupRef, role: "presentation", children: panel }) }) }));
|
|
64
64
|
}
|
package/snackbar/snack-view.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import React
|
|
4
|
+
import React from 'react';
|
|
5
5
|
import { CollapseBox } from '../_internal/collapse-box';
|
|
6
6
|
import { contextProvider, withRef } from '../_internal/compat';
|
|
7
|
-
import { useControllableState } from '../_internal/hooks';
|
|
8
7
|
import { useUniqID } from '../hooks';
|
|
9
8
|
import { Icon } from '../icon';
|
|
10
9
|
import { ArrowIcon } from '../icons';
|
|
@@ -12,6 +11,7 @@ import { useLocale } from '../locale/use-locale';
|
|
|
12
11
|
import { useOppositeTheme, useThemeAttribute } from '../theme-provider/theme-context';
|
|
13
12
|
import { useClassNames } from '../utils';
|
|
14
13
|
import styles from './styles/snack.module.css';
|
|
14
|
+
import { useSnackViewState } from './use-snack-view';
|
|
15
15
|
export const SnackViewContext = React.createContext({});
|
|
16
16
|
const SnackViewProvider = contextProvider(SnackViewContext);
|
|
17
17
|
/** Заливки, цвет текста на которых — `text-invert`: на них схема обратна окружению */
|
|
@@ -36,10 +36,11 @@ export const SnackView = withRef(function SnackView({ className, classNames: cla
|
|
|
36
36
|
const classNames = useClassNames('Snack', classNamesProp);
|
|
37
37
|
const { t } = useLocale();
|
|
38
38
|
const detailsId = useUniqID(5, 'snack-details');
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const { expanded, setExpanded, contextValue } = useSnackViewState({
|
|
40
|
+
variant,
|
|
41
|
+
expanded: expandedProp,
|
|
42
|
+
defaultExpanded,
|
|
43
|
+
onExpandedChange,
|
|
43
44
|
});
|
|
44
45
|
const hasText = header || paragraph;
|
|
45
46
|
const snackClassName = clsx(styles.snack, styles[variant], classNames.root, className);
|
|
@@ -47,7 +48,6 @@ export const SnackView = withRef(function SnackView({ className, classNames: cla
|
|
|
47
48
|
const haveButtonsInHeader = closeButton || (!wideButton && haveChildren);
|
|
48
49
|
const haveButtonsInFooter = haveChildren && (wideButton || closeButton);
|
|
49
50
|
const expandable = expandedContent != null && expandedContent !== false;
|
|
50
|
-
const contextValue = useMemo(() => ({ variant }), [variant]);
|
|
51
51
|
// Заливки с цветом текста `text-invert`: кнопки на них берут схему, обратную окружению (текст остаётся ambient)
|
|
52
52
|
const opposite = useOppositeTheme();
|
|
53
53
|
// Жёлтая заливка одинакова в обеих схемах: кнопки на ней всегда в светлой
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SnackViewProps } from './types';
|
|
2
|
+
export declare function useSnackViewState(props: Pick<SnackViewProps, 'variant' | 'expanded' | 'defaultExpanded' | 'onExpandedChange'>): {
|
|
3
|
+
expanded: boolean;
|
|
4
|
+
setExpanded: (next: boolean) => void;
|
|
5
|
+
contextValue: {
|
|
6
|
+
variant: import("./types").SnackVariant | undefined;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useControllableState } from '../_internal/hooks';
|
|
4
|
+
export function useSnackViewState(props) {
|
|
5
|
+
const { variant, expanded: expandedProp, defaultExpanded, onExpandedChange } = props;
|
|
6
|
+
const [expanded, setExpanded] = useControllableState({
|
|
7
|
+
value: expandedProp,
|
|
8
|
+
defaultValue: defaultExpanded !== null && defaultExpanded !== void 0 ? defaultExpanded : false,
|
|
9
|
+
onChange: onExpandedChange,
|
|
10
|
+
});
|
|
11
|
+
const contextValue = useMemo(() => ({ variant }), [variant]);
|
|
12
|
+
return { expanded, setExpanded, contextValue };
|
|
13
|
+
}
|
package/tabs/tab-list.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React, { useContext
|
|
3
|
+
import React, { useContext } from 'react';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useThemeAttribute } from '../theme-provider/theme-context';
|
|
6
|
-
import { ListNavigationContext
|
|
6
|
+
import { ListNavigationContext } from '../hooks';
|
|
7
7
|
import { TabsContext } from './context';
|
|
8
8
|
import { useTabs } from './use-tabs';
|
|
9
|
+
import { useTabListNavigation } from './use-tab-list-navigation';
|
|
9
10
|
import styles from './styles/tab-list.module.css';
|
|
10
11
|
import { contextProvider, withRef } from '../_internal/compat';
|
|
11
12
|
const ListNavigationProvider = contextProvider(ListNavigationContext);
|
|
@@ -26,27 +27,8 @@ const StandaloneList = withRef(function StandaloneList(props, ref) {
|
|
|
26
27
|
return (_jsx(TabsProvider, { value: context, children: _jsx(TabListView, { ...rest, context: context, ref: ref }) }));
|
|
27
28
|
});
|
|
28
29
|
const TabListView = withRef(function TabListView({ context, align = 'start', className, children, theme, ...rest }, ref) {
|
|
29
|
-
const { value, activation, select, getTabId, valueById } = context;
|
|
30
30
|
const themeAttribute = useThemeAttribute(theme);
|
|
31
|
-
const navigation =
|
|
32
|
-
mode: 'focus',
|
|
33
|
-
tabStop: 'single',
|
|
34
|
-
orientation: 'horizontal',
|
|
35
|
-
defaultActiveId: value === undefined ? undefined : getTabId(value),
|
|
36
|
-
onActiveChange: (id, reason) => {
|
|
37
|
-
if (activation !== 'auto' || reason !== 'keyboard' || id === null)
|
|
38
|
-
return;
|
|
39
|
-
const next = valueById.get(id);
|
|
40
|
-
if (next !== undefined && next !== value)
|
|
41
|
-
select(next);
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
// Выбранная снаружи вкладка становится точкой входа в список
|
|
45
|
-
const { api } = navigation;
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (value !== undefined)
|
|
48
|
-
api.setActive(getTabId(value), 'api');
|
|
49
|
-
}, [value, api, getTabId]);
|
|
31
|
+
const navigation = useTabListNavigation(context);
|
|
50
32
|
return (_jsx("div", { role: "tablist", "aria-orientation": "horizontal", ...rest, ...navigation.rootProps, ref: ref, className: clsx(styles.tabList, styles[align], styles[context.variant], context.divider && context.variant === 'line' && styles.divider, context.classNames.list, className), "data-lt-ui-theme": themeAttribute, "data-lt-ui": "tab-list", children: _jsx(ListNavigationProvider, { value: navigation.context, children: children }) }));
|
|
51
33
|
});
|
|
52
34
|
/**
|
package/tabs/tab-panel.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
-
import { useTabsContext } from './context';
|
|
6
5
|
import styles from './styles/tab-panel.module.css';
|
|
7
6
|
import { withRef } from '../_internal/compat';
|
|
7
|
+
import { useTabPanel } from './use-tab-panel';
|
|
8
8
|
/**
|
|
9
9
|
* `<TabPanel />` — содержимое вкладки. Скрыта, пока вкладка не выбрана; размонтируется, если не задан `keepMounted`.
|
|
10
10
|
*/
|
|
11
11
|
export const TabPanel = withRef(function TabPanel({ value, keepMounted = false, className, children, ...rest }, ref) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
useEffect(() => registerPanel(value), [registerPanel, value]);
|
|
15
|
-
return (_jsx("div", { role: "tabpanel", tabIndex: selected ? 0 : -1, ...rest, ref: ref, id: getPanelId(value), "aria-labelledby": getTabId(value), hidden: !selected, className: clsx(styles.panel, classNames.panel, className), "data-lt-ui": "tab-panel", children: selected || keepMounted ? children : null }));
|
|
12
|
+
const { selected, tabId, panelId, classNames } = useTabPanel(value);
|
|
13
|
+
return (_jsx("div", { role: "tabpanel", tabIndex: selected ? 0 : -1, ...rest, ref: ref, id: panelId, "aria-labelledby": tabId, hidden: !selected, className: clsx(styles.panel, classNames.panel, className), "data-lt-ui": "tab-panel", children: selected || keepMounted ? children : null }));
|
|
16
14
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useListNavigation } from '../hooks';
|
|
4
|
+
export function useTabListNavigation(context) {
|
|
5
|
+
const { value, activation, select, getTabId, valueById } = context;
|
|
6
|
+
const navigation = useListNavigation({
|
|
7
|
+
mode: 'focus',
|
|
8
|
+
tabStop: 'single',
|
|
9
|
+
orientation: 'horizontal',
|
|
10
|
+
defaultActiveId: value === undefined ? undefined : getTabId(value),
|
|
11
|
+
onActiveChange: (id, reason) => {
|
|
12
|
+
if (activation !== 'auto' || reason !== 'keyboard' || id === null)
|
|
13
|
+
return;
|
|
14
|
+
const next = valueById.get(id);
|
|
15
|
+
if (next !== undefined && next !== value)
|
|
16
|
+
select(next);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (value !== undefined)
|
|
21
|
+
navigation.api.setActive(getTabId(value), 'api');
|
|
22
|
+
}, [value, navigation.api, getTabId]);
|
|
23
|
+
return navigation;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useTabsContext } from './context';
|
|
4
|
+
export function useTabPanel(value) {
|
|
5
|
+
const { value: selectedValue, getTabId, getPanelId, registerPanel, classNames, } = useTabsContext('TabPanel');
|
|
6
|
+
const selected = selectedValue === value;
|
|
7
|
+
useEffect(() => registerPanel(value), [registerPanel, value]);
|
|
8
|
+
return { selected, tabId: getTabId(value), panelId: getPanelId(value), classNames };
|
|
9
|
+
}
|
|
@@ -1,61 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import { useEffect, useRef } from 'react';
|
|
5
4
|
import { withRef } from '../_internal/compat';
|
|
6
5
|
import { useUniqID } from '../hooks';
|
|
7
6
|
import { useLocale } from '../locale/use-locale';
|
|
8
7
|
import { getDataAttributes } from '../utils/data-attributes';
|
|
9
8
|
import styles from './styles.module.css';
|
|
10
9
|
import { useTimePanel } from './use-time-panel';
|
|
10
|
+
import { useTimeColumnList } from './use-time-column-list';
|
|
11
11
|
/** Одна колонка: список вариантов с блуждающим фокусом; стрелки двигают фокус и сразу выбирают значение */
|
|
12
12
|
function TimeColumnList({ column, label, onSelect }) {
|
|
13
|
-
const listRef =
|
|
14
|
-
const selectedIndex = column.options.findIndex(option => option.selected);
|
|
15
|
-
const firstEnabled = column.options.findIndex(option => !option.disabled);
|
|
16
|
-
const rovingIndex = selectedIndex !== -1 ? selectedIndex : Math.max(firstEnabled, 0);
|
|
17
|
-
// Выбранный вариант держим в видимой части колонки, строки целиком: он становится третьим сверху,
|
|
18
|
-
// а колонка прокручивается кратно высоте строки (сверху и снизу нет «обрезанных» вариантов).
|
|
19
|
-
// Первый показ — сразу, без анимации. Дальше, если вариант уже виден целиком, колонка стоит на месте
|
|
20
|
-
// (клик по видимому значению ничего не двигает), иначе плавно подъезжает к нужной строке
|
|
21
|
-
const placed = useRef(false);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
const list = listRef.current;
|
|
24
|
-
// Без выбранного значения показываем первый доступный вариант (например, начало рабочих часов)
|
|
25
|
-
const target = list === null || list === void 0 ? void 0 : list.querySelectorAll('[role="option"]')[rovingIndex];
|
|
26
|
-
if (!list || !target)
|
|
27
|
-
return;
|
|
28
|
-
const gap = Number.parseFloat(getComputedStyle(list).rowGap) || 0;
|
|
29
|
-
const top = target.offsetTop - 2 * (target.offsetHeight + gap);
|
|
30
|
-
const first = !placed.current;
|
|
31
|
-
placed.current = true;
|
|
32
|
-
const visible = target.offsetTop >= list.scrollTop &&
|
|
33
|
-
target.offsetTop + target.offsetHeight <= list.scrollTop + list.clientHeight;
|
|
34
|
-
if (!first && visible)
|
|
35
|
-
return;
|
|
36
|
-
const calm = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
37
|
-
if (first || calm || typeof list.scrollTo !== 'function')
|
|
38
|
-
list.scrollTop = top;
|
|
39
|
-
else
|
|
40
|
-
list.scrollTo({ top, behavior: 'smooth' });
|
|
41
|
-
}, [rovingIndex]);
|
|
42
|
-
const onKeyDown = (event) => {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
const step = { ArrowDown: 1, ArrowUp: -1 }[event.key];
|
|
45
|
-
const edge = { Home: 0, End: column.options.length - 1 }[event.key];
|
|
46
|
-
if (step === undefined && edge === undefined)
|
|
47
|
-
return;
|
|
48
|
-
event.preventDefault();
|
|
49
|
-
let index = step === undefined ? edge : rovingIndex + step;
|
|
50
|
-
const direction = step !== null && step !== void 0 ? step : (edge === 0 ? 1 : -1);
|
|
51
|
-
while (index >= 0 && index < column.options.length && column.options[index].disabled)
|
|
52
|
-
index += direction;
|
|
53
|
-
if (index < 0 || index >= column.options.length)
|
|
54
|
-
return;
|
|
55
|
-
onSelect(column.options[index].value);
|
|
56
|
-
const options = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="option"]');
|
|
57
|
-
(_b = options === null || options === void 0 ? void 0 : options[index]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
58
|
-
};
|
|
13
|
+
const { listRef, rovingIndex, onKeyDown } = useTimeColumnList(column, onSelect);
|
|
59
14
|
return (_jsx("div", { ref: listRef, role: "listbox", "aria-label": label, className: styles.column, onKeyDown: onKeyDown, children: column.options.map((option, index) => (_jsx("button", { type: "button", role: "option", className: clsx(styles.option, option.selected && styles.selected), "aria-selected": option.selected, disabled: option.disabled, tabIndex: index === rovingIndex ? 0 : -1, onClick: () => onSelect(option.value), children: option.label }, option.value))) }));
|
|
60
15
|
}
|
|
61
16
|
/**
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
import type { TimeColumn } from './time-model';
|
|
3
|
+
export declare function useTimeColumnList(column: TimeColumn, onSelect: (value: number) => void): {
|
|
4
|
+
listRef: import("react").RefObject<HTMLDivElement | null>;
|
|
5
|
+
rovingIndex: number;
|
|
6
|
+
onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;
|
|
7
|
+
};
|