UNPKG

fomantic-ui-react

Version:

Fomantic-UI React -- A React Component Library.

120 lines (100 loc) 4.29 kB
/** * fomantic-ui-react v0.0.1-alpha.10 * (c) 2022 FireLoong <fireloong@foxmail.com> * @license MIT */ import { _ as _defineProperty, a as _objectWithoutProperties } from '../_chunks/dep-9f1126c1.js'; import { _ as _slicedToArray } from '../_chunks/dep-dc9b74a1.js'; import classNames from 'classnames'; import _ from 'lodash'; import React, { useState, Children, isValidElement, createElement } from 'react'; import { Icon } from '../icon/index.js'; import DropdownDivider from './DropdownDivider.js'; import DropdownMenu from './DropdownMenu.js'; import '../icon/Icon.js'; import './style/css.js'; import '../icon/type.js'; import '../transition/index.js'; import '../transition/Transition.js'; import '../transition/type.js'; var _excluded = ["as", "active", "selected", "className", "text", "description", "icon", "value", "unfilterable", "divider", "children"]; 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; } var DropdownItem = function DropdownItem(_ref) { var _ref$as = _ref.as, as = _ref$as === void 0 ? "div" : _ref$as, active = _ref.active, selected = _ref.selected, className = _ref.className, text = _ref.text, description = _ref.description, icon = _ref.icon, value = _ref.value, unfilterable = _ref.unfilterable, divider = _ref.divider, children = _ref.children, props = _objectWithoutProperties(_ref, _excluded); var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), visible = _useState2[0], setVisible = _useState2[1]; if (!as) { as = "div"; } if (divider) { return /* @__PURE__ */React.createElement(DropdownDivider, { as: as, className: className }); } var content; if (icon) { content = /* @__PURE__ */React.createElement(React.Fragment, null, content, /* @__PURE__ */React.createElement(Icon, { name: icon })); } if (description) { content = /* @__PURE__ */React.createElement(React.Fragment, null, content, /* @__PURE__ */React.createElement("span", { className: "description" }, description)); } if (text) { content = /* @__PURE__ */React.createElement(React.Fragment, null, content, text); } if (children) { var dropdownMenu = _.filter(Children.toArray(children), { type: DropdownMenu }); if (dropdownMenu.length === 1) { if (icon !== "dropdown") { content = /* @__PURE__ */React.createElement(React.Fragment, null, content, /* @__PURE__ */React.createElement(Icon, { name: "dropdown" })); } children = Children.map(children, function (child) { if ( /*#__PURE__*/isValidElement(child) && child.type === DropdownMenu) { return /* @__PURE__ */React.createElement(DropdownMenu, _objectSpread({ open: visible }, child.props)); } return child; }); } } return /*#__PURE__*/createElement(as, _objectSpread({ className: classNames("item", { active: active, selected: selected, unfilterable: unfilterable }, className), onMouseEnter: function onMouseEnter() { return setVisible(true); }, onMouseLeave: function onMouseLeave() { return setVisible(false); } }, props), /* @__PURE__ */React.createElement(React.Fragment, null, content, children)); }; DropdownItem.displayName = "DropdownItem"; export { DropdownItem as default }; //# sourceMappingURL=DropdownItem.js.map