office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
48 lines • 2.75 kB
JavaScript
import * as tslib_1 from "tslib";
import * as React from 'react';
import { anchorProperties, BaseComponent, buttonProperties, classNamesFunction, customizable, getNativeProps, createRef } from '../../Utilities';
import { KeytipData } from '../../KeytipData';
var getClassNames = classNamesFunction();
var LinkBase = /** @class */ (function (_super) {
tslib_1.__extends(LinkBase, _super);
function LinkBase() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._link = createRef();
_this._onClick = function (ev) {
var _a = _this.props, onClick = _a.onClick, disabled = _a.disabled;
if (disabled) {
ev.preventDefault();
}
else if (onClick) {
onClick(ev);
}
};
return _this;
}
LinkBase.prototype.render = function () {
var _this = this;
var _a = this.props, disabled = _a.disabled, children = _a.children, className = _a.className, href = _a.href, theme = _a.theme, getStyles = _a.getStyles, keytipProps = _a.keytipProps;
var classNames = getClassNames(getStyles, {
className: className,
isButton: !href,
isDisabled: disabled,
theme: theme
});
var anchorNativeProps = getNativeProps(this.props, anchorProperties);
var buttonNativeProps = getNativeProps(this.props, buttonProperties);
var anchorElement = (React.createElement(KeytipData, { keytipProps: keytipProps, ariaDescribedBy: anchorNativeProps['aria-describedby'], disabled: disabled }, function (keytipAttributes) { return (React.createElement("a", tslib_1.__assign({}, anchorNativeProps, keytipAttributes, { className: classNames.root, onClick: _this._onClick, ref: _this._link, target: _this.props.target, "aria-disabled": disabled }), children)); }));
var buttonElement = (React.createElement(KeytipData, { keytipProps: keytipProps, ariaDescribedBy: buttonNativeProps['aria-describedby'], disabled: disabled }, function (keytipAttributes) { return (React.createElement("button", tslib_1.__assign({}, buttonNativeProps, keytipAttributes, { className: classNames.root, onClick: _this._onClick, ref: _this._link, "aria-disabled": disabled }), children)); }));
return href ? anchorElement : buttonElement;
};
LinkBase.prototype.focus = function () {
if (this._link.current) {
this._link.current.focus();
}
};
LinkBase = tslib_1.__decorate([
customizable('Link', ['theme', 'getStyles'])
], LinkBase);
return LinkBase;
}(BaseComponent));
export { LinkBase };
//# sourceMappingURL=Link.base.js.map