UNPKG

@lvxiaowu/antd4

Version:

antd4-components

66 lines (50 loc) 4.11 kB
var _excluded = ["label", "children", "style", "col", "initialValue", "autoPlaceholder"]; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from "react"; import { cloneElement, isValidElement, useContext } from 'react'; import { Col, Form } from 'antd'; import { SearchCtx } from './Context'; var Item = Form.Item; function SearchItem(_ref) { var label = _ref.label, children = _ref.children, style = _ref.style, col = _ref.col, initialValue = _ref.initialValue, _ref$autoPlaceholder = _ref.autoPlaceholder, autoPlaceholder = _ref$autoPlaceholder === void 0 ? true : _ref$autoPlaceholder, rest = _objectWithoutProperties(_ref, _excluded); var _useContext = useContext(SearchCtx), row = _useContext.row, itemCol = _useContext.itemCol, itemChildProps = _useContext.itemChildProps; var _itemCol = row ? _objectSpread(_objectSpread({}, itemCol), col) : null; var child = children; var isValidEle = /*#__PURE__*/isValidElement(children); if (isValidEle) { var _children$props$place; var _ref2 = children.props.style || {}, width = _ref2.width; child = /*#__PURE__*/cloneElement(children, _objectSpread(_objectSpread(_objectSpread({}, itemChildProps), autoPlaceholder ? { placeholder: (_children$props$place = children.props.placeholder) !== null && _children$props$place !== void 0 ? _children$props$place : label } : {}), {}, { style: _objectSpread(_objectSpread({ width: '100%', minWidth: _itemCol ? 0 : width || 120 }, itemChildProps === null || itemChildProps === void 0 ? void 0 : itemChildProps.style), children.props.style) })); } var res = /*#__PURE__*/React.createElement(Item, _extends({ label: label, style: _objectSpread({ marginBottom: 12 }, style) }, rest), child); return _itemCol && isValidEle ? /*#__PURE__*/React.createElement(Col, _itemCol, res) : res; } export default SearchItem;