@instructure/ui-tag 8.13.1-snapshot.26 → 8.13.1-snapshot.36

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.
@@ -22,5 +22,6 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
  import { locator } from '@instructure/ui-test-locator';
25
- import { Tag } from './index';
25
+ import { Tag } from './index'; // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
26
+
26
27
  export const TagLocator = locator(Tag.selector);
@@ -26,7 +26,7 @@ export default {
26
26
  propValues: {
27
27
  text: ['Some tag', 'A lot of content which will truncate']
28
28
  },
29
- getComponentProps: props => {
29
+ getComponentProps: () => {
30
30
  return {
31
31
  onClick: () => {}
32
32
  };
package/es/Tag/index.js CHANGED
@@ -25,7 +25,7 @@ var _dec, _dec2, _class, _class2, _temp;
25
25
  */
26
26
 
27
27
  /** @jsx jsx */
28
- import { Component } from 'react';
28
+ import React, { Component } from 'react';
29
29
  import { IconXSolid } from '@instructure/ui-icons';
30
30
  import { View } from '@instructure/ui-view';
31
31
  import { omitProps } from '@instructure/ui-react-utils';
@@ -39,14 +39,16 @@ import { allowedProps, propTypes } from './props';
39
39
  ---
40
40
  category: components
41
41
  ---
42
+ @tsProps
42
43
  **/
43
44
 
44
45
  let Tag = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class Tag extends Component {
45
46
  constructor() {
46
47
  super(...arguments);
48
+ this.ref = null;
47
49
 
48
50
  this.focus = () => {
49
- this._container && this._container.focus();
51
+ this.ref && this.ref.focus();
50
52
  };
51
53
 
52
54
  this.handleClick = e => {
@@ -63,8 +65,12 @@ let Tag = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = test
63
65
  }
64
66
  };
65
67
 
66
- this.handleRef = node => {
67
- this._container = node;
68
+ this.handleRef = element => {
69
+ this.ref = element;
70
+
71
+ if (typeof this.props.elementRef === 'function') {
72
+ this.props.elementRef(element);
73
+ }
68
74
  };
69
75
  }
70
76
 
@@ -74,14 +80,14 @@ let Tag = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = test
74
80
  (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
75
81
  }
76
82
 
77
- componentDidUpdate(prevProps, prevState, snapshot) {
83
+ componentDidUpdate() {
78
84
  var _this$props$makeStyle2, _this$props3;
79
85
 
80
86
  (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
81
87
  }
82
88
 
83
89
  get focused() {
84
- return isActiveElement(this._container);
90
+ return isActiveElement(this.ref);
85
91
  }
86
92
 
87
93
  render() {
@@ -97,8 +103,7 @@ let Tag = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = test
97
103
  styles = _this$props4.styles;
98
104
  const passthroughProps = View.omitViewProps(omitProps(this.props, Tag.allowedProps), Tag);
99
105
  return jsx(View, Object.assign({}, passthroughProps, {
100
- ref: this.handleRef,
101
- elementRef: this.props.elementRef,
106
+ elementRef: this.handleRef,
102
107
  css: styles === null || styles === void 0 ? void 0 : styles.tag,
103
108
  className: className,
104
109
  as: onClick ? 'button' : 'span',
package/es/Tag/props.js CHANGED
@@ -27,33 +27,11 @@ const propTypes = {
27
27
  className: PropTypes.string,
28
28
  text: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
29
29
  title: PropTypes.string,
30
-
31
- /**
32
- * Whether or not to disable the tag
33
- */
34
30
  disabled: PropTypes.bool,
35
-
36
- /**
37
- * Works just like disabled but keeps the same styles as if it were active
38
- */
39
31
  readOnly: PropTypes.bool,
40
32
  dismissible: PropTypes.bool,
41
-
42
- /**
43
- * Valid values are `0`, `none`, `auto`, `xxxx-small`, `xx-small`, `x-small`,
44
- * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
45
- * familiar CSS-like shorthand. For example: `margin="small auto large"`.
46
- */
47
33
  margin: ThemeablePropTypes.spacing,
48
-
49
- /**
50
- * If you add an onClick prop, Tag renders as a clickable button
51
- */
52
34
  onClick: PropTypes.func,
53
-
54
- /**
55
- * Provides a reference to the underlying html root element
56
- */
57
35
  elementRef: PropTypes.func,
58
36
  size: PropTypes.oneOf(['small', 'medium', 'large']),
59
37
  variant: PropTypes.oneOf(['default', 'inline'])
@@ -32,5 +32,6 @@ var _index = require("./index");
32
32
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
33
  * SOFTWARE.
34
34
  */
35
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
35
36
  const TagLocator = (0, _locator.locator)(_index.Tag.selector);
36
37
  exports.TagLocator = TagLocator;
@@ -33,7 +33,7 @@ var _default = {
33
33
  propValues: {
34
34
  text: ['Some tag', 'A lot of content which will truncate']
35
35
  },
36
- getComponentProps: props => {
36
+ getComponentProps: () => {
37
37
  return {
38
38
  onClick: () => {}
39
39
  };
package/lib/Tag/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
3
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -7,7 +9,7 @@ Object.defineProperty(exports, "__esModule", {
7
9
  });
8
10
  exports.default = exports.Tag = void 0;
9
11
 
10
- var _react = require("react");
12
+ var _react = _interopRequireWildcard(require("react"));
11
13
 
12
14
  var _IconXSolid = require("@instructure/ui-icons/lib/IconXSolid.js");
13
15
 
@@ -33,13 +35,15 @@ var _dec, _dec2, _class, _class2, _temp;
33
35
  ---
34
36
  category: components
35
37
  ---
38
+ @tsProps
36
39
  **/
37
40
  let Tag = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class Tag extends _react.Component {
38
41
  constructor() {
39
42
  super(...arguments);
43
+ this.ref = null;
40
44
 
41
45
  this.focus = () => {
42
- this._container && this._container.focus();
46
+ this.ref && this.ref.focus();
43
47
  };
44
48
 
45
49
  this.handleClick = e => {
@@ -56,8 +60,12 @@ let Tag = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec
56
60
  }
57
61
  };
58
62
 
59
- this.handleRef = node => {
60
- this._container = node;
63
+ this.handleRef = element => {
64
+ this.ref = element;
65
+
66
+ if (typeof this.props.elementRef === 'function') {
67
+ this.props.elementRef(element);
68
+ }
61
69
  };
62
70
  }
63
71
 
@@ -67,14 +75,14 @@ let Tag = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec
67
75
  (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
68
76
  }
69
77
 
70
- componentDidUpdate(prevProps, prevState, snapshot) {
78
+ componentDidUpdate() {
71
79
  var _this$props$makeStyle2, _this$props3;
72
80
 
73
81
  (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
74
82
  }
75
83
 
76
84
  get focused() {
77
- return (0, _isActiveElement.isActiveElement)(this._container);
85
+ return (0, _isActiveElement.isActiveElement)(this.ref);
78
86
  }
79
87
 
80
88
  render() {
@@ -92,8 +100,7 @@ let Tag = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec
92
100
  const passthroughProps = _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Tag.allowedProps), Tag);
93
101
 
94
102
  return (0, _emotion.jsx)(_View.View, Object.assign({}, passthroughProps, {
95
- ref: this.handleRef,
96
- elementRef: this.props.elementRef,
103
+ elementRef: this.handleRef,
97
104
  css: styles === null || styles === void 0 ? void 0 : styles.tag,
98
105
  className: className,
99
106
  as: onClick ? 'button' : 'span',
package/lib/Tag/props.js CHANGED
@@ -38,33 +38,11 @@ const propTypes = {
38
38
  className: _propTypes.default.string,
39
39
  text: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]).isRequired,
40
40
  title: _propTypes.default.string,
41
-
42
- /**
43
- * Whether or not to disable the tag
44
- */
45
41
  disabled: _propTypes.default.bool,
46
-
47
- /**
48
- * Works just like disabled but keeps the same styles as if it were active
49
- */
50
42
  readOnly: _propTypes.default.bool,
51
43
  dismissible: _propTypes.default.bool,
52
-
53
- /**
54
- * Valid values are `0`, `none`, `auto`, `xxxx-small`, `xx-small`, `x-small`,
55
- * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
56
- * familiar CSS-like shorthand. For example: `margin="small auto large"`.
57
- */
58
44
  margin: _emotion.ThemeablePropTypes.spacing,
59
-
60
- /**
61
- * If you add an onClick prop, Tag renders as a clickable button
62
- */
63
45
  onClick: _propTypes.default.func,
64
-
65
- /**
66
- * Provides a reference to the underlying html root element
67
- */
68
46
  elementRef: _propTypes.default.func,
69
47
  size: _propTypes.default.oneOf(['small', 'medium', 'large']),
70
48
  variant: _propTypes.default.oneOf(['default', 'inline'])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tag",
3
- "version": "8.13.1-snapshot.26+46fefbe37",
3
+ "version": "8.13.1-snapshot.36+fc6f2ce45",
4
4
  "description": "A tag component",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -25,22 +25,22 @@
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "@babel/runtime": "^7.13.10",
28
- "@instructure/console": "8.13.1-snapshot.26+46fefbe37",
29
- "@instructure/emotion": "8.13.1-snapshot.26+46fefbe37",
30
- "@instructure/shared-types": "8.13.1-snapshot.26+46fefbe37",
31
- "@instructure/ui-color-utils": "8.13.1-snapshot.26+46fefbe37",
32
- "@instructure/ui-dom-utils": "8.13.1-snapshot.26+46fefbe37",
33
- "@instructure/ui-icons": "8.13.1-snapshot.26+46fefbe37",
34
- "@instructure/ui-react-utils": "8.13.1-snapshot.26+46fefbe37",
35
- "@instructure/ui-testable": "8.13.1-snapshot.26+46fefbe37",
36
- "@instructure/ui-view": "8.13.1-snapshot.26+46fefbe37",
28
+ "@instructure/console": "8.13.1-snapshot.36+fc6f2ce45",
29
+ "@instructure/emotion": "8.13.1-snapshot.36+fc6f2ce45",
30
+ "@instructure/shared-types": "8.13.1-snapshot.36+fc6f2ce45",
31
+ "@instructure/ui-color-utils": "8.13.1-snapshot.36+fc6f2ce45",
32
+ "@instructure/ui-dom-utils": "8.13.1-snapshot.36+fc6f2ce45",
33
+ "@instructure/ui-icons": "8.13.1-snapshot.36+fc6f2ce45",
34
+ "@instructure/ui-react-utils": "8.13.1-snapshot.36+fc6f2ce45",
35
+ "@instructure/ui-testable": "8.13.1-snapshot.36+fc6f2ce45",
36
+ "@instructure/ui-view": "8.13.1-snapshot.36+fc6f2ce45",
37
37
  "prop-types": "^15"
38
38
  },
39
39
  "devDependencies": {
40
- "@instructure/ui-babel-preset": "8.13.1-snapshot.26+46fefbe37",
41
- "@instructure/ui-test-locator": "8.13.1-snapshot.26+46fefbe37",
42
- "@instructure/ui-test-utils": "8.13.1-snapshot.26+46fefbe37",
43
- "@instructure/ui-themes": "8.13.1-snapshot.26+46fefbe37"
40
+ "@instructure/ui-babel-preset": "8.13.1-snapshot.36+fc6f2ce45",
41
+ "@instructure/ui-test-locator": "8.13.1-snapshot.36+fc6f2ce45",
42
+ "@instructure/ui-test-utils": "8.13.1-snapshot.36+fc6f2ce45",
43
+ "@instructure/ui-themes": "8.13.1-snapshot.36+fc6f2ce45"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=16.8 <=17"
@@ -49,5 +49,5 @@
49
49
  "access": "public"
50
50
  },
51
51
  "sideEffects": false,
52
- "gitHead": "46fefbe371fc4000ebcc26609d003d75eb81eb69"
52
+ "gitHead": "fc6f2ce45e81843342834c2fd6526c30441c0928"
53
53
  }
@@ -21,15 +21,18 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
25
+ import type { StoryConfig } from '@instructure/ui-test-utils'
26
+ import type { TagProps } from '../props'
27
+
24
28
  export default {
25
29
  sectionProp: 'variant',
26
30
  propValues: {
27
31
  text: ['Some tag', 'A lot of content which will truncate']
28
32
  },
29
- // @ts-expect-error ts-migrate(6133) FIXME: 'props' is declared but its value is never read.
30
- getComponentProps: (props) => {
33
+ getComponentProps: () => {
31
34
  return {
32
35
  onClick: () => {}
33
36
  }
34
37
  }
35
- }
38
+ } as StoryConfig<TagProps>
package/src/Tag/index.tsx CHANGED
@@ -22,10 +22,11 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
  /** @jsx jsx */
25
- import { Component } from 'react'
25
+ import React, { Component } from 'react'
26
26
 
27
27
  import { IconXSolid } from '@instructure/ui-icons'
28
28
  import { View } from '@instructure/ui-view'
29
+ import type { ViewProps } from '@instructure/ui-view'
29
30
  import { omitProps } from '@instructure/ui-react-utils'
30
31
  import { isActiveElement } from '@instructure/ui-dom-utils'
31
32
  import { testable } from '@instructure/ui-testable'
@@ -40,6 +41,7 @@ import { allowedProps, propTypes } from './props'
40
41
  ---
41
42
  category: components
42
43
  ---
44
+ @tsProps
43
45
  **/
44
46
 
45
47
  @withStyle(generateStyle, generateComponentTheme)
@@ -57,27 +59,25 @@ class Tag extends Component<TagProps> {
57
59
  readOnly: false
58
60
  }
59
61
 
62
+ ref: Element | null = null
63
+
60
64
  componentDidMount() {
61
65
  this.props.makeStyles?.()
62
66
  }
63
67
 
64
- // @ts-expect-error ts-migrate(6133) FIXME: 'prevProps' is declared but its value is never rea... Remove this comment to see the full error message
65
- componentDidUpdate(prevProps, prevState, snapshot) {
68
+ componentDidUpdate() {
66
69
  this.props.makeStyles?.()
67
70
  }
68
71
 
69
72
  get focused() {
70
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_container' does not exist on type 'Tag'... Remove this comment to see the full error message
71
- return isActiveElement(this._container)
73
+ return isActiveElement(this.ref)
72
74
  }
73
75
 
74
76
  focus = () => {
75
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_container' does not exist on type 'Tag'... Remove this comment to see the full error message
76
- this._container && this._container.focus()
77
+ this.ref && (this.ref as HTMLElement).focus()
77
78
  }
78
79
 
79
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'e' implicitly has an 'any' type.
80
- handleClick = (e) => {
80
+ handleClick = (e: React.MouseEvent<ViewProps>) => {
81
81
  const { disabled, readOnly, onClick } = this.props
82
82
 
83
83
  if (disabled || readOnly) {
@@ -88,10 +88,12 @@ class Tag extends Component<TagProps> {
88
88
  }
89
89
  }
90
90
 
91
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'node' implicitly has an 'any' type.
92
- handleRef = (node) => {
93
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_container' does not exist on type 'Tag'... Remove this comment to see the full error message
94
- this._container = node
91
+ handleRef = (element: Element | null) => {
92
+ this.ref = element
93
+
94
+ if (typeof this.props.elementRef === 'function') {
95
+ this.props.elementRef(element)
96
+ }
95
97
  }
96
98
 
97
99
  render() {
@@ -115,8 +117,7 @@ class Tag extends Component<TagProps> {
115
117
  return (
116
118
  <View
117
119
  {...passthroughProps}
118
- ref={this.handleRef}
119
- elementRef={this.props.elementRef}
120
+ elementRef={this.handleRef}
120
121
  css={styles?.tag}
121
122
  className={className}
122
123
  as={onClick ? 'button' : 'span'}
package/src/Tag/props.ts CHANGED
@@ -21,10 +21,13 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
25
+ import React from 'react'
24
26
  import PropTypes from 'prop-types'
25
27
 
26
28
  import { ThemeablePropTypes } from '@instructure/emotion'
27
29
 
30
+ import type { ViewProps } from '@instructure/ui-view'
28
31
  import type {
29
32
  Spacing,
30
33
  WithStyleProps,
@@ -40,11 +43,28 @@ type TagOwnProps = {
40
43
  className?: string
41
44
  text: string | React.ReactNode
42
45
  title?: string
46
+ /**
47
+ * Whether or not to disable the tag
48
+ */
43
49
  disabled?: boolean
50
+ /**
51
+ * Works just like disabled but keeps the same styles as if it were active
52
+ */
44
53
  readOnly?: boolean
45
54
  dismissible?: boolean
55
+ /**
56
+ * Valid values are `0`, `none`, `auto`, `xxxx-small`, `xx-small`, `x-small`,
57
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
58
+ * familiar CSS-like shorthand. For example: `margin="small auto large"`.
59
+ */
46
60
  margin?: Spacing
47
- onClick?: (...args: any[]) => any
61
+ /**
62
+ * If you add an onClick prop, Tag renders as a clickable button
63
+ */
64
+ onClick?: (event: React.MouseEvent<ViewProps>) => void
65
+ /**
66
+ * Provides a reference to the underlying html root element
67
+ */
48
68
  elementRef?: (element: Element | null) => void
49
69
  size?: 'small' | 'medium' | 'large'
50
70
  variant?: 'default' | 'inline'
@@ -64,28 +84,11 @@ const propTypes: PropValidators<PropKeys> = {
64
84
  className: PropTypes.string,
65
85
  text: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
66
86
  title: PropTypes.string,
67
- /**
68
- * Whether or not to disable the tag
69
- */
70
87
  disabled: PropTypes.bool,
71
- /**
72
- * Works just like disabled but keeps the same styles as if it were active
73
- */
74
88
  readOnly: PropTypes.bool,
75
89
  dismissible: PropTypes.bool,
76
- /**
77
- * Valid values are `0`, `none`, `auto`, `xxxx-small`, `xx-small`, `x-small`,
78
- * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
79
- * familiar CSS-like shorthand. For example: `margin="small auto large"`.
80
- */
81
90
  margin: ThemeablePropTypes.spacing,
82
- /**
83
- * If you add an onClick prop, Tag renders as a clickable button
84
- */
85
91
  onClick: PropTypes.func,
86
- /**
87
- * Provides a reference to the underlying html root element
88
- */
89
92
  elementRef: PropTypes.func,
90
93
  size: PropTypes.oneOf(['small', 'medium', 'large']),
91
94
  variant: PropTypes.oneOf(['default', 'inline'])