@instructure/ui-tag 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.
Files changed (56) hide show
  1. package/CHANGELOG.md +36 -284
  2. package/es/Tag/{index.js → v1/index.js} +2 -2
  3. package/es/Tag/v2/index.js +163 -0
  4. package/es/Tag/v2/props.js +26 -0
  5. package/es/Tag/v2/styles.js +208 -0
  6. package/es/{index.js → exports/a.js} +1 -1
  7. package/{src/index.ts → es/exports/b.js} +1 -3
  8. package/lib/Tag/{index.js → v1/index.js} +5 -5
  9. package/lib/Tag/v2/index.js +168 -0
  10. package/lib/Tag/v2/props.js +31 -0
  11. package/lib/Tag/v2/styles.js +213 -0
  12. package/lib/{index.js → exports/a.js} +2 -2
  13. package/lib/exports/b.js +12 -0
  14. package/package.json +41 -19
  15. package/src/Tag/{index.tsx → v1/index.tsx} +3 -3
  16. package/src/Tag/{props.ts → v1/props.ts} +1 -1
  17. package/src/Tag/v2/README.md +119 -0
  18. package/src/Tag/v2/index.tsx +180 -0
  19. package/src/Tag/v2/props.ts +93 -0
  20. package/src/Tag/v2/styles.ts +219 -0
  21. package/src/exports/a.ts +26 -0
  22. package/src/exports/b.ts +26 -0
  23. package/tsconfig.build.tsbuildinfo +1 -1
  24. package/types/Tag/{index.d.ts → v1/index.d.ts} +1 -1
  25. package/types/Tag/v1/index.d.ts.map +1 -0
  26. package/types/Tag/{props.d.ts → v1/props.d.ts} +1 -1
  27. package/types/Tag/v1/props.d.ts.map +1 -0
  28. package/types/Tag/v1/styles.d.ts.map +1 -0
  29. package/types/Tag/v1/theme.d.ts.map +1 -0
  30. package/types/Tag/v2/index.d.ts +48 -0
  31. package/types/Tag/v2/index.d.ts.map +1 -0
  32. package/types/Tag/v2/props.d.ts +46 -0
  33. package/types/Tag/v2/props.d.ts.map +1 -0
  34. package/types/Tag/v2/styles.d.ts +15 -0
  35. package/types/Tag/v2/styles.d.ts.map +1 -0
  36. package/types/exports/a.d.ts +3 -0
  37. package/types/exports/a.d.ts.map +1 -0
  38. package/types/exports/b.d.ts +3 -0
  39. package/types/exports/b.d.ts.map +1 -0
  40. package/types/Tag/index.d.ts.map +0 -1
  41. package/types/Tag/props.d.ts.map +0 -1
  42. package/types/Tag/styles.d.ts.map +0 -1
  43. package/types/Tag/theme.d.ts.map +0 -1
  44. package/types/index.d.ts +0 -3
  45. package/types/index.d.ts.map +0 -1
  46. /package/es/Tag/{props.js → v1/props.js} +0 -0
  47. /package/es/Tag/{styles.js → v1/styles.js} +0 -0
  48. /package/es/Tag/{theme.js → v1/theme.js} +0 -0
  49. /package/lib/Tag/{props.js → v1/props.js} +0 -0
  50. /package/lib/Tag/{styles.js → v1/styles.js} +0 -0
  51. /package/lib/Tag/{theme.js → v1/theme.js} +0 -0
  52. /package/src/Tag/{README.md → v1/README.md} +0 -0
  53. /package/src/Tag/{styles.ts → v1/styles.ts} +0 -0
  54. /package/src/Tag/{theme.ts → v1/theme.ts} +0 -0
  55. /package/types/Tag/{styles.d.ts → v1/styles.d.ts} +0 -0
  56. /package/types/Tag/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,163 @@
1
+ var _dec, _class, _Tag;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Component } from 'react';
27
+ import { XInstUIIcon } from '@instructure/ui-icons';
28
+ import { View } from '@instructure/ui-view/latest';
29
+ import { omitProps } from '@instructure/ui-react-utils';
30
+ import { isActiveElement } from '@instructure/ui-dom-utils';
31
+ import { withStyle } from '@instructure/emotion';
32
+ import generateStyle from "./styles.js";
33
+ import { allowedProps } from "./props.js";
34
+ /**
35
+ ---
36
+ category: components
37
+ ---
38
+ **/
39
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
40
+ let Tag = (_dec = withStyle(generateStyle), _dec(_class = (_Tag = class Tag extends Component {
41
+ constructor(...args) {
42
+ super(...args);
43
+ this.state = {
44
+ iconHovered: false
45
+ };
46
+ this.ref = null;
47
+ this.focus = () => {
48
+ this.ref && this.ref.focus();
49
+ };
50
+ this.handleIconMouseEnter = () => {
51
+ this.setState({
52
+ iconHovered: true
53
+ });
54
+ };
55
+ this.handleIconMouseLeave = () => {
56
+ this.setState({
57
+ iconHovered: false
58
+ });
59
+ };
60
+ this.handleClick = e => {
61
+ const _this$props = this.props,
62
+ disabled = _this$props.disabled,
63
+ readOnly = _this$props.readOnly,
64
+ onClick = _this$props.onClick;
65
+ if (disabled || readOnly) {
66
+ e.preventDefault();
67
+ e.stopPropagation();
68
+ } else if (typeof onClick === 'function') {
69
+ onClick(e);
70
+ }
71
+ };
72
+ this.handleRef = element => {
73
+ this.ref = element;
74
+ if (typeof this.props.elementRef === 'function') {
75
+ this.props.elementRef(element);
76
+ }
77
+ };
78
+ this.getIconSize = () => {
79
+ const _this$props2 = this.props,
80
+ size = _this$props2.size,
81
+ variant = _this$props2.variant;
82
+ if (variant === 'inline') {
83
+ return 'xs';
84
+ }
85
+ const sizeMap = {
86
+ small: 'xs',
87
+ medium: 'sm',
88
+ large: 'md'
89
+ };
90
+ return sizeMap[size];
91
+ };
92
+ }
93
+ componentDidMount() {
94
+ var _this$props$makeStyle, _this$props3;
95
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
96
+ }
97
+ componentDidUpdate() {
98
+ var _this$props$makeStyle2, _this$props4;
99
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
100
+ }
101
+ get focused() {
102
+ return isActiveElement(this.ref);
103
+ }
104
+ render() {
105
+ const _this$props5 = this.props,
106
+ className = _this$props5.className,
107
+ dismissible = _this$props5.dismissible,
108
+ disabled = _this$props5.disabled,
109
+ readOnly = _this$props5.readOnly,
110
+ text = _this$props5.text,
111
+ title = _this$props5.title,
112
+ onClick = _this$props5.onClick,
113
+ margin = _this$props5.margin,
114
+ styles = _this$props5.styles,
115
+ variant = _this$props5.variant;
116
+ const passthroughProps = View.omitViewProps(omitProps(this.props, Tag.allowedProps), Tag);
117
+ const getIconColor = () => {
118
+ if (disabled) {
119
+ return 'mutedColor';
120
+ }
121
+ if (variant === 'inline') {
122
+ return 'inverseColor';
123
+ }
124
+ return this.state.iconHovered ? 'actionSecondaryHoverColor' : 'baseColor';
125
+ };
126
+ return _jsxs(View, {
127
+ ...passthroughProps,
128
+ elementRef: this.handleRef,
129
+ css: styles === null || styles === void 0 ? void 0 : styles.tag,
130
+ className: className,
131
+ as: onClick ? 'button' : 'span',
132
+ margin: margin,
133
+ type: onClick ? 'button' : void 0,
134
+ ...(onClick && {
135
+ onClick: this.handleClick
136
+ }),
137
+ disabled: disabled || readOnly,
138
+ display: void 0,
139
+ title: title || (typeof text === 'string' ? text : void 0),
140
+ "data-cid": "Tag",
141
+ onMouseEnter: this.handleIconMouseEnter,
142
+ onMouseLeave: this.handleIconMouseLeave,
143
+ children: [_jsx("span", {
144
+ css: styles === null || styles === void 0 ? void 0 : styles.text,
145
+ children: text
146
+ }), onClick && dismissible ? _jsx("span", {
147
+ css: styles === null || styles === void 0 ? void 0 : styles.icon,
148
+ children: _jsx(XInstUIIcon, {
149
+ size: this.getIconSize(),
150
+ color: getIconColor()
151
+ })
152
+ }) : null]
153
+ });
154
+ }
155
+ }, _Tag.displayName = "Tag", _Tag.componentId = 'Tag', _Tag.allowedProps = allowedProps, _Tag.defaultProps = {
156
+ size: 'medium',
157
+ dismissible: false,
158
+ variant: 'default',
159
+ disabled: false,
160
+ readOnly: false
161
+ }, _Tag)) || _class);
162
+ export default Tag;
163
+ export { Tag };
@@ -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 = ['className', 'text', 'title', 'disabled', 'readOnly', 'dismissible', 'margin', 'onClick', 'elementRef', 'size', 'variant'];
26
+ export { allowedProps };
@@ -0,0 +1,208 @@
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 } from '@instructure/emotion';
26
+
27
+ /**
28
+ * ---
29
+ * private: true
30
+ * ---
31
+ * Generates the style object from the theme and provided additional information
32
+ * @param {Object} componentTheme The theme variable object.
33
+ * @param {Object} props the props of the component, the style is applied to
34
+ * @param {Object} sharedTokens 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) => {
38
+ const variant = props.variant,
39
+ size = props.size,
40
+ dismissible = props.dismissible,
41
+ onClick = props.onClick,
42
+ disabled = props.disabled;
43
+ const isButton = !!onClick;
44
+ const sizeVariants = {
45
+ small: {
46
+ tag: {
47
+ paddingLeft: componentTheme.paddingHorizontalSmall,
48
+ paddingRight: componentTheme.paddingHorizontalSmall,
49
+ fontSize: componentTheme.fontSizeSmall
50
+ },
51
+ text: {
52
+ lineHeight: `calc(${componentTheme.heightSmall} - (${componentTheme.defaultBorderWidth} * 2))`
53
+ }
54
+ },
55
+ medium: {
56
+ tag: {
57
+ paddingLeft: componentTheme.paddingHorizontal,
58
+ paddingRight: componentTheme.paddingHorizontal,
59
+ fontSize: `calc(${componentTheme.fontSizeMedium} - 0.0625rem)`
60
+ },
61
+ text: {
62
+ lineHeight: `calc(${componentTheme.heightMedium} - (${componentTheme.defaultBorderWidth} * 2))`
63
+ }
64
+ },
65
+ large: {
66
+ tag: {
67
+ paddingLeft: componentTheme.paddingHorizontalSmall,
68
+ paddingRight: componentTheme.paddingHorizontal,
69
+ fontSize: `calc(${componentTheme.fontSizeLarge} - 0.0625rem)`
70
+ },
71
+ text: {
72
+ lineHeight: `calc(${componentTheme.heightLarge} - (${componentTheme.defaultBorderWidth} * 2))`
73
+ }
74
+ }
75
+ };
76
+ const buttonVariant = isButton ? {
77
+ tag: {
78
+ touchAction: 'manipulation',
79
+ outline: 'none',
80
+ position: 'relative',
81
+ overflow: 'visible',
82
+ transition: `background-color ${componentTheme.transitionTiming}`,
83
+ ...(!dismissible && {
84
+ cursor: 'pointer'
85
+ }),
86
+ '&:focus': {
87
+ '&::before': {
88
+ opacity: 1,
89
+ transform: 'scale(1)'
90
+ }
91
+ },
92
+ ...(disabled && {
93
+ cursor: 'not-allowed',
94
+ pointerEvents: 'none',
95
+ opacity: 0.5
96
+ })
97
+ },
98
+ tagBefore: {
99
+ content: '""',
100
+ boxSizing: 'border-box',
101
+ border: calcFocusOutlineStyles(sharedTokens.focusOutline),
102
+ position: 'absolute',
103
+ top: '-0.3125rem',
104
+ bottom: '-0.3125rem',
105
+ left: '-0.3125rem',
106
+ right: '-0.3125rem',
107
+ opacity: 0,
108
+ transform: 'scale(0.9)',
109
+ transition: `all ${componentTheme.transitionTiming}`,
110
+ pointerEvents: 'none'
111
+ }
112
+ } : {};
113
+ const tagVariantVariants = {
114
+ default: {
115
+ tag: {
116
+ backgroundColor: componentTheme.defaultBackground,
117
+ border: `${componentTheme.defaultBorderWidth} ${componentTheme.defaultBorderStyle} ${componentTheme.defaultBorderColor}`,
118
+ borderRadius: componentTheme.defaultBorderRadius,
119
+ color: componentTheme.defaultColor,
120
+ ...(isButton && {
121
+ '&:hover': {
122
+ backgroundColor: componentTheme.defaultBackgroundHover
123
+ }
124
+ })
125
+ },
126
+ tagBefore: {
127
+ ...(isButton && {
128
+ borderRadius: componentTheme.defaultBorderRadius
129
+ })
130
+ }
131
+ },
132
+ inline: {
133
+ tag: {
134
+ backgroundColor: componentTheme.inlineBackground,
135
+ border: `${componentTheme.inlineBorderWidth} ${componentTheme.inlineBorderStyle} ${componentTheme.inlineBorderColor}`,
136
+ borderRadius: componentTheme.inlineBorderRadius,
137
+ color: componentTheme.inlineColor,
138
+ cursor: 'text',
139
+ margin: '0 0.1875rem 0.1875rem',
140
+ ...(isButton && {
141
+ '&:hover': {
142
+ backgroundColor: componentTheme.inlineBackgroundHover
143
+ }
144
+ })
145
+ },
146
+ tagBefore: {
147
+ ...(isButton && {
148
+ borderRadius: `calc(${componentTheme.inlineBorderRadius} * 1.5)`
149
+ })
150
+ }
151
+ }
152
+ };
153
+ const inlineIconVariant = variant === 'inline' && dismissible ? {
154
+ backgroundColor: componentTheme.inlineIconColor,
155
+ borderRadius: '50%',
156
+ padding: '0.25rem',
157
+ position: 'absolute',
158
+ insetInlineEnd: 0,
159
+ insetInlineStart: 'auto',
160
+ top: 0,
161
+ transform: 'translate(40%, -40%)',
162
+ display: 'flex',
163
+ alignItems: 'center',
164
+ justifyContent: 'center',
165
+ '[class$="-tag"]:hover > &': {
166
+ backgroundColor: componentTheme.inlineIconHoverColor
167
+ },
168
+ '[dir="rtl"] &': {
169
+ transform: 'translate(-40%, -40%)'
170
+ }
171
+ } : {};
172
+ return {
173
+ tag: {
174
+ label: 'tag',
175
+ boxSizing: 'border-box',
176
+ fontFamily: componentTheme.fontFamily,
177
+ display: 'inline-flex',
178
+ alignItems: 'center',
179
+ textAlign: 'center',
180
+ verticalAlign: 'middle',
181
+ userSelect: 'none',
182
+ ...sizeVariants[size].tag,
183
+ ...buttonVariant.tag,
184
+ ...tagVariantVariants[variant].tag,
185
+ '&::before': {
186
+ ...buttonVariant.tagBefore,
187
+ ...tagVariantVariants[variant].tagBefore
188
+ }
189
+ },
190
+ text: {
191
+ label: 'tag__text',
192
+ whiteSpace: 'nowrap',
193
+ overflow: 'hidden',
194
+ textOverflow: 'ellipsis',
195
+ maxWidth: componentTheme.maxWidth,
196
+ ...sizeVariants[size].text
197
+ },
198
+ icon: {
199
+ label: 'tag__icon',
200
+ marginInlineStart: componentTheme.iconMargin,
201
+ marginInlineEnd: 0,
202
+ transition: `all ${componentTheme.transitionTiming}`,
203
+ cursor: 'pointer',
204
+ ...inlineIconVariant
205
+ }
206
+ };
207
+ };
208
+ export default generateStyle;
@@ -21,4 +21,4 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { Tag } from "./Tag/index.js";
24
+ export { Tag } from "../Tag/v1/index.js";
@@ -21,6 +21,4 @@
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
- export { Tag } from './Tag'
26
- export type { TagProps } from './Tag/props'
24
+ export { Tag } from "../Tag/v2/index.js";
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.Tag = void 0;
8
8
  var _react = require("react");
9
- var _IconXLine = require("@instructure/ui-icons/lib/IconXLine.js");
10
- var _View = require("@instructure/ui-view/lib/View");
9
+ var _IconXLine = require("@instructure/ui-icons/lib/generated/IconXLine.js");
10
+ var _v11_ = require("@instructure/ui-view/v11_6");
11
11
  var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
12
12
  var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
13
13
  var _emotion = require("@instructure/emotion");
@@ -44,7 +44,7 @@ var _dec, _class, _Tag;
44
44
  category: components
45
45
  ---
46
46
  **/
47
- let Tag = exports.Tag = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_Tag = class Tag extends _react.Component {
47
+ let Tag = exports.Tag = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_Tag = class Tag extends _react.Component {
48
48
  constructor(...args) {
49
49
  super(...args);
50
50
  this.ref = null;
@@ -92,8 +92,8 @@ let Tag = exports.Tag = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.
92
92
  onClick = _this$props4.onClick,
93
93
  margin = _this$props4.margin,
94
94
  styles = _this$props4.styles;
95
- const passthroughProps = _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Tag.allowedProps), Tag);
96
- return (0, _jsxRuntime.jsxs)(_View.View, {
95
+ const passthroughProps = _v11_.View.omitViewProps((0, _omitProps.omitProps)(this.props, Tag.allowedProps), Tag);
96
+ return (0, _jsxRuntime.jsxs)(_v11_.View, {
97
97
  ...passthroughProps,
98
98
  elementRef: this.handleRef,
99
99
  css: styles === null || styles === void 0 ? void 0 : styles.tag,
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.Tag = void 0;
8
+ var _react = require("react");
9
+ var _uiIcons = require("@instructure/ui-icons");
10
+ var _latest = require("@instructure/ui-view/latest");
11
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
12
+ var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
13
+ var _emotion = require("@instructure/emotion");
14
+ var _styles = _interopRequireDefault(require("./styles"));
15
+ var _props = require("./props");
16
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
+ var _dec, _class, _Tag;
18
+ /*
19
+ * The MIT License (MIT)
20
+ *
21
+ * Copyright (c) 2015 - present Instructure, Inc.
22
+ *
23
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ * of this software and associated documentation files (the "Software"), to deal
25
+ * in the Software without restriction, including without limitation the rights
26
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ * copies of the Software, and to permit persons to whom the Software is
28
+ * furnished to do so, subject to the following conditions:
29
+ *
30
+ * The above copyright notice and this permission notice shall be included in all
31
+ * copies or substantial portions of the Software.
32
+ *
33
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ * SOFTWARE.
40
+ */
41
+ /**
42
+ ---
43
+ category: components
44
+ ---
45
+ **/
46
+ let Tag = exports.Tag = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = (_Tag = class Tag extends _react.Component {
47
+ constructor(...args) {
48
+ super(...args);
49
+ this.state = {
50
+ iconHovered: false
51
+ };
52
+ this.ref = null;
53
+ this.focus = () => {
54
+ this.ref && this.ref.focus();
55
+ };
56
+ this.handleIconMouseEnter = () => {
57
+ this.setState({
58
+ iconHovered: true
59
+ });
60
+ };
61
+ this.handleIconMouseLeave = () => {
62
+ this.setState({
63
+ iconHovered: false
64
+ });
65
+ };
66
+ this.handleClick = e => {
67
+ const _this$props = this.props,
68
+ disabled = _this$props.disabled,
69
+ readOnly = _this$props.readOnly,
70
+ onClick = _this$props.onClick;
71
+ if (disabled || readOnly) {
72
+ e.preventDefault();
73
+ e.stopPropagation();
74
+ } else if (typeof onClick === 'function') {
75
+ onClick(e);
76
+ }
77
+ };
78
+ this.handleRef = element => {
79
+ this.ref = element;
80
+ if (typeof this.props.elementRef === 'function') {
81
+ this.props.elementRef(element);
82
+ }
83
+ };
84
+ this.getIconSize = () => {
85
+ const _this$props2 = this.props,
86
+ size = _this$props2.size,
87
+ variant = _this$props2.variant;
88
+ if (variant === 'inline') {
89
+ return 'xs';
90
+ }
91
+ const sizeMap = {
92
+ small: 'xs',
93
+ medium: 'sm',
94
+ large: 'md'
95
+ };
96
+ return sizeMap[size];
97
+ };
98
+ }
99
+ componentDidMount() {
100
+ var _this$props$makeStyle, _this$props3;
101
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
102
+ }
103
+ componentDidUpdate() {
104
+ var _this$props$makeStyle2, _this$props4;
105
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
106
+ }
107
+ get focused() {
108
+ return (0, _isActiveElement.isActiveElement)(this.ref);
109
+ }
110
+ render() {
111
+ const _this$props5 = this.props,
112
+ className = _this$props5.className,
113
+ dismissible = _this$props5.dismissible,
114
+ disabled = _this$props5.disabled,
115
+ readOnly = _this$props5.readOnly,
116
+ text = _this$props5.text,
117
+ title = _this$props5.title,
118
+ onClick = _this$props5.onClick,
119
+ margin = _this$props5.margin,
120
+ styles = _this$props5.styles,
121
+ variant = _this$props5.variant;
122
+ const passthroughProps = _latest.View.omitViewProps((0, _omitProps.omitProps)(this.props, Tag.allowedProps), Tag);
123
+ const getIconColor = () => {
124
+ if (disabled) {
125
+ return 'mutedColor';
126
+ }
127
+ if (variant === 'inline') {
128
+ return 'inverseColor';
129
+ }
130
+ return this.state.iconHovered ? 'actionSecondaryHoverColor' : 'baseColor';
131
+ };
132
+ return (0, _jsxRuntime.jsxs)(_latest.View, {
133
+ ...passthroughProps,
134
+ elementRef: this.handleRef,
135
+ css: styles === null || styles === void 0 ? void 0 : styles.tag,
136
+ className: className,
137
+ as: onClick ? 'button' : 'span',
138
+ margin: margin,
139
+ type: onClick ? 'button' : void 0,
140
+ ...(onClick && {
141
+ onClick: this.handleClick
142
+ }),
143
+ disabled: disabled || readOnly,
144
+ display: void 0,
145
+ title: title || (typeof text === 'string' ? text : void 0),
146
+ "data-cid": "Tag",
147
+ onMouseEnter: this.handleIconMouseEnter,
148
+ onMouseLeave: this.handleIconMouseLeave,
149
+ children: [(0, _jsxRuntime.jsx)("span", {
150
+ css: styles === null || styles === void 0 ? void 0 : styles.text,
151
+ children: text
152
+ }), onClick && dismissible ? (0, _jsxRuntime.jsx)("span", {
153
+ css: styles === null || styles === void 0 ? void 0 : styles.icon,
154
+ children: (0, _jsxRuntime.jsx)(_uiIcons.XInstUIIcon, {
155
+ size: this.getIconSize(),
156
+ color: getIconColor()
157
+ })
158
+ }) : null]
159
+ });
160
+ }
161
+ }, _Tag.displayName = "Tag", _Tag.componentId = 'Tag', _Tag.allowedProps = _props.allowedProps, _Tag.defaultProps = {
162
+ size: 'medium',
163
+ dismissible: false,
164
+ variant: 'default',
165
+ disabled: false,
166
+ readOnly: false
167
+ }, _Tag)) || _class);
168
+ var _default = exports.default = Tag;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ const allowedProps = exports.allowedProps = ['className', 'text', 'title', 'disabled', 'readOnly', 'dismissible', 'margin', 'onClick', 'elementRef', 'size', 'variant'];