@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
|
@@ -4,6 +4,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
4
4
|
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); }
|
|
5
5
|
import { genComponentStyleHook } from "../../_util/genComponentStyleHook";
|
|
6
6
|
export var genDateRangerStyle = function genDateRangerStyle(token) {
|
|
7
|
+
var _ref;
|
|
7
8
|
var componentCls = token.componentCls,
|
|
8
9
|
antCls = token.antCls,
|
|
9
10
|
colorBgContainer = token.colorBgContainer,
|
|
@@ -12,7 +13,7 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
|
|
|
12
13
|
colorTextSecondary = token.colorTextSecondary,
|
|
13
14
|
colorFillSecondary = token.colorFillSecondary,
|
|
14
15
|
colorFill = token.colorFill;
|
|
15
|
-
return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(
|
|
16
|
+
return _ref = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref, "".concat(componentCls), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
|
|
16
17
|
cursor: 'pointer'
|
|
17
18
|
}, "".concat(componentCls, "-wrapper"), _defineProperty(_defineProperty({
|
|
18
19
|
backgroundColor: colorBgContainer,
|
|
@@ -99,7 +100,14 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
|
|
|
99
100
|
width: 52,
|
|
100
101
|
borderRadius: token.borderRadiusSM,
|
|
101
102
|
textAlign: 'center'
|
|
102
|
-
}), "".concat(componentCls, "-
|
|
103
|
+
}), "".concat(componentCls, "-dashed"), _defineProperty(_defineProperty({}, "".concat(componentCls, "-wrapper"), {
|
|
104
|
+
borderStyle: 'dashed'
|
|
105
|
+
}), "".concat(componentCls, "-playback-control"), _defineProperty({}, "".concat(antCls, "-radio-button-wrapper"), {
|
|
106
|
+
borderStyle: 'dashed',
|
|
107
|
+
'&::before': {
|
|
108
|
+
borderStyle: 'dashed'
|
|
109
|
+
}
|
|
110
|
+
}))), "".concat(componentCls, "-back-radio-focused"), _defineProperty(_defineProperty({}, "".concat(componentCls, "-wrapper"), {
|
|
103
111
|
borderRightColor: token.gray7
|
|
104
112
|
}), "".concat(componentCls, "-playback-control"), _defineProperty({}, "".concat(antCls, "-radio-button-wrapper:first-child"), _defineProperty({}, "+ ".concat(antCls, "-radio-button-wrapper::before"), {
|
|
105
113
|
backgroundColor: token.gray7
|
|
@@ -120,6 +128,7 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
|
|
|
120
128
|
display: 'inline-flex',
|
|
121
129
|
alignItems: 'center'
|
|
122
130
|
}), "".concat(componentCls, "-range-editable"), {
|
|
131
|
+
position: 'relative',
|
|
123
132
|
display: 'inline-flex',
|
|
124
133
|
alignItems: 'center',
|
|
125
134
|
cursor: 'text',
|
|
@@ -127,10 +136,21 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
|
|
|
127
136
|
cursor: 'not-allowed',
|
|
128
137
|
opacity: 0.6
|
|
129
138
|
}
|
|
139
|
+
}), _defineProperty(_defineProperty(_ref, "".concat(componentCls, "-range-editable-sizer"), {
|
|
140
|
+
position: 'absolute',
|
|
141
|
+
top: 0,
|
|
142
|
+
left: 0,
|
|
143
|
+
height: 0,
|
|
144
|
+
overflow: 'hidden',
|
|
145
|
+
whiteSpace: 'pre',
|
|
146
|
+
visibility: 'hidden',
|
|
147
|
+
pointerEvents: 'none'
|
|
130
148
|
}), "".concat(componentCls, "-range-editable-input"), {
|
|
131
|
-
|
|
149
|
+
minWidth: 80,
|
|
150
|
+
maxWidth: '100%',
|
|
132
151
|
cursor: 'text',
|
|
133
152
|
caretColor: 'transparent',
|
|
153
|
+
fontVariantNumeric: 'tabular-nums',
|
|
134
154
|
'&:focus, &:focus-within': _defineProperty({}, "".concat(antCls, "-input"), {
|
|
135
155
|
caretColor: token.colorPrimary
|
|
136
156
|
})
|
|
@@ -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;
|
|
@@ -8,11 +8,12 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
9
|
var _design = require("@oceanbase/design");
|
|
10
10
|
var _useSegmentedInput = require("./hooks/useSegmentedInput");
|
|
11
|
+
var _useAutoWidthInput = require("./hooks/useAutoWidthInput");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
-
const EditableDateTimeInput = props => {
|
|
16
|
+
const EditableDateTimeInput = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
16
17
|
const {
|
|
17
18
|
value,
|
|
18
19
|
onChange,
|
|
@@ -24,7 +25,8 @@ const EditableDateTimeInput = props => {
|
|
|
24
25
|
className,
|
|
25
26
|
prefixCls = 'ant-picker',
|
|
26
27
|
disabled = false,
|
|
27
|
-
onClick
|
|
28
|
+
onClick,
|
|
29
|
+
open = false
|
|
28
30
|
} = props;
|
|
29
31
|
|
|
30
32
|
// 根据配置生成格式,优先使用外部传入的 format
|
|
@@ -70,9 +72,10 @@ const EditableDateTimeInput = props => {
|
|
|
70
72
|
displayValue,
|
|
71
73
|
handleClick,
|
|
72
74
|
handleDoubleClick,
|
|
73
|
-
handleKeyDown,
|
|
74
75
|
handleBlur,
|
|
75
|
-
|
|
76
|
+
handleKeyDown,
|
|
77
|
+
hasPastedValue,
|
|
78
|
+
confirmPastedValue
|
|
76
79
|
} = (0, _useSegmentedInput.useSegmentedInput)({
|
|
77
80
|
value,
|
|
78
81
|
onChange,
|
|
@@ -80,28 +83,49 @@ const EditableDateTimeInput = props => {
|
|
|
80
83
|
baseFormat,
|
|
81
84
|
isMoment,
|
|
82
85
|
isCn,
|
|
83
|
-
onClick
|
|
86
|
+
onClick,
|
|
87
|
+
open
|
|
88
|
+
});
|
|
89
|
+
const {
|
|
90
|
+
sizerRef,
|
|
91
|
+
inputWidth
|
|
92
|
+
} = (0, _useAutoWidthInput.useAutoWidthInput)({
|
|
93
|
+
inputRef,
|
|
94
|
+
value: displayValue,
|
|
95
|
+
minWidth: 80,
|
|
96
|
+
extraWidth: isCn ? 26 : 0
|
|
84
97
|
});
|
|
85
|
-
|
|
98
|
+
|
|
99
|
+
// 暴露方法给父组件
|
|
100
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
101
|
+
hasPastedValue,
|
|
102
|
+
confirmPastedValue
|
|
103
|
+
}));
|
|
104
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
86
105
|
className: (0, _classnames.default)(`${prefixCls}-range-editable`, className, {
|
|
87
106
|
[`${prefixCls}-range-editable-focused`]: isEditing,
|
|
88
107
|
[`${prefixCls}-range-editable-disabled`]: disabled
|
|
89
108
|
}),
|
|
90
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
109
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
110
|
+
ref: sizerRef,
|
|
111
|
+
className: `${prefixCls}-range-editable-sizer`,
|
|
112
|
+
"aria-hidden": true
|
|
113
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.Input, {
|
|
91
114
|
ref: inputRef,
|
|
92
115
|
className: `${prefixCls}-range-editable-input`,
|
|
116
|
+
style: {
|
|
117
|
+
width: inputWidth
|
|
118
|
+
},
|
|
93
119
|
value: displayValue,
|
|
94
120
|
readOnly: true,
|
|
95
121
|
disabled: disabled,
|
|
96
122
|
variant: "borderless",
|
|
97
123
|
onClick: handleClick,
|
|
98
124
|
onDoubleClick: handleDoubleClick,
|
|
99
|
-
onKeyDown: handleKeyDown
|
|
100
|
-
// onFocus={handleFocus}
|
|
101
|
-
,
|
|
102
125
|
onBlur: handleBlur,
|
|
103
|
-
|
|
104
|
-
})
|
|
126
|
+
onKeyDown: handleKeyDown
|
|
127
|
+
})]
|
|
105
128
|
});
|
|
106
|
-
};
|
|
129
|
+
});
|
|
130
|
+
EditableDateTimeInput.displayName = 'EditableDateTimeInput';
|
|
107
131
|
var _default = exports.default = EditableDateTimeInput;
|
|
@@ -171,7 +171,7 @@ const InternalPickerPanel = props => {
|
|
|
171
171
|
}],
|
|
172
172
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.DatePicker, {
|
|
173
173
|
format: {
|
|
174
|
-
format:
|
|
174
|
+
format: DATE_FORMAT,
|
|
175
175
|
type: 'mask'
|
|
176
176
|
},
|
|
177
177
|
style: {
|
|
@@ -243,7 +243,7 @@ const InternalPickerPanel = props => {
|
|
|
243
243
|
}],
|
|
244
244
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.DatePicker, {
|
|
245
245
|
format: {
|
|
246
|
-
format:
|
|
246
|
+
format: DATE_FORMAT,
|
|
247
247
|
type: 'mask'
|
|
248
248
|
},
|
|
249
249
|
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/lib/DateRanger/Ranger.js
CHANGED
|
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _design = require("@oceanbase/design");
|
|
9
9
|
var _icons = require("@oceanbase/icons");
|
|
10
10
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
11
|
+
require("dayjs/locale/zh-cn");
|
|
11
12
|
var _lodash = require("lodash");
|
|
12
13
|
var _moment = _interopRequireDefault(require("moment"));
|
|
13
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
@@ -56,6 +57,7 @@ const Ranger = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
56
57
|
size,
|
|
57
58
|
//固定 rangeName
|
|
58
59
|
stickRangeName = false,
|
|
60
|
+
variant,
|
|
59
61
|
tooltipProps,
|
|
60
62
|
isMoment: isMomentProps,
|
|
61
63
|
rules,
|
|
@@ -90,6 +92,7 @@ const Ranger = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
90
92
|
const rangeRef = (0, _react.useRef)(null);
|
|
91
93
|
const popRef = (0, _react.useRef)(null);
|
|
92
94
|
const labelRef = (0, _react.useRef)(null);
|
|
95
|
+
const editableInputRef = (0, _react.useRef)(null);
|
|
93
96
|
|
|
94
97
|
// 没有 selects 时,回退到普通 RangePicker, 当前时间选项为自定义时,应该显示 RangePicker
|
|
95
98
|
const [isPlay, setIsPlay] = (0, _react.useState)(rangeName !== _constant.CUSTOMIZE);
|
|
@@ -258,6 +261,7 @@ const Ranger = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
258
261
|
className: (0, _classnames.default)(rest.className, {
|
|
259
262
|
[prefix]: true,
|
|
260
263
|
[`${prefix}-show-range`]: true,
|
|
264
|
+
[`${prefix}-dashed`]: variant === 'dashed',
|
|
261
265
|
[`${prefix}-back-radio-focused`]: backRadioFocused
|
|
262
266
|
}),
|
|
263
267
|
style: rest.style,
|
|
@@ -393,12 +397,21 @@ const Ranger = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
393
397
|
rules: rules,
|
|
394
398
|
hideSecond: hideSecond,
|
|
395
399
|
onOk: vList => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
// 如果有粘贴值,优先使用粘贴值
|
|
401
|
+
if (editableInputRef.current?.hasPastedValue) {
|
|
402
|
+
editableInputRef.current.confirmPastedValue();
|
|
403
|
+
setIsPlay(false);
|
|
404
|
+
handleNameChange(_constant.CUSTOMIZE);
|
|
405
|
+
closeTooltip();
|
|
406
|
+
} else {
|
|
407
|
+
// 否则使用面板中的值
|
|
408
|
+
setIsPlay(false);
|
|
409
|
+
handleNameChange(_constant.CUSTOMIZE);
|
|
410
|
+
rangeChange(vList.map(v => {
|
|
411
|
+
return isMoment ? (0, _moment.default)(v) : (0, _dayjs.default)(v);
|
|
412
|
+
}));
|
|
413
|
+
closeTooltip();
|
|
414
|
+
}
|
|
402
415
|
},
|
|
403
416
|
onCancel: () => {
|
|
404
417
|
closeTooltip();
|
|
@@ -461,6 +474,7 @@ const Ranger = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
461
474
|
ref: rangeRef,
|
|
462
475
|
className: `${prefix}-editable-wrapper`,
|
|
463
476
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_EditableDateTimeInput.default, {
|
|
477
|
+
ref: editableInputRef,
|
|
464
478
|
prefixCls: prefixCls,
|
|
465
479
|
value: innerValue,
|
|
466
480
|
onChange: newValue => {
|
|
@@ -470,11 +484,13 @@ const Ranger = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
470
484
|
hideSecond: hideSecond,
|
|
471
485
|
isMoment: isMoment,
|
|
472
486
|
isCn: isCn,
|
|
487
|
+
format: rest?.format || _constant.YEAR_DATE_TIME_SECOND_FORMAT_CN,
|
|
488
|
+
open: open,
|
|
473
489
|
onClick: () => {
|
|
474
490
|
setOpen(true);
|
|
475
491
|
setTooltipOpen(true);
|
|
476
492
|
},
|
|
477
|
-
...(0, _lodash.omit)(rest, 'value', 'onChange', 'style', 'className', 'onClick', '
|
|
493
|
+
...(0, _lodash.omit)(rest, 'value', 'onChange', 'style', 'className', 'onClick', 'disabled', 'format')
|
|
478
494
|
})
|
|
479
495
|
})]
|
|
480
496
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_design.Radio.Group, {
|
|
@@ -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';
|
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "useAutoWidthInput", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useAutoWidthInput.useAutoWidthInput;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "useSegmentedInput", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
9
15
|
return _useSegmentedInput.useSegmentedInput;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
12
|
-
var _useSegmentedInput = require("./useSegmentedInput");
|
|
18
|
+
var _useSegmentedInput = require("./useSegmentedInput");
|
|
19
|
+
var _useAutoWidthInput = require("./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,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAutoWidthInput = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const getHorizontalSpacing = computedStyle => (parseFloat(computedStyle.paddingLeft) || 0) + (parseFloat(computedStyle.paddingRight) || 0) + (parseFloat(computedStyle.borderLeftWidth) || 0) + (parseFloat(computedStyle.borderRightWidth) || 0);
|
|
9
|
+
const getSizingValue = value => value ? value.replace(/\d/g, '0') : '\u00a0';
|
|
10
|
+
const useAutoWidthInput = options => {
|
|
11
|
+
const {
|
|
12
|
+
inputRef,
|
|
13
|
+
value,
|
|
14
|
+
minWidth = 80,
|
|
15
|
+
extraWidth = 0
|
|
16
|
+
} = options;
|
|
17
|
+
const sizerRef = (0, _react.useRef)(null);
|
|
18
|
+
const [inputWidth, setInputWidth] = (0, _react.useState)(minWidth);
|
|
19
|
+
(0, _react.useLayoutEffect)(() => {
|
|
20
|
+
const nativeInput = inputRef.current?.input;
|
|
21
|
+
const sizer = sizerRef.current;
|
|
22
|
+
if (!nativeInput || !sizer) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const computedStyle = window.getComputedStyle(nativeInput);
|
|
26
|
+
sizer.style.font = computedStyle.font;
|
|
27
|
+
sizer.style.letterSpacing = computedStyle.letterSpacing;
|
|
28
|
+
sizer.style.fontVariantNumeric = computedStyle.fontVariantNumeric;
|
|
29
|
+
sizer.textContent = getSizingValue(value);
|
|
30
|
+
setInputWidth(Math.max(minWidth, Math.ceil(sizer.getBoundingClientRect().width + getHorizontalSpacing(computedStyle) + extraWidth)));
|
|
31
|
+
}, [extraWidth, inputRef, minWidth, value]);
|
|
32
|
+
return {
|
|
33
|
+
inputWidth,
|
|
34
|
+
sizerRef
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.useAutoWidthInput = useAutoWidthInput;
|
|
@@ -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;
|