@instructure/ui-link 11.6.0 → 11.6.1-snapshot-129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -288
- package/es/Link/{index.js → v1/index.js} +2 -2
- package/es/Link/v2/index.js +253 -0
- package/es/Link/v2/props.js +26 -0
- package/es/Link/v2/styles.js +242 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/Link/{index.js → v1/index.js} +3 -3
- package/lib/Link/v2/index.js +262 -0
- package/lib/Link/v2/props.js +31 -0
- package/lib/Link/v2/styles.js +248 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +43 -21
- package/src/Link/{index.tsx → v1/index.tsx} +3 -3
- package/src/Link/{props.ts → v1/props.ts} +1 -1
- package/src/Link/v2/README.md +261 -0
- package/src/Link/v2/index.tsx +321 -0
- package/src/Link/v2/props.ts +184 -0
- package/src/Link/v2/styles.ts +267 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Link/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Link/v1/index.d.ts.map +1 -0
- package/types/Link/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Link/v1/props.d.ts.map +1 -0
- package/types/Link/v1/styles.d.ts.map +1 -0
- package/types/Link/v1/theme.d.ts.map +1 -0
- package/types/Link/v2/index.d.ts +66 -0
- package/types/Link/v2/index.d.ts.map +1 -0
- package/types/Link/v2/props.d.ts +105 -0
- package/types/Link/v2/props.d.ts.map +1 -0
- package/types/Link/v2/styles.d.ts +19 -0
- package/types/Link/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Link/index.d.ts.map +0 -1
- package/types/Link/props.d.ts.map +0 -1
- package/types/Link/styles.d.ts.map +0 -1
- package/types/Link/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Link/{props.js → v1/props.js} +0 -0
- /package/es/Link/{styles.js → v1/styles.js} +0 -0
- /package/es/Link/{theme.js → v1/theme.js} +0 -0
- /package/lib/Link/{props.js → v1/props.js} +0 -0
- /package/lib/Link/{styles.js → v1/styles.js} +0 -0
- /package/lib/Link/{theme.js → v1/theme.js} +0 -0
- /package/src/Link/{README.md → v1/README.md} +0 -0
- /package/src/Link/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Link/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Link/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Link/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
const _excluded = ["children", "onClick", "onMouseEnter", "color", "href", "margin", "renderIcon", "iconPlacement"];
|
|
3
|
+
var _dec, _class, _Link;
|
|
4
|
+
/*
|
|
5
|
+
* The MIT License (MIT)
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { Children, Component } from 'react';
|
|
29
|
+
import { View } from '@instructure/ui-view/latest';
|
|
30
|
+
import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
|
|
31
|
+
import { isActiveElement, findFocusable } from '@instructure/ui-dom-utils';
|
|
32
|
+
import { getElementType, getInteraction, matchComponentTypes, passthroughProps } from '@instructure/ui-react-utils';
|
|
33
|
+
import { combineDataCid } from '@instructure/ui-utils';
|
|
34
|
+
import { logWarn as warn } from '@instructure/console';
|
|
35
|
+
import { renderIconWithProps } from '@instructure/ui-icons';
|
|
36
|
+
import { withStyle } from '@instructure/emotion';
|
|
37
|
+
import generateStyle from "./styles.js";
|
|
38
|
+
import { allowedProps } from "./props.js";
|
|
39
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
40
|
+
/**
|
|
41
|
+
---
|
|
42
|
+
category: components
|
|
43
|
+
---
|
|
44
|
+
**/
|
|
45
|
+
let Link = (_dec = withStyle(generateStyle), _dec(_class = (_Link = class Link extends Component {
|
|
46
|
+
constructor(...args) {
|
|
47
|
+
super(...args);
|
|
48
|
+
this.state = {
|
|
49
|
+
hasFocus: false
|
|
50
|
+
};
|
|
51
|
+
this.ref = null;
|
|
52
|
+
this.makeStyleProps = () => {
|
|
53
|
+
const _this$props = this.props,
|
|
54
|
+
variantProp = _this$props.variant,
|
|
55
|
+
sizeProp = _this$props.size;
|
|
56
|
+
|
|
57
|
+
// Handle deprecated variant values by mapping them to new variant + size props
|
|
58
|
+
let variant = variantProp;
|
|
59
|
+
let size = sizeProp;
|
|
60
|
+
if (variantProp === 'inline-small' || variantProp === 'standalone-small') {
|
|
61
|
+
warn(false, `[Link] The variant value "${variantProp}" is deprecated. Use variant="${variantProp.replace('-small', '')}" with size="small" instead.`);
|
|
62
|
+
variant = variantProp.replace('-small', '');
|
|
63
|
+
// Only set size from deprecated variant if size prop is not explicitly provided
|
|
64
|
+
if (!sizeProp) {
|
|
65
|
+
size = 'small';
|
|
66
|
+
}
|
|
67
|
+
} else if ((variantProp === 'inline' || variantProp === 'standalone') && !sizeProp) {
|
|
68
|
+
// When using new variant values without explicit size, default to medium
|
|
69
|
+
// This maintains the old behavior where 'inline' and 'standalone' were medium-sized
|
|
70
|
+
size = 'medium';
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
containsTruncateText: this.containsTruncateText,
|
|
74
|
+
hasVisibleChildren: this.hasVisibleChildren,
|
|
75
|
+
variant,
|
|
76
|
+
size
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
this.handleElementRef = el => {
|
|
80
|
+
const elementRef = this.props.elementRef;
|
|
81
|
+
this.ref = el;
|
|
82
|
+
if (typeof elementRef === 'function') {
|
|
83
|
+
elementRef(el);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this.handleClick = event => {
|
|
87
|
+
const onClick = this.props.onClick;
|
|
88
|
+
const interaction = this.interaction;
|
|
89
|
+
if (interaction === 'disabled') {
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
event.stopPropagation();
|
|
92
|
+
} else if (typeof onClick === 'function') {
|
|
93
|
+
onClick(event);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
this.handleFocus = event => {
|
|
97
|
+
this.setState({
|
|
98
|
+
hasFocus: true
|
|
99
|
+
});
|
|
100
|
+
if (typeof this.props.onFocus === 'function') {
|
|
101
|
+
this.props.onFocus(event);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
this.handleBlur = event => {
|
|
105
|
+
this.setState({
|
|
106
|
+
hasFocus: false
|
|
107
|
+
});
|
|
108
|
+
if (typeof this.props.onBlur === 'function') {
|
|
109
|
+
this.props.onBlur(event);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
get _link() {
|
|
114
|
+
return this.ref;
|
|
115
|
+
}
|
|
116
|
+
componentDidMount() {
|
|
117
|
+
var _this$props$makeStyle, _this$props2;
|
|
118
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2, this.makeStyleProps());
|
|
119
|
+
}
|
|
120
|
+
componentDidUpdate() {
|
|
121
|
+
var _this$props$makeStyle2, _this$props3;
|
|
122
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3, this.makeStyleProps());
|
|
123
|
+
}
|
|
124
|
+
get containsTruncateText() {
|
|
125
|
+
let truncateText = false;
|
|
126
|
+
Children.forEach(this.props.children, child => {
|
|
127
|
+
if (child && matchComponentTypes(child, ['TruncateText'])) {
|
|
128
|
+
truncateText = true;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
warn(
|
|
132
|
+
// if display prop is used, warn about icon or TruncateText
|
|
133
|
+
!truncateText || this.props.display === void 0, '[Link] Using the display property with TruncateText may cause layout issues.');
|
|
134
|
+
return truncateText;
|
|
135
|
+
}
|
|
136
|
+
get display() {
|
|
137
|
+
if (this.props.display) {
|
|
138
|
+
return this.props.display; // user-entered display property
|
|
139
|
+
}
|
|
140
|
+
const containsTruncateText = this.containsTruncateText;
|
|
141
|
+
if (this.props.renderIcon) {
|
|
142
|
+
return containsTruncateText ? 'inline-flex' : 'inline-block';
|
|
143
|
+
} else {
|
|
144
|
+
return containsTruncateText ? 'block' : 'auto';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
get interaction() {
|
|
148
|
+
return getInteraction({
|
|
149
|
+
props: this.props,
|
|
150
|
+
interactionTypes: ['disabled']
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
get element() {
|
|
154
|
+
return getElementType(Link, this.props);
|
|
155
|
+
}
|
|
156
|
+
get focused() {
|
|
157
|
+
return isActiveElement(this.ref);
|
|
158
|
+
}
|
|
159
|
+
get focusable() {
|
|
160
|
+
return findFocusable(this.ref);
|
|
161
|
+
}
|
|
162
|
+
get hasVisibleChildren() {
|
|
163
|
+
return hasVisibleChildren(this.props.children);
|
|
164
|
+
}
|
|
165
|
+
get role() {
|
|
166
|
+
const _this$props4 = this.props,
|
|
167
|
+
role = _this$props4.role,
|
|
168
|
+
forceButtonRole = _this$props4.forceButtonRole,
|
|
169
|
+
onClick = _this$props4.onClick;
|
|
170
|
+
if (forceButtonRole) {
|
|
171
|
+
return onClick && this.element !== 'button' ? 'button' : role;
|
|
172
|
+
}
|
|
173
|
+
return role;
|
|
174
|
+
}
|
|
175
|
+
focus() {
|
|
176
|
+
this.ref && this.ref.focus();
|
|
177
|
+
}
|
|
178
|
+
renderIcon() {
|
|
179
|
+
var _this$props$styles;
|
|
180
|
+
const _this$props5 = this.props,
|
|
181
|
+
display = _this$props5.display,
|
|
182
|
+
renderIcon = _this$props5.renderIcon,
|
|
183
|
+
variantProp = _this$props5.variant,
|
|
184
|
+
sizeProp = _this$props5.size;
|
|
185
|
+
warn(
|
|
186
|
+
// if display prop is used, warn about icon or TruncateText
|
|
187
|
+
display === void 0, '[Link] Using the display property with an icon may cause layout issues.');
|
|
188
|
+
|
|
189
|
+
// Determine the actual size being used (considering deprecated variants)
|
|
190
|
+
let size = sizeProp;
|
|
191
|
+
if (variantProp === 'inline-small' || variantProp === 'standalone-small') {
|
|
192
|
+
size = sizeProp || 'small';
|
|
193
|
+
} else if ((variantProp === 'inline' || variantProp === 'standalone') && !sizeProp) {
|
|
194
|
+
size = 'medium';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Map Link sizes to icon sizes
|
|
198
|
+
const linkSizeToIconSize = {
|
|
199
|
+
small: 'xs',
|
|
200
|
+
medium: 'sm',
|
|
201
|
+
large: 'lg'
|
|
202
|
+
};
|
|
203
|
+
const iconSize = linkSizeToIconSize[size || 'medium'];
|
|
204
|
+
return _jsx("span", {
|
|
205
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon,
|
|
206
|
+
children: renderIconWithProps(renderIcon, iconSize, void 0)
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
render() {
|
|
210
|
+
var _this$props$styles2;
|
|
211
|
+
const _this$props6 = this.props,
|
|
212
|
+
children = _this$props6.children,
|
|
213
|
+
onClick = _this$props6.onClick,
|
|
214
|
+
onMouseEnter = _this$props6.onMouseEnter,
|
|
215
|
+
color = _this$props6.color,
|
|
216
|
+
href = _this$props6.href,
|
|
217
|
+
margin = _this$props6.margin,
|
|
218
|
+
renderIcon = _this$props6.renderIcon,
|
|
219
|
+
iconPlacement = _this$props6.iconPlacement,
|
|
220
|
+
props = _objectWithoutProperties(_this$props6, _excluded);
|
|
221
|
+
const interaction = this.interaction;
|
|
222
|
+
const isDisabled = interaction === 'disabled';
|
|
223
|
+
const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
|
|
224
|
+
const tabIndex = this.role === 'button' && !isDisabled ? 0 : void 0;
|
|
225
|
+
return _jsxs(View, {
|
|
226
|
+
...passthroughProps(props),
|
|
227
|
+
elementRef: this.handleElementRef,
|
|
228
|
+
as: this.element,
|
|
229
|
+
display: this.display,
|
|
230
|
+
margin: margin,
|
|
231
|
+
href: href,
|
|
232
|
+
onMouseEnter: onMouseEnter,
|
|
233
|
+
onClick: this.handleClick,
|
|
234
|
+
onFocus: this.handleFocus,
|
|
235
|
+
onBlur: this.handleBlur,
|
|
236
|
+
"aria-disabled": isDisabled ? 'true' : void 0,
|
|
237
|
+
role: this.role,
|
|
238
|
+
type: type,
|
|
239
|
+
tabIndex: tabIndex,
|
|
240
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link,
|
|
241
|
+
"data-cid": combineDataCid('Link', this.props),
|
|
242
|
+
children: [renderIcon && iconPlacement === 'start' ? this.renderIcon() : null, children, renderIcon && iconPlacement === 'end' ? this.renderIcon() : null]
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}, _Link.displayName = "Link", _Link.componentId = 'Link', _Link.allowedProps = allowedProps, _Link.defaultProps = {
|
|
246
|
+
// Leave interaction default undefined so that `disabled` can also be supplied
|
|
247
|
+
interaction: void 0,
|
|
248
|
+
color: 'link',
|
|
249
|
+
iconPlacement: 'start',
|
|
250
|
+
forceButtonRole: true
|
|
251
|
+
}, _Link)) || _class);
|
|
252
|
+
export default Link;
|
|
253
|
+
export { Link };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const allowedProps = ['children', 'href', 'color', 'elementRef', 'as', 'role', 'forceButtonRole', 'interaction', 'margin', 'renderIcon', 'iconPlacement', 'display', 'onBlur', 'onClick', 'onFocus', 'onMouseEnter', 'size', 'variant'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { calcFocusOutlineStyles, calcSpacingFromShorthand } from '@instructure/emotion';
|
|
26
|
+
/**
|
|
27
|
+
* ---
|
|
28
|
+
* private: true
|
|
29
|
+
* ---
|
|
30
|
+
* Generates the style object from the theme and provided additional information
|
|
31
|
+
* @param {Object} componentTheme The theme variable object.
|
|
32
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
33
|
+
* @param {Object} sharedTokens Shared token object that stores common values for the theme.
|
|
34
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
35
|
+
* @return {Object} The final style object, which will be used in the component
|
|
36
|
+
*/
|
|
37
|
+
const generateStyle = (componentTheme, props, sharedTokens, state = {}) => {
|
|
38
|
+
var _state$size, _state$variant, _state$hasVisibleChil;
|
|
39
|
+
const renderIcon = props.renderIcon,
|
|
40
|
+
_props$iconPlacement = props.iconPlacement,
|
|
41
|
+
iconPlacement = _props$iconPlacement === void 0 ? 'start' : _props$iconPlacement,
|
|
42
|
+
color = props.color,
|
|
43
|
+
margin = props.margin;
|
|
44
|
+
|
|
45
|
+
// Get size and variant from state (passed from makeStyleProps) or fall back to props
|
|
46
|
+
const size = (_state$size = state.size) !== null && _state$size !== void 0 ? _state$size : props.size;
|
|
47
|
+
const variant = (_state$variant = state.variant) !== null && _state$variant !== void 0 ? _state$variant : props.variant;
|
|
48
|
+
const hasVisibleChildren = (_state$hasVisibleChil = state.hasVisibleChildren) !== null && _state$hasVisibleChil !== void 0 ? _state$hasVisibleChil : false;
|
|
49
|
+
const isInverseStyle = color === 'link-inverse';
|
|
50
|
+
const inlineLinkSizeStyles = {
|
|
51
|
+
small: {
|
|
52
|
+
fontFamily: componentTheme.inlineLink.small.fontFamily,
|
|
53
|
+
fontWeight: componentTheme.inlineLink.small.fontWeight,
|
|
54
|
+
fontSize: componentTheme.inlineLink.small.fontSize,
|
|
55
|
+
lineHeight: componentTheme.inlineLink.small.lineHeight,
|
|
56
|
+
textDecoration: componentTheme.inlineLink.small.textDecoration,
|
|
57
|
+
gap: componentTheme.gapSm
|
|
58
|
+
},
|
|
59
|
+
medium: {
|
|
60
|
+
fontFamily: componentTheme.inlineLink.medium.fontFamily,
|
|
61
|
+
fontWeight: componentTheme.inlineLink.medium.fontWeight,
|
|
62
|
+
fontSize: componentTheme.inlineLink.medium.fontSize,
|
|
63
|
+
lineHeight: componentTheme.inlineLink.medium.lineHeight,
|
|
64
|
+
textDecoration: componentTheme.inlineLink.medium.textDecoration,
|
|
65
|
+
gap: componentTheme.gapMd
|
|
66
|
+
},
|
|
67
|
+
large: {
|
|
68
|
+
fontFamily: componentTheme.inlineLink.large.fontFamily,
|
|
69
|
+
fontWeight: componentTheme.inlineLink.large.fontWeight,
|
|
70
|
+
fontSize: componentTheme.inlineLink.large.fontSize,
|
|
71
|
+
lineHeight: componentTheme.inlineLink.large.lineHeight,
|
|
72
|
+
textDecoration: componentTheme.inlineLink.large.textDecoration,
|
|
73
|
+
gap: componentTheme.gapLg
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// For standalone variant, use the base component theme tokens
|
|
78
|
+
const standaloneLinkSizeStyles = {
|
|
79
|
+
small: {
|
|
80
|
+
fontFamily: componentTheme.fontFamily,
|
|
81
|
+
fontWeight: componentTheme.fontWeight,
|
|
82
|
+
fontSize: componentTheme.fontSizeSm,
|
|
83
|
+
lineHeight: componentTheme.lineHeightSm,
|
|
84
|
+
textDecoration: 'none',
|
|
85
|
+
gap: componentTheme.gapSm
|
|
86
|
+
},
|
|
87
|
+
medium: {
|
|
88
|
+
fontFamily: componentTheme.fontFamily,
|
|
89
|
+
fontWeight: componentTheme.fontWeight,
|
|
90
|
+
fontSize: componentTheme.fontSizeMd,
|
|
91
|
+
lineHeight: componentTheme.lineHeightMd,
|
|
92
|
+
textDecoration: 'none',
|
|
93
|
+
gap: componentTheme.gapMd
|
|
94
|
+
},
|
|
95
|
+
large: {
|
|
96
|
+
fontFamily: componentTheme.fontFamily,
|
|
97
|
+
fontWeight: componentTheme.fontWeight,
|
|
98
|
+
fontSize: componentTheme.fontSizeLg,
|
|
99
|
+
lineHeight: componentTheme.lineHeightLg,
|
|
100
|
+
textDecoration: 'none',
|
|
101
|
+
gap: componentTheme.gapLg
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Get proper styles based on variant and size
|
|
106
|
+
let variantStyles;
|
|
107
|
+
if (size && variant === 'inline') {
|
|
108
|
+
variantStyles = inlineLinkSizeStyles[size];
|
|
109
|
+
} else if (size && variant === 'standalone') {
|
|
110
|
+
variantStyles = standaloneLinkSizeStyles[size];
|
|
111
|
+
} else if (size) {
|
|
112
|
+
// Fallback if variant is not specified but size is
|
|
113
|
+
variantStyles = standaloneLinkSizeStyles[size];
|
|
114
|
+
} else {
|
|
115
|
+
// No size provided, use inherit
|
|
116
|
+
variantStyles = {
|
|
117
|
+
fontSize: 'inherit',
|
|
118
|
+
lineHeight: 'inherit',
|
|
119
|
+
textDecoration: void 0,
|
|
120
|
+
gap: componentTheme.gapMd // Default gap for icons when no size is specified
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const baseStyles = {
|
|
124
|
+
boxSizing: 'border-box',
|
|
125
|
+
fontFamily: componentTheme.fontFamily,
|
|
126
|
+
fontWeight: componentTheme.fontWeight,
|
|
127
|
+
verticalAlign: 'baseline',
|
|
128
|
+
fontSize: variantStyles.fontSize,
|
|
129
|
+
lineHeight: variantStyles.lineHeight,
|
|
130
|
+
color: componentTheme.unstyledTextColor,
|
|
131
|
+
// set up focus styles
|
|
132
|
+
borderRadius: '0.125rem',
|
|
133
|
+
// If icon is present, use flex to align icon with text
|
|
134
|
+
// Use 'flex' for standalone variant (block-level), 'inline-flex' for inline variant
|
|
135
|
+
...(renderIcon && hasVisibleChildren && {
|
|
136
|
+
display: variant === 'standalone' ? 'flex' : 'inline-flex',
|
|
137
|
+
alignItems: 'baseline'
|
|
138
|
+
}),
|
|
139
|
+
'&[aria-disabled]': {
|
|
140
|
+
cursor: 'not-allowed',
|
|
141
|
+
pointerEvents: 'none',
|
|
142
|
+
opacity: '1',
|
|
143
|
+
color: componentTheme.textDisabledColor
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// If Link is a button or link, it should look clickable
|
|
148
|
+
const isClickableStyles = {
|
|
149
|
+
...baseStyles,
|
|
150
|
+
cursor: 'pointer',
|
|
151
|
+
color: componentTheme.textColor,
|
|
152
|
+
fontSize: variantStyles.fontSize,
|
|
153
|
+
lineHeight: variantStyles.lineHeight,
|
|
154
|
+
...(variantStyles.fontFamily && {
|
|
155
|
+
fontFamily: variantStyles.fontFamily
|
|
156
|
+
}),
|
|
157
|
+
...(variantStyles.fontWeight && {
|
|
158
|
+
fontWeight: variantStyles.fontWeight
|
|
159
|
+
}),
|
|
160
|
+
'&:hover, &:active, &:focus': {
|
|
161
|
+
color: componentTheme.textHoverColor,
|
|
162
|
+
// a11y requirement: interactive links must be underlined on interaction
|
|
163
|
+
textDecoration: 'underline'
|
|
164
|
+
},
|
|
165
|
+
// Use textDecoration from variantStyles if available (from inlineLink token), otherwise fallback
|
|
166
|
+
...(variantStyles.textDecoration ? {
|
|
167
|
+
textDecoration: variantStyles.textDecoration
|
|
168
|
+
} : {
|
|
169
|
+
textDecoration: 'underline'
|
|
170
|
+
})
|
|
171
|
+
};
|
|
172
|
+
const buttonStyle = {
|
|
173
|
+
appearance: 'none',
|
|
174
|
+
userSelect: 'text',
|
|
175
|
+
background: 'none',
|
|
176
|
+
border: 'none',
|
|
177
|
+
cursor: 'pointer',
|
|
178
|
+
margin: 0,
|
|
179
|
+
padding: 0,
|
|
180
|
+
textAlign: 'inherit',
|
|
181
|
+
fontSize: variantStyles.fontSize,
|
|
182
|
+
lineHeight: variantStyles.lineHeight,
|
|
183
|
+
...(variantStyles.textDecoration && {
|
|
184
|
+
textDecoration: variantStyles.textDecoration
|
|
185
|
+
})
|
|
186
|
+
};
|
|
187
|
+
const inverseStyles = {
|
|
188
|
+
color: componentTheme.onColorTextColor,
|
|
189
|
+
// TODO remove double (here with the util and in View) focus ring calculations
|
|
190
|
+
// in the future after the View refactor is complete
|
|
191
|
+
// This needs stronger specificity than `View`
|
|
192
|
+
'&&&&&:focus': {
|
|
193
|
+
outlineColor: sharedTokens.focusOutline.onColor
|
|
194
|
+
},
|
|
195
|
+
'&:hover, &:active': {
|
|
196
|
+
color: componentTheme.onColorTextHoverColor
|
|
197
|
+
},
|
|
198
|
+
'&[aria-disabled]': {
|
|
199
|
+
color: componentTheme.onColorTextDisabledColor
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Icon styles based on size - use gap from variantStyles
|
|
204
|
+
const iconStyles = {
|
|
205
|
+
paddingInlineStart: iconPlacement === 'start' ? 0 : variantStyles.gap || componentTheme.gapMd,
|
|
206
|
+
paddingInlineEnd: iconPlacement === 'start' ? variantStyles.gap || componentTheme.gapMd : 0
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
link: {
|
|
210
|
+
label: 'link',
|
|
211
|
+
...baseStyles,
|
|
212
|
+
// TODO handle the merging on tokens inside the util
|
|
213
|
+
margin: calcSpacingFromShorthand(margin, {
|
|
214
|
+
...sharedTokens.spacing,
|
|
215
|
+
...sharedTokens.legacy.spacing
|
|
216
|
+
}),
|
|
217
|
+
...calcFocusOutlineStyles(sharedTokens.focusOutline, isInverseStyle ? {
|
|
218
|
+
focusColor: 'inverse'
|
|
219
|
+
} : void 0),
|
|
220
|
+
// NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
|
|
221
|
+
'&:is(a), &:is(button)': isClickableStyles,
|
|
222
|
+
'&:-webkit-any(a), &:-webkit-any(button)': isClickableStyles,
|
|
223
|
+
'&:is(button)': buttonStyle,
|
|
224
|
+
'&:-webkit-any(button)': buttonStyle,
|
|
225
|
+
...(isInverseStyle && {
|
|
226
|
+
...inverseStyles,
|
|
227
|
+
'&:is(a):link, &:is(a):visited, &:is(button)': inverseStyles,
|
|
228
|
+
'&:-webkit-any(a):link, &:-webkit-any(a):visited, &:-webkit-any(button)': inverseStyles
|
|
229
|
+
})
|
|
230
|
+
},
|
|
231
|
+
icon: {
|
|
232
|
+
label: 'icon',
|
|
233
|
+
...(renderIcon && {
|
|
234
|
+
boxSizing: 'border-box',
|
|
235
|
+
display: 'flex',
|
|
236
|
+
alignSelf: 'center',
|
|
237
|
+
...iconStyles
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
export default generateStyle;
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.Link = void 0;
|
|
8
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
9
|
var _react = require("react");
|
|
10
|
-
var
|
|
10
|
+
var _v11_ = require("@instructure/ui-view/v11_6");
|
|
11
11
|
var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
|
|
12
12
|
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
13
13
|
var _findFocusable = require("@instructure/ui-dom-utils/lib/findFocusable.js");
|
|
@@ -53,7 +53,7 @@ var _dec, _class, _Link;
|
|
|
53
53
|
category: components
|
|
54
54
|
---
|
|
55
55
|
**/
|
|
56
|
-
let Link = exports.Link = (_dec = (0, _emotion.
|
|
56
|
+
let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_Link = class Link extends _react.Component {
|
|
57
57
|
constructor(...args) {
|
|
58
58
|
super(...args);
|
|
59
59
|
this.state = {
|
|
@@ -192,7 +192,7 @@ let Link = exports.Link = (_dec = (0, _emotion.withStyle)(_styles.default, _them
|
|
|
192
192
|
const isDisabled = interaction === 'disabled';
|
|
193
193
|
const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
|
|
194
194
|
const tabIndex = this.role === 'button' && !isDisabled ? 0 : void 0;
|
|
195
|
-
return (0, _jsxRuntime.jsxs)(
|
|
195
|
+
return (0, _jsxRuntime.jsxs)(_v11_.View, {
|
|
196
196
|
...(0, _passthroughProps.passthroughProps)(props),
|
|
197
197
|
elementRef: this.handleElementRef,
|
|
198
198
|
as: this.element,
|