zent
Version:
一套前端设计语言和基于React的实现
46 lines (45 loc) • 4.79 kB
JavaScript
import { __assign, __rest } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from 'react';
import cx from 'classnames';
import Icon from '../../icon';
import { formatDate, formatDateRange } from '../utils';
var TriggerPrefixCls = 'zent-datepicker-trigger';
var TriggerDiv = function (_a) {
var _b;
var disabled = _a.disabled, canClear = _a.canClear, panelVisible = _a.panelVisible, width = _a.width, children = _a.children;
var triggerStyle = {
width: width,
};
return (_jsx("div", __assign({ className: cx(TriggerPrefixCls, (_b = {
'zent-datepicker-can-clear': !disabled && canClear,
'zent-datepicker-disabled': disabled
},
_b[TriggerPrefixCls + "-focus"] = panelVisible,
_b)), style: triggerStyle, "data-zv": '10.0.17' }, { children: children }), void 0));
};
export var SingleInputTrigger = function (_a) {
var _b, _c;
var value = _a.value, format = _a.format, seperator = _a.seperator, placeholder = _a.placeholder, onClearInput = _a.onClearInput, text = _a.text, name = _a.name, canClear = _a.canClear, icon = _a.icon, hiddenIcon = _a.hiddenIcon, disabled = _a.disabled, restProps = __rest(_a, ["value", "format", "seperator", "placeholder", "onClearInput", "text", "name", "canClear", "icon", "hiddenIcon", "disabled"]);
var _d = Array.isArray(text) ? text : [text], startText = _d[0], endText = _d[1];
var canClearMerge = canClear && !!value;
return (_jsxs(TriggerDiv, __assign({}, restProps, { disabled: disabled, canClear: canClearMerge }, { children: [name && (_jsx("input", { type: "hidden", name: name, readOnly: true, value: formatDate(format, value), "data-zv": '10.0.17' }, void 0)), _jsx("span", __assign({ className: cx(TriggerPrefixCls + "-input", (_b = {},
_b[TriggerPrefixCls + "-empty-input"] = !startText || disabled,
_b)), "data-zv": '10.0.17' }, { children: startText || placeholder }), void 0), endText && (_jsxs(_Fragment, { children: [_jsx("span", __assign({ className: TriggerPrefixCls + "-seperator", "data-zv": '10.0.17' }, { children: seperator }), void 0), _jsx("span", __assign({ className: cx(TriggerPrefixCls + "-input", (_c = {},
_c[TriggerPrefixCls + "-empty-input"] = !endText,
_c)), "data-zv": '10.0.17' }, { children: endText }), void 0)] }, void 0)), !hiddenIcon && (_jsxs(_Fragment, { children: [_jsx(Icon, { type: icon || 'calendar-o' }, void 0), canClearMerge && _jsx(Icon, { type: "close-circle", onClick: onClearInput }, void 0)] }, void 0))] }), void 0));
};
export var CombinedInputTrigger = function (_a) {
var _b, _c;
var format = _a.format, value = _a.value, selected = _a.selected, seperator = _a.seperator, _d = _a.placeholder, startPlaceholder = _d[0], endPlaceholder = _d[1], name = _a.name, canClear = _a.canClear, icon = _a.icon, onClearInput = _a.onClearInput, disabled = _a.disabled, restProps = __rest(_a, ["format", "value", "selected", "seperator", "placeholder", "name", "canClear", "icon", "onClearInput", "disabled"]);
var _e = useMemo(function () {
if (!selected)
return [null, null];
return formatDateRange(selected, format);
}, [selected, format]), leftText = _e[0], rightText = _e[1];
return (_jsxs(TriggerDiv, __assign({}, restProps, { disabled: disabled, canClear: canClear && (!!leftText || !!rightText) }, { children: [name && (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: name === null || name === void 0 ? void 0 : name[0], readOnly: true, value: formatDate(format, value === null || value === void 0 ? void 0 : value[0]), "data-zv": '10.0.17' }, void 0), _jsx("input", { readOnly: true, type: "hidden", name: name === null || name === void 0 ? void 0 : name[1], value: formatDate(format, value === null || value === void 0 ? void 0 : value[1]), "data-zv": '10.0.17' }, void 0)] }, void 0)), _jsx("span", __assign({ className: cx(TriggerPrefixCls + "-input", (_b = {},
_b[TriggerPrefixCls + "-empty-input"] = !leftText,
_b)), "data-zv": '10.0.17' }, { children: leftText || startPlaceholder }), void 0), _jsx("span", __assign({ className: TriggerPrefixCls + "-seperator", "data-zv": '10.0.17' }, { children: seperator }), void 0), _jsx("span", __assign({ className: cx(TriggerPrefixCls + "-input", (_c = {},
_c[TriggerPrefixCls + "-empty-input"] = !rightText,
_c)), "data-zv": '10.0.17' }, { children: rightText || endPlaceholder }), void 0), _jsx(Icon, { type: icon || 'calendar-o' }, void 0), _jsx(Icon, { type: "close-circle", onClick: onClearInput }, void 0)] }), void 0));
};