@mezzanine-ui/react 1.0.0-beta.5 → 1.0.0-beta.7
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/Accordion/Accordion.d.ts +23 -1
- package/Accordion/Accordion.js +59 -11
- package/Accordion/AccordionActions.d.ts +13 -0
- package/Accordion/AccordionActions.js +24 -0
- package/Accordion/AccordionContent.d.ts +9 -0
- package/Accordion/{AccordionDetails.js → AccordionContent.js} +4 -6
- package/Accordion/AccordionControlContext.d.ts +2 -2
- package/Accordion/AccordionGroup.d.ts +10 -0
- package/Accordion/AccordionGroup.js +26 -0
- package/Accordion/AccordionTitle.d.ts +14 -0
- package/Accordion/AccordionTitle.js +56 -0
- package/Accordion/index.d.ts +8 -4
- package/Accordion/index.js +4 -2
- package/AutoComplete/AutoComplete.d.ts +25 -6
- package/AutoComplete/AutoComplete.js +119 -30
- package/Backdrop/Backdrop.js +15 -19
- package/Breadcrumb/BreadcrumbDropdown.js +1 -1
- package/Breadcrumb/BreadcrumbItem.js +1 -1
- package/Breadcrumb/BreadcrumbOverflowMenuItem.js +1 -1
- package/Calendar/CalendarDays.js +1 -1
- package/Card/BaseCard.d.ts +11 -0
- package/Card/BaseCard.js +48 -0
- package/Card/BaseCardSkeleton.d.ts +14 -0
- package/Card/BaseCardSkeleton.js +18 -0
- package/Card/CardGroup.d.ts +47 -0
- package/Card/CardGroup.js +147 -0
- package/Card/FourThumbnailCard.d.ts +14 -0
- package/Card/FourThumbnailCard.js +73 -0
- package/Card/FourThumbnailCardSkeleton.d.ts +14 -0
- package/Card/FourThumbnailCardSkeleton.js +20 -0
- package/Card/QuickActionCard.d.ts +12 -0
- package/Card/QuickActionCard.js +23 -0
- package/Card/QuickActionCardSkeleton.d.ts +14 -0
- package/Card/QuickActionCardSkeleton.js +18 -0
- package/Card/SingleThumbnailCard.d.ts +13 -0
- package/Card/SingleThumbnailCard.js +44 -0
- package/Card/SingleThumbnailCardSkeleton.d.ts +19 -0
- package/Card/SingleThumbnailCardSkeleton.js +18 -0
- package/Card/Thumbnail.d.ts +12 -0
- package/Card/Thumbnail.js +18 -0
- package/Card/ThumbnailCardInfo.d.ts +34 -0
- package/Card/ThumbnailCardInfo.js +43 -0
- package/Card/index.d.ts +43 -4
- package/Card/index.js +19 -2
- package/Card/typings.d.ts +442 -0
- package/Checkbox/Checkbox.d.ts +8 -0
- package/Checkbox/Checkbox.js +3 -2
- package/Checkbox/CheckboxGroup.js +1 -1
- package/ContentHeader/ContentHeader.d.ts +22 -70
- package/ContentHeader/ContentHeader.js +1 -1
- package/ContentHeader/ContentHeaderResponsive.d.ts +9 -0
- package/ContentHeader/ContentHeaderResponsive.js +7 -0
- package/ContentHeader/utils.d.ts +3 -3
- package/ContentHeader/utils.js +66 -20
- package/Cropper/Cropper.d.ts +66 -0
- package/Cropper/Cropper.js +115 -0
- package/Cropper/CropperElement.d.ts +10 -0
- package/Cropper/CropperElement.js +892 -0
- package/Cropper/index.d.ts +18 -0
- package/Cropper/index.js +8 -0
- package/Cropper/tools.d.ts +90 -0
- package/Cropper/tools.js +143 -0
- package/Cropper/typings.d.ts +69 -0
- package/Cropper/utils/cropper-calculations.d.ts +39 -0
- package/Cropper/utils/cropper-calculations.js +95 -0
- package/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.js +22 -5
- package/DateTimeRangePicker/DateTimeRangePicker.d.ts +34 -0
- package/DateTimeRangePicker/DateTimeRangePicker.js +118 -0
- package/DateTimeRangePicker/index.d.ts +2 -0
- package/DateTimeRangePicker/index.js +1 -0
- package/Drawer/Drawer.d.ts +132 -1
- package/Drawer/Drawer.js +47 -3
- package/Dropdown/Dropdown.d.ts +10 -4
- package/Dropdown/Dropdown.js +37 -42
- package/Dropdown/DropdownItem.d.ts +7 -1
- package/Dropdown/DropdownItem.js +36 -6
- package/Dropdown/DropdownItemCard.js +2 -1
- package/FloatingButton/FloatingButton.d.ts +21 -0
- package/FloatingButton/FloatingButton.js +18 -0
- package/FloatingButton/index.d.ts +2 -0
- package/FloatingButton/index.js +1 -0
- package/Form/FormField.d.ts +30 -7
- package/Form/FormField.js +12 -4
- package/Input/Input.js +12 -21
- package/Input/SelectButton/SelectButton.d.ts +25 -4
- package/Input/SelectButton/SelectButton.js +21 -9
- package/Message/Message.js +1 -1
- package/Modal/MediaPreviewModal.d.ts +11 -0
- package/Modal/MediaPreviewModal.js +24 -7
- package/Modal/Modal.d.ts +1 -1
- package/Modal/Modal.js +1 -1
- package/Modal/useModalContainer.js +6 -2
- package/MultipleDatePicker/MultipleDatePicker.d.ts +62 -0
- package/MultipleDatePicker/MultipleDatePicker.js +176 -0
- package/MultipleDatePicker/MultipleDatePickerTrigger.d.ts +56 -0
- package/MultipleDatePicker/MultipleDatePickerTrigger.js +92 -0
- package/MultipleDatePicker/index.d.ts +6 -0
- package/MultipleDatePicker/index.js +3 -0
- package/MultipleDatePicker/useMultipleDatePickerValue.d.ts +55 -0
- package/MultipleDatePicker/useMultipleDatePickerValue.js +68 -0
- package/Navigation/NavigationHeader.js +1 -1
- package/NotificationCenter/NotificationCenterDrawer.d.ts +10 -52
- package/NotificationCenter/NotificationCenterDrawer.js +128 -0
- package/NotificationCenter/index.d.ts +2 -0
- package/NotificationCenter/index.js +1 -0
- package/OverflowTooltip/index.d.ts +2 -2
- package/Picker/FormattedInput.d.ts +1 -1
- package/Picker/FormattedInput.js +2 -1
- package/Picker/PickerTriggerWithSeparator.d.ts +10 -0
- package/Picker/PickerTriggerWithSeparator.js +2 -2
- package/Picker/RangePickerTrigger.js +1 -1
- package/Picker/useDateInputFormatter.d.ts +6 -0
- package/Picker/useDateInputFormatter.js +4 -1
- package/Section/Section.d.ts +32 -0
- package/Section/Section.js +62 -0
- package/Section/index.d.ts +2 -0
- package/Select/Select.d.ts +11 -12
- package/Select/Select.js +13 -34
- package/Select/SelectTrigger.js +21 -7
- package/Select/index.d.ts +0 -4
- package/Select/index.js +0 -2
- package/Select/typings.d.ts +0 -4
- package/Select/useSelectTriggerTags.d.ts +1 -1
- package/Select/useSelectTriggerTags.js +9 -6
- package/Separator/Separator.d.ts +14 -0
- package/Separator/Separator.js +17 -0
- package/Separator/index.d.ts +2 -0
- package/Separator/index.js +1 -0
- package/Table/utils/useTableRowSelection.js +6 -0
- package/Tag/TagGroup.d.ts +4 -2
- package/Tag/TagGroup.js +7 -4
- package/TextField/TextField.d.ts +1 -1
- package/TextField/TextField.js +63 -9
- package/TimePanel/TimePanelColumn.js +30 -21
- package/TimeRangePicker/TimeRangePicker.d.ts +29 -0
- package/TimeRangePicker/TimeRangePicker.js +96 -0
- package/TimeRangePicker/index.d.ts +3 -0
- package/TimeRangePicker/index.js +2 -0
- package/TimeRangePicker/useTimeRangePickerValue.d.ts +30 -0
- package/TimeRangePicker/useTimeRangePickerValue.js +92 -0
- package/Transition/Rotate.js +2 -5
- package/index.d.ts +30 -28
- package/index.js +26 -27
- package/package.json +4 -4
- package/Accordion/AccordionDetails.d.ts +0 -9
- package/Accordion/AccordionSummary.d.ts +0 -18
- package/Accordion/AccordionSummary.js +0 -51
- package/Alert/Alert.d.ts +0 -20
- package/Alert/Alert.js +0 -18
- package/Alert/index.d.ts +0 -3
- package/Alert/index.js +0 -1
- package/AppBar/AppBar.d.ts +0 -14
- package/AppBar/AppBar.js +0 -33
- package/AppBar/AppBarBrand.d.ts +0 -4
- package/AppBar/AppBarBrand.js +0 -11
- package/AppBar/AppBarMain.d.ts +0 -4
- package/AppBar/AppBarMain.js +0 -11
- package/AppBar/AppBarSupport.d.ts +0 -4
- package/AppBar/AppBarSupport.js +0 -11
- package/AppBar/index.d.ts +0 -8
- package/AppBar/index.js +0 -4
- package/Card/Card.d.ts +0 -51
- package/Card/Card.js +0 -20
- package/Card/CardActions.d.ts +0 -34
- package/Card/CardActions.js +0 -15
- package/ConfirmActions/ConfirmActions.d.ts +0 -46
- package/ConfirmActions/ConfirmActions.js +0 -15
- package/ConfirmActions/index.d.ts +0 -2
- package/ConfirmActions/index.js +0 -1
- package/Popconfirm/Popconfirm.d.ts +0 -16
- package/Popconfirm/Popconfirm.js +0 -15
- package/Popconfirm/index.d.ts +0 -2
- package/Popconfirm/index.js +0 -1
- package/Popover/Popover.d.ts +0 -23
- package/Popover/Popover.js +0 -35
- package/Popover/index.d.ts +0 -2
- package/Popover/index.js +0 -1
- package/Select/Option.d.ts +0 -18
- package/Select/Option.js +0 -45
- package/Select/TreeSelect.d.ts +0 -67
- package/Select/TreeSelect.js +0 -198
- package/Tree/Tree.d.ts +0 -70
- package/Tree/Tree.js +0 -139
- package/Tree/TreeNode.d.ts +0 -40
- package/Tree/TreeNode.js +0 -50
- package/Tree/TreeNodeList.d.ts +0 -24
- package/Tree/TreeNodeList.js +0 -28
- package/Tree/getTreeNodeEntities.d.ts +0 -11
- package/Tree/getTreeNodeEntities.js +0 -92
- package/Tree/index.d.ts +0 -13
- package/Tree/index.js +0 -7
- package/Tree/toggleValue.d.ts +0 -4
- package/Tree/toggleValue.js +0 -19
- package/Tree/traverseTree.d.ts +0 -2
- package/Tree/traverseTree.js +0 -11
- package/Tree/typings.d.ts +0 -16
- package/Tree/useTreeExpandedValue.d.ts +0 -14
- package/Tree/useTreeExpandedValue.js +0 -33
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useState, useRef, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
3
2
|
import { selectClasses } from '@mezzanine-ui/core/select';
|
|
3
|
+
import { useState, useRef, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
4
4
|
import Tag from '../Tag/Tag.js';
|
|
5
5
|
|
|
6
6
|
const fakeTagClassName = 'mzn-select-trigger__fake-tag';
|
|
@@ -16,22 +16,25 @@ function useSelectTriggerTags(props) {
|
|
|
16
16
|
const { containerRef, tagsRef, value = [], size, enabled = false } = props;
|
|
17
17
|
const [takeCount, setTakeCount] = useState(value.length);
|
|
18
18
|
const fakeContainerRef = useRef(null);
|
|
19
|
+
const updateTakeCount = useCallback((nextCount) => {
|
|
20
|
+
setTakeCount((prevCount) => prevCount === nextCount ? prevCount : nextCount);
|
|
21
|
+
}, []);
|
|
19
22
|
const measure = useCallback(() => {
|
|
20
23
|
var _a, _b;
|
|
21
24
|
if (!enabled) {
|
|
22
|
-
|
|
25
|
+
updateTakeCount(value.length);
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
25
28
|
const container = (_a = containerRef.current) !== null && _a !== void 0 ? _a : tagsRef.current;
|
|
26
29
|
const fakeContainer = fakeContainerRef.current;
|
|
27
30
|
if (!container || !fakeContainer) {
|
|
28
|
-
|
|
31
|
+
// Keep current takeCount when refs are temporarily unavailable to avoid flicker.
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
34
|
const fakeTags = Array.from(fakeContainer.getElementsByClassName(fakeTagClassName));
|
|
32
35
|
const fakeEllipsis = fakeContainer.getElementsByClassName(fakeEllipsisClassName)[0];
|
|
33
36
|
if (!fakeTags.length) {
|
|
34
|
-
|
|
37
|
+
// Keep current takeCount until fake tags are ready in DOM.
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
37
40
|
const computedStyleTarget = (_b = tagsRef.current) !== null && _b !== void 0 ? _b : container;
|
|
@@ -56,8 +59,8 @@ function useSelectTriggerTags(props) {
|
|
|
56
59
|
consumedWidth += tagWidth;
|
|
57
60
|
nextCount = i + 1;
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
}, [containerRef, enabled, tagsRef, value.length]);
|
|
62
|
+
updateTakeCount(nextCount);
|
|
63
|
+
}, [containerRef, enabled, tagsRef, updateTakeCount, value.length]);
|
|
61
64
|
useLayoutEffect(() => {
|
|
62
65
|
measure();
|
|
63
66
|
}, [value, size, enabled, measure]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SeparatorOrientation } from '@mezzanine-ui/core/separator';
|
|
2
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
3
|
+
export interface SeparatorProps extends NativeElementPropsWithoutKeyAndRef<'hr'> {
|
|
4
|
+
/**
|
|
5
|
+
* The orientation of the separator.
|
|
6
|
+
* @default 'horizontal'
|
|
7
|
+
*/
|
|
8
|
+
orientation?: SeparatorOrientation;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The react component for `mezzanine` separator.
|
|
12
|
+
*/
|
|
13
|
+
declare const Separator: import("react").ForwardRefExoticComponent<SeparatorProps & import("react").RefAttributes<HTMLHRElement>>;
|
|
14
|
+
export default Separator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { separatorClasses } from '@mezzanine-ui/core/separator';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import cx from 'clsx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The react component for `mezzanine` separator.
|
|
8
|
+
*/
|
|
9
|
+
const Separator = forwardRef(function Separator(props, ref) {
|
|
10
|
+
const { className, orientation = 'horizontal', ...rest } = props;
|
|
11
|
+
return (jsx("hr", { ...rest, "aria-orientation": orientation === 'vertical' ? 'vertical' : undefined, ref: ref, className: cx(separatorClasses.host, {
|
|
12
|
+
[separatorClasses.horizontal]: orientation === 'horizontal',
|
|
13
|
+
[separatorClasses.vertical]: orientation === 'vertical',
|
|
14
|
+
}, className) }));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { Separator as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Separator.js';
|
|
@@ -20,6 +20,12 @@ function useTableRowSelection(props) {
|
|
|
20
20
|
? subData.map((subRow) => getRowKey(subRow))
|
|
21
21
|
: undefined;
|
|
22
22
|
}
|
|
23
|
+
if (!selectedRow) {
|
|
24
|
+
// trigger select all or deselect all, need to find subKeys for all selected rows
|
|
25
|
+
return (subData === null || subData === void 0 ? void 0 : subData.length)
|
|
26
|
+
? subData.map((subRow) => getRowKey(subRow))
|
|
27
|
+
: undefined;
|
|
28
|
+
}
|
|
23
29
|
return (_a = prev.find((item) => item.key === pk)) === null || _a === void 0 ? void 0 : _a.subKeys;
|
|
24
30
|
})();
|
|
25
31
|
return {
|
package/Tag/TagGroup.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
3
|
-
import Tag, { TagProps } from '../Tag';
|
|
4
2
|
import OverflowCounterTag, { OverflowCounterTagProps } from '../OverflowTooltip/OverflowCounterTag';
|
|
3
|
+
import Tag, { TagProps } from '../Tag';
|
|
4
|
+
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
5
5
|
import { TransitionImplementationChildProps } from '../Transition';
|
|
6
6
|
type TagElement = ReactElement<TagProps & TransitionImplementationChildProps, typeof Tag>;
|
|
7
7
|
type OverflowCounterTagElement = ReactElement<OverflowCounterTagProps & TransitionImplementationChildProps, typeof OverflowCounterTag>;
|
|
8
8
|
type TagGroupChild = TagElement | OverflowCounterTagElement;
|
|
9
9
|
export type TagGroupProps = Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'children'> & {
|
|
10
10
|
children: TagGroupChild | TagGroupChild[];
|
|
11
|
+
transition?: 'fade' | 'none';
|
|
11
12
|
};
|
|
12
13
|
declare const TagGroup: import("react").ForwardRefExoticComponent<Omit<NativeElementPropsWithoutKeyAndRef<"div">, "children"> & {
|
|
13
14
|
children: TagGroupChild | TagGroupChild[];
|
|
15
|
+
transition?: "fade" | "none";
|
|
14
16
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
15
17
|
export default TagGroup;
|
package/Tag/TagGroup.js
CHANGED
|
@@ -2,8 +2,8 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { forwardRef, Children, isValidElement, createElement } from 'react';
|
|
3
3
|
import OverflowCounterTag from '../OverflowTooltip/OverflowCounterTag.js';
|
|
4
4
|
import { tagClasses } from '@mezzanine-ui/core/tag';
|
|
5
|
-
import { TransitionGroup } from 'react-transition-group';
|
|
6
5
|
import { MOTION_EASING, MOTION_DURATION } from '@mezzanine-ui/system/motion';
|
|
6
|
+
import { TransitionGroup } from 'react-transition-group';
|
|
7
7
|
import Fade from '../Transition/Fade.js';
|
|
8
8
|
import Tag from './Tag.js';
|
|
9
9
|
import cx from 'clsx';
|
|
@@ -20,7 +20,7 @@ const fadeProps = {
|
|
|
20
20
|
exit: MOTION_EASING.standard,
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
|
-
const TagGroup = forwardRef(function TagGroup({ className, children, ...rest }, ref) {
|
|
23
|
+
const TagGroup = forwardRef(function TagGroup({ className, children, transition = 'none', ...rest }, ref) {
|
|
24
24
|
const hasInvalidChild = Children.toArray(children).some((child) => {
|
|
25
25
|
if (!isTagElement(child) && !isOverflowCounterElement(child)) {
|
|
26
26
|
console.error('<TagGroup> only accepts <Tag> or <OverflowCounterTag>');
|
|
@@ -31,11 +31,14 @@ const TagGroup = forwardRef(function TagGroup({ className, children, ...rest },
|
|
|
31
31
|
if (hasInvalidChild) {
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
|
-
return (jsx("div", { ...rest, ref: ref, className: cx(tagClasses.group, className), children: jsx(TransitionGroup, { component: null, children: Children.map(children, (child, index) => {
|
|
34
|
+
return (jsx("div", { ...rest, ref: ref, className: cx(tagClasses.group, className), children: transition === 'fade' ? (jsx(TransitionGroup, { component: null, children: Children.map(children, (child, index) => {
|
|
35
35
|
var _a;
|
|
36
36
|
return (createElement(Fade, { ...fadeProps, key: (_a = child.key) !== null && _a !== void 0 ? _a : index },
|
|
37
37
|
jsx("span", { children: child })));
|
|
38
|
-
}) })
|
|
38
|
+
}) })) : (Children.map(children, (child, index) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return (jsx("span", { children: child }, (_a = child.key) !== null && _a !== void 0 ? _a : index));
|
|
41
|
+
})) }));
|
|
39
42
|
});
|
|
40
43
|
|
|
41
44
|
export { TagGroup as default };
|
package/TextField/TextField.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MouseEventHandler, ReactNode } from 'react';
|
|
2
1
|
import { TextFieldSize } from '@mezzanine-ui/core/text-field';
|
|
2
|
+
import { MouseEventHandler, ReactNode } from 'react';
|
|
3
3
|
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
|
|
4
4
|
/**
|
|
5
5
|
* Padding info provided to children function
|
package/TextField/TextField.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { forwardRef, useState, useRef, useEffect } from 'react';
|
|
4
3
|
import { textFieldClasses } from '@mezzanine-ui/core/text-field';
|
|
5
|
-
import {
|
|
4
|
+
import { forwardRef, useState, useRef, useEffect } from 'react';
|
|
6
5
|
import ClearActions from '../ClearActions/ClearActions.js';
|
|
7
6
|
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
7
|
+
import { useTextFieldControl } from './useTextFieldControl.js';
|
|
8
8
|
import cx from 'clsx';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -13,7 +13,11 @@ import cx from 'clsx';
|
|
|
13
13
|
const TextField = forwardRef(function TextField(props, ref) {
|
|
14
14
|
const { active = false, children, className, clearable = false, disabled, error = false, fullWidth = true, onClear, onClick: onClickProps, onKeyDown: onKeyDownProps, prefix, readonly, role: roleProp, size = 'main', suffix, typing: typingProp, warning, ...rest } = props;
|
|
15
15
|
const [isTyping, setIsTyping] = useState(false);
|
|
16
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
17
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
18
|
+
const [hasValue, setHasValue] = useState(false);
|
|
16
19
|
const containerRef = useRef(null);
|
|
20
|
+
const checkValueRef = useRef(null);
|
|
17
21
|
const hostRef = useComposeRefs([ref, containerRef]);
|
|
18
22
|
const typing = disabled || readonly
|
|
19
23
|
? false
|
|
@@ -21,27 +25,67 @@ const TextField = forwardRef(function TextField(props, ref) {
|
|
|
21
25
|
? typingProp
|
|
22
26
|
: isTyping;
|
|
23
27
|
useEffect(() => {
|
|
24
|
-
if (typingProp !== undefined || disabled || readonly)
|
|
25
|
-
return;
|
|
26
28
|
const container = containerRef.current;
|
|
27
29
|
if (!container)
|
|
28
30
|
return;
|
|
29
31
|
const input = container.querySelector('input, textarea');
|
|
30
32
|
if (!input)
|
|
31
33
|
return;
|
|
34
|
+
const checkValue = () => {
|
|
35
|
+
// 檢查值是否為空(包括空字符串和只有空白字符)
|
|
36
|
+
const value = (input.value || '').trim();
|
|
37
|
+
setHasValue(value.length > 0);
|
|
38
|
+
};
|
|
39
|
+
// 保存 checkValue 函數到 ref,以便在 onClear 後可以立即調用
|
|
40
|
+
checkValueRef.current = checkValue;
|
|
32
41
|
const handleInput = () => {
|
|
33
42
|
setIsTyping(true);
|
|
43
|
+
checkValue();
|
|
44
|
+
};
|
|
45
|
+
const handleFocus = () => {
|
|
46
|
+
setIsFocused(true);
|
|
47
|
+
checkValue();
|
|
34
48
|
};
|
|
35
49
|
const handleBlur = () => {
|
|
36
50
|
setIsTyping(false);
|
|
51
|
+
setIsFocused(false);
|
|
52
|
+
checkValue();
|
|
53
|
+
};
|
|
54
|
+
const handleMouseEnter = () => {
|
|
55
|
+
checkValue(); // 在 hover 時也檢查值,確保狀態正確
|
|
56
|
+
setIsHovered(true);
|
|
57
|
+
};
|
|
58
|
+
const handleMouseLeave = () => {
|
|
59
|
+
setIsHovered(false);
|
|
37
60
|
};
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
// 初始化檢查值
|
|
62
|
+
checkValue();
|
|
63
|
+
// 監聽輸入框事件(用於 typing 狀態)
|
|
64
|
+
if (typingProp === undefined && !disabled && !readonly) {
|
|
65
|
+
input.addEventListener('input', handleInput, false);
|
|
66
|
+
input.addEventListener('mousedown', handleInput, false);
|
|
67
|
+
}
|
|
68
|
+
// 監聽 focus/blur 事件
|
|
69
|
+
input.addEventListener('focus', handleFocus, false);
|
|
40
70
|
input.addEventListener('blur', handleBlur, false);
|
|
71
|
+
// 監聽 hover 事件(在容器上)
|
|
72
|
+
container.addEventListener('mouseenter', handleMouseEnter, false);
|
|
73
|
+
container.addEventListener('mouseleave', handleMouseLeave, false);
|
|
74
|
+
// 監聽值變化(適用於受控組件)
|
|
75
|
+
input.addEventListener('input', checkValue, false);
|
|
76
|
+
input.addEventListener('change', checkValue, false);
|
|
41
77
|
return () => {
|
|
42
|
-
|
|
43
|
-
|
|
78
|
+
if (typingProp === undefined && !disabled && !readonly) {
|
|
79
|
+
input.removeEventListener('input', handleInput, false);
|
|
80
|
+
input.removeEventListener('mousedown', handleInput, false);
|
|
81
|
+
}
|
|
82
|
+
input.removeEventListener('focus', handleFocus, false);
|
|
44
83
|
input.removeEventListener('blur', handleBlur, false);
|
|
84
|
+
container.removeEventListener('mouseenter', handleMouseEnter, false);
|
|
85
|
+
container.removeEventListener('mouseleave', handleMouseLeave, false);
|
|
86
|
+
input.removeEventListener('input', checkValue, false);
|
|
87
|
+
input.removeEventListener('change', checkValue, false);
|
|
88
|
+
checkValueRef.current = null;
|
|
45
89
|
};
|
|
46
90
|
}, [typingProp, disabled, readonly]);
|
|
47
91
|
const { role, onClick, onKeyDown } = useTextFieldControl({
|
|
@@ -49,6 +93,9 @@ const TextField = forwardRef(function TextField(props, ref) {
|
|
|
49
93
|
onKeyDown: onKeyDownProps,
|
|
50
94
|
});
|
|
51
95
|
const isChildrenFunction = typeof children === 'function';
|
|
96
|
+
const shouldShowClearable = clearable &&
|
|
97
|
+
hasValue &&
|
|
98
|
+
(isHovered || typing || isFocused);
|
|
52
99
|
const paddingInfo = {
|
|
53
100
|
paddingClassName: cx(textFieldClasses.inputPadding, size === 'main' ? textFieldClasses.inputPaddingMain : textFieldClasses.inputPaddingSub),
|
|
54
101
|
};
|
|
@@ -71,9 +118,16 @@ const TextField = forwardRef(function TextField(props, ref) {
|
|
|
71
118
|
[textFieldClasses.typing]: typing,
|
|
72
119
|
[textFieldClasses.active]: active,
|
|
73
120
|
[textFieldClasses.warning]: warning,
|
|
74
|
-
}, className), children: [prefix && jsx("div", { className: textFieldClasses.prefix, children: prefix }), renderedChildren, clearable && (jsx(ClearActions, { type: "clearable", className: textFieldClasses.clearIcon,
|
|
121
|
+
}, className), children: [prefix && jsx("div", { className: textFieldClasses.prefix, children: prefix }), renderedChildren, clearable && (jsx(ClearActions, { type: "clearable", className: textFieldClasses.clearIcon, style: {
|
|
122
|
+
opacity: shouldShowClearable ? 1 : 0,
|
|
123
|
+
pointerEvents: shouldShowClearable ? 'auto' : 'none',
|
|
124
|
+
}, onClick: (event) => {
|
|
75
125
|
if (!disabled && !readonly && onClear) {
|
|
76
126
|
onClear(event);
|
|
127
|
+
requestAnimationFrame(() => {
|
|
128
|
+
var _a;
|
|
129
|
+
(_a = checkValueRef.current) === null || _a === void 0 ? void 0 : _a.call(checkValueRef);
|
|
130
|
+
});
|
|
77
131
|
}
|
|
78
132
|
}, onMouseDown: (event) => event.preventDefault(), tabIndex: -1 })), suffix && jsx("div", { className: textFieldClasses.suffix, children: suffix })] }));
|
|
79
133
|
});
|
|
@@ -1,35 +1,44 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { timePanelClasses } from '@mezzanine-ui/core/time-panel';
|
|
3
|
-
import { forwardRef, useRef, useEffect } from 'react';
|
|
3
|
+
import { forwardRef, useRef, useCallback, useEffect } from 'react';
|
|
4
|
+
import { getNumericCSSVariablePixelValue } from '../utils/get-css-variable-value.js';
|
|
5
|
+
import Scrollbar from '../Scrollbar/Scrollbar.js';
|
|
4
6
|
import cx from 'clsx';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* The react component for `mezzanine` time panel column.
|
|
8
10
|
*/
|
|
9
11
|
const TimePanelColumn = forwardRef(function TimePanelColumn(props, ref) {
|
|
10
|
-
const { activeUnit, cellHeight
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
onChange(unit);
|
|
17
|
-
};
|
|
18
|
-
};
|
|
12
|
+
const { activeUnit, cellHeight: cellHeightProp, onChange, units } = props;
|
|
13
|
+
const cellHeight = cellHeightProp !== null && cellHeightProp !== void 0 ? cellHeightProp : getNumericCSSVariablePixelValue('--mzn-spacing-size-element-loose');
|
|
14
|
+
const viewportRef = useRef(null);
|
|
15
|
+
const getChangeHandler = useCallback((unit) => () => {
|
|
16
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(unit);
|
|
17
|
+
}, [onChange]);
|
|
19
18
|
const preferSmoothScrollRef = useRef(true);
|
|
20
|
-
|
|
19
|
+
const onScrollToTarget = useCallback((element) => {
|
|
21
20
|
const activeIndex = units.findIndex(({ value }) => value === activeUnit);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
}
|
|
21
|
+
element.scrollTo({
|
|
22
|
+
behavior: preferSmoothScrollRef.current ? 'auto' : 'smooth',
|
|
23
|
+
top: activeIndex * cellHeight,
|
|
24
|
+
});
|
|
28
25
|
preferSmoothScrollRef.current = false;
|
|
29
26
|
}, [activeUnit, cellHeight, units]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (viewportRef.current) {
|
|
29
|
+
onScrollToTarget(viewportRef.current);
|
|
30
|
+
}
|
|
31
|
+
}, [onScrollToTarget]);
|
|
32
|
+
const handleViewportReady = useCallback((viewport) => {
|
|
33
|
+
viewportRef.current = viewport;
|
|
34
|
+
onScrollToTarget(viewport);
|
|
35
|
+
}, [onScrollToTarget]);
|
|
36
|
+
// Number of padding cells needed for centering (3 cells above and below the center position)
|
|
37
|
+
const paddingCellCount = 3;
|
|
38
|
+
const placeholders = Array.from({ length: paddingCellCount }, (_, i) => (jsx("div", { className: timePanelClasses.columnPlaceholder, style: { height: cellHeight }, "aria-hidden": true }, `placeholder-${i}`)));
|
|
39
|
+
return (jsx("div", { ref: ref, className: timePanelClasses.column, children: jsxs(Scrollbar, { maxHeight: cellHeight * 7, onViewportReady: handleViewportReady, children: [placeholders, units.map((unit) => (jsx("button", { type: "button", className: cx(timePanelClasses.button, timePanelClasses.columnButton, {
|
|
40
|
+
[timePanelClasses.buttonActive]: unit.value === activeUnit,
|
|
41
|
+
}), onClick: getChangeHandler(unit), children: unit.label }, unit.value))), placeholders] }) }));
|
|
33
42
|
});
|
|
34
43
|
|
|
35
44
|
export { TimePanelColumn as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RangePickerTriggerProps } from '../Picker';
|
|
2
|
+
import { TimeRangePickerValue } from './useTimeRangePickerValue';
|
|
3
|
+
import { TimePickerPanelProps } from '../TimePicker/TimePickerPanel';
|
|
4
|
+
export interface TimeRangePickerProps extends Pick<TimePickerPanelProps, 'fadeProps' | 'hideHour' | 'hideMinute' | 'hideSecond' | 'hourStep' | 'minuteStep' | 'popperProps' | 'secondStep'>, Pick<RangePickerTriggerProps, 'className' | 'clearable' | 'disabled' | 'error' | 'errorMessagesFrom' | 'errorMessagesTo' | 'fullWidth' | 'inputFromPlaceholder' | 'inputFromProps' | 'inputToPlaceholder' | 'inputToProps' | 'prefix' | 'readOnly' | 'required' | 'size' | 'validateFrom' | 'validateTo'> {
|
|
5
|
+
/**
|
|
6
|
+
* The format for displaying time.
|
|
7
|
+
* @default 'HH:mm:ss' or 'HH:mm' based on hideSecond
|
|
8
|
+
*/
|
|
9
|
+
format?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A function that fires when panel toggle. Receive open status in boolean format as props.
|
|
12
|
+
*/
|
|
13
|
+
onPanelToggle?: (open: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Change handler. Takes an array of your declared `DateType` which represents from and to in order.
|
|
16
|
+
*/
|
|
17
|
+
onChange?: (target?: TimeRangePickerValue) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Value of the range picker.
|
|
20
|
+
* It is an array of your declared `DateType` which represents from and to in order.
|
|
21
|
+
*/
|
|
22
|
+
value?: TimeRangePickerValue;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The react component for `mezzanine` time range picker.
|
|
26
|
+
* Notice that any component related to time-range-picker should be used along with `CalendarContext`.
|
|
27
|
+
*/
|
|
28
|
+
declare const TimeRangePicker: import("react").ForwardRefExoticComponent<TimeRangePickerProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
29
|
+
export default TimeRangePicker;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef, useState, useCallback, useRef, useMemo } from 'react';
|
|
4
|
+
import { ClockIcon } from '@mezzanine-ui/icons';
|
|
5
|
+
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
6
|
+
import { useTimeRangePickerValue } from './useTimeRangePickerValue.js';
|
|
7
|
+
import TimePickerPanel from '../TimePicker/TimePickerPanel.js';
|
|
8
|
+
import { useCalendarContext } from '../Calendar/CalendarContext.js';
|
|
9
|
+
import { usePickerDocumentEventClose } from '../Picker/usePickerDocumentEventClose.js';
|
|
10
|
+
import Icon from '../Icon/Icon.js';
|
|
11
|
+
import RangePickerTrigger from '../Picker/RangePickerTrigger.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The react component for `mezzanine` time range picker.
|
|
15
|
+
* Notice that any component related to time-range-picker should be used along with `CalendarContext`.
|
|
16
|
+
*/
|
|
17
|
+
const TimeRangePicker = forwardRef(function TimeRangePicker(props, ref) {
|
|
18
|
+
const { defaultTimeFormat } = useCalendarContext();
|
|
19
|
+
const { className, clearable = true, disabled = false, error = false, errorMessagesFrom, errorMessagesTo, fadeProps, format: formatProp, fullWidth = false, hideHour, hideMinute, hideSecond, hourStep, inputFromPlaceholder, inputFromProps, inputToPlaceholder, inputToProps, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, popperProps, prefix, readOnly, required = false, secondStep, size, validateFrom, validateTo, value: valueProp, } = props;
|
|
20
|
+
// Determine default format based on hideSecond
|
|
21
|
+
const resolvedFormat = formatProp !== null && formatProp !== void 0 ? formatProp : (hideSecond ? 'HH:mm' : defaultTimeFormat);
|
|
22
|
+
/** Panel open control */
|
|
23
|
+
const [open, setOpen] = useState(false);
|
|
24
|
+
const preventOpen = readOnly;
|
|
25
|
+
const onPanelToggle = useCallback((nextOpen) => {
|
|
26
|
+
if (!preventOpen) {
|
|
27
|
+
setOpen(nextOpen);
|
|
28
|
+
onPanelToggleProp === null || onPanelToggleProp === void 0 ? void 0 : onPanelToggleProp(nextOpen);
|
|
29
|
+
}
|
|
30
|
+
}, [onPanelToggleProp, preventOpen]);
|
|
31
|
+
/** Values and onChange */
|
|
32
|
+
const inputToRef = useRef(null);
|
|
33
|
+
const inputFromRef = useRef(null);
|
|
34
|
+
const { focusedInput, inputFromValue, inputToValue, onChange, onClear, onFromFocus, onInputFromChange, onInputToChange, onPanelChange, onToFocus, panelValue, value: internalValue, } = useTimeRangePickerValue({
|
|
35
|
+
format: resolvedFormat,
|
|
36
|
+
onChange: onChangeProp,
|
|
37
|
+
value: valueProp,
|
|
38
|
+
});
|
|
39
|
+
/** Popper settings */
|
|
40
|
+
const anchorRef = useRef(null);
|
|
41
|
+
const panelRef = useRef(null);
|
|
42
|
+
const triggerComposedRef = useComposeRefs([anchorRef, ref]);
|
|
43
|
+
/** Dynamic anchor for panel - follows the focused input */
|
|
44
|
+
const panelAnchor = useMemo(() => {
|
|
45
|
+
if (focusedInput === 'from') {
|
|
46
|
+
return inputFromRef;
|
|
47
|
+
}
|
|
48
|
+
if (focusedInput === 'to') {
|
|
49
|
+
return inputToRef;
|
|
50
|
+
}
|
|
51
|
+
return inputFromRef;
|
|
52
|
+
}, [focusedInput]);
|
|
53
|
+
/** Input focus handlers */
|
|
54
|
+
const onFromFocusHandler = useCallback((_event) => {
|
|
55
|
+
onFromFocus();
|
|
56
|
+
onPanelToggle(true);
|
|
57
|
+
}, [onPanelToggle, onFromFocus]);
|
|
58
|
+
const onToFocusHandler = useCallback((_event) => {
|
|
59
|
+
onToFocus();
|
|
60
|
+
onPanelToggle(true);
|
|
61
|
+
}, [onPanelToggle, onToFocus]);
|
|
62
|
+
/** Icon click handler */
|
|
63
|
+
const onIconClick = useCallback((e) => {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
if (open) {
|
|
66
|
+
onChange(valueProp);
|
|
67
|
+
}
|
|
68
|
+
onPanelToggle(!open);
|
|
69
|
+
}, [open, onChange, onPanelToggle, valueProp]);
|
|
70
|
+
/** Clear handler */
|
|
71
|
+
const onClearHandler = useCallback(() => {
|
|
72
|
+
onClear();
|
|
73
|
+
}, [onClear]);
|
|
74
|
+
/** Close handlers */
|
|
75
|
+
const onClose = useCallback(() => {
|
|
76
|
+
onChange(valueProp);
|
|
77
|
+
onPanelToggle(false);
|
|
78
|
+
}, [onChange, onPanelToggle, valueProp]);
|
|
79
|
+
const onChangeClose = useCallback(() => {
|
|
80
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(internalValue);
|
|
81
|
+
onPanelToggle(false);
|
|
82
|
+
}, [internalValue, onChangeProp, onPanelToggle]);
|
|
83
|
+
usePickerDocumentEventClose({
|
|
84
|
+
anchorRef,
|
|
85
|
+
lastElementRefInFlow: inputToRef,
|
|
86
|
+
onChangeClose,
|
|
87
|
+
onClose,
|
|
88
|
+
open,
|
|
89
|
+
popperRef: panelRef,
|
|
90
|
+
});
|
|
91
|
+
/** Suffix icon */
|
|
92
|
+
const suffixIcon = (jsx(Icon, { "aria-label": "Open time picker", icon: ClockIcon, onClick: readOnly ? undefined : onIconClick }));
|
|
93
|
+
return (jsxs(Fragment, { children: [jsx(RangePickerTrigger, { className: className, clearable: clearable, disabled: disabled, error: error, errorMessagesFrom: errorMessagesFrom, errorMessagesTo: errorMessagesTo, format: resolvedFormat, fullWidth: fullWidth, inputFromPlaceholder: inputFromPlaceholder, inputFromProps: inputFromProps, inputFromRef: inputFromRef, inputFromValue: inputFromValue, inputToPlaceholder: inputToPlaceholder, inputToProps: inputToProps, inputToRef: inputToRef, inputToValue: inputToValue, onClear: onClearHandler, onFromFocus: onFromFocusHandler, onIconClick: onIconClick, onInputFromChange: onInputFromChange, onInputToChange: onInputToChange, onToFocus: onToFocusHandler, prefix: prefix, readOnly: readOnly, ref: triggerComposedRef, required: required, size: size, suffixActionIcon: suffixIcon, validateFrom: validateFrom, validateTo: validateTo }), focusedInput && (jsx(TimePickerPanel, { anchor: panelAnchor, fadeProps: fadeProps, hideHour: hideHour, hideMinute: hideMinute, hideSecond: hideSecond, hourStep: hourStep, minuteStep: minuteStep, onChange: onPanelChange, open: open, popperProps: popperProps, ref: panelRef, secondStep: secondStep, value: panelValue }))] }));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export { TimeRangePicker as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DateType } from '@mezzanine-ui/core/calendar';
|
|
2
|
+
export type TimeRangePickerValue = [DateType | undefined, DateType | undefined];
|
|
3
|
+
export interface UseTimeRangePickerValueProps {
|
|
4
|
+
/**
|
|
5
|
+
* The format pattern for the inputs (e.g., "HH:mm:ss")
|
|
6
|
+
*/
|
|
7
|
+
format: string;
|
|
8
|
+
/**
|
|
9
|
+
* Change handler called when value changes
|
|
10
|
+
*/
|
|
11
|
+
onChange?: (value?: TimeRangePickerValue) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Controlled value
|
|
14
|
+
*/
|
|
15
|
+
value?: TimeRangePickerValue;
|
|
16
|
+
}
|
|
17
|
+
export declare function useTimeRangePickerValue({ format, onChange: onChangeProp, value: valueProp, }: UseTimeRangePickerValueProps): {
|
|
18
|
+
focusedInput: "from" | "to" | null;
|
|
19
|
+
inputFromValue: string;
|
|
20
|
+
inputToValue: string;
|
|
21
|
+
onChange: (target?: TimeRangePickerValue) => TimeRangePickerValue | undefined;
|
|
22
|
+
onClear: () => void;
|
|
23
|
+
onFromFocus: () => void;
|
|
24
|
+
onInputFromChange: (formattedValue: string | undefined) => void;
|
|
25
|
+
onInputToChange: (formattedValue: string | undefined) => void;
|
|
26
|
+
onPanelChange: (newTime: DateType | undefined) => void;
|
|
27
|
+
onToFocus: () => void;
|
|
28
|
+
panelValue: string | undefined;
|
|
29
|
+
value: TimeRangePickerValue;
|
|
30
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState, useCallback } from 'react';
|
|
3
|
+
import { useCalendarContext } from '../Calendar/CalendarContext.js';
|
|
4
|
+
|
|
5
|
+
function useTimeRangePickerValue({ format, onChange: onChangeProp, value: valueProp, }) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const { formatToString, locale } = useCalendarContext();
|
|
8
|
+
const [internalFrom, setInternalFrom] = useState(valueProp === null || valueProp === void 0 ? void 0 : valueProp[0]);
|
|
9
|
+
const [internalTo, setInternalTo] = useState(valueProp === null || valueProp === void 0 ? void 0 : valueProp[1]);
|
|
10
|
+
// Track which input is focused: 'from' | 'to' | null
|
|
11
|
+
const [focusedInput, setFocusedInput] = useState(null);
|
|
12
|
+
const from = (_a = valueProp === null || valueProp === void 0 ? void 0 : valueProp[0]) !== null && _a !== void 0 ? _a : internalFrom;
|
|
13
|
+
const to = (_b = valueProp === null || valueProp === void 0 ? void 0 : valueProp[1]) !== null && _b !== void 0 ? _b : internalTo;
|
|
14
|
+
const value = [from, to];
|
|
15
|
+
const formatTime = useCallback((time) => {
|
|
16
|
+
if (!time)
|
|
17
|
+
return '';
|
|
18
|
+
return formatToString(locale, time, format);
|
|
19
|
+
}, [formatToString, locale, format]);
|
|
20
|
+
const inputFromValue = formatTime(from);
|
|
21
|
+
const inputToValue = formatTime(to);
|
|
22
|
+
const onInputFromChange = useCallback((formattedValue) => {
|
|
23
|
+
if (formattedValue) {
|
|
24
|
+
setInternalFrom(formattedValue);
|
|
25
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([formattedValue, to]);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setInternalFrom(undefined);
|
|
29
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([undefined, to]);
|
|
30
|
+
}
|
|
31
|
+
}, [to, onChangeProp]);
|
|
32
|
+
const onInputToChange = useCallback((formattedValue) => {
|
|
33
|
+
if (formattedValue) {
|
|
34
|
+
setInternalTo(formattedValue);
|
|
35
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([from, formattedValue]);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
setInternalTo(undefined);
|
|
39
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([from, undefined]);
|
|
40
|
+
}
|
|
41
|
+
}, [from, onChangeProp]);
|
|
42
|
+
const onPanelChange = useCallback((newTime) => {
|
|
43
|
+
if (focusedInput === 'from') {
|
|
44
|
+
setInternalFrom(newTime);
|
|
45
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([newTime, to]);
|
|
46
|
+
}
|
|
47
|
+
else if (focusedInput === 'to') {
|
|
48
|
+
setInternalTo(newTime);
|
|
49
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([from, newTime]);
|
|
50
|
+
}
|
|
51
|
+
}, [focusedInput, from, to, onChangeProp]);
|
|
52
|
+
const onChange = useCallback((target) => {
|
|
53
|
+
if (!target) {
|
|
54
|
+
setInternalFrom(undefined);
|
|
55
|
+
setInternalTo(undefined);
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const [newFrom, newTo] = target;
|
|
59
|
+
setInternalFrom(newFrom);
|
|
60
|
+
setInternalTo(newTo);
|
|
61
|
+
return target;
|
|
62
|
+
}, []);
|
|
63
|
+
const onClear = useCallback(() => {
|
|
64
|
+
setInternalFrom(undefined);
|
|
65
|
+
setInternalTo(undefined);
|
|
66
|
+
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(undefined);
|
|
67
|
+
}, [onChangeProp]);
|
|
68
|
+
const onFromFocus = useCallback(() => {
|
|
69
|
+
setFocusedInput('from');
|
|
70
|
+
}, []);
|
|
71
|
+
const onToFocus = useCallback(() => {
|
|
72
|
+
setFocusedInput('to');
|
|
73
|
+
}, []);
|
|
74
|
+
// Get the currently focused value for the panel
|
|
75
|
+
const panelValue = focusedInput === 'from' ? from : focusedInput === 'to' ? to : undefined;
|
|
76
|
+
return {
|
|
77
|
+
focusedInput,
|
|
78
|
+
inputFromValue,
|
|
79
|
+
inputToValue,
|
|
80
|
+
onChange,
|
|
81
|
+
onClear,
|
|
82
|
+
onFromFocus,
|
|
83
|
+
onInputFromChange,
|
|
84
|
+
onInputToChange,
|
|
85
|
+
onPanelChange,
|
|
86
|
+
onToFocus,
|
|
87
|
+
panelValue,
|
|
88
|
+
value,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { useTimeRangePickerValue };
|
package/Transition/Rotate.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MOTION_DURATION, MOTION_EASING } from '@mezzanine-ui/system/motion';
|
|
2
2
|
import { forwardRef, cloneElement } from 'react';
|
|
3
|
-
import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* The react component for `mezzanine` transition rotate.
|
|
@@ -11,18 +10,16 @@ import { useComposeRefs } from '../hooks/useComposeRefs.js';
|
|
|
11
10
|
*/
|
|
12
11
|
const Rotate = forwardRef(function Rotate(props, ref) {
|
|
13
12
|
const { children, degrees = 180, duration = MOTION_DURATION.fast, easing = MOTION_EASING.standard, in: inProp = false, transformOrigin = 'center', } = props;
|
|
14
|
-
const childRef = 'ref' in children ? children.ref : undefined;
|
|
15
|
-
const composedRef = useComposeRefs([ref, childRef]);
|
|
16
13
|
const childProps = children.props;
|
|
17
14
|
const style = {
|
|
18
15
|
transform: inProp ? `rotate(${degrees}deg)` : 'rotate(0deg)',
|
|
19
16
|
transformOrigin,
|
|
20
17
|
transition: `transform ${duration}ms ${easing}`,
|
|
21
|
-
...(childProps.style || {}),
|
|
18
|
+
...((childProps === null || childProps === void 0 ? void 0 : childProps.style) || {}),
|
|
22
19
|
};
|
|
23
20
|
return cloneElement(children, {
|
|
24
21
|
...childProps,
|
|
25
|
-
ref
|
|
22
|
+
ref,
|
|
26
23
|
style,
|
|
27
24
|
});
|
|
28
25
|
});
|