@oceanbase/ui 1.0.0-alpha.17 → 1.0.0-alpha.19
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/ui.min.js +1 -1
- package/es/DateRanger/EditableDateTimeInput.d.ts +6 -1
- package/es/DateRanger/EditableDateTimeInput.js +41 -14
- package/es/DateRanger/PickerPanel.js +2 -2
- package/es/DateRanger/Ranger.d.ts +4 -1
- package/es/DateRanger/Ranger.js +25 -9
- package/es/DateRanger/hooks/index.d.ts +3 -1
- package/es/DateRanger/hooks/index.js +2 -1
- package/es/DateRanger/hooks/useAutoWidthInput.d.ts +13 -0
- package/es/DateRanger/hooks/useAutoWidthInput.js +44 -0
- package/es/DateRanger/hooks/useSegmentedInput.d.ts +8 -16
- package/es/DateRanger/hooks/useSegmentedInput.js +228 -351
- package/es/DateRanger/style/index.js +23 -3
- package/lib/DateRanger/EditableDateTimeInput.d.ts +6 -1
- package/lib/DateRanger/EditableDateTimeInput.js +37 -13
- package/lib/DateRanger/PickerPanel.js +2 -2
- package/lib/DateRanger/Ranger.d.ts +4 -1
- package/lib/DateRanger/Ranger.js +23 -7
- package/lib/DateRanger/hooks/index.d.ts +3 -1
- package/lib/DateRanger/hooks/index.js +8 -1
- package/lib/DateRanger/hooks/useAutoWidthInput.d.ts +13 -0
- package/lib/DateRanger/hooks/useAutoWidthInput.js +37 -0
- package/lib/DateRanger/hooks/useSegmentedInput.d.ts +8 -16
- package/lib/DateRanger/hooks/useSegmentedInput.js +158 -298
- package/lib/DateRanger/style/index.js +27 -1
- package/package.json +3 -3
|
@@ -13,6 +13,11 @@ export interface EditableDateTimeInputProps {
|
|
|
13
13
|
prefixCls?: string;
|
|
14
14
|
disabled?: boolean;
|
|
15
15
|
onClick?: () => void;
|
|
16
|
+
open?: boolean;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
export interface EditableDateTimeInputRef {
|
|
19
|
+
hasPastedValue: boolean;
|
|
20
|
+
confirmPastedValue: () => void;
|
|
21
|
+
}
|
|
22
|
+
declare const EditableDateTimeInput: React.ForwardRefExoticComponent<EditableDateTimeInputProps & React.RefAttributes<EditableDateTimeInputRef>>;
|
|
18
23
|
export default EditableDateTimeInput;
|
|
@@ -3,12 +3,14 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
3
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
-
import React, { useMemo } from 'react';
|
|
6
|
+
import React, { useMemo, useImperativeHandle, forwardRef } from 'react';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
8
|
import { Input } from '@oceanbase/design';
|
|
9
9
|
import { useSegmentedInput } from "./hooks/useSegmentedInput";
|
|
10
|
+
import { useAutoWidthInput } from "./hooks/useAutoWidthInput";
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
var EditableDateTimeInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
12
14
|
var value = props.value,
|
|
13
15
|
onChange = props.onChange,
|
|
14
16
|
formatProp = props.format,
|
|
@@ -25,7 +27,9 @@ var EditableDateTimeInput = function EditableDateTimeInput(props) {
|
|
|
25
27
|
prefixCls = _props$prefixCls === void 0 ? 'ant-picker' : _props$prefixCls,
|
|
26
28
|
_props$disabled = props.disabled,
|
|
27
29
|
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
28
|
-
onClick = props.onClick
|
|
30
|
+
onClick = props.onClick,
|
|
31
|
+
_props$open = props.open,
|
|
32
|
+
open = _props$open === void 0 ? false : _props$open;
|
|
29
33
|
|
|
30
34
|
// 根据配置生成格式,优先使用外部传入的 format
|
|
31
35
|
var format = useMemo(function () {
|
|
@@ -70,33 +74,56 @@ var EditableDateTimeInput = function EditableDateTimeInput(props) {
|
|
|
70
74
|
baseFormat: baseFormat,
|
|
71
75
|
isMoment: isMoment,
|
|
72
76
|
isCn: isCn,
|
|
73
|
-
onClick: onClick
|
|
77
|
+
onClick: onClick,
|
|
78
|
+
open: open
|
|
74
79
|
}),
|
|
75
80
|
inputRef = _useSegmentedInput.inputRef,
|
|
76
81
|
isEditing = _useSegmentedInput.isEditing,
|
|
77
82
|
displayValue = _useSegmentedInput.displayValue,
|
|
78
83
|
handleClick = _useSegmentedInput.handleClick,
|
|
79
84
|
handleDoubleClick = _useSegmentedInput.handleDoubleClick,
|
|
80
|
-
handleKeyDown = _useSegmentedInput.handleKeyDown,
|
|
81
85
|
handleBlur = _useSegmentedInput.handleBlur,
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
handleKeyDown = _useSegmentedInput.handleKeyDown,
|
|
87
|
+
hasPastedValue = _useSegmentedInput.hasPastedValue,
|
|
88
|
+
confirmPastedValue = _useSegmentedInput.confirmPastedValue;
|
|
89
|
+
var _useAutoWidthInput = useAutoWidthInput({
|
|
90
|
+
inputRef: inputRef,
|
|
91
|
+
value: displayValue,
|
|
92
|
+
minWidth: 80,
|
|
93
|
+
extraWidth: isCn ? 26 : 0
|
|
94
|
+
}),
|
|
95
|
+
sizerRef = _useAutoWidthInput.sizerRef,
|
|
96
|
+
inputWidth = _useAutoWidthInput.inputWidth;
|
|
97
|
+
|
|
98
|
+
// 暴露方法给父组件
|
|
99
|
+
useImperativeHandle(ref, function () {
|
|
100
|
+
return {
|
|
101
|
+
hasPastedValue: hasPastedValue,
|
|
102
|
+
confirmPastedValue: confirmPastedValue
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
84
106
|
className: classNames("".concat(prefixCls, "-range-editable"), className, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-range-editable-focused"), isEditing), "".concat(prefixCls, "-range-editable-disabled"), disabled)),
|
|
85
|
-
children: /*#__PURE__*/_jsx(
|
|
107
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
108
|
+
ref: sizerRef,
|
|
109
|
+
className: "".concat(prefixCls, "-range-editable-sizer"),
|
|
110
|
+
"aria-hidden": true
|
|
111
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
86
112
|
ref: inputRef,
|
|
87
113
|
className: "".concat(prefixCls, "-range-editable-input"),
|
|
114
|
+
style: {
|
|
115
|
+
width: inputWidth
|
|
116
|
+
},
|
|
88
117
|
value: displayValue,
|
|
89
118
|
readOnly: true,
|
|
90
119
|
disabled: disabled,
|
|
91
120
|
variant: "borderless",
|
|
92
121
|
onClick: handleClick,
|
|
93
122
|
onDoubleClick: handleDoubleClick,
|
|
94
|
-
onKeyDown: handleKeyDown
|
|
95
|
-
// onFocus={handleFocus}
|
|
96
|
-
,
|
|
97
123
|
onBlur: handleBlur,
|
|
98
|
-
|
|
99
|
-
})
|
|
124
|
+
onKeyDown: handleKeyDown
|
|
125
|
+
})]
|
|
100
126
|
});
|
|
101
|
-
};
|
|
127
|
+
});
|
|
128
|
+
EditableDateTimeInput.displayName = 'EditableDateTimeInput';
|
|
102
129
|
export default EditableDateTimeInput;
|
|
@@ -211,7 +211,7 @@ var InternalPickerPanel = function InternalPickerPanel(props) {
|
|
|
211
211
|
}],
|
|
212
212
|
children: /*#__PURE__*/_jsx(DatePicker, {
|
|
213
213
|
format: {
|
|
214
|
-
format:
|
|
214
|
+
format: DATE_FORMAT,
|
|
215
215
|
type: 'mask'
|
|
216
216
|
},
|
|
217
217
|
style: {
|
|
@@ -287,7 +287,7 @@ var InternalPickerPanel = function InternalPickerPanel(props) {
|
|
|
287
287
|
}],
|
|
288
288
|
children: /*#__PURE__*/_jsx(DatePicker, {
|
|
289
289
|
format: {
|
|
290
|
-
format:
|
|
290
|
+
format: DATE_FORMAT,
|
|
291
291
|
type: 'mask'
|
|
292
292
|
},
|
|
293
293
|
style: {
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { TooltipProps } from '@oceanbase/design';
|
|
3
3
|
import type { RangePickerProps } from '@oceanbase/design/es/date-picker';
|
|
4
4
|
import type { Dayjs } from 'dayjs';
|
|
5
|
+
import 'dayjs/locale/zh-cn';
|
|
5
6
|
import type { Moment } from 'moment';
|
|
6
7
|
import type { RangeOption } from './typing';
|
|
7
8
|
import type { Rule } from './PickerPanel';
|
|
@@ -12,7 +13,7 @@ export type RangeDateValue = {
|
|
|
12
13
|
name: RangeName;
|
|
13
14
|
range: RangeValue;
|
|
14
15
|
};
|
|
15
|
-
export interface DateRangerProps extends Omit<RangePickerProps, 'mode' | 'picker' | 'value' | 'defaultValue'> {
|
|
16
|
+
export interface DateRangerProps extends Omit<RangePickerProps, 'mode' | 'picker' | 'value' | 'defaultValue' | 'variant'> {
|
|
16
17
|
selects?: RangeOption[];
|
|
17
18
|
defaultQuickValue?: string;
|
|
18
19
|
hasRewind?: boolean;
|
|
@@ -37,6 +38,8 @@ export interface DateRangerProps extends Omit<RangePickerProps, 'mode' | 'picker
|
|
|
37
38
|
value?: RangeValue;
|
|
38
39
|
defaultValue?: RangeValue;
|
|
39
40
|
size?: 'small' | 'large' | 'middle';
|
|
41
|
+
/** 边框变体,默认实线,可配置为 dashed 虚线 */
|
|
42
|
+
variant?: 'dashed';
|
|
40
43
|
tooltipProps?: TooltipProps;
|
|
41
44
|
autoAdjustOverflow?: boolean;
|
|
42
45
|
overlayClassName?: string;
|
package/es/DateRanger/Ranger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var _excluded = ["selects", "value", "defaultValue", "defaultQuickValue", "hasRewind", "hasPlay", "hasSync", "hasForward", "hasZoomOut", "hasTagInPicker", "pastOnly", "simpleMode", "hideYear", "hideSecond", "autoCalcRange", "history", "onChange", "disabledDate", "locale", "size", "stickRangeName", "tooltipProps", "isMoment", "rules", "tip", "autoAdjustOverflow", "overlayClassName", "overlayStyle", "getPopupContainer"];
|
|
2
|
+
var _excluded = ["selects", "value", "defaultValue", "defaultQuickValue", "hasRewind", "hasPlay", "hasSync", "hasForward", "hasZoomOut", "hasTagInPicker", "pastOnly", "simpleMode", "hideYear", "hideSecond", "autoCalcRange", "history", "onChange", "disabledDate", "locale", "size", "stickRangeName", "variant", "tooltipProps", "isMoment", "rules", "tip", "autoAdjustOverflow", "overlayClassName", "overlayStyle", "getPopupContainer"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -22,6 +22,7 @@ import React, { useContext, useEffect, useRef, useState, useImperativeHandle, us
|
|
|
22
22
|
import { Button, ConfigProvider, Divider, Dropdown, Flex, Menu, Radio, Space, Tooltip, message, theme } from '@oceanbase/design';
|
|
23
23
|
import { LeftOutlined, RightOutlined, ZoomOutOutlined, SyncOutlined, ArrowLeftOutlined, CopyOutlined, DeleteOutlined } from '@oceanbase/icons';
|
|
24
24
|
import dayjs from 'dayjs';
|
|
25
|
+
import 'dayjs/locale/zh-cn';
|
|
25
26
|
import { findIndex, isEqual as _isEqual, isNil, noop, omit } from 'lodash';
|
|
26
27
|
import moment from 'moment';
|
|
27
28
|
import classNames from 'classnames';
|
|
@@ -80,6 +81,7 @@ var Ranger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
80
81
|
size = props.size,
|
|
81
82
|
_props$stickRangeName = props.stickRangeName,
|
|
82
83
|
stickRangeName = _props$stickRangeName === void 0 ? false : _props$stickRangeName,
|
|
84
|
+
variant = props.variant,
|
|
83
85
|
tooltipProps = props.tooltipProps,
|
|
84
86
|
isMomentProps = props.isMoment,
|
|
85
87
|
rules = props.rules,
|
|
@@ -133,6 +135,7 @@ var Ranger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
133
135
|
var rangeRef = useRef(null);
|
|
134
136
|
var popRef = useRef(null);
|
|
135
137
|
var labelRef = useRef(null);
|
|
138
|
+
var editableInputRef = useRef(null);
|
|
136
139
|
|
|
137
140
|
// 没有 selects 时,回退到普通 RangePicker, 当前时间选项为自定义时,应该显示 RangePicker
|
|
138
141
|
var _useState13 = useState(rangeName !== CUSTOMIZE),
|
|
@@ -317,7 +320,7 @@ var Ranger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
317
320
|
return diffMs > differenceMs;
|
|
318
321
|
}) : selects[rangeNameIndex + 1];
|
|
319
322
|
return wrapSSR( /*#__PURE__*/_jsxs(Space, {
|
|
320
|
-
className: classNames(rest.className, _defineProperty(_defineProperty(_defineProperty({}, prefix, true), "".concat(prefix, "-show-range"), true), "".concat(prefix, "-back-radio-focused"), backRadioFocused)),
|
|
323
|
+
className: classNames(rest.className, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, prefix, true), "".concat(prefix, "-show-range"), true), "".concat(prefix, "-dashed"), variant === 'dashed'), "".concat(prefix, "-back-radio-focused"), backRadioFocused)),
|
|
321
324
|
style: rest.style,
|
|
322
325
|
children: [/*#__PURE__*/_jsxs(Space, {
|
|
323
326
|
size: 0,
|
|
@@ -452,12 +455,22 @@ var Ranger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
452
455
|
rules: rules,
|
|
453
456
|
hideSecond: hideSecond,
|
|
454
457
|
onOk: function onOk(vList) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
458
|
+
var _editableInputRef$cur;
|
|
459
|
+
// 如果有粘贴值,优先使用粘贴值
|
|
460
|
+
if ((_editableInputRef$cur = editableInputRef.current) !== null && _editableInputRef$cur !== void 0 && _editableInputRef$cur.hasPastedValue) {
|
|
461
|
+
editableInputRef.current.confirmPastedValue();
|
|
462
|
+
setIsPlay(false);
|
|
463
|
+
handleNameChange(CUSTOMIZE);
|
|
464
|
+
closeTooltip();
|
|
465
|
+
} else {
|
|
466
|
+
// 否则使用面板中的值
|
|
467
|
+
setIsPlay(false);
|
|
468
|
+
handleNameChange(CUSTOMIZE);
|
|
469
|
+
rangeChange(vList.map(function (v) {
|
|
470
|
+
return isMoment ? moment(v) : dayjs(v);
|
|
471
|
+
}));
|
|
472
|
+
closeTooltip();
|
|
473
|
+
}
|
|
461
474
|
},
|
|
462
475
|
onCancel: function onCancel() {
|
|
463
476
|
closeTooltip();
|
|
@@ -521,6 +534,7 @@ var Ranger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
521
534
|
ref: rangeRef,
|
|
522
535
|
className: "".concat(prefix, "-editable-wrapper"),
|
|
523
536
|
children: /*#__PURE__*/_jsx(EditableDateTimeInput, _objectSpread({
|
|
537
|
+
ref: editableInputRef,
|
|
524
538
|
prefixCls: prefixCls,
|
|
525
539
|
value: innerValue,
|
|
526
540
|
onChange: function onChange(newValue) {
|
|
@@ -530,11 +544,13 @@ var Ranger = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
530
544
|
hideSecond: hideSecond,
|
|
531
545
|
isMoment: isMoment,
|
|
532
546
|
isCn: isCn,
|
|
547
|
+
format: (rest === null || rest === void 0 ? void 0 : rest.format) || YEAR_DATE_TIME_SECOND_FORMAT_CN,
|
|
548
|
+
open: open,
|
|
533
549
|
onClick: function onClick() {
|
|
534
550
|
setOpen(true);
|
|
535
551
|
setTooltipOpen(true);
|
|
536
552
|
}
|
|
537
|
-
}, omit(rest, 'value', 'onChange', 'style', 'className', 'onClick', '
|
|
553
|
+
}, omit(rest, 'value', 'onChange', 'style', 'className', 'onClick', 'disabled', 'format')))
|
|
538
554
|
})]
|
|
539
555
|
}), /*#__PURE__*/_jsxs(Radio.Group, {
|
|
540
556
|
value: isPlay ? 'play' : '',
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { useSegmentedInput } from './useSegmentedInput';
|
|
2
|
-
export
|
|
2
|
+
export { useAutoWidthInput } from './useAutoWidthInput';
|
|
3
|
+
export type { UseSegmentedInputOptions, UseSegmentedInputReturn } from './useSegmentedInput';
|
|
4
|
+
export type { UseAutoWidthInputOptions, UseAutoWidthInputReturn } from './useAutoWidthInput';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { useSegmentedInput } from "./useSegmentedInput";
|
|
1
|
+
export { useSegmentedInput } from "./useSegmentedInput";
|
|
2
|
+
export { useAutoWidthInput } from "./useAutoWidthInput";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { InputRef } from '@oceanbase/design';
|
|
3
|
+
export interface UseAutoWidthInputOptions {
|
|
4
|
+
inputRef: React.RefObject<InputRef>;
|
|
5
|
+
value: string;
|
|
6
|
+
minWidth?: number;
|
|
7
|
+
extraWidth?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface UseAutoWidthInputReturn {
|
|
10
|
+
inputWidth: number;
|
|
11
|
+
sizerRef: React.RefObject<HTMLSpanElement>;
|
|
12
|
+
}
|
|
13
|
+
export declare const useAutoWidthInput: (options: UseAutoWidthInputOptions) => UseAutoWidthInputReturn;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
8
|
+
var getHorizontalSpacing = function getHorizontalSpacing(computedStyle) {
|
|
9
|
+
return (parseFloat(computedStyle.paddingLeft) || 0) + (parseFloat(computedStyle.paddingRight) || 0) + (parseFloat(computedStyle.borderLeftWidth) || 0) + (parseFloat(computedStyle.borderRightWidth) || 0);
|
|
10
|
+
};
|
|
11
|
+
var getSizingValue = function getSizingValue(value) {
|
|
12
|
+
return value ? value.replace(/\d/g, '0') : "\xA0";
|
|
13
|
+
};
|
|
14
|
+
export var useAutoWidthInput = function useAutoWidthInput(options) {
|
|
15
|
+
var inputRef = options.inputRef,
|
|
16
|
+
value = options.value,
|
|
17
|
+
_options$minWidth = options.minWidth,
|
|
18
|
+
minWidth = _options$minWidth === void 0 ? 80 : _options$minWidth,
|
|
19
|
+
_options$extraWidth = options.extraWidth,
|
|
20
|
+
extraWidth = _options$extraWidth === void 0 ? 0 : _options$extraWidth;
|
|
21
|
+
var sizerRef = useRef(null);
|
|
22
|
+
var _useState = useState(minWidth),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
+
inputWidth = _useState2[0],
|
|
25
|
+
setInputWidth = _useState2[1];
|
|
26
|
+
useLayoutEffect(function () {
|
|
27
|
+
var _inputRef$current;
|
|
28
|
+
var nativeInput = (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.input;
|
|
29
|
+
var sizer = sizerRef.current;
|
|
30
|
+
if (!nativeInput || !sizer) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var computedStyle = window.getComputedStyle(nativeInput);
|
|
34
|
+
sizer.style.font = computedStyle.font;
|
|
35
|
+
sizer.style.letterSpacing = computedStyle.letterSpacing;
|
|
36
|
+
sizer.style.fontVariantNumeric = computedStyle.fontVariantNumeric;
|
|
37
|
+
sizer.textContent = getSizingValue(value);
|
|
38
|
+
setInputWidth(Math.max(minWidth, Math.ceil(sizer.getBoundingClientRect().width + getHorizontalSpacing(computedStyle) + extraWidth)));
|
|
39
|
+
}, [extraWidth, inputRef, minWidth, value]);
|
|
40
|
+
return {
|
|
41
|
+
inputWidth: inputWidth,
|
|
42
|
+
sizerRef: sizerRef
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Dayjs } from 'dayjs';
|
|
3
3
|
import type { Moment } from 'moment';
|
|
4
|
+
import 'dayjs/locale/en';
|
|
5
|
+
import 'dayjs/locale/zh-cn';
|
|
4
6
|
import type { InputRef } from '@oceanbase/design';
|
|
5
|
-
export type SegmentType = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second';
|
|
6
|
-
export type RangeType = 'start' | 'end';
|
|
7
|
-
export interface Segment {
|
|
8
|
-
type: SegmentType;
|
|
9
|
-
range: RangeType;
|
|
10
|
-
start: number;
|
|
11
|
-
end: number;
|
|
12
|
-
value: string;
|
|
13
|
-
min: number;
|
|
14
|
-
max: number;
|
|
15
|
-
padLength: number;
|
|
16
|
-
}
|
|
17
7
|
export interface UseSegmentedInputOptions {
|
|
18
8
|
value?: [Dayjs | Moment | null, Dayjs | Moment | null];
|
|
19
9
|
onChange?: (value: [Dayjs | Moment, Dayjs | Moment]) => void;
|
|
@@ -22,18 +12,20 @@ export interface UseSegmentedInputOptions {
|
|
|
22
12
|
isMoment?: boolean;
|
|
23
13
|
isCn?: boolean;
|
|
24
14
|
onClick?: () => void;
|
|
15
|
+
locale?: string;
|
|
16
|
+
open?: boolean;
|
|
25
17
|
}
|
|
26
18
|
export interface UseSegmentedInputReturn {
|
|
27
19
|
inputRef: React.RefObject<InputRef>;
|
|
28
20
|
isEditing: boolean;
|
|
29
21
|
displayValue: string;
|
|
30
|
-
currentSegment: Segment | null;
|
|
31
|
-
allSegments: Segment[];
|
|
32
22
|
handleClick: (e: React.MouseEvent<HTMLInputElement>) => void;
|
|
33
23
|
handleDoubleClick: (e: React.MouseEvent<HTMLInputElement>) => void;
|
|
34
|
-
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
35
24
|
handleBlur: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
36
|
-
|
|
25
|
+
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
26
|
+
confirmPastedValue: () => void;
|
|
27
|
+
hasPastedValue: boolean;
|
|
28
|
+
getPastedValue: () => [Dayjs | Moment, Dayjs | Moment] | null;
|
|
37
29
|
}
|
|
38
30
|
export declare const useSegmentedInput: (options: UseSegmentedInputOptions) => UseSegmentedInputReturn;
|
|
39
31
|
export default useSegmentedInput;
|