azure-devops-ui
Version:
React components for building web UI in Azure DevOps
1 lines • 2.08 kB
JavaScript
import"../../CommonImports";import"../../Core/core.css";import"./Link.css";import*as React from"react";import{FocusGroupContext}from"../../FocusGroup";import{FocusZoneContext}from"../../FocusZone";import{Tooltip}from"../../TooltipEx";import{css,getSafeId,KeyCode}from"../../Util";import{getTabIndex}from"../../Utilities/Focus";class Link extends React.Component{constructor(){super(...arguments),this.ref=React.createRef(),this.onClick=e=>{this.handleActivation(e)},this.onKeyPress=e=>{this.props.href||e.which!==KeyCode.enter||this.handleActivation(e)},this.onFocus=e=>{this.props.onFocus&&this.props.onFocus(e),this.props.id&&this.context.onFocus(this.props.id)}}render(){return React.createElement(FocusZoneContext.Consumer,null,e=>{var o=this["props"],{ariaDescribedBy:t,ariaLabel:r,ariaLabelledBy:s,ariaExpanded:n,ariaHasPopup:a,ariaSelected:i,className:c,draggable:l,excludeFocusZone:p,target:u,dataIsFocusable:d}=o;let{rel:h,role:f}=o,m="a",b=(u&&!h&&(h="noopener"),o.href||o.role||(f="button"),o.href||(m="span"),React.createElement(m,{ref:this.ref,"aria-describedby":getSafeId(t),"aria-expanded":n,"aria-haspopup":a,"aria-label":r,"aria-labelledby":s,"aria-selected":i,className:css(c,"bolt-link",o.disabled&&"disabled",o.subtle&&"subtle",o.underline&&"underline",o.removeUnderline&&"no-underline-link"),"data-focuszone":!p&&e.focuszoneId,"data-is-focusable":d,download:o.download,draggable:l,href:o.href,id:getSafeId(o.id),onBlur:o.onBlur,onClick:this.onClick,onFocus:this.onFocus,onKeyPress:this.onKeyPress,onMouseEnter:o.onMouseEnter,onMouseLeave:o.onMouseLeave,onMouseOver:o.onMouseOver,onTouchEnd:o.onTouchEnd,onTouchMove:o.onTouchMove,onTouchStart:o.onTouchStart,rel:h,role:f,tabIndex:getTabIndex(this.props,this.context),target:u},this.props.children));return b=o.tooltipProps?React.createElement(Tooltip,Object.assign({},o.tooltipProps),b):b})}focus(){this.ref.current&&this.ref.current.focus()}handleActivation(e){e.defaultPrevented||(this.props.disabled?e.preventDefault():this.props.onClick&&this.props.onClick(e))}}Link.contextType=FocusGroupContext;export{Link};