1 | import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
2 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
3 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
4 | import _extends from "@babel/runtime/helpers/esm/extends";
|
5 | import * as React from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import clsx from 'clsx';
|
8 | import { elementTypeAcceptingRef } from '@mui/utils';
|
9 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
10 | import capitalize from '../utils/capitalize';
|
11 | import styled from '../styles/styled';
|
12 | import useThemeProps from '../styles/useThemeProps';
|
13 | import useIsFocusVisible from '../utils/useIsFocusVisible';
|
14 | import useForkRef from '../utils/useForkRef';
|
15 | import Typography from '../Typography';
|
16 | import linkClasses, { getLinkUtilityClass } from './linkClasses';
|
17 | import getTextDecoration, { colorTransformations } from './getTextDecoration';
|
18 | import { jsx as _jsx } from "react/jsx-runtime";
|
19 |
|
20 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
21 | var classes = ownerState.classes,
|
22 | component = ownerState.component,
|
23 | focusVisible = ownerState.focusVisible,
|
24 | underline = ownerState.underline;
|
25 | var slots = {
|
26 | root: ['root', "underline".concat(capitalize(underline)), component === 'button' && 'button', focusVisible && 'focusVisible']
|
27 | };
|
28 | return composeClasses(slots, getLinkUtilityClass, classes);
|
29 | };
|
30 |
|
31 | var LinkRoot = styled(Typography, {
|
32 | name: 'MuiLink',
|
33 | slot: 'Root',
|
34 | overridesResolver: function overridesResolver(props, styles) {
|
35 | var ownerState = props.ownerState;
|
36 | return [styles.root, styles["underline".concat(capitalize(ownerState.underline))], ownerState.component === 'button' && styles.button];
|
37 | }
|
38 | })(function (_ref) {
|
39 | var theme = _ref.theme,
|
40 | ownerState = _ref.ownerState;
|
41 | return _extends({}, ownerState.underline === 'none' && {
|
42 | textDecoration: 'none'
|
43 | }, ownerState.underline === 'hover' && {
|
44 | textDecoration: 'none',
|
45 | '&:hover': {
|
46 | textDecoration: 'underline'
|
47 | }
|
48 | }, ownerState.underline === 'always' && _extends({
|
49 | textDecoration: 'underline'
|
50 | }, ownerState.color !== 'inherit' && {
|
51 | textDecorationColor: getTextDecoration({
|
52 | theme: theme,
|
53 | ownerState: ownerState
|
54 | })
|
55 | }, {
|
56 | '&:hover': {
|
57 | textDecorationColor: 'inherit'
|
58 | }
|
59 | }), ownerState.component === 'button' && _defineProperty({
|
60 | position: 'relative',
|
61 | WebkitTapHighlightColor: 'transparent',
|
62 | backgroundColor: 'transparent',
|
63 |
|
64 |
|
65 | outline: 0,
|
66 | border: 0,
|
67 | margin: 0,
|
68 |
|
69 | borderRadius: 0,
|
70 | padding: 0,
|
71 |
|
72 | cursor: 'pointer',
|
73 | userSelect: 'none',
|
74 | verticalAlign: 'middle',
|
75 | MozAppearance: 'none',
|
76 |
|
77 | WebkitAppearance: 'none',
|
78 |
|
79 | '&::-moz-focus-inner': {
|
80 | borderStyle: 'none'
|
81 |
|
82 | }
|
83 | }, "&.".concat(linkClasses.focusVisible), {
|
84 | outline: 'auto'
|
85 | }));
|
86 | });
|
87 | var Link = React.forwardRef(function Link(inProps, ref) {
|
88 | var props = useThemeProps({
|
89 | props: inProps,
|
90 | name: 'MuiLink'
|
91 | });
|
92 |
|
93 | var className = props.className,
|
94 | _props$color = props.color,
|
95 | color = _props$color === void 0 ? 'primary' : _props$color,
|
96 | _props$component = props.component,
|
97 | component = _props$component === void 0 ? 'a' : _props$component,
|
98 | onBlur = props.onBlur,
|
99 | onFocus = props.onFocus,
|
100 | TypographyClasses = props.TypographyClasses,
|
101 | _props$underline = props.underline,
|
102 | underline = _props$underline === void 0 ? 'always' : _props$underline,
|
103 | _props$variant = props.variant,
|
104 | variant = _props$variant === void 0 ? 'inherit' : _props$variant,
|
105 | sx = props.sx,
|
106 | other = _objectWithoutProperties(props, ["className", "color", "component", "onBlur", "onFocus", "TypographyClasses", "underline", "variant", "sx"]);
|
107 |
|
108 | var _useIsFocusVisible = useIsFocusVisible(),
|
109 | isFocusVisibleRef = _useIsFocusVisible.isFocusVisibleRef,
|
110 | handleBlurVisible = _useIsFocusVisible.onBlur,
|
111 | handleFocusVisible = _useIsFocusVisible.onFocus,
|
112 | focusVisibleRef = _useIsFocusVisible.ref;
|
113 |
|
114 | var _React$useState = React.useState(false),
|
115 | focusVisible = _React$useState[0],
|
116 | setFocusVisible = _React$useState[1];
|
117 |
|
118 | var handlerRef = useForkRef(ref, focusVisibleRef);
|
119 |
|
120 | var handleBlur = function handleBlur(event) {
|
121 | handleBlurVisible(event);
|
122 |
|
123 | if (isFocusVisibleRef.current === false) {
|
124 | setFocusVisible(false);
|
125 | }
|
126 |
|
127 | if (onBlur) {
|
128 | onBlur(event);
|
129 | }
|
130 | };
|
131 |
|
132 | var handleFocus = function handleFocus(event) {
|
133 | handleFocusVisible(event);
|
134 |
|
135 | if (isFocusVisibleRef.current === true) {
|
136 | setFocusVisible(true);
|
137 | }
|
138 |
|
139 | if (onFocus) {
|
140 | onFocus(event);
|
141 | }
|
142 | };
|
143 |
|
144 | var ownerState = _extends({}, props, {
|
145 | color: color,
|
146 | component: component,
|
147 | focusVisible: focusVisible,
|
148 | underline: underline,
|
149 | variant: variant
|
150 | });
|
151 |
|
152 | var classes = useUtilityClasses(ownerState);
|
153 | return _jsx(LinkRoot, _extends({
|
154 | color: color,
|
155 | className: clsx(classes.root, className),
|
156 | classes: TypographyClasses,
|
157 | component: component,
|
158 | onBlur: handleBlur,
|
159 | onFocus: handleFocus,
|
160 | ref: handlerRef,
|
161 | ownerState: ownerState,
|
162 | variant: variant,
|
163 | sx: [].concat(_toConsumableArray(!Object.keys(colorTransformations).includes(color) ? [{
|
164 | color: color
|
165 | }] : []), _toConsumableArray(Array.isArray(sx) ? sx : [sx]))
|
166 | }, other));
|
167 | });
|
168 | process.env.NODE_ENV !== "production" ? Link.propTypes
|
169 |
|
170 | = {
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | |
177 |
|
178 |
|
179 | children: PropTypes.node,
|
180 |
|
181 | |
182 |
|
183 |
|
184 | classes: PropTypes.object,
|
185 |
|
186 | |
187 |
|
188 |
|
189 | className: PropTypes.string,
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 | color: PropTypes
|
196 |
|
197 | .any,
|
198 |
|
199 | |
200 |
|
201 |
|
202 |
|
203 | component: elementTypeAcceptingRef,
|
204 |
|
205 | |
206 |
|
207 |
|
208 | onBlur: PropTypes.func,
|
209 |
|
210 | |
211 |
|
212 |
|
213 | onFocus: PropTypes.func,
|
214 |
|
215 | |
216 |
|
217 |
|
218 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
219 |
|
220 | |
221 |
|
222 |
|
223 | TypographyClasses: PropTypes.object,
|
224 |
|
225 | |
226 |
|
227 |
|
228 |
|
229 | underline: PropTypes.oneOf(['always', 'hover', 'none']),
|
230 |
|
231 | |
232 |
|
233 |
|
234 |
|
235 | variant: PropTypes
|
236 |
|
237 | .oneOfType([PropTypes.oneOf(['body1', 'body2', 'button', 'caption', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'inherit', 'overline', 'subtitle1', 'subtitle2']), PropTypes.string])
|
238 | } : void 0;
|
239 | export default Link; |
\ | No newline at end of file |