@instructure/ui-link 8.33.1-snapshot-1 → 8.33.2-snapshot-5
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 +4 -8
- package/es/Link/LinkLocator.js +3 -2
- package/es/Link/__examples__/Link.examples.js +1 -0
- package/es/Link/index.js +16 -49
- package/es/Link/locator.js +1 -0
- package/es/Link/props.js +1 -0
- package/es/Link/styles.js +10 -9
- package/es/Link/theme.js +11 -9
- package/es/index.js +1 -0
- package/lib/Link/LinkLocator.js +1 -5
- package/lib/Link/__examples__/Link.examples.js +1 -2
- package/lib/Link/index.js +16 -69
- package/lib/Link/locator.js +0 -2
- package/lib/Link/props.js +1 -4
- package/lib/Link/styles.js +10 -10
- package/lib/Link/theme.js +10 -10
- package/lib/index.js +0 -1
- package/package.json +17 -17
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [8.33.
|
|
6
|
+
## [8.33.2-snapshot-5](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2-snapshot-5) (2023-01-23)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-link
|
|
9
9
|
|
|
@@ -11,22 +11,18 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @instructure/ui-link
|
|
17
17
|
|
|
18
|
+
# [8.33.0](https://github.com/instructure/instructure-ui/compare/v8.32.1...v8.33.0) (2023-01-04)
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
**Note:** Version bump only for package @instructure/ui-link
|
|
21
21
|
|
|
22
22
|
## [8.32.1](https://github.com/instructure/instructure-ui/compare/v8.30.0...v8.32.1) (2022-12-01)
|
|
23
23
|
|
|
24
24
|
**Note:** Version bump only for package @instructure/ui-link
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
26
|
# [8.32.0](https://github.com/instructure/instructure-ui/compare/v8.31.0...v8.32.0) (2022-11-23)
|
|
31
27
|
|
|
32
28
|
**Note:** Version bump only for package @instructure/ui-link
|
package/es/Link/LinkLocator.js
CHANGED
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
26
|
import { find } from '@instructure/ui-test-queries';
|
|
26
|
-
import { Link } from './index';
|
|
27
|
+
import { Link } from './index';
|
|
27
28
|
|
|
29
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
28
30
|
export const LinkLocator = locator(Link.selector, {
|
|
29
31
|
click: async function (element) {
|
|
30
32
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
31
33
|
args[_key - 1] = arguments[_key];
|
|
32
34
|
}
|
|
33
|
-
|
|
34
35
|
return (await find(element, 'a,button,[role="button"]')).click(...args);
|
|
35
36
|
}
|
|
36
37
|
});
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { IconTrashSolid } from '@instructure/ui-icons';
|
|
25
26
|
const longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat';
|
|
26
27
|
const shortString = 'Delete';
|
package/es/Link/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
const _excluded = ["children", "onClick", "color", "href", "margin", "renderIcon", "iconPlacement", "isWithinText"];
|
|
3
|
-
|
|
4
3
|
var _dec, _dec2, _class, _class2;
|
|
5
|
-
|
|
6
4
|
/*
|
|
7
5
|
* The MIT License (MIT)
|
|
8
6
|
*
|
|
@@ -39,7 +37,6 @@ import { withStyle, jsx } from '@instructure/emotion';
|
|
|
39
37
|
import generateStyle from './styles';
|
|
40
38
|
import generateComponentTheme from './theme';
|
|
41
39
|
import { propTypes, allowedProps } from './props';
|
|
42
|
-
|
|
43
40
|
/**
|
|
44
41
|
---
|
|
45
42
|
category: components
|
|
@@ -53,27 +50,22 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
53
50
|
hasFocus: false
|
|
54
51
|
};
|
|
55
52
|
this.ref = null;
|
|
56
|
-
|
|
57
53
|
this.makeStyleProps = () => {
|
|
58
54
|
return {
|
|
59
55
|
containsTruncateText: this.containsTruncateText,
|
|
60
56
|
hasVisibleChildren: this.hasVisibleChildren
|
|
61
57
|
};
|
|
62
58
|
};
|
|
63
|
-
|
|
64
59
|
this.handleElementRef = el => {
|
|
65
60
|
const elementRef = this.props.elementRef;
|
|
66
61
|
this.ref = el;
|
|
67
|
-
|
|
68
62
|
if (typeof elementRef === 'function') {
|
|
69
63
|
elementRef(el);
|
|
70
64
|
}
|
|
71
65
|
};
|
|
72
|
-
|
|
73
66
|
this.handleClick = event => {
|
|
74
67
|
const onClick = this.props.onClick;
|
|
75
68
|
const interaction = this.interaction;
|
|
76
|
-
|
|
77
69
|
if (interaction === 'disabled') {
|
|
78
70
|
event.preventDefault();
|
|
79
71
|
event.stopPropagation();
|
|
@@ -81,44 +73,34 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
81
73
|
onClick(event);
|
|
82
74
|
}
|
|
83
75
|
};
|
|
84
|
-
|
|
85
76
|
this.handleFocus = event => {
|
|
86
77
|
this.setState({
|
|
87
78
|
hasFocus: true
|
|
88
79
|
});
|
|
89
|
-
|
|
90
80
|
if (typeof this.props.onFocus === 'function') {
|
|
91
81
|
this.props.onFocus(event);
|
|
92
82
|
}
|
|
93
83
|
};
|
|
94
|
-
|
|
95
84
|
this.handleBlur = event => {
|
|
96
85
|
this.setState({
|
|
97
86
|
hasFocus: false
|
|
98
87
|
});
|
|
99
|
-
|
|
100
88
|
if (typeof this.props.onBlur === 'function') {
|
|
101
89
|
this.props.onBlur(event);
|
|
102
90
|
}
|
|
103
91
|
};
|
|
104
92
|
}
|
|
105
|
-
|
|
106
93
|
get _link() {
|
|
107
94
|
return this.ref;
|
|
108
95
|
}
|
|
109
|
-
|
|
110
96
|
componentDidMount() {
|
|
111
97
|
var _this$props$makeStyle, _this$props;
|
|
112
|
-
|
|
113
98
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
|
|
114
99
|
}
|
|
115
|
-
|
|
116
100
|
componentDidUpdate() {
|
|
117
101
|
var _this$props$makeStyle2, _this$props2;
|
|
118
|
-
|
|
119
102
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
|
|
120
103
|
}
|
|
121
|
-
|
|
122
104
|
get containsTruncateText() {
|
|
123
105
|
let truncateText = false;
|
|
124
106
|
React.Children.forEach(this.props.children, child => {
|
|
@@ -126,89 +108,75 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
126
108
|
truncateText = true;
|
|
127
109
|
}
|
|
128
110
|
});
|
|
129
|
-
warn(
|
|
111
|
+
warn(
|
|
112
|
+
// if display prop is used, warn about icon or TruncateText
|
|
130
113
|
!truncateText || this.props.display === void 0, '[Link] Using the display property with TruncateText may cause layout issues.');
|
|
131
114
|
return truncateText;
|
|
132
115
|
}
|
|
133
|
-
|
|
134
116
|
get display() {
|
|
135
117
|
if (this.props.display) {
|
|
136
118
|
return this.props.display; // user-entered display property
|
|
137
119
|
}
|
|
138
120
|
|
|
139
121
|
const containsTruncateText = this.containsTruncateText;
|
|
140
|
-
|
|
141
122
|
if (this.props.renderIcon) {
|
|
142
123
|
return containsTruncateText ? 'inline-flex' : 'inline-block';
|
|
143
124
|
} else {
|
|
144
125
|
return containsTruncateText ? 'block' : 'auto';
|
|
145
126
|
}
|
|
146
127
|
}
|
|
147
|
-
|
|
148
128
|
get interaction() {
|
|
149
129
|
return getInteraction({
|
|
150
130
|
props: this.props,
|
|
151
131
|
interactionTypes: ['disabled']
|
|
152
132
|
});
|
|
153
133
|
}
|
|
154
|
-
|
|
155
134
|
get element() {
|
|
156
135
|
return getElementType(Link, this.props);
|
|
157
136
|
}
|
|
158
|
-
|
|
159
137
|
get focused() {
|
|
160
138
|
return isActiveElement(this.ref);
|
|
161
139
|
}
|
|
162
|
-
|
|
163
140
|
get focusable() {
|
|
164
141
|
return findFocusable(this.ref);
|
|
165
142
|
}
|
|
166
|
-
|
|
167
143
|
get hasVisibleChildren() {
|
|
168
144
|
return hasVisibleChildren(this.props.children);
|
|
169
145
|
}
|
|
170
|
-
|
|
171
146
|
get role() {
|
|
172
147
|
const _this$props3 = this.props,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
148
|
+
role = _this$props3.role,
|
|
149
|
+
forceButtonRole = _this$props3.forceButtonRole,
|
|
150
|
+
onClick = _this$props3.onClick;
|
|
177
151
|
if (forceButtonRole) {
|
|
178
152
|
return onClick && this.element !== 'button' ? 'button' : role;
|
|
179
153
|
}
|
|
180
|
-
|
|
181
154
|
return role;
|
|
182
155
|
}
|
|
183
|
-
|
|
184
156
|
focus() {
|
|
185
157
|
this.ref && this.ref.focus();
|
|
186
158
|
}
|
|
187
|
-
|
|
188
159
|
renderIcon() {
|
|
189
160
|
var _this$props$styles;
|
|
190
|
-
|
|
191
|
-
|
|
161
|
+
warn(
|
|
162
|
+
// if display prop is used, warn about icon or TruncateText
|
|
192
163
|
this.props.display === void 0, '[Link] Using the display property with an icon may cause layout issues.');
|
|
193
164
|
return jsx("span", {
|
|
194
165
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon
|
|
195
166
|
}, callRenderProp(this.props.renderIcon));
|
|
196
167
|
}
|
|
197
|
-
|
|
198
168
|
render() {
|
|
199
169
|
var _this$props$styles2;
|
|
200
|
-
|
|
201
170
|
const _this$props4 = this.props,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
171
|
+
children = _this$props4.children,
|
|
172
|
+
onClick = _this$props4.onClick,
|
|
173
|
+
color = _this$props4.color,
|
|
174
|
+
href = _this$props4.href,
|
|
175
|
+
margin = _this$props4.margin,
|
|
176
|
+
renderIcon = _this$props4.renderIcon,
|
|
177
|
+
iconPlacement = _this$props4.iconPlacement,
|
|
178
|
+
isWithinText = _this$props4.isWithinText,
|
|
179
|
+
props = _objectWithoutProperties(_this$props4, _excluded);
|
|
212
180
|
const interaction = this.interaction;
|
|
213
181
|
const isDisabled = interaction === 'disabled';
|
|
214
182
|
const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
|
|
@@ -229,7 +197,6 @@ let Link = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = tes
|
|
|
229
197
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link
|
|
230
198
|
}), renderIcon && iconPlacement === 'start' && this.renderIcon(), children, renderIcon && iconPlacement === 'end' && this.renderIcon());
|
|
231
199
|
}
|
|
232
|
-
|
|
233
200
|
}, _class2.displayName = "Link", _class2.componentId = 'Link', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
|
|
234
201
|
// Leave interaction default undefined so that `disabled` can also be supplied
|
|
235
202
|
interaction: void 0,
|
package/es/Link/locator.js
CHANGED
package/es/Link/props.js
CHANGED
package/es/Link/styles.js
CHANGED
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
*/
|
|
35
35
|
const generateStyle = (componentTheme, props, state) => {
|
|
36
36
|
const isWithinText = props.isWithinText,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
renderIcon = props.renderIcon,
|
|
38
|
+
iconPlacement = props.iconPlacement,
|
|
39
|
+
color = props.color;
|
|
40
40
|
const containsTruncateText = state.containsTruncateText,
|
|
41
|
-
|
|
41
|
+
hasVisibleChildren = state.hasVisibleChildren;
|
|
42
42
|
const inverseStyle = color === 'link-inverse';
|
|
43
43
|
const baseStyles = {
|
|
44
44
|
boxSizing: 'border-box',
|
|
@@ -65,11 +65,12 @@ const generateStyle = (componentTheme, props, state) => {
|
|
|
65
65
|
},
|
|
66
66
|
'&::-moz-focus-inner': {
|
|
67
67
|
border: 0 // removes default dotted focus outline in Firefox
|
|
68
|
-
|
|
69
68
|
}
|
|
70
|
-
};
|
|
69
|
+
};
|
|
71
70
|
|
|
72
|
-
|
|
71
|
+
// If Link is a button or link, it should look clickable
|
|
72
|
+
const isClickableStyles = {
|
|
73
|
+
...baseStyles,
|
|
73
74
|
cursor: 'pointer',
|
|
74
75
|
color: componentTheme.color,
|
|
75
76
|
textDecoration: isWithinText ? componentTheme.textDecorationWithinText : componentTheme.textDecorationOutsideText,
|
|
@@ -111,7 +112,8 @@ const generateStyle = (componentTheme, props, state) => {
|
|
|
111
112
|
'&:-webkit-any(a), &:-webkit-any(button)': isClickableStyles,
|
|
112
113
|
'&:is(button)': buttonStyle,
|
|
113
114
|
'&:-webkit-any(button)': buttonStyle,
|
|
114
|
-
...(inverseStyle && {
|
|
115
|
+
...(inverseStyle && {
|
|
116
|
+
...inverseStyles,
|
|
115
117
|
'&:is(a):link, &:is(a):visited, &:is(button)': inverseStyles,
|
|
116
118
|
'&:-webkit-any(a):link, &:-webkit-any(a):visited, &:-webkit-any(button)': inverseStyles
|
|
117
119
|
})
|
|
@@ -127,5 +129,4 @@ const generateStyle = (componentTheme, props, state) => {
|
|
|
127
129
|
}
|
|
128
130
|
};
|
|
129
131
|
};
|
|
130
|
-
|
|
131
132
|
export default generateStyle;
|
package/es/Link/theme.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { darken } from '@instructure/ui-color-utils';
|
|
25
24
|
|
|
25
|
+
import { darken } from '@instructure/ui-color-utils';
|
|
26
26
|
/**
|
|
27
27
|
* Generates the theme object for the component from the theme and provided additional information
|
|
28
28
|
* @param {Object} theme The actual theme object.
|
|
@@ -30,12 +30,13 @@ import { darken } from '@instructure/ui-color-utils';
|
|
|
30
30
|
*/
|
|
31
31
|
const generateComponentTheme = theme => {
|
|
32
32
|
const colors = theme.colors,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// this object should specify it
|
|
33
|
+
borders = theme.borders,
|
|
34
|
+
typography = theme.typography,
|
|
35
|
+
spacing = theme.spacing,
|
|
36
|
+
themeName = theme.key;
|
|
38
37
|
|
|
38
|
+
// if any styling should depend on the theme itself,
|
|
39
|
+
// this object should specify it
|
|
39
40
|
const themeSpecificStyle = {
|
|
40
41
|
canvas: {
|
|
41
42
|
color: theme['ic-link-color'],
|
|
@@ -46,8 +47,9 @@ const generateComponentTheme = theme => {
|
|
|
46
47
|
textDecorationOutsideText: 'underline',
|
|
47
48
|
hoverTextDecorationOutsideText: 'none'
|
|
48
49
|
}
|
|
49
|
-
};
|
|
50
|
+
};
|
|
50
51
|
|
|
52
|
+
// maps the theme variables to component specific style variables
|
|
51
53
|
const componentVariables = {
|
|
52
54
|
fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
|
|
53
55
|
fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightNormal,
|
|
@@ -67,9 +69,9 @@ const generateComponentTheme = theme => {
|
|
|
67
69
|
// make icon slightly larger than inherited font-size,
|
|
68
70
|
iconPlusTextMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall
|
|
69
71
|
};
|
|
70
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
...componentVariables,
|
|
71
74
|
...themeSpecificStyle[themeName]
|
|
72
75
|
};
|
|
73
76
|
};
|
|
74
|
-
|
|
75
77
|
export default generateComponentTheme;
|
package/es/index.js
CHANGED
package/lib/Link/LinkLocator.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.LinkLocator = void 0;
|
|
7
|
-
|
|
8
7
|
var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
|
|
9
|
-
|
|
10
8
|
var _uiTestQueries = require("@instructure/ui-test-queries");
|
|
11
|
-
|
|
12
9
|
var _index = require("./index");
|
|
13
|
-
|
|
14
10
|
/*
|
|
15
11
|
* The MIT License (MIT)
|
|
16
12
|
*
|
|
@@ -34,13 +30,13 @@ var _index = require("./index");
|
|
|
34
30
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
31
|
* SOFTWARE.
|
|
36
32
|
*/
|
|
33
|
+
|
|
37
34
|
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
38
35
|
const LinkLocator = (0, _locator.locator)(_index.Link.selector, {
|
|
39
36
|
click: async function (element) {
|
|
40
37
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
41
38
|
args[_key - 1] = arguments[_key];
|
|
42
39
|
}
|
|
43
|
-
|
|
44
40
|
return (await (0, _uiTestQueries.find)(element, 'a,button,[role="button"]')).click(...args);
|
|
45
41
|
}
|
|
46
42
|
});
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _IconTrashSolid = require("@instructure/ui-icons/lib/IconTrashSolid.js");
|
|
9
|
-
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -30,6 +28,7 @@ var _IconTrashSolid = require("@instructure/ui-icons/lib/IconTrashSolid.js");
|
|
|
30
28
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
29
|
* SOFTWARE.
|
|
32
30
|
*/
|
|
31
|
+
|
|
33
32
|
const longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat';
|
|
34
33
|
const shortString = 'Delete';
|
|
35
34
|
var _default = {
|
package/lib/Link/index.js
CHANGED
|
@@ -1,52 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = exports.Link = void 0;
|
|
11
|
-
|
|
12
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
-
|
|
14
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
-
|
|
16
11
|
var _View = require("@instructure/ui-view/lib/View");
|
|
17
|
-
|
|
18
12
|
var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
|
|
19
|
-
|
|
20
13
|
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
21
|
-
|
|
22
14
|
var _findFocusable = require("@instructure/ui-dom-utils/lib/findFocusable.js");
|
|
23
|
-
|
|
24
15
|
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
25
|
-
|
|
26
16
|
var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
|
|
27
|
-
|
|
28
17
|
var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
|
|
29
|
-
|
|
30
18
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
31
|
-
|
|
32
19
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
33
|
-
|
|
34
20
|
var _console = require("@instructure/console");
|
|
35
|
-
|
|
36
21
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
37
|
-
|
|
38
22
|
var _emotion = require("@instructure/emotion");
|
|
39
|
-
|
|
40
23
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
41
|
-
|
|
42
24
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
43
|
-
|
|
44
25
|
var _props = require("./props");
|
|
45
|
-
|
|
46
26
|
const _excluded = ["children", "onClick", "color", "href", "margin", "renderIcon", "iconPlacement", "isWithinText"];
|
|
47
|
-
|
|
48
27
|
var _dec, _dec2, _class, _class2;
|
|
49
|
-
|
|
50
28
|
/**
|
|
51
29
|
---
|
|
52
30
|
category: components
|
|
@@ -60,27 +38,22 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
|
|
|
60
38
|
hasFocus: false
|
|
61
39
|
};
|
|
62
40
|
this.ref = null;
|
|
63
|
-
|
|
64
41
|
this.makeStyleProps = () => {
|
|
65
42
|
return {
|
|
66
43
|
containsTruncateText: this.containsTruncateText,
|
|
67
44
|
hasVisibleChildren: this.hasVisibleChildren
|
|
68
45
|
};
|
|
69
46
|
};
|
|
70
|
-
|
|
71
47
|
this.handleElementRef = el => {
|
|
72
48
|
const elementRef = this.props.elementRef;
|
|
73
49
|
this.ref = el;
|
|
74
|
-
|
|
75
50
|
if (typeof elementRef === 'function') {
|
|
76
51
|
elementRef(el);
|
|
77
52
|
}
|
|
78
53
|
};
|
|
79
|
-
|
|
80
54
|
this.handleClick = event => {
|
|
81
55
|
const onClick = this.props.onClick;
|
|
82
56
|
const interaction = this.interaction;
|
|
83
|
-
|
|
84
57
|
if (interaction === 'disabled') {
|
|
85
58
|
event.preventDefault();
|
|
86
59
|
event.stopPropagation();
|
|
@@ -88,135 +61,110 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
|
|
|
88
61
|
onClick(event);
|
|
89
62
|
}
|
|
90
63
|
};
|
|
91
|
-
|
|
92
64
|
this.handleFocus = event => {
|
|
93
65
|
this.setState({
|
|
94
66
|
hasFocus: true
|
|
95
67
|
});
|
|
96
|
-
|
|
97
68
|
if (typeof this.props.onFocus === 'function') {
|
|
98
69
|
this.props.onFocus(event);
|
|
99
70
|
}
|
|
100
71
|
};
|
|
101
|
-
|
|
102
72
|
this.handleBlur = event => {
|
|
103
73
|
this.setState({
|
|
104
74
|
hasFocus: false
|
|
105
75
|
});
|
|
106
|
-
|
|
107
76
|
if (typeof this.props.onBlur === 'function') {
|
|
108
77
|
this.props.onBlur(event);
|
|
109
78
|
}
|
|
110
79
|
};
|
|
111
80
|
}
|
|
112
|
-
|
|
113
81
|
get _link() {
|
|
114
82
|
return this.ref;
|
|
115
83
|
}
|
|
116
|
-
|
|
117
84
|
componentDidMount() {
|
|
118
85
|
var _this$props$makeStyle, _this$props;
|
|
119
|
-
|
|
120
86
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
|
|
121
87
|
}
|
|
122
|
-
|
|
123
88
|
componentDidUpdate() {
|
|
124
89
|
var _this$props$makeStyle2, _this$props2;
|
|
125
|
-
|
|
126
90
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
|
|
127
91
|
}
|
|
128
|
-
|
|
129
92
|
get containsTruncateText() {
|
|
130
93
|
let truncateText = false;
|
|
131
|
-
|
|
132
94
|
_react.default.Children.forEach(this.props.children, child => {
|
|
133
95
|
if (child && (0, _matchComponentTypes.matchComponentTypes)(child, ['TruncateText'])) {
|
|
134
96
|
truncateText = true;
|
|
135
97
|
}
|
|
136
98
|
});
|
|
137
|
-
|
|
138
|
-
|
|
99
|
+
(0, _console.logWarn)(
|
|
100
|
+
// if display prop is used, warn about icon or TruncateText
|
|
139
101
|
!truncateText || this.props.display === void 0, '[Link] Using the display property with TruncateText may cause layout issues.');
|
|
140
102
|
return truncateText;
|
|
141
103
|
}
|
|
142
|
-
|
|
143
104
|
get display() {
|
|
144
105
|
if (this.props.display) {
|
|
145
106
|
return this.props.display; // user-entered display property
|
|
146
107
|
}
|
|
147
108
|
|
|
148
109
|
const containsTruncateText = this.containsTruncateText;
|
|
149
|
-
|
|
150
110
|
if (this.props.renderIcon) {
|
|
151
111
|
return containsTruncateText ? 'inline-flex' : 'inline-block';
|
|
152
112
|
} else {
|
|
153
113
|
return containsTruncateText ? 'block' : 'auto';
|
|
154
114
|
}
|
|
155
115
|
}
|
|
156
|
-
|
|
157
116
|
get interaction() {
|
|
158
117
|
return (0, _getInteraction.getInteraction)({
|
|
159
118
|
props: this.props,
|
|
160
119
|
interactionTypes: ['disabled']
|
|
161
120
|
});
|
|
162
121
|
}
|
|
163
|
-
|
|
164
122
|
get element() {
|
|
165
123
|
return (0, _getElementType.getElementType)(Link, this.props);
|
|
166
124
|
}
|
|
167
|
-
|
|
168
125
|
get focused() {
|
|
169
126
|
return (0, _isActiveElement.isActiveElement)(this.ref);
|
|
170
127
|
}
|
|
171
|
-
|
|
172
128
|
get focusable() {
|
|
173
129
|
return (0, _findFocusable.findFocusable)(this.ref);
|
|
174
130
|
}
|
|
175
|
-
|
|
176
131
|
get hasVisibleChildren() {
|
|
177
132
|
return (0, _hasVisibleChildren.hasVisibleChildren)(this.props.children);
|
|
178
133
|
}
|
|
179
|
-
|
|
180
134
|
get role() {
|
|
181
135
|
const _this$props3 = this.props,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
136
|
+
role = _this$props3.role,
|
|
137
|
+
forceButtonRole = _this$props3.forceButtonRole,
|
|
138
|
+
onClick = _this$props3.onClick;
|
|
186
139
|
if (forceButtonRole) {
|
|
187
140
|
return onClick && this.element !== 'button' ? 'button' : role;
|
|
188
141
|
}
|
|
189
|
-
|
|
190
142
|
return role;
|
|
191
143
|
}
|
|
192
|
-
|
|
193
144
|
focus() {
|
|
194
145
|
this.ref && this.ref.focus();
|
|
195
146
|
}
|
|
196
|
-
|
|
197
147
|
renderIcon() {
|
|
198
148
|
var _this$props$styles;
|
|
199
|
-
|
|
200
|
-
|
|
149
|
+
(0, _console.logWarn)(
|
|
150
|
+
// if display prop is used, warn about icon or TruncateText
|
|
201
151
|
this.props.display === void 0, '[Link] Using the display property with an icon may cause layout issues.');
|
|
202
152
|
return (0, _emotion.jsx)("span", {
|
|
203
153
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon
|
|
204
154
|
}, (0, _callRenderProp.callRenderProp)(this.props.renderIcon));
|
|
205
155
|
}
|
|
206
|
-
|
|
207
156
|
render() {
|
|
208
157
|
var _this$props$styles2;
|
|
209
|
-
|
|
210
158
|
const _this$props4 = this.props,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
159
|
+
children = _this$props4.children,
|
|
160
|
+
onClick = _this$props4.onClick,
|
|
161
|
+
color = _this$props4.color,
|
|
162
|
+
href = _this$props4.href,
|
|
163
|
+
margin = _this$props4.margin,
|
|
164
|
+
renderIcon = _this$props4.renderIcon,
|
|
165
|
+
iconPlacement = _this$props4.iconPlacement,
|
|
166
|
+
isWithinText = _this$props4.isWithinText,
|
|
167
|
+
props = (0, _objectWithoutProperties2.default)(_this$props4, _excluded);
|
|
220
168
|
const interaction = this.interaction;
|
|
221
169
|
const isDisabled = interaction === 'disabled';
|
|
222
170
|
const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
|
|
@@ -237,7 +185,6 @@ let Link = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _de
|
|
|
237
185
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link
|
|
238
186
|
}), renderIcon && iconPlacement === 'start' && this.renderIcon(), children, renderIcon && iconPlacement === 'end' && this.renderIcon());
|
|
239
187
|
}
|
|
240
|
-
|
|
241
188
|
}, _class2.displayName = "Link", _class2.componentId = 'Link', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
|
|
242
189
|
// Leave interaction default undefined so that `disabled` can also be supplied
|
|
243
190
|
interaction: void 0,
|