208 lines
5.8 KiB
JavaScript
208 lines
5.8 KiB
JavaScript
|
|
"use strict";
|
||
|
|
|
||
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||
|
|
|
||
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||
|
|
|
||
|
|
Object.defineProperty(exports, "__esModule", {
|
||
|
|
value: true
|
||
|
|
});
|
||
|
|
exports.default = exports.styles = void 0;
|
||
|
|
|
||
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
||
|
|
|
||
|
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
||
|
|
|
||
|
|
var React = _interopRequireWildcard(require("react"));
|
||
|
|
|
||
|
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||
|
|
|
||
|
|
var _clsx = _interopRequireDefault(require("clsx"));
|
||
|
|
|
||
|
|
var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
|
||
|
|
|
||
|
|
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
||
|
|
|
||
|
|
var _utils = require("@material-ui/utils");
|
||
|
|
|
||
|
|
var _useIsFocusVisible2 = _interopRequireDefault(require("../utils/useIsFocusVisible"));
|
||
|
|
|
||
|
|
var _useForkRef = _interopRequireDefault(require("../utils/useForkRef"));
|
||
|
|
|
||
|
|
var _Typography = _interopRequireDefault(require("../Typography"));
|
||
|
|
|
||
|
|
var styles = {
|
||
|
|
/* Styles applied to the root element. */
|
||
|
|
root: {},
|
||
|
|
|
||
|
|
/* Styles applied to the root element if `underline="none"`. */
|
||
|
|
underlineNone: {
|
||
|
|
textDecoration: 'none'
|
||
|
|
},
|
||
|
|
|
||
|
|
/* Styles applied to the root element if `underline="hover"`. */
|
||
|
|
underlineHover: {
|
||
|
|
textDecoration: 'none',
|
||
|
|
'&:hover': {
|
||
|
|
textDecoration: 'underline'
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
/* Styles applied to the root element if `underline="always"`. */
|
||
|
|
underlineAlways: {
|
||
|
|
textDecoration: 'underline'
|
||
|
|
},
|
||
|
|
// Same reset as ButtonBase.root
|
||
|
|
|
||
|
|
/* Styles applied to the root element if `component="button"`. */
|
||
|
|
button: {
|
||
|
|
position: 'relative',
|
||
|
|
WebkitTapHighlightColor: 'transparent',
|
||
|
|
backgroundColor: 'transparent',
|
||
|
|
// Reset default value
|
||
|
|
// We disable the focus ring for mouse, touch and keyboard users.
|
||
|
|
outline: 0,
|
||
|
|
border: 0,
|
||
|
|
margin: 0,
|
||
|
|
// Remove the margin in Safari
|
||
|
|
borderRadius: 0,
|
||
|
|
padding: 0,
|
||
|
|
// Remove the padding in Firefox
|
||
|
|
cursor: 'pointer',
|
||
|
|
userSelect: 'none',
|
||
|
|
verticalAlign: 'middle',
|
||
|
|
'-moz-appearance': 'none',
|
||
|
|
// Reset
|
||
|
|
'-webkit-appearance': 'none',
|
||
|
|
// Reset
|
||
|
|
'&::-moz-focus-inner': {
|
||
|
|
borderStyle: 'none' // Remove Firefox dotted outline.
|
||
|
|
|
||
|
|
},
|
||
|
|
'&$focusVisible': {
|
||
|
|
outline: 'auto'
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
/* Pseudo-class applied to the root element if the link is keyboard focused. */
|
||
|
|
focusVisible: {}
|
||
|
|
};
|
||
|
|
exports.styles = styles;
|
||
|
|
var Link = /*#__PURE__*/React.forwardRef(function Link(props, ref) {
|
||
|
|
var classes = props.classes,
|
||
|
|
className = props.className,
|
||
|
|
_props$color = props.color,
|
||
|
|
color = _props$color === void 0 ? 'primary' : _props$color,
|
||
|
|
_props$component = props.component,
|
||
|
|
component = _props$component === void 0 ? 'a' : _props$component,
|
||
|
|
onBlur = props.onBlur,
|
||
|
|
onFocus = props.onFocus,
|
||
|
|
TypographyClasses = props.TypographyClasses,
|
||
|
|
_props$underline = props.underline,
|
||
|
|
underline = _props$underline === void 0 ? 'hover' : _props$underline,
|
||
|
|
_props$variant = props.variant,
|
||
|
|
variant = _props$variant === void 0 ? 'inherit' : _props$variant,
|
||
|
|
other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "color", "component", "onBlur", "onFocus", "TypographyClasses", "underline", "variant"]);
|
||
|
|
|
||
|
|
var _useIsFocusVisible = (0, _useIsFocusVisible2.default)(),
|
||
|
|
isFocusVisible = _useIsFocusVisible.isFocusVisible,
|
||
|
|
onBlurVisible = _useIsFocusVisible.onBlurVisible,
|
||
|
|
focusVisibleRef = _useIsFocusVisible.ref;
|
||
|
|
|
||
|
|
var _React$useState = React.useState(false),
|
||
|
|
focusVisible = _React$useState[0],
|
||
|
|
setFocusVisible = _React$useState[1];
|
||
|
|
|
||
|
|
var handlerRef = (0, _useForkRef.default)(ref, focusVisibleRef);
|
||
|
|
|
||
|
|
var handleBlur = function handleBlur(event) {
|
||
|
|
if (focusVisible) {
|
||
|
|
onBlurVisible();
|
||
|
|
setFocusVisible(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (onBlur) {
|
||
|
|
onBlur(event);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
var handleFocus = function handleFocus(event) {
|
||
|
|
if (isFocusVisible(event)) {
|
||
|
|
setFocusVisible(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (onFocus) {
|
||
|
|
onFocus(event);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
return /*#__PURE__*/React.createElement(_Typography.default, (0, _extends2.default)({
|
||
|
|
className: (0, _clsx.default)(classes.root, classes["underline".concat((0, _capitalize.default)(underline))], className, focusVisible && classes.focusVisible, component === 'button' && classes.button),
|
||
|
|
classes: TypographyClasses,
|
||
|
|
color: color,
|
||
|
|
component: component,
|
||
|
|
onBlur: handleBlur,
|
||
|
|
onFocus: handleFocus,
|
||
|
|
ref: handlerRef,
|
||
|
|
variant: variant
|
||
|
|
}, other));
|
||
|
|
});
|
||
|
|
process.env.NODE_ENV !== "production" ? Link.propTypes = {
|
||
|
|
/**
|
||
|
|
* The content of the link.
|
||
|
|
*/
|
||
|
|
children: _propTypes.default.node.isRequired,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Override or extend the styles applied to the component.
|
||
|
|
* See [CSS API](#css) below for more details.
|
||
|
|
*/
|
||
|
|
classes: _propTypes.default.object.isRequired,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ignore
|
||
|
|
*/
|
||
|
|
className: _propTypes.default.string,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The color of the link.
|
||
|
|
*/
|
||
|
|
color: _propTypes.default.oneOf(['initial', 'inherit', 'primary', 'secondary', 'textPrimary', 'textSecondary', 'error']),
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The component used for the root node.
|
||
|
|
* Either a string to use a HTML element or a component.
|
||
|
|
*/
|
||
|
|
component: _utils.elementTypeAcceptingRef,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ignore
|
||
|
|
*/
|
||
|
|
onBlur: _propTypes.default.func,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ignore
|
||
|
|
*/
|
||
|
|
onFocus: _propTypes.default.func,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* `classes` prop applied to the [`Typography`](/api/typography/) element.
|
||
|
|
*/
|
||
|
|
TypographyClasses: _propTypes.default.object,
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Controls when the link should have an underline.
|
||
|
|
*/
|
||
|
|
underline: _propTypes.default.oneOf(['none', 'hover', 'always']),
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Applies the theme typography styles.
|
||
|
|
*/
|
||
|
|
variant: _propTypes.default.string
|
||
|
|
} : void 0;
|
||
|
|
|
||
|
|
var _default = (0, _withStyles.default)(styles, {
|
||
|
|
name: 'MuiLink'
|
||
|
|
})(Link);
|
||
|
|
|
||
|
|
exports.default = _default;
|