@choice-ui/react 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/calendar/dist/index.d.ts +5 -12
- package/dist/components/calendar/dist/index.js +200 -82
- package/dist/components/calendar/src/utils/parsers/parsers.js +40 -23
- package/dist/components/dialog/dist/index.d.ts +2 -1
- package/dist/components/dialog/dist/index.js +5 -1
- package/dist/components/dialog/src/dialog.d.ts +2 -1
- package/dist/components/dialog/src/dialog.js +5 -1
- package/dist/components/dropdown/dist/index.js +16 -41
- package/dist/components/list/dist/index.d.ts +8 -3
- package/dist/components/list/src/components/list-content.d.ts +3 -2
- package/dist/components/list/src/components/list-content.js +2 -2
- package/dist/components/list/src/components/list-item.d.ts +3 -0
- package/dist/components/list/src/list.d.ts +2 -1
- package/dist/components/list/src/list.js +4 -2
- package/dist/components/md-render/src/tv.js +1 -1
- package/dist/components/menus/dist/index.js +20 -25
- package/dist/components/modal/dist/index.d.ts +2 -1
- package/dist/components/modal/dist/index.js +2 -2
- package/dist/components/modal/src/modal.d.ts +2 -1
- package/dist/components/modal/src/modal.js +2 -2
- package/dist/components/multi-select/dist/index.js +11 -16
- package/dist/components/popover/dist/index.d.ts +11 -10
- package/dist/components/popover/dist/index.js +5 -1
- package/dist/components/popover/src/popover.d.ts +2 -1
- package/dist/components/popover/src/popover.js +5 -1
- package/dist/components/scroll-area/dist/index.d.ts +6 -1
- package/dist/components/scroll-area/dist/index.js +2 -2
- package/dist/components/scroll-area/src/components/scroll-area-content.d.ts +4 -1
- package/dist/components/scroll-area/src/components/scroll-area-content.js +2 -2
- package/dist/components/scroll-area/src/scroll-area.d.ts +1 -1
- package/dist/components/select/dist/index.js +15 -47
- package/dist/components/slot/dist/index.d.ts +10 -6
- package/dist/components/slot/dist/index.js +51 -45
- package/dist/components/tooltip/dist/index.js +2 -7
- package/dist/components/virtual-select/dist/index.d.ts +48 -0
- package/dist/styles/components.css +220 -193
- package/dist/styles/markdown.css +362 -360
- package/package.json +1 -1
- package/dist/styles/preflight.css +0 -97
- package/dist/styles/stories.css +0 -5
- package/dist/styles/theme.css +0 -597
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { default as React__default } from 'react';
|
|
2
2
|
import { Locale, Quarter as Quarter$1, Day, isSameDay, isSameMonth, isSameYear, addMonths, startOfMonth, endOfMonth, startOfWeek, endOfWeek } from 'date-fns';
|
|
3
3
|
import { TextFieldProps } from '../../text-field/src';
|
|
4
|
-
import { DropdownProps } from '../../dropdown/src';
|
|
5
|
-
import { MenuTrigger } from '../../menus/src';
|
|
6
4
|
import { TZDate } from '@date-fns/tz';
|
|
7
5
|
import { Locale as Locale$1 } from 'date-fns/locale';
|
|
8
6
|
import { PressMoveProps } from '../../../../../shared/src';
|
|
@@ -569,21 +567,16 @@ interface DateRangeInputProps extends Omit<TextFieldProps, "value" | "onChange"
|
|
|
569
567
|
}
|
|
570
568
|
declare const DateRangeInput: (props: DateRangeInputProps) => react_jsx_runtime.JSX.Element;
|
|
571
569
|
|
|
572
|
-
interface
|
|
573
|
-
Trigger: typeof MenuTrigger;
|
|
574
|
-
}
|
|
575
|
-
interface TimeCalendarProps extends BaseTimeProps, StepProps, Pick<DropdownProps, "offset" | "placement" | "matchTriggerWidth" | "variant" | "readOnly"> {
|
|
570
|
+
interface TimeCalendarProps extends BaseTimeProps, StepProps {
|
|
576
571
|
children?: React__default.ReactNode;
|
|
572
|
+
/** Custom class name */
|
|
577
573
|
className?: string;
|
|
574
|
+
/** Hour step, default 1 hour */
|
|
578
575
|
hourStep?: number;
|
|
576
|
+
/** Minute step, default 15 minutes */
|
|
579
577
|
minuteStep?: number;
|
|
580
|
-
open?: boolean;
|
|
581
|
-
onOpenChange?: (open: boolean) => void;
|
|
582
|
-
closeOnSelect?: boolean;
|
|
583
|
-
triggerRef?: React__default.RefObject<HTMLElement>;
|
|
584
|
-
triggerSelector?: string;
|
|
585
578
|
}
|
|
586
|
-
declare const TimeCalendar:
|
|
579
|
+
declare const TimeCalendar: React__default.NamedExoticComponent<TimeCalendarProps>;
|
|
587
580
|
|
|
588
581
|
interface TimeInputProps extends Omit<TextFieldProps, "value" | "onChange" | "format" | "defaultValue" | "step">, BaseTimeProps, StepProps, TimeInteractionProps {
|
|
589
582
|
prefixElement?: React__default.ReactNode;
|
|
@@ -10,8 +10,7 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
|
10
10
|
import { IconButton } from "../../icon-button/dist/index.js";
|
|
11
11
|
import { FieldTypeDate, Undo, ChevronUpSmall, ChevronLeftSmall, ChevronDownSmall, ChevronRightSmall, Check, Clock } from "@choiceform/icons-react";
|
|
12
12
|
import { TextField } from "../../text-field/dist/index.js";
|
|
13
|
-
import {
|
|
14
|
-
import { MenuTrigger } from "../../menus/dist/index.js";
|
|
13
|
+
import { Menus } from "../../menus/dist/index.js";
|
|
15
14
|
import { tcx, tcv } from "../../../shared/utils/tcx/tcx.js";
|
|
16
15
|
import { useMergedValue } from "../../../shared/hooks/use-merged-value/use-merged-value.js";
|
|
17
16
|
import { useModifierKeys } from "../../../shared/hooks/use-modifier-keys/use-modifier-keys.js";
|
|
@@ -1716,7 +1715,7 @@ var generateTimeOptions = (format10, step = 15) => {
|
|
|
1716
1715
|
const minutes = i % 60;
|
|
1717
1716
|
if (is12Hour) {
|
|
1718
1717
|
const displayHour = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;
|
|
1719
|
-
const ampm = hours < 12 ? "
|
|
1718
|
+
const ampm = hours < 12 ? "AM" : "PM";
|
|
1720
1719
|
const value = `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}`;
|
|
1721
1720
|
const label = `${displayHour}:${minutes.toString().padStart(2, "0")} ${ampm}`;
|
|
1722
1721
|
options.push({ value, label });
|
|
@@ -3035,7 +3034,7 @@ var DateInput = forwardRef((props, ref) => {
|
|
|
3035
3034
|
);
|
|
3036
3035
|
});
|
|
3037
3036
|
DateInput.displayName = "DateInput";
|
|
3038
|
-
var
|
|
3037
|
+
var TimeCalendar = memo(function TimeCalendar2(props) {
|
|
3039
3038
|
const {
|
|
3040
3039
|
value,
|
|
3041
3040
|
defaultValue,
|
|
@@ -3045,25 +3044,16 @@ var TimeCalendarBase = memo(function TimeCalendar(props) {
|
|
|
3045
3044
|
className,
|
|
3046
3045
|
children,
|
|
3047
3046
|
readOnly = false,
|
|
3048
|
-
open: controlledOpen,
|
|
3049
|
-
onOpenChange,
|
|
3050
|
-
closeOnSelect = true,
|
|
3051
|
-
triggerRef,
|
|
3052
|
-
triggerSelector,
|
|
3053
|
-
offset,
|
|
3054
|
-
placement,
|
|
3055
|
-
matchTriggerWidth,
|
|
3056
|
-
variant,
|
|
3057
3047
|
...rest
|
|
3058
3048
|
} = props;
|
|
3059
|
-
const
|
|
3060
|
-
const
|
|
3061
|
-
const
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3049
|
+
const scrollRef = useRef(null);
|
|
3050
|
+
const elementsRef = useRef([]);
|
|
3051
|
+
const customElementRef = useRef(null);
|
|
3052
|
+
const hasInitialScrolled = useRef(false);
|
|
3053
|
+
const lastSelectedIndexRef = useRef(null);
|
|
3054
|
+
const isInternalOperationRef = useRef(false);
|
|
3055
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
3056
|
+
const [isScrolling, setIsScrolling] = useState(false);
|
|
3067
3057
|
const [innerValue, setValue] = useMergedValue({
|
|
3068
3058
|
value,
|
|
3069
3059
|
defaultValue,
|
|
@@ -3079,7 +3069,7 @@ var TimeCalendarBase = memo(function TimeCalendar(props) {
|
|
|
3079
3069
|
const formatTo12Hour = useCallback((timeStr) => {
|
|
3080
3070
|
const [hour, minute] = timeStr.split(":").map(Number);
|
|
3081
3071
|
const displayHour = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;
|
|
3082
|
-
const ampm = hour < 12 ? "
|
|
3072
|
+
const ampm = hour < 12 ? "AM" : "PM";
|
|
3083
3073
|
return `${displayHour}:${minute.toString().padStart(2, "0")} ${ampm}`;
|
|
3084
3074
|
}, []);
|
|
3085
3075
|
const customTimeOption = useMemo(() => {
|
|
@@ -3106,95 +3096,222 @@ var TimeCalendarBase = memo(function TimeCalendar(props) {
|
|
|
3106
3096
|
},
|
|
3107
3097
|
[timeFormat]
|
|
3108
3098
|
);
|
|
3099
|
+
const selectedIndex = useMemo(() => {
|
|
3100
|
+
if (!normalizedTimeString) return null;
|
|
3101
|
+
const index = timeOptions.findIndex((option) => option.value === normalizedTimeString);
|
|
3102
|
+
return index === -1 ? -1 : index;
|
|
3103
|
+
}, [normalizedTimeString, timeOptions]);
|
|
3109
3104
|
const needsDivider = useMemo(() => {
|
|
3110
3105
|
const is12Hour = timeFormat.toLowerCase().includes("a") || timeFormat === "12h";
|
|
3111
3106
|
if (!is12Hour) return () => false;
|
|
3112
3107
|
return (index) => {
|
|
3113
|
-
return index > 0 && timeOptions[index].label.
|
|
3108
|
+
return index > 0 && timeOptions[index].label.includes("PM") && timeOptions[index - 1].label.includes("AM");
|
|
3114
3109
|
};
|
|
3115
3110
|
}, [timeFormat, timeOptions]);
|
|
3116
3111
|
const createPrefixElement = useCallback((isSelected) => {
|
|
3117
3112
|
return isSelected ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Fragment, {});
|
|
3118
3113
|
}, []);
|
|
3114
|
+
const scrollTimeoutRef = useRef(null);
|
|
3115
|
+
const mousePositionRef = useRef(null);
|
|
3116
|
+
const handleScroll = useEventCallback(() => {
|
|
3117
|
+
if (!isScrolling) {
|
|
3118
|
+
setIsScrolling(true);
|
|
3119
|
+
setActiveIndex(null);
|
|
3120
|
+
}
|
|
3121
|
+
if (scrollTimeoutRef.current) {
|
|
3122
|
+
clearTimeout(scrollTimeoutRef.current);
|
|
3123
|
+
}
|
|
3124
|
+
scrollTimeoutRef.current = setTimeout(() => {
|
|
3125
|
+
var _a;
|
|
3126
|
+
setIsScrolling(false);
|
|
3127
|
+
if (mousePositionRef.current) {
|
|
3128
|
+
const elementUnderMouse = document.elementFromPoint(
|
|
3129
|
+
mousePositionRef.current.x,
|
|
3130
|
+
mousePositionRef.current.y
|
|
3131
|
+
);
|
|
3132
|
+
if (customElementRef.current && (customElementRef.current === elementUnderMouse || customElementRef.current.contains(elementUnderMouse))) {
|
|
3133
|
+
setActiveIndex(-1);
|
|
3134
|
+
return;
|
|
3135
|
+
}
|
|
3136
|
+
const elements = elementsRef.current;
|
|
3137
|
+
for (let i = 0; i < elements.length; i++) {
|
|
3138
|
+
if (elements[i] && (elements[i] === elementUnderMouse || ((_a = elements[i]) == null ? void 0 : _a.contains(elementUnderMouse)))) {
|
|
3139
|
+
setActiveIndex(i);
|
|
3140
|
+
break;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
}, 200);
|
|
3145
|
+
});
|
|
3146
|
+
const handleMouseMove = useEventCallback((event) => {
|
|
3147
|
+
mousePositionRef.current = { x: event.clientX, y: event.clientY };
|
|
3148
|
+
});
|
|
3119
3149
|
useEffect(() => {
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
const scrollToSelected = () => {
|
|
3124
|
-
const selectedItem = document.querySelector(
|
|
3125
|
-
`[data-testid="${normalizedTimeString}"]`
|
|
3126
|
-
);
|
|
3127
|
-
if (selectedItem) {
|
|
3128
|
-
selectedItem.scrollIntoView({ block: "center" });
|
|
3129
|
-
} else if (attempts < maxAttempts) {
|
|
3130
|
-
attempts++;
|
|
3131
|
-
requestAnimationFrame(scrollToSelected);
|
|
3150
|
+
return () => {
|
|
3151
|
+
if (scrollTimeoutRef.current) {
|
|
3152
|
+
clearTimeout(scrollTimeoutRef.current);
|
|
3132
3153
|
}
|
|
3133
3154
|
};
|
|
3134
|
-
|
|
3135
|
-
|
|
3155
|
+
}, []);
|
|
3156
|
+
useEffect(() => {
|
|
3157
|
+
var _a;
|
|
3158
|
+
if (selectedIndex === -1) {
|
|
3159
|
+
const customElement = customElementRef.current;
|
|
3160
|
+
if (!customElement || !scrollRef.current) {
|
|
3161
|
+
return;
|
|
3162
|
+
}
|
|
3163
|
+
const previousSelectedIndex2 = lastSelectedIndexRef.current;
|
|
3164
|
+
const isSelectedIndexChanged2 = previousSelectedIndex2 !== selectedIndex;
|
|
3165
|
+
lastSelectedIndexRef.current = selectedIndex;
|
|
3166
|
+
const shouldScroll2 = !hasInitialScrolled.current || // Initial scrolling
|
|
3167
|
+
isSelectedIndexChanged2 && !isInternalOperationRef.current;
|
|
3168
|
+
if (shouldScroll2) {
|
|
3169
|
+
const isInitialScroll = !hasInitialScrolled.current;
|
|
3170
|
+
if (isInitialScroll) {
|
|
3171
|
+
scrollRef.current.scrollTo({
|
|
3172
|
+
top: 0,
|
|
3173
|
+
behavior: "auto"
|
|
3174
|
+
});
|
|
3175
|
+
} else {
|
|
3176
|
+
customElement.scrollIntoView({
|
|
3177
|
+
block: "nearest",
|
|
3178
|
+
behavior: "smooth"
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
if (!hasInitialScrolled.current) {
|
|
3182
|
+
hasInitialScrolled.current = true;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
if (isInternalOperationRef.current) {
|
|
3186
|
+
isInternalOperationRef.current = false;
|
|
3187
|
+
}
|
|
3188
|
+
return;
|
|
3189
|
+
}
|
|
3190
|
+
if (selectedIndex === null || !scrollRef.current || !elementsRef.current[selectedIndex]) {
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
const previousSelectedIndex = lastSelectedIndexRef.current;
|
|
3194
|
+
const isSelectedIndexChanged = previousSelectedIndex !== selectedIndex;
|
|
3195
|
+
lastSelectedIndexRef.current = selectedIndex;
|
|
3196
|
+
const shouldScroll = !hasInitialScrolled.current || // Initial scrolling
|
|
3197
|
+
isSelectedIndexChanged && !isInternalOperationRef.current;
|
|
3198
|
+
if (shouldScroll) {
|
|
3199
|
+
const isInitialScroll = !hasInitialScrolled.current;
|
|
3200
|
+
if (isInitialScroll) {
|
|
3201
|
+
(_a = elementsRef.current[selectedIndex]) == null ? void 0 : _a.scrollIntoView({
|
|
3202
|
+
block: "center",
|
|
3203
|
+
behavior: "auto"
|
|
3204
|
+
});
|
|
3205
|
+
} else {
|
|
3206
|
+
const container = scrollRef.current;
|
|
3207
|
+
const element = elementsRef.current[selectedIndex];
|
|
3208
|
+
if (container && element) {
|
|
3209
|
+
const containerRect = container.getBoundingClientRect();
|
|
3210
|
+
const elementRect = element.getBoundingClientRect();
|
|
3211
|
+
const margin = 8;
|
|
3212
|
+
const elementTop = elementRect.top - containerRect.top + container.scrollTop;
|
|
3213
|
+
const elementBottom = elementTop + elementRect.height;
|
|
3214
|
+
const visibleTop = container.scrollTop + margin;
|
|
3215
|
+
const visibleBottom = container.scrollTop + container.clientHeight - margin;
|
|
3216
|
+
let targetScrollTop = container.scrollTop;
|
|
3217
|
+
if (elementTop < visibleTop) {
|
|
3218
|
+
targetScrollTop = elementTop - margin;
|
|
3219
|
+
} else if (elementBottom > visibleBottom) {
|
|
3220
|
+
targetScrollTop = elementBottom - container.clientHeight + margin;
|
|
3221
|
+
}
|
|
3222
|
+
if (targetScrollTop !== container.scrollTop) {
|
|
3223
|
+
container.scrollTo({
|
|
3224
|
+
top: targetScrollTop
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
if (!hasInitialScrolled.current) {
|
|
3230
|
+
hasInitialScrolled.current = true;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
if (isInternalOperationRef.current) {
|
|
3234
|
+
isInternalOperationRef.current = false;
|
|
3235
|
+
}
|
|
3236
|
+
}, [selectedIndex]);
|
|
3136
3237
|
const handleTimeSelect = useEventCallback((timeValue) => {
|
|
3137
3238
|
if (readOnly) return;
|
|
3239
|
+
isInternalOperationRef.current = true;
|
|
3138
3240
|
const dateValue = timeStringToDate(timeValue);
|
|
3139
3241
|
setValue(dateValue);
|
|
3140
|
-
|
|
3141
|
-
|
|
3242
|
+
});
|
|
3243
|
+
const handleMouseEnter = useEventCallback((index) => {
|
|
3244
|
+
if (isScrolling) {
|
|
3245
|
+
return;
|
|
3142
3246
|
}
|
|
3247
|
+
setActiveIndex(index);
|
|
3248
|
+
});
|
|
3249
|
+
const handleMouseLeave = useEventCallback(() => {
|
|
3250
|
+
setActiveIndex(null);
|
|
3251
|
+
});
|
|
3252
|
+
const handleClick = useEventCallback((timeValue) => {
|
|
3253
|
+
handleTimeSelect(timeValue);
|
|
3143
3254
|
});
|
|
3144
3255
|
return /* @__PURE__ */ jsxs(
|
|
3145
|
-
|
|
3256
|
+
Menus,
|
|
3146
3257
|
{
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
placement,
|
|
3154
|
-
matchTriggerWidth,
|
|
3155
|
-
variant,
|
|
3156
|
-
readOnly,
|
|
3258
|
+
ref: scrollRef,
|
|
3259
|
+
onScroll: handleScroll,
|
|
3260
|
+
onMouseLeave: handleMouseLeave,
|
|
3261
|
+
onMouseMove: handleMouseMove,
|
|
3262
|
+
className,
|
|
3263
|
+
"data-testid": "time-calendar-menu",
|
|
3157
3264
|
...rest,
|
|
3158
3265
|
children: [
|
|
3159
|
-
children
|
|
3160
|
-
|
|
3161
|
-
|
|
3266
|
+
customTimeOption && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3267
|
+
/* @__PURE__ */ jsx(
|
|
3268
|
+
Menus.Item,
|
|
3269
|
+
{
|
|
3270
|
+
ref: (node) => {
|
|
3271
|
+
customElementRef.current = node;
|
|
3272
|
+
},
|
|
3273
|
+
selected: selectedIndex === -1,
|
|
3274
|
+
active: !isScrolling && activeIndex === -1,
|
|
3275
|
+
onClick: () => handleClick(customTimeOption.value),
|
|
3276
|
+
onMouseEnter: () => handleMouseEnter(-1),
|
|
3277
|
+
prefixElement: createPrefixElement(selectedIndex === -1),
|
|
3278
|
+
variant: "highlight",
|
|
3279
|
+
"data-testid": "custom-time-item",
|
|
3280
|
+
children: renderTimeLabel(customTimeOption.label)
|
|
3281
|
+
}
|
|
3282
|
+
),
|
|
3283
|
+
/* @__PURE__ */ jsx(Menus.Divider, { "data-testid": "custom-time-divider" })
|
|
3284
|
+
] }),
|
|
3285
|
+
timeOptions.map((option, index) => {
|
|
3286
|
+
const isAmToPmTransition = needsDivider(index);
|
|
3287
|
+
const isItemSelected = selectedIndex === index;
|
|
3288
|
+
const isItemActive = !isScrolling && activeIndex === index;
|
|
3289
|
+
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
3290
|
+
isAmToPmTransition && /* @__PURE__ */ jsx(Menus.Divider, { "data-testid": "ampm-divider" }),
|
|
3162
3291
|
/* @__PURE__ */ jsx(
|
|
3163
|
-
|
|
3292
|
+
Menus.Item,
|
|
3164
3293
|
{
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3294
|
+
ref: (node) => {
|
|
3295
|
+
elementsRef.current[index] = node;
|
|
3296
|
+
},
|
|
3297
|
+
selected: isItemSelected,
|
|
3298
|
+
active: isItemActive,
|
|
3299
|
+
onClick: () => handleClick(option.value),
|
|
3300
|
+
onMouseEnter: () => handleMouseEnter(index),
|
|
3301
|
+
prefixElement: createPrefixElement(isItemSelected),
|
|
3302
|
+
variant: "highlight",
|
|
3303
|
+
"data-testid": option.value,
|
|
3304
|
+
children: renderTimeLabel(option.label)
|
|
3169
3305
|
}
|
|
3170
|
-
)
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
const isAmToPmTransition = needsDivider(index);
|
|
3175
|
-
const isSelected = normalizedTimeString === option.value;
|
|
3176
|
-
return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
|
|
3177
|
-
isAmToPmTransition && /* @__PURE__ */ jsx(Dropdown2.Divider, { "data-testid": "ampm-divider" }),
|
|
3178
|
-
/* @__PURE__ */ jsx(
|
|
3179
|
-
Dropdown2.Item,
|
|
3180
|
-
{
|
|
3181
|
-
onMouseUp: () => handleTimeSelect(option.value),
|
|
3182
|
-
prefixElement: createPrefixElement(isSelected),
|
|
3183
|
-
"data-testid": option.value,
|
|
3184
|
-
children: renderTimeLabel(option.label)
|
|
3185
|
-
}
|
|
3186
|
-
)
|
|
3187
|
-
] }, option.value);
|
|
3188
|
-
})
|
|
3189
|
-
] })
|
|
3306
|
+
)
|
|
3307
|
+
] }, option.value);
|
|
3308
|
+
}),
|
|
3309
|
+
children
|
|
3190
3310
|
]
|
|
3191
3311
|
}
|
|
3192
3312
|
);
|
|
3193
3313
|
});
|
|
3194
|
-
|
|
3195
|
-
Object.assign(TimeCalendarBase, {
|
|
3196
|
-
Trigger: MenuTrigger
|
|
3197
|
-
});
|
|
3314
|
+
TimeCalendar.displayName = "TimeCalendar";
|
|
3198
3315
|
function useTimeInput(props) {
|
|
3199
3316
|
const {
|
|
3200
3317
|
value,
|
|
@@ -4412,6 +4529,7 @@ export {
|
|
|
4412
4529
|
LOCALE_MAP,
|
|
4413
4530
|
MonthCalendar,
|
|
4414
4531
|
QuarterCalendar,
|
|
4532
|
+
TimeCalendar,
|
|
4415
4533
|
TimeInput,
|
|
4416
4534
|
YearCalendar,
|
|
4417
4535
|
calculateWeekNumbers,
|
|
@@ -501,54 +501,71 @@ function parseCompositeFormat(input, format2, locale) {
|
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
function removeWeekdayFromFormat(format2) {
|
|
504
|
-
return format2.replace(/\s*[eEic]{1,4}\s*/g, "").replace(/\s+/g, " ").replace(/\s*([,,、])\s*/g, "$1").trim();
|
|
504
|
+
return format2.replace(/\s*[eEic]{1,4}\s*/g, "").replace(/MMM(?!M)/g, "M月").replace(/\s+/g, " ").replace(/\s*([,,、])\s*/g, "$1").trim();
|
|
505
505
|
}
|
|
506
506
|
function removeWeekdayFromInput(input, locale) {
|
|
507
507
|
try {
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
508
|
+
const { longNames, shortNames } = generateWeekdayNames(locale);
|
|
509
|
+
let result = input;
|
|
510
|
+
if (longNames.length > 0) {
|
|
511
|
+
const sortedLongNames = longNames.sort((a, b) => b.length - a.length);
|
|
512
|
+
const longPattern = new RegExp(`\\s*(${sortedLongNames.join("|")})\\s*`, "gi");
|
|
513
|
+
result = result.replace(longPattern, " ");
|
|
511
514
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
+
if (shortNames.length > 0) {
|
|
516
|
+
const sortedShortNames = shortNames.sort((a, b) => b.length - a.length);
|
|
517
|
+
const singleCharNames = sortedShortNames.filter((name) => name.length === 1);
|
|
518
|
+
const multiCharNames = sortedShortNames.filter((name) => name.length > 1);
|
|
519
|
+
if (multiCharNames.length > 0) {
|
|
520
|
+
const multiPattern = new RegExp(`\\s*(${multiCharNames.join("|")})\\s*`, "gi");
|
|
521
|
+
result = result.replace(multiPattern, " ");
|
|
522
|
+
}
|
|
523
|
+
if (singleCharNames.length > 0) {
|
|
524
|
+
const singlePattern = new RegExp(
|
|
525
|
+
`([((「【])(${singleCharNames.join("|")})([))」】])`,
|
|
526
|
+
"gi"
|
|
527
|
+
);
|
|
528
|
+
result = result.replace(singlePattern, "$1$3");
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return result.replace(/\s+/g, " ").trim();
|
|
515
532
|
} catch {
|
|
516
533
|
return input.replace(/\s*(星期[一二三四五六日天]|周[一二三四五六日天])\s*/g, "").replace(/\s+/g, " ").trim();
|
|
517
534
|
}
|
|
518
535
|
}
|
|
519
536
|
function generateWeekdayNames(locale) {
|
|
520
|
-
const
|
|
537
|
+
const longNames = [];
|
|
538
|
+
const shortNames = [];
|
|
521
539
|
try {
|
|
522
540
|
const baseDate = new Date(2024, 0, 7);
|
|
523
541
|
for (let i = 0; i < 7; i++) {
|
|
524
542
|
const currentDate = new Date(baseDate);
|
|
525
543
|
currentDate.setDate(baseDate.getDate() + i);
|
|
526
544
|
const fullName = format(currentDate, "eeee", { locale });
|
|
527
|
-
if (fullName && fullName !== "eeee") {
|
|
528
|
-
|
|
545
|
+
if (fullName && fullName !== "eeee" && !fullName.includes("e")) {
|
|
546
|
+
longNames.push(fullName);
|
|
529
547
|
}
|
|
530
548
|
const shortName = format(currentDate, "eee", { locale });
|
|
531
|
-
if (shortName && shortName !== "eee" && shortName !== fullName) {
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
const veryShortName = format(currentDate, "ee", { locale });
|
|
535
|
-
if (veryShortName && veryShortName !== "ee" && veryShortName !== shortName && veryShortName !== fullName) {
|
|
536
|
-
names.push(veryShortName);
|
|
549
|
+
if (shortName && shortName !== "eee" && shortName !== fullName && !shortName.includes("e")) {
|
|
550
|
+
shortNames.push(shortName);
|
|
537
551
|
}
|
|
538
552
|
const localeKey = getLocaleKey(locale);
|
|
539
|
-
if (localeKey === "zh") {
|
|
540
|
-
const weekFormat =
|
|
553
|
+
if (localeKey === "zh" && fullName) {
|
|
554
|
+
const weekFormat = fullName.replace("星期", "周");
|
|
541
555
|
if (weekFormat !== fullName) {
|
|
542
|
-
|
|
556
|
+
shortNames.push(weekFormat);
|
|
543
557
|
}
|
|
544
558
|
}
|
|
545
559
|
}
|
|
546
|
-
|
|
547
|
-
(name) => name && name.length > 0 &&
|
|
548
|
-
name !== "Invalid Date"
|
|
560
|
+
const filterNames = (names) => [...new Set(names)].filter(
|
|
561
|
+
(name) => name && name.length > 0 && !/^\d+$/.test(name) && name !== "Invalid Date"
|
|
549
562
|
);
|
|
563
|
+
return {
|
|
564
|
+
longNames: filterNames(longNames),
|
|
565
|
+
shortNames: filterNames(shortNames)
|
|
566
|
+
};
|
|
550
567
|
} catch {
|
|
551
|
-
return [];
|
|
568
|
+
return { longNames: [], shortNames: [] };
|
|
552
569
|
}
|
|
553
570
|
}
|
|
554
571
|
function parseInvalidFormattedDate(input, targetFormat, locale) {
|
|
@@ -13,8 +13,9 @@ declare const DialogTrigger: react.MemoExoticComponent<react.ForwardRefExoticCom
|
|
|
13
13
|
|
|
14
14
|
type DialogPosition = "left-top" | "center-top" | "right-top" | "left-center" | "center" | "right-center" | "left-bottom" | "center-bottom" | "right-bottom";
|
|
15
15
|
|
|
16
|
-
interface DialogProps {
|
|
16
|
+
interface DialogProps extends Omit<react__default.HTMLAttributes<HTMLElement>, "title"> {
|
|
17
17
|
afterOpenChange?: (isOpen: boolean) => void;
|
|
18
|
+
as?: react__default.ElementType;
|
|
18
19
|
children?: react__default.ReactNode;
|
|
19
20
|
className?: string;
|
|
20
21
|
closeOnEscape?: boolean;
|
|
@@ -645,6 +645,7 @@ var dragDialogTv = tcv({
|
|
|
645
645
|
});
|
|
646
646
|
var PORTAL_ROOT_ID = "floating-modal-root";
|
|
647
647
|
var DialogComponent = memo(function DialogComponent2({
|
|
648
|
+
as,
|
|
648
649
|
className,
|
|
649
650
|
children,
|
|
650
651
|
closeOnEscape = true,
|
|
@@ -667,7 +668,8 @@ var DialogComponent = memo(function DialogComponent2({
|
|
|
667
668
|
rememberSize = false,
|
|
668
669
|
focusManagerProps = { initialFocus: 1 },
|
|
669
670
|
transitionStylesProps,
|
|
670
|
-
root
|
|
671
|
+
root,
|
|
672
|
+
...restProps
|
|
671
673
|
}) {
|
|
672
674
|
const dialogRef = useRef(null);
|
|
673
675
|
const contentRef = useRef(null);
|
|
@@ -829,9 +831,11 @@ var DialogComponent = memo(function DialogComponent2({
|
|
|
829
831
|
floating.refs.setFloating(node);
|
|
830
832
|
}
|
|
831
833
|
},
|
|
834
|
+
as,
|
|
832
835
|
style: getStyleWithDefaults,
|
|
833
836
|
className: tcx(style.dialog(), className),
|
|
834
837
|
...floating.getFloatingProps(),
|
|
838
|
+
...restProps,
|
|
835
839
|
"aria-labelledby": titleId,
|
|
836
840
|
"aria-describedby": descriptionId,
|
|
837
841
|
role: "dialog",
|
|
@@ -3,8 +3,9 @@ import { FloatingFocusManagerProps, UseTransitionStylesProps } from '@floating-u
|
|
|
3
3
|
import { default as React } from 'react';
|
|
4
4
|
import { DialogHeader, DialogTrigger } from './components';
|
|
5
5
|
import { DialogPosition } from './types';
|
|
6
|
-
export interface DialogProps {
|
|
6
|
+
export interface DialogProps extends Omit<React.HTMLAttributes<HTMLElement>, "title"> {
|
|
7
7
|
afterOpenChange?: (isOpen: boolean) => void;
|
|
8
|
+
as?: React.ElementType;
|
|
8
9
|
children?: React.ReactNode;
|
|
9
10
|
className?: string;
|
|
10
11
|
closeOnEscape?: boolean;
|
|
@@ -14,6 +14,7 @@ import { findChildByType } from "../../../shared/utils/assertion.js";
|
|
|
14
14
|
import { tcx } from "../../../shared/utils/tcx/tcx.js";
|
|
15
15
|
const PORTAL_ROOT_ID = "floating-modal-root";
|
|
16
16
|
const DialogComponent = memo(function DialogComponent2({
|
|
17
|
+
as,
|
|
17
18
|
className,
|
|
18
19
|
children,
|
|
19
20
|
closeOnEscape = true,
|
|
@@ -36,7 +37,8 @@ const DialogComponent = memo(function DialogComponent2({
|
|
|
36
37
|
rememberSize = false,
|
|
37
38
|
focusManagerProps = { initialFocus: 1 },
|
|
38
39
|
transitionStylesProps,
|
|
39
|
-
root
|
|
40
|
+
root,
|
|
41
|
+
...restProps
|
|
40
42
|
}) {
|
|
41
43
|
const dialogRef = useRef(null);
|
|
42
44
|
const contentRef = useRef(null);
|
|
@@ -198,9 +200,11 @@ const DialogComponent = memo(function DialogComponent2({
|
|
|
198
200
|
floating.refs.setFloating(node);
|
|
199
201
|
}
|
|
200
202
|
},
|
|
203
|
+
as,
|
|
201
204
|
style: getStyleWithDefaults,
|
|
202
205
|
className: tcx(style.dialog(), className),
|
|
203
206
|
...floating.getFloatingProps(),
|
|
207
|
+
...restProps,
|
|
204
208
|
"aria-labelledby": titleId,
|
|
205
209
|
"aria-describedby": descriptionId,
|
|
206
210
|
role: "dialog",
|
|
@@ -279,52 +279,27 @@ var DropdownComponent = memo(function DropdownComponent2(props) {
|
|
|
279
279
|
}),
|
|
280
280
|
[activeIndex, getItemProps, handleClose, isControlledOpen, readOnly, selection, variant]
|
|
281
281
|
);
|
|
282
|
-
const parentActiveIndex = parent == null ? void 0 : parent.activeIndex;
|
|
283
|
-
const parentGetItemProps = parent == null ? void 0 : parent.getItemProps;
|
|
284
|
-
const slotProps = useMemo(() => {
|
|
285
|
-
const referenceProps = getReferenceProps(
|
|
286
|
-
parentGetItemProps ? parentGetItemProps({
|
|
287
|
-
onFocus: handleFocus
|
|
288
|
-
}) : {}
|
|
289
|
-
);
|
|
290
|
-
return {
|
|
291
|
-
tabIndex: !isNested ? void 0 : parentActiveIndex === item.index ? 0 : -1,
|
|
292
|
-
role: isNested ? "menuitem" : void 0,
|
|
293
|
-
"data-open": isControlledOpen ? "" : void 0,
|
|
294
|
-
"data-nested": isNested ? "" : void 0,
|
|
295
|
-
"data-focus-inside": hasFocusInside ? "" : void 0,
|
|
296
|
-
onTouchStart: handleTouchStart,
|
|
297
|
-
onPointerMove: handlePointerMove,
|
|
298
|
-
"aria-haspopup": "menu",
|
|
299
|
-
"aria-expanded": isControlledOpen,
|
|
300
|
-
"aria-controls": menuId,
|
|
301
|
-
...referenceProps
|
|
302
|
-
};
|
|
303
|
-
}, [
|
|
304
|
-
isNested,
|
|
305
|
-
parentActiveIndex,
|
|
306
|
-
parentGetItemProps,
|
|
307
|
-
item.index,
|
|
308
|
-
isControlledOpen,
|
|
309
|
-
hasFocusInside,
|
|
310
|
-
handleTouchStart,
|
|
311
|
-
handlePointerMove,
|
|
312
|
-
menuId,
|
|
313
|
-
getReferenceProps,
|
|
314
|
-
handleFocus
|
|
315
|
-
]);
|
|
316
|
-
const slotChildren = useMemo(() => {
|
|
317
|
-
const element = isNested ? subTriggerElement : triggerElement;
|
|
318
|
-
if (!element) return null;
|
|
319
|
-
return cloneElement(element, { active: isControlledOpen });
|
|
320
|
-
}, [isNested, subTriggerElement, triggerElement, isControlledOpen]);
|
|
321
282
|
return /* @__PURE__ */ jsxs(FloatingNode, { id: nodeId, children: [
|
|
322
283
|
!isCoordinateMode && !hasExternalTrigger && /* @__PURE__ */ jsx(
|
|
323
284
|
Slot,
|
|
324
285
|
{
|
|
325
286
|
ref: refs.setReference,
|
|
326
|
-
|
|
327
|
-
|
|
287
|
+
tabIndex: !isNested ? void 0 : (parent == null ? void 0 : parent.activeIndex) === item.index ? 0 : -1,
|
|
288
|
+
role: isNested ? "menuitem" : void 0,
|
|
289
|
+
"data-open": isControlledOpen ? "" : void 0,
|
|
290
|
+
"data-nested": isNested ? "" : void 0,
|
|
291
|
+
"data-focus-inside": hasFocusInside ? "" : void 0,
|
|
292
|
+
onTouchStart: handleTouchStart,
|
|
293
|
+
onPointerMove: handlePointerMove,
|
|
294
|
+
"aria-haspopup": "menu",
|
|
295
|
+
"aria-expanded": isControlledOpen,
|
|
296
|
+
"aria-controls": menuId,
|
|
297
|
+
...getReferenceProps(
|
|
298
|
+
parent ? parent.getItemProps({
|
|
299
|
+
onFocus: handleFocus
|
|
300
|
+
}) : {}
|
|
301
|
+
),
|
|
302
|
+
children: isNested ? subTriggerElement && cloneElement(subTriggerElement, { active: isControlledOpen }) : triggerElement && cloneElement(triggerElement, { active: isControlledOpen })
|
|
328
303
|
}
|
|
329
304
|
),
|
|
330
305
|
/* @__PURE__ */ jsx(
|