@talend/react-bootstrap
Version:
Bootstrap 3 components built with React
81 lines (77 loc) • 2.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _Dropdown = _interopRequireDefault(require("./Dropdown"));
var _splitComponentProps = _interopRequireDefault(require("./utils/splitComponentProps"));
var _ValidComponentChildren = _interopRequireDefault(require("./utils/ValidComponentChildren"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const propTypes = {
..._Dropdown.default.propTypes,
// Toggle props.
title: _propTypes.default.node.isRequired,
noCaret: _propTypes.default.bool,
active: _propTypes.default.bool,
activeKey: _propTypes.default.any,
activeHref: _propTypes.default.string,
// Override generated docs from <Dropdown>.
/**
* @private
*/
children: _propTypes.default.node
};
class NavDropdown extends _react.default.Component {
isActive({
props
}, activeKey, activeHref) {
if (props.active || activeKey != null && props.eventKey === activeKey || activeHref && props.href === activeHref) {
return true;
}
if (_ValidComponentChildren.default.some(props.children, child => this.isActive(child, activeKey, activeHref))) {
return true;
}
return props.active;
}
render() {
const {
title,
activeKey,
activeHref,
className,
style,
children,
...props
} = this.props;
const active = this.isActive(this, activeKey, activeHref);
delete props.active; // Accessed via this.isActive().
delete props.eventKey; // Accessed via this.isActive().
const [dropdownProps, toggleProps] = (0, _splitComponentProps.default)(props, _Dropdown.default.ControlledComponent);
// Unlike for the other dropdowns, styling needs to go to the `<Dropdown>`
// rather than the `<Dropdown.Toggle>`.
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dropdown.default, {
...dropdownProps,
componentClass: "li",
className: (0, _classnames.default)(className, {
active
}),
style: style,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.default.Toggle, {
...toggleProps,
useAnchor: true,
children: title
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.default.Menu, {
children: _ValidComponentChildren.default.map(children, child => /*#__PURE__*/_react.default.cloneElement(child, {
active: this.isActive(child, activeKey, activeHref)
}))
})]
});
}
}
NavDropdown.propTypes = propTypes;
var _default = exports.default = NavDropdown;
//# sourceMappingURL=NavDropdown.js.map