UNPKG

bloom-layout

Version:
69 lines (59 loc) 2.66 kB
var _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; }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } import React from 'react'; import PropTypes from 'prop-types'; import Route from './Route'; import Link from './Link'; /** * A <Link> wrapper that knows if it's "active" or not. */ var NavLink = function NavLink(_ref) { var to = _ref.to, exact = _ref.exact, strict = _ref.strict, location = _ref.location, activeClassName = _ref.activeClassName, className = _ref.className, activeStyle = _ref.activeStyle, style = _ref.style, getIsActive = _ref.isActive, ariaCurrent = _ref.ariaCurrent, rest = _objectWithoutProperties(_ref, ['to', 'exact', 'strict', 'location', 'activeClassName', 'className', 'activeStyle', 'style', 'isActive', 'ariaCurrent']); return React.createElement(Route, { path: (typeof to === 'undefined' ? 'undefined' : _typeof(to)) === 'object' ? to.pathname : to, exact: exact, strict: strict, location: location, children: function children(_ref2) { var location = _ref2.location, match = _ref2.match; var isActive = !!(getIsActive ? getIsActive(match, location) : match); return React.createElement(Link, _extends({ to: to, className: isActive ? [className, activeClassName].filter(function (i) { return i; }).join(' ') : className, style: isActive ? _extends({}, style, activeStyle) : style, 'aria-current': isActive && ariaCurrent }, rest)); } }); }; NavLink.propTypes = { to: Link.propTypes.to, exact: PropTypes.bool, strict: PropTypes.bool, location: PropTypes.object, activeClassName: PropTypes.string, className: PropTypes.string, activeStyle: PropTypes.object, style: PropTypes.object, isActive: PropTypes.func, ariaCurrent: PropTypes.oneOf(['page', 'step', 'location', 'true']) }; NavLink.defaultProps = { activeClassName: 'active', ariaCurrent: 'true' }; export default NavLink;