UNPKG

@flatbiz/antd

Version:
58 lines (54 loc) 2.06 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { classNames } from '@dimjs/utils/class-names/class-names'; import { hooks } from '@wove/react/hooks'; import { a as _slicedToArray } from './_rollupPluginBabelHelpers-BYm17lo8.js'; import { useState } from 'react'; import { Upload, Button } from 'antd'; import { isUndefinedOrNull } from '@flatbiz/utils'; import { jsx } from 'react/jsx-runtime'; /** * 文件选择,内部不调用服务上传 * ``` * 默认选择文件格式:.xlsx,.xls * ``` */ var FileSelect = function FileSelect(props) { var buttonName = props.buttonName; var _useState = useState([]), _useState2 = _slicedToArray(_useState, 2), fileList = _useState2[0], setFileList = _useState2[1]; var direction = isUndefinedOrNull(props.direction) ? 'horizontal' : props.direction; var beforeUpload = hooks.useCallbackRef(function (file) { var _props$onChange; setFileList([file]); (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, file); return false; }); var onChange = hooks.useCallbackRef(function (info) { var _info$file; if ((info === null || info === void 0 || (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.status) === 'removed') { var _props$onChange2; setFileList([]); (_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 || _props$onChange2.call(props); } }); return /*#__PURE__*/jsx(Upload, { showUploadList: true, onChange: onChange, maxCount: 1, beforeUpload: beforeUpload, fileList: fileList, accept: props.accept || '.xlsx,.xls', className: classNames('file-select', { 'file-select-horizontal': direction === 'horizontal' }, props.className), children: props.children ? props.children : /*#__PURE__*/jsx(Button, { type: "primary", ghost: true, children: buttonName || '选择文件' }) }); }; export { FileSelect as F }; //# sourceMappingURL=file-select-C56tgs1o.js.map