UNPKG

@primer/components

Version:
93 lines (73 loc) 6.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _constants = require("./constants"); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _Box = _interopRequireDefault(require("./Box")); var _Link = _interopRequireDefault(require("./Link")); var _react = _interopRequireDefault(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _sx = _interopRequireDefault(require("./sx")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 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 SideNavBase({ variant, className, bordered, children, ...props }) { const variantClassName = variant === 'lightweight' ? 'lightweight' : 'normal'; const newClassName = (0, _classnames.default)(className, `variant-${variantClassName}`); if (!bordered) { props = { ...props, borderWidth: 0 }; } return /*#__PURE__*/_react.default.createElement(_Box.default, _extends({ borderWidth: "1px", borderStyle: "solid", borderColor: "border.default", borderRadius: 2, as: "nav", className: newClassName }, props), children); } SideNavBase.displayName = "SideNavBase"; const SideNav = (0, _styledComponents.default)(SideNavBase).withConfig({ displayName: "SideNav", componentId: "sc-15k667c-0" })(["background-color:", ";", " ", ";", ";"], (0, _constants.get)('colors.canvas.subtle'), props => props.bordered && (0, _styledComponents.css)(["& > &{border-left:0;border-right:0;border-bottom:0;}"]), _constants.COMMON, _sx.default); // used for variant normal hover, focus pseudo selectors const CommonAccessibilityVariantNormalStyles = (0, _styledComponents.css)(["background-color:", ";outline:none;text-decoration:none;"], (0, _constants.get)('colors.neutral.subtle')); // used for light weight hover, focus pseudo selectors const CommonAccessibilityVariantLightWeightStyles = (0, _styledComponents.css)(["color:", ";text-decoration:none;outline:none;"], (0, _constants.get)('colors.fg.default')); const SideNavLink = (0, _styledComponents.default)(_Link.default).attrs(props => { const isReactRouter = typeof props.to === 'string'; if (isReactRouter || props.selected) { // according to their docs, NavLink supports aria-current: // https://reacttraining.com/react-router/web/api/NavLink/aria-current-string return { 'aria-current': 'page' }; } else { return {}; } }).withConfig({ displayName: "SideNav__SideNavLink", componentId: "sc-15k667c-1" })(["position:relative;display:block;", " width:100%;text-align:left;font-size:", ";& > ", "{border-bottom:none;}", ".variant-normal > &{color:", ";padding:", ";border:0;border-top:", " solid ", ";&:first-child{border-top:0;border-top-right-radius:", ";border-top-left-radius:", ";}&:last-child{border-bottom-right-radius:", ";border-bottom-left-radius:", ";}&::before{position:absolute;top:0;bottom:0;left:0;z-index:1;width:3px;pointer-events:none;content:'';}&:hover{", "}&:focus{", " box-shadow:", ";z-index:1;}&[aria-current='page'],&[aria-selected='true']{background-color:", ";&::before{background-color:", ";}}}", ".variant-lightweight > &{padding:", " 0;color:", ";&:hover{", "}&:focus{", " box-shadow:", ";z-index:1;}&[aria-current='page'],&[aria-selected='true']{color:", ";font-weight:", ";}}", ";"], props => props.variant === 'full' && (0, _styledComponents.css)(["display:flex;align-items:center;justify-content:space-between;"]), (0, _constants.get)('fontSizes.1'), SideNav, SideNav, (0, _constants.get)('colors.fg.default'), (0, _constants.get)('space.3'), (0, _constants.get)('borderWidths.1'), (0, _constants.get)('colors.border.muted'), (0, _constants.get)('radii.2'), (0, _constants.get)('radii.2'), (0, _constants.get)('radii.2'), (0, _constants.get)('radii.2'), CommonAccessibilityVariantNormalStyles, CommonAccessibilityVariantNormalStyles, (0, _constants.get)('shadows.primer.shadow.focus'), (0, _constants.get)('colors.sidenav.selectedBg'), (0, _constants.get)('colors.primer.border.active'), SideNav, (0, _constants.get)('space.1'), (0, _constants.get)('colors.accent.fg'), CommonAccessibilityVariantLightWeightStyles, CommonAccessibilityVariantLightWeightStyles, (0, _constants.get)('shadows.primer.shadow.focus'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('fontWeights.semibold'), _sx.default); SideNav.defaultProps = { variant: 'normal' }; SideNavLink.defaultProps = { variant: 'normal' }; SideNavLink.displayName = 'SideNav.Link'; var _default = Object.assign(SideNav, { Link: SideNavLink }); exports.default = _default;