@instructure/ui-link 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -35,17 +35,18 @@ import { calcFocusOutlineStyles, calcSpacingFromShorthand } from '@instructure/e
35
35
  * @return {Object} The final style object, which will be used in the component
36
36
  */
37
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;
38
+ const {
39
+ renderIcon,
40
+ iconPlacement = 'start',
41
+ // TODO workaround needed for react 19 where defaultprops doesn't apply for some reasong
42
+ color,
43
+ margin
44
+ } = props;
44
45
 
45
46
  // 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;
47
+ const size = state.size ?? props.size;
48
+ const variant = state.variant ?? props.variant;
49
+ const hasVisibleChildren = state.hasVisibleChildren ?? false;
49
50
  const isInverseStyle = color === 'link-inverse';
50
51
  const inlineLinkSizeStyles = {
51
52
  small: {
@@ -116,7 +117,7 @@ const generateStyle = (componentTheme, props, sharedTokens, state = {}) => {
116
117
  variantStyles = {
117
118
  fontSize: 'inherit',
118
119
  lineHeight: 'inherit',
119
- textDecoration: void 0,
120
+ textDecoration: undefined,
120
121
  gap: componentTheme.gapMd // Default gap for icons when no size is specified
121
122
  };
122
123
  }
@@ -216,7 +217,7 @@ const generateStyle = (componentTheme, props, sharedTokens, state = {}) => {
216
217
  }),
217
218
  ...calcFocusOutlineStyles(sharedTokens.focusOutline, isInverseStyle ? {
218
219
  focusColor: 'inverse'
219
- } : void 0),
220
+ } : undefined),
220
221
  // 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
222
  '&:is(a), &:is(button)': isClickableStyles,
222
223
  '&:-webkit-any(a), &:-webkit-any(button)': isClickableStyles,
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.Link = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
8
  var _react = require("react");
10
9
  var _v11_ = require("@instructure/ui-view/v11_6");
11
10
  var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
@@ -23,8 +22,7 @@ var _styles = _interopRequireDefault(require("./styles"));
23
22
  var _theme = _interopRequireDefault(require("./theme"));
24
23
  var _props = require("./props");
25
24
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
26
- const _excluded = ["children", "onClick", "onMouseEnter", "color", "href", "margin", "renderIcon", "iconPlacement", "isWithinText"];
27
- var _dec, _class, _Link;
25
+ var _dec, _class;
28
26
  /*
29
27
  * The MIT License (MIT)
30
28
  *
@@ -53,64 +51,76 @@ var _dec, _class, _Link;
53
51
  category: components
54
52
  ---
55
53
  **/
56
- let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_Link = class Link extends _react.Component {
57
- constructor(...args) {
58
- super(...args);
59
- this.state = {
60
- hasFocus: false
61
- };
62
- this.ref = null;
63
- this.makeStyleProps = () => {
64
- return {
65
- containsTruncateText: this.containsTruncateText,
66
- hasVisibleChildren: this.hasVisibleChildren
67
- };
68
- };
69
- this.handleElementRef = el => {
70
- const elementRef = this.props.elementRef;
71
- this.ref = el;
72
- if (typeof elementRef === 'function') {
73
- elementRef(el);
74
- }
75
- };
76
- this.handleClick = event => {
77
- const onClick = this.props.onClick;
78
- const interaction = this.interaction;
79
- if (interaction === 'disabled') {
80
- event.preventDefault();
81
- event.stopPropagation();
82
- } else if (typeof onClick === 'function') {
83
- onClick(event);
84
- }
85
- };
86
- this.handleFocus = event => {
87
- this.setState({
88
- hasFocus: true
89
- });
90
- if (typeof this.props.onFocus === 'function') {
91
- this.props.onFocus(event);
92
- }
93
- };
94
- this.handleBlur = event => {
95
- this.setState({
96
- hasFocus: false
97
- });
98
- if (typeof this.props.onBlur === 'function') {
99
- this.props.onBlur(event);
100
- }
101
- };
102
- }
54
+ let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = class Link extends _react.Component {
55
+ static displayName = "Link";
56
+ static componentId = 'Link';
57
+ static allowedProps = _props.allowedProps;
58
+ static defaultProps = {
59
+ // Leave interaction default undefined so that `disabled` can also be supplied
60
+ interaction: undefined,
61
+ color: 'link',
62
+ iconPlacement: 'start',
63
+ isWithinText: true,
64
+ forceButtonRole: true
65
+ };
66
+ state = {
67
+ hasFocus: false
68
+ };
103
69
  get _link() {
104
70
  return this.ref;
105
71
  }
72
+ ref = null;
106
73
  componentDidMount() {
107
- var _this$props$makeStyle, _this$props;
108
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
74
+ this.props.makeStyles?.(this.makeStyleProps());
109
75
  }
110
76
  componentDidUpdate() {
111
- var _this$props$makeStyle2, _this$props2;
112
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
77
+ this.props.makeStyles?.(this.makeStyleProps());
113
78
  }
79
+ makeStyleProps = () => {
80
+ return {
81
+ containsTruncateText: this.containsTruncateText,
82
+ hasVisibleChildren: this.hasVisibleChildren
83
+ };
84
+ };
85
+ handleElementRef = el => {
86
+ const {
87
+ elementRef
88
+ } = this.props;
89
+ this.ref = el;
90
+ if (typeof elementRef === 'function') {
91
+ elementRef(el);
92
+ }
93
+ };
94
+ handleClick = event => {
95
+ const {
96
+ onClick
97
+ } = this.props;
98
+ const {
99
+ interaction
100
+ } = this;
101
+ if (interaction === 'disabled') {
102
+ event.preventDefault();
103
+ event.stopPropagation();
104
+ } else if (typeof onClick === 'function') {
105
+ onClick(event);
106
+ }
107
+ };
108
+ handleFocus = event => {
109
+ this.setState({
110
+ hasFocus: true
111
+ });
112
+ if (typeof this.props.onFocus === 'function') {
113
+ this.props.onFocus(event);
114
+ }
115
+ };
116
+ handleBlur = event => {
117
+ this.setState({
118
+ hasFocus: false
119
+ });
120
+ if (typeof this.props.onBlur === 'function') {
121
+ this.props.onBlur(event);
122
+ }
123
+ };
114
124
  get containsTruncateText() {
115
125
  let truncateText = false;
116
126
  _react.Children.forEach(this.props.children, child => {
@@ -120,14 +130,16 @@ let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default,
120
130
  });
121
131
  (0, _console.logWarn)(
122
132
  // if display prop is used, warn about icon or TruncateText
123
- !truncateText || this.props.display === void 0, '[Link] Using the display property with TruncateText may cause layout issues.');
133
+ !truncateText || this.props.display === undefined, '[Link] Using the display property with TruncateText may cause layout issues.');
124
134
  return truncateText;
125
135
  }
126
136
  get display() {
127
137
  if (this.props.display) {
128
138
  return this.props.display; // user-entered display property
129
139
  }
130
- const containsTruncateText = this.containsTruncateText;
140
+ const {
141
+ containsTruncateText
142
+ } = this;
131
143
  if (this.props.renderIcon) {
132
144
  return containsTruncateText ? 'inline-flex' : 'inline-block';
133
145
  } else {
@@ -153,10 +165,11 @@ let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default,
153
165
  return (0, _hasVisibleChildren.hasVisibleChildren)(this.props.children);
154
166
  }
155
167
  get role() {
156
- const _this$props3 = this.props,
157
- role = _this$props3.role,
158
- forceButtonRole = _this$props3.forceButtonRole,
159
- onClick = _this$props3.onClick;
168
+ const {
169
+ role,
170
+ forceButtonRole,
171
+ onClick
172
+ } = this.props;
160
173
  if (forceButtonRole) {
161
174
  return onClick && this.element !== 'button' ? 'button' : role;
162
175
  }
@@ -166,32 +179,33 @@ let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default,
166
179
  this.ref && this.ref.focus();
167
180
  }
168
181
  renderIcon() {
169
- var _this$props$styles;
170
182
  (0, _console.logWarn)(
171
183
  // if display prop is used, warn about icon or TruncateText
172
- this.props.display === void 0, '[Link] Using the display property with an icon may cause layout issues.');
184
+ this.props.display === undefined, '[Link] Using the display property with an icon may cause layout issues.');
173
185
  return (0, _jsxRuntime.jsx)("span", {
174
- css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon,
186
+ css: this.props.styles?.icon,
175
187
  children: (0, _callRenderProp.callRenderProp)(this.props.renderIcon)
176
188
  });
177
189
  }
178
190
  render() {
179
- var _this$props$styles2;
180
- const _this$props4 = this.props,
181
- children = _this$props4.children,
182
- onClick = _this$props4.onClick,
183
- onMouseEnter = _this$props4.onMouseEnter,
184
- color = _this$props4.color,
185
- href = _this$props4.href,
186
- margin = _this$props4.margin,
187
- renderIcon = _this$props4.renderIcon,
188
- iconPlacement = _this$props4.iconPlacement,
189
- isWithinText = _this$props4.isWithinText,
190
- props = (0, _objectWithoutProperties2.default)(_this$props4, _excluded);
191
- const interaction = this.interaction;
191
+ const {
192
+ children,
193
+ onClick,
194
+ onMouseEnter,
195
+ color,
196
+ href,
197
+ margin,
198
+ renderIcon,
199
+ iconPlacement,
200
+ isWithinText,
201
+ ...props
202
+ } = this.props;
203
+ const {
204
+ interaction
205
+ } = this;
192
206
  const isDisabled = interaction === 'disabled';
193
- const type = this.element === 'button' || this.element === 'input' ? 'button' : void 0;
194
- const tabIndex = this.role === 'button' && !isDisabled ? 0 : void 0;
207
+ const type = this.element === 'button' || this.element === 'input' ? 'button' : undefined;
208
+ const tabIndex = this.role === 'button' && !isDisabled ? 0 : undefined;
195
209
  return (0, _jsxRuntime.jsxs)(_v11_.View, {
196
210
  ...(0, _passthroughProps.passthroughProps)(props),
197
211
  elementRef: this.handleElementRef,
@@ -203,21 +217,14 @@ let Link = exports.Link = (_dec = (0, _emotion.withStyleLegacy)(_styles.default,
203
217
  onClick: this.handleClick,
204
218
  onFocus: this.handleFocus,
205
219
  onBlur: this.handleBlur,
206
- "aria-disabled": isDisabled ? 'true' : void 0,
220
+ "aria-disabled": isDisabled ? 'true' : undefined,
207
221
  role: this.role,
208
222
  type: type,
209
223
  tabIndex: tabIndex,
210
- css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.link,
224
+ css: this.props.styles?.link,
211
225
  "data-cid": (0, _combineDataCid.combineDataCid)('Link', this.props),
212
226
  children: [renderIcon && iconPlacement === 'start' ? this.renderIcon() : null, children, renderIcon && iconPlacement === 'end' ? this.renderIcon() : null]
213
227
  });
214
228
  }
215
- }, _Link.displayName = "Link", _Link.componentId = 'Link', _Link.allowedProps = _props.allowedProps, _Link.defaultProps = {
216
- // Leave interaction default undefined so that `disabled` can also be supplied
217
- interaction: void 0,
218
- color: 'link',
219
- iconPlacement: 'start',
220
- isWithinText: true,
221
- forceButtonRole: true
222
- }, _Link)) || _class);
229
+ }) || _class);
223
230
  var _default = exports.default = Link;
@@ -39,14 +39,18 @@ exports.default = void 0;
39
39
  * @return {Object} The final style object, which will be used in the component
40
40
  */
41
41
  const generateStyle = (componentTheme, props, state) => {
42
- const isWithinText = props.isWithinText,
43
- renderIcon = props.renderIcon,
44
- _props$iconPlacement = props.iconPlacement,
45
- iconPlacement = _props$iconPlacement === void 0 ? 'start' : _props$iconPlacement,
46
- color = props.color,
47
- variant = props.variant;
48
- const containsTruncateText = state.containsTruncateText,
49
- hasVisibleChildren = state.hasVisibleChildren;
42
+ const {
43
+ isWithinText,
44
+ renderIcon,
45
+ iconPlacement = 'start',
46
+ // TODO workaround needed for react 19 where defaultprops doesn't apply for some reasong
47
+ color,
48
+ variant
49
+ } = props;
50
+ const {
51
+ containsTruncateText,
52
+ hasVisibleChildren
53
+ } = state;
50
54
  const inverseStyle = color === 'link-inverse';
51
55
  const variantStyles = {
52
56
  inline: {
@@ -35,12 +35,13 @@ var _darken = require("@instructure/ui-color-utils/lib/darken.js");
35
35
  * @return {Object} The final theme object with the overrides and component variables
36
36
  */
37
37
  const generateComponentTheme = theme => {
38
- var _colors$contrasts, _colors$contrasts2, _colors$contrasts3, _colors$contrasts4, _colors$contrasts5, _colors$contrasts6;
39
- const colors = theme.colors,
40
- borders = theme.borders,
41
- typography = theme.typography,
42
- spacing = theme.spacing,
43
- themeName = theme.key;
38
+ const {
39
+ colors,
40
+ borders,
41
+ typography,
42
+ spacing,
43
+ key: themeName
44
+ } = theme;
44
45
 
45
46
  // if any styling should depend on the theme itself,
46
47
  // this object should specify it
@@ -58,24 +59,24 @@ const generateComponentTheme = theme => {
58
59
 
59
60
  // maps the theme variables to component specific style variables
60
61
  const componentVariables = {
61
- fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
62
- fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightNormal,
63
- fontSize: typography === null || typography === void 0 ? void 0 : typography.content,
64
- lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeight150,
65
- fontSizeSmall: typography === null || typography === void 0 ? void 0 : typography.contentSmall,
66
- color: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.blue5782,
62
+ fontFamily: typography?.fontFamily,
63
+ fontWeight: typography?.fontWeightNormal,
64
+ fontSize: typography?.content,
65
+ lineHeight: typography?.lineHeight150,
66
+ fontSizeSmall: typography?.contentSmall,
67
+ color: colors?.contrasts?.blue5782,
67
68
  textDecorationWithinText: 'underline',
68
69
  hoverTextDecorationWithinText: 'none',
69
70
  textDecorationOutsideText: 'none',
70
71
  hoverTextDecorationOutsideText: 'underline',
71
- focusOutlineWidth: borders === null || borders === void 0 ? void 0 : borders.widthMedium,
72
- focusOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.blue4570,
73
- focusOutlineStyle: borders === null || borders === void 0 ? void 0 : borders.style,
74
- focusOutlineBorderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusSmall,
75
- hoverColor: (0, _darken.darken)(colors === null || colors === void 0 ? void 0 : (_colors$contrasts3 = colors.contrasts) === null || _colors$contrasts3 === void 0 ? void 0 : _colors$contrasts3.blue5782, 10),
76
- colorInverse: colors === null || colors === void 0 ? void 0 : (_colors$contrasts4 = colors.contrasts) === null || _colors$contrasts4 === void 0 ? void 0 : _colors$contrasts4.grey1111,
77
- focusInverseOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts5 = colors.contrasts) === null || _colors$contrasts5 === void 0 ? void 0 : _colors$contrasts5.white1010,
78
- focusInverseIconOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts6 = colors.contrasts) === null || _colors$contrasts6 === void 0 ? void 0 : _colors$contrasts6.white1010,
72
+ focusOutlineWidth: borders?.widthMedium,
73
+ focusOutlineColor: colors?.contrasts?.blue4570,
74
+ focusOutlineStyle: borders?.style,
75
+ focusOutlineBorderRadius: borders?.radiusSmall,
76
+ hoverColor: (0, _darken.darken)(colors?.contrasts?.blue5782, 10),
77
+ colorInverse: colors?.contrasts?.grey1111,
78
+ focusInverseOutlineColor: colors?.contrasts?.white1010,
79
+ focusInverseIconOutlineColor: colors?.contrasts?.white1010,
79
80
  iconSize: '1.125em',
80
81
  // make icon slightly larger than inherited font-size,
81
82
  iconPlusTextMargin: spacing.space4,