@instructure/ui-tag 9.3.0 → 9.3.1-pr-snapshot-1721388565180

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 CHANGED
@@ -3,6 +3,22 @@
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
+ ## [9.3.1-pr-snapshot-1721388565180](https://github.com/instructure/instructure-ui/compare/v9.3.0...v9.3.1-pr-snapshot-1721388565180) (2024-07-19)
7
+
8
+
9
+ ### Features
10
+
11
+ * **many:** rewrite color system ([daa119c](https://github.com/instructure/instructure-ui/commit/daa119c31a8b6d35389909e27da5aaf17b654f4e))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * **many:** Breaks color overrides in certain cases
17
+
18
+
19
+
20
+
21
+
6
22
  # [9.3.0](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.3.0) (2024-07-17)
7
23
 
8
24
  **Note:** Version bump only for package @instructure/ui-tag
@@ -0,0 +1,125 @@
1
+ var _Tag, _Tag2;
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 React from 'react';
27
+ import { render, screen, waitFor } from '@testing-library/react';
28
+ import { userEvent } from '@testing-library/user-event';
29
+ import '@testing-library/jest-dom';
30
+ import { vi } from 'vitest';
31
+ import { Tag } from '../index';
32
+ import { runAxeCheck } from '@instructure/ui-axe-check';
33
+ import { View } from '@instructure/ui-view';
34
+ const originalOmitViewProps = View.omitViewProps;
35
+ describe('<Tag />', async () => {
36
+ beforeAll(() => {
37
+ // View component read Component.name instead of Component.displayName
38
+ // causing [undefined] in error messages
39
+
40
+ View.omitViewProps = (props, Component) => {
41
+ const ModifiedComponent = {
42
+ ...Component,
43
+ name: 'Tag'
44
+ };
45
+ return originalOmitViewProps(props, ModifiedComponent);
46
+ };
47
+ });
48
+ afterAll(() => {
49
+ View.omitViewProps = originalOmitViewProps;
50
+ });
51
+ it('should display text', async () => {
52
+ render(_Tag || (_Tag = /*#__PURE__*/React.createElement(Tag, {
53
+ text: "Summer"
54
+ })));
55
+ const tag = screen.getByText('Summer');
56
+ expect(tag).toBeInTheDocument();
57
+ });
58
+ it('should render as a button and respond to onClick event', async () => {
59
+ const onClick = vi.fn();
60
+ render( /*#__PURE__*/React.createElement(Tag, {
61
+ "data-testid": "summer-button",
62
+ text: "Summer",
63
+ onClick: onClick
64
+ }));
65
+ const button = screen.getByTestId('summer-button');
66
+ userEvent.click(button);
67
+ await waitFor(() => {
68
+ expect(onClick).toHaveBeenCalledTimes(1);
69
+ expect(button.tagName).toBe('BUTTON');
70
+ });
71
+ });
72
+ it('should render a close icon when it is dismissible and clickable', async () => {
73
+ const onClick = vi.fn();
74
+ const _render = render( /*#__PURE__*/React.createElement(Tag, {
75
+ text: "Summer",
76
+ onClick: onClick,
77
+ dismissible: true
78
+ })),
79
+ container = _render.container;
80
+ const icon = container.querySelector('svg');
81
+ expect(icon).toHaveAttribute('name', 'IconX');
82
+ });
83
+ it('should meet a11y standards', async () => {
84
+ const _render2 = render(_Tag2 || (_Tag2 = /*#__PURE__*/React.createElement(Tag, {
85
+ text: "Summer"
86
+ }))),
87
+ container = _render2.container;
88
+ const axeCheck = await runAxeCheck(container);
89
+ expect(axeCheck).toBe(true);
90
+ });
91
+ describe('when passing down props to View', async () => {
92
+ const allowedProps = {
93
+ margin: 'small',
94
+ elementRef: () => {}
95
+ };
96
+ View.allowedProps.filter(prop => prop !== 'children').forEach(prop => {
97
+ if (Object.keys(allowedProps).indexOf(prop) < 0) {
98
+ it(`should NOT allow the '${prop}' prop`, async () => {
99
+ const props = {
100
+ [prop]: 'foo'
101
+ };
102
+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
103
+ render( /*#__PURE__*/React.createElement(Tag, Object.assign({
104
+ text: "Summer"
105
+ }, props)));
106
+ const warning = `Warning: [Tag] prop '${prop}' is not allowed.`;
107
+ expect(consoleError.mock.calls[0][0]).toBe(warning);
108
+ consoleError.mockRestore();
109
+ });
110
+ } else {
111
+ it(`should allow the '${prop}' prop`, async () => {
112
+ const props = {
113
+ [prop]: allowedProps[prop]
114
+ };
115
+ const consoleError = vi.spyOn(console, 'error');
116
+ render( /*#__PURE__*/React.createElement(Tag, Object.assign({
117
+ text: "Summer"
118
+ }, props)));
119
+ expect(consoleError).not.toHaveBeenCalled();
120
+ consoleError.mockRestore();
121
+ });
122
+ }
123
+ });
124
+ });
125
+ });
package/es/Tag/theme.js CHANGED
@@ -22,13 +22,13 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import { darken } from '@instructure/ui-color-utils';
26
25
  /**
27
26
  * Generates the theme object for the component from the theme and provided additional information
28
27
  * @param {Object} theme The actual theme object.
29
28
  * @return {Object} The final theme object with the overrides and component variables
30
29
  */
31
30
  const generateComponentTheme = theme => {
31
+ var _colors$contrasts, _colors$contrasts2, _colors$contrasts3, _colors$contrasts4, _colors$contrasts5, _colors$contrasts6, _colors$contrasts7, _colors$contrasts8, _colors$contrasts9, _colors$contrasts10, _colors$contrasts11, _colors$contrasts12, _colors$contrasts13, _colors$contrasts14, _colors$contrasts15;
32
32
  const borders = theme.borders,
33
33
  colors = theme.colors,
34
34
  forms = theme.forms,
@@ -37,8 +37,8 @@ const generateComponentTheme = theme => {
37
37
  themeName = theme.key;
38
38
  const themeSpecificStyle = {
39
39
  'canvas-high-contrast': {
40
- defaultBackground: colors.backgroundLightest,
41
- defaultBorderColor: colors.borderDarkest
40
+ defaultBackground: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.white1010,
41
+ defaultBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.grey125125
42
42
  },
43
43
  canvas: {
44
44
  focusOutlineColor: theme['ic-brand-primary'],
@@ -47,31 +47,6 @@ const generateComponentTheme = theme => {
47
47
  defaultColor: theme['ic-brand-font-color-dark']
48
48
  }
49
49
  };
50
- const tagVariant = function (style, {
51
- borderColor,
52
- borderRadius,
53
- borderStyle,
54
- borderWidth,
55
- hoverColor,
56
- iconColor,
57
- iconHoverColor,
58
- mainColor,
59
- textColor
60
- }) {
61
- return {
62
- [`${style}BackgroundHover`]: hoverColor || darken(mainColor, 5),
63
- [`${style}Background`]: mainColor,
64
- [`${style}BorderColor`]: borderColor,
65
- // For 'pill'-style rounded corners
66
- // https://stackoverflow.com/questions/22578979/border-radius-50-vs-border-radius-999em
67
- [`${style}BorderRadius`]: borderRadius || '999rem',
68
- [`${style}BorderStyle`]: borderStyle || borders.style,
69
- [`${style}BorderWidth`]: borderWidth || borders.widthSmall,
70
- [`${style}Color`]: textColor,
71
- [`${style}IconColor`]: iconColor || textColor,
72
- [`${style}IconHoverColor`]: iconHoverColor || iconColor || textColor
73
- };
74
- };
75
50
  const componentVariables = {
76
51
  fontFamily: typography.fontFamily,
77
52
  heightSmall: '1.3125rem',
@@ -83,27 +58,30 @@ const generateComponentTheme = theme => {
83
58
  fontSizeLarge: typography.fontSizeMedium,
84
59
  padding: `0 ${spacing.xSmall}`,
85
60
  paddingSmall: `0 ${spacing.xSmall}`,
86
- focusOutlineColor: colors.borderBrand,
61
+ focusOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts3 = colors.contrasts) === null || _colors$contrasts3 === void 0 ? void 0 : _colors$contrasts3.blue4570,
87
62
  focusOutlineWidth: borders.widthMedium,
88
63
  focusOutlineStyle: borders.style,
89
64
  maxWidth: '10rem',
90
65
  iconMargin: spacing.xSmall,
91
66
  transitionTiming: '0.2s',
92
- ...tagVariant('default', {
93
- borderColor: colors.borderMedium,
94
- iconColor: colors.textDarkest,
95
- iconHoverColor: colors.textBrand,
96
- mainColor: colors.textLight,
97
- textColor: colors.textDarkest
98
- }),
99
- ...tagVariant('inline', {
100
- borderColor: colors.borderDark,
101
- borderRadius: borders.radiusMedium,
102
- iconColor: colors.textDark,
103
- iconHoverColor: colors.textDark,
104
- mainColor: colors.textLightest,
105
- textColor: colors.textDarkest
106
- })
67
+ defaultBackgroundHover: colors === null || colors === void 0 ? void 0 : (_colors$contrasts4 = colors.contrasts) === null || _colors$contrasts4 === void 0 ? void 0 : _colors$contrasts4.grey1214,
68
+ defaultBackground: colors === null || colors === void 0 ? void 0 : (_colors$contrasts5 = colors.contrasts) === null || _colors$contrasts5 === void 0 ? void 0 : _colors$contrasts5.grey1111,
69
+ defaultBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts6 = colors.contrasts) === null || _colors$contrasts6 === void 0 ? void 0 : _colors$contrasts6.grey1214,
70
+ defaultBorderRadius: '999rem',
71
+ defaultBorderStyle: borders.style,
72
+ defaultBorderWidth: borders.widthSmall,
73
+ defaultColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts7 = colors.contrasts) === null || _colors$contrasts7 === void 0 ? void 0 : _colors$contrasts7.grey125125,
74
+ defaultIconColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts8 = colors.contrasts) === null || _colors$contrasts8 === void 0 ? void 0 : _colors$contrasts8.grey125125,
75
+ defaultIconHoverColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts9 = colors.contrasts) === null || _colors$contrasts9 === void 0 ? void 0 : _colors$contrasts9.blue4570,
76
+ inlineBackgroundHover: colors === null || colors === void 0 ? void 0 : (_colors$contrasts10 = colors.contrasts) === null || _colors$contrasts10 === void 0 ? void 0 : _colors$contrasts10.grey1111,
77
+ inlineBackground: colors === null || colors === void 0 ? void 0 : (_colors$contrasts11 = colors.contrasts) === null || _colors$contrasts11 === void 0 ? void 0 : _colors$contrasts11.white1010,
78
+ inlineBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts12 = colors.contrasts) === null || _colors$contrasts12 === void 0 ? void 0 : _colors$contrasts12.grey4570,
79
+ inlineBorderRadius: borders.radiusMedium,
80
+ inlineBorderStyle: borders.style,
81
+ inlineBorderWidth: borders.widthSmall,
82
+ inlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts13 = colors.contrasts) === null || _colors$contrasts13 === void 0 ? void 0 : _colors$contrasts13.grey125125,
83
+ inlineIconColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts14 = colors.contrasts) === null || _colors$contrasts14 === void 0 ? void 0 : _colors$contrasts14.grey4570,
84
+ inlineIconHoverColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts15 = colors.contrasts) === null || _colors$contrasts15 === void 0 ? void 0 : _colors$contrasts15.blue4570
107
85
  };
108
86
  return {
109
87
  ...componentVariables,
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ var _userEvent = require("@testing-library/user-event");
7
+ require("@testing-library/jest-dom");
8
+ var _vitest = require("vitest");
9
+ var _index = require("../index");
10
+ var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
11
+ var _View = require("@instructure/ui-view/lib/View");
12
+ var _Tag, _Tag2;
13
+ /*
14
+ * The MIT License (MIT)
15
+ *
16
+ * Copyright (c) 2015 - present Instructure, Inc.
17
+ *
18
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ * of this software and associated documentation files (the "Software"), to deal
20
+ * in the Software without restriction, including without limitation the rights
21
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ * copies of the Software, and to permit persons to whom the Software is
23
+ * furnished to do so, subject to the following conditions:
24
+ *
25
+ * The above copyright notice and this permission notice shall be included in all
26
+ * copies or substantial portions of the Software.
27
+ *
28
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
+ * SOFTWARE.
35
+ */
36
+ const originalOmitViewProps = _View.View.omitViewProps;
37
+ describe('<Tag />', async () => {
38
+ beforeAll(() => {
39
+ // View component read Component.name instead of Component.displayName
40
+ // causing [undefined] in error messages
41
+
42
+ _View.View.omitViewProps = (props, Component) => {
43
+ const ModifiedComponent = {
44
+ ...Component,
45
+ name: 'Tag'
46
+ };
47
+ return originalOmitViewProps(props, ModifiedComponent);
48
+ };
49
+ });
50
+ afterAll(() => {
51
+ _View.View.omitViewProps = originalOmitViewProps;
52
+ });
53
+ it('should display text', async () => {
54
+ (0, _react2.render)(_Tag || (_Tag = /*#__PURE__*/_react.default.createElement(_index.Tag, {
55
+ text: "Summer"
56
+ })));
57
+ const tag = _react2.screen.getByText('Summer');
58
+ expect(tag).toBeInTheDocument();
59
+ });
60
+ it('should render as a button and respond to onClick event', async () => {
61
+ const onClick = _vitest.vi.fn();
62
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, {
63
+ "data-testid": "summer-button",
64
+ text: "Summer",
65
+ onClick: onClick
66
+ }));
67
+ const button = _react2.screen.getByTestId('summer-button');
68
+ _userEvent.userEvent.click(button);
69
+ await (0, _react2.waitFor)(() => {
70
+ expect(onClick).toHaveBeenCalledTimes(1);
71
+ expect(button.tagName).toBe('BUTTON');
72
+ });
73
+ });
74
+ it('should render a close icon when it is dismissible and clickable', async () => {
75
+ const onClick = _vitest.vi.fn();
76
+ const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, {
77
+ text: "Summer",
78
+ onClick: onClick,
79
+ dismissible: true
80
+ })),
81
+ container = _render.container;
82
+ const icon = container.querySelector('svg');
83
+ expect(icon).toHaveAttribute('name', 'IconX');
84
+ });
85
+ it('should meet a11y standards', async () => {
86
+ const _render2 = (0, _react2.render)(_Tag2 || (_Tag2 = /*#__PURE__*/_react.default.createElement(_index.Tag, {
87
+ text: "Summer"
88
+ }))),
89
+ container = _render2.container;
90
+ const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
91
+ expect(axeCheck).toBe(true);
92
+ });
93
+ describe('when passing down props to View', async () => {
94
+ const allowedProps = {
95
+ margin: 'small',
96
+ elementRef: () => {}
97
+ };
98
+ _View.View.allowedProps.filter(prop => prop !== 'children').forEach(prop => {
99
+ if (Object.keys(allowedProps).indexOf(prop) < 0) {
100
+ it(`should NOT allow the '${prop}' prop`, async () => {
101
+ const props = {
102
+ [prop]: 'foo'
103
+ };
104
+ const consoleError = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
105
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, Object.assign({
106
+ text: "Summer"
107
+ }, props)));
108
+ const warning = `Warning: [Tag] prop '${prop}' is not allowed.`;
109
+ expect(consoleError.mock.calls[0][0]).toBe(warning);
110
+ consoleError.mockRestore();
111
+ });
112
+ } else {
113
+ it(`should allow the '${prop}' prop`, async () => {
114
+ const props = {
115
+ [prop]: allowedProps[prop]
116
+ };
117
+ const consoleError = _vitest.vi.spyOn(console, 'error');
118
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, Object.assign({
119
+ text: "Summer"
120
+ }, props)));
121
+ expect(consoleError).not.toHaveBeenCalled();
122
+ consoleError.mockRestore();
123
+ });
124
+ }
125
+ });
126
+ });
127
+ });
package/lib/Tag/theme.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _darken = require("@instructure/ui-color-utils/lib/darken.js");
8
7
  /*
9
8
  * The MIT License (MIT)
10
9
  *
@@ -35,6 +34,7 @@ var _darken = require("@instructure/ui-color-utils/lib/darken.js");
35
34
  * @return {Object} The final theme object with the overrides and component variables
36
35
  */
37
36
  const generateComponentTheme = theme => {
37
+ var _colors$contrasts, _colors$contrasts2, _colors$contrasts3, _colors$contrasts4, _colors$contrasts5, _colors$contrasts6, _colors$contrasts7, _colors$contrasts8, _colors$contrasts9, _colors$contrasts10, _colors$contrasts11, _colors$contrasts12, _colors$contrasts13, _colors$contrasts14, _colors$contrasts15;
38
38
  const borders = theme.borders,
39
39
  colors = theme.colors,
40
40
  forms = theme.forms,
@@ -43,8 +43,8 @@ const generateComponentTheme = theme => {
43
43
  themeName = theme.key;
44
44
  const themeSpecificStyle = {
45
45
  'canvas-high-contrast': {
46
- defaultBackground: colors.backgroundLightest,
47
- defaultBorderColor: colors.borderDarkest
46
+ defaultBackground: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.white1010,
47
+ defaultBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.grey125125
48
48
  },
49
49
  canvas: {
50
50
  focusOutlineColor: theme['ic-brand-primary'],
@@ -53,31 +53,6 @@ const generateComponentTheme = theme => {
53
53
  defaultColor: theme['ic-brand-font-color-dark']
54
54
  }
55
55
  };
56
- const tagVariant = function (style, {
57
- borderColor,
58
- borderRadius,
59
- borderStyle,
60
- borderWidth,
61
- hoverColor,
62
- iconColor,
63
- iconHoverColor,
64
- mainColor,
65
- textColor
66
- }) {
67
- return {
68
- [`${style}BackgroundHover`]: hoverColor || (0, _darken.darken)(mainColor, 5),
69
- [`${style}Background`]: mainColor,
70
- [`${style}BorderColor`]: borderColor,
71
- // For 'pill'-style rounded corners
72
- // https://stackoverflow.com/questions/22578979/border-radius-50-vs-border-radius-999em
73
- [`${style}BorderRadius`]: borderRadius || '999rem',
74
- [`${style}BorderStyle`]: borderStyle || borders.style,
75
- [`${style}BorderWidth`]: borderWidth || borders.widthSmall,
76
- [`${style}Color`]: textColor,
77
- [`${style}IconColor`]: iconColor || textColor,
78
- [`${style}IconHoverColor`]: iconHoverColor || iconColor || textColor
79
- };
80
- };
81
56
  const componentVariables = {
82
57
  fontFamily: typography.fontFamily,
83
58
  heightSmall: '1.3125rem',
@@ -89,27 +64,30 @@ const generateComponentTheme = theme => {
89
64
  fontSizeLarge: typography.fontSizeMedium,
90
65
  padding: `0 ${spacing.xSmall}`,
91
66
  paddingSmall: `0 ${spacing.xSmall}`,
92
- focusOutlineColor: colors.borderBrand,
67
+ focusOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts3 = colors.contrasts) === null || _colors$contrasts3 === void 0 ? void 0 : _colors$contrasts3.blue4570,
93
68
  focusOutlineWidth: borders.widthMedium,
94
69
  focusOutlineStyle: borders.style,
95
70
  maxWidth: '10rem',
96
71
  iconMargin: spacing.xSmall,
97
72
  transitionTiming: '0.2s',
98
- ...tagVariant('default', {
99
- borderColor: colors.borderMedium,
100
- iconColor: colors.textDarkest,
101
- iconHoverColor: colors.textBrand,
102
- mainColor: colors.textLight,
103
- textColor: colors.textDarkest
104
- }),
105
- ...tagVariant('inline', {
106
- borderColor: colors.borderDark,
107
- borderRadius: borders.radiusMedium,
108
- iconColor: colors.textDark,
109
- iconHoverColor: colors.textDark,
110
- mainColor: colors.textLightest,
111
- textColor: colors.textDarkest
112
- })
73
+ defaultBackgroundHover: colors === null || colors === void 0 ? void 0 : (_colors$contrasts4 = colors.contrasts) === null || _colors$contrasts4 === void 0 ? void 0 : _colors$contrasts4.grey1214,
74
+ defaultBackground: colors === null || colors === void 0 ? void 0 : (_colors$contrasts5 = colors.contrasts) === null || _colors$contrasts5 === void 0 ? void 0 : _colors$contrasts5.grey1111,
75
+ defaultBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts6 = colors.contrasts) === null || _colors$contrasts6 === void 0 ? void 0 : _colors$contrasts6.grey1214,
76
+ defaultBorderRadius: '999rem',
77
+ defaultBorderStyle: borders.style,
78
+ defaultBorderWidth: borders.widthSmall,
79
+ defaultColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts7 = colors.contrasts) === null || _colors$contrasts7 === void 0 ? void 0 : _colors$contrasts7.grey125125,
80
+ defaultIconColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts8 = colors.contrasts) === null || _colors$contrasts8 === void 0 ? void 0 : _colors$contrasts8.grey125125,
81
+ defaultIconHoverColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts9 = colors.contrasts) === null || _colors$contrasts9 === void 0 ? void 0 : _colors$contrasts9.blue4570,
82
+ inlineBackgroundHover: colors === null || colors === void 0 ? void 0 : (_colors$contrasts10 = colors.contrasts) === null || _colors$contrasts10 === void 0 ? void 0 : _colors$contrasts10.grey1111,
83
+ inlineBackground: colors === null || colors === void 0 ? void 0 : (_colors$contrasts11 = colors.contrasts) === null || _colors$contrasts11 === void 0 ? void 0 : _colors$contrasts11.white1010,
84
+ inlineBorderColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts12 = colors.contrasts) === null || _colors$contrasts12 === void 0 ? void 0 : _colors$contrasts12.grey4570,
85
+ inlineBorderRadius: borders.radiusMedium,
86
+ inlineBorderStyle: borders.style,
87
+ inlineBorderWidth: borders.widthSmall,
88
+ inlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts13 = colors.contrasts) === null || _colors$contrasts13 === void 0 ? void 0 : _colors$contrasts13.grey125125,
89
+ inlineIconColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts14 = colors.contrasts) === null || _colors$contrasts14 === void 0 ? void 0 : _colors$contrasts14.grey4570,
90
+ inlineIconHoverColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts15 = colors.contrasts) === null || _colors$contrasts15 === void 0 ? void 0 : _colors$contrasts15.blue4570
113
91
  };
114
92
  return {
115
93
  ...componentVariables,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tag",
3
- "version": "9.3.0",
3
+ "version": "9.3.1-pr-snapshot-1721388565180",
4
4
  "description": "A tag component",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,22 +24,26 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.24.5",
27
- "@instructure/console": "9.3.0",
28
- "@instructure/emotion": "9.3.0",
29
- "@instructure/shared-types": "9.3.0",
30
- "@instructure/ui-color-utils": "9.3.0",
31
- "@instructure/ui-dom-utils": "9.3.0",
32
- "@instructure/ui-icons": "9.3.0",
33
- "@instructure/ui-react-utils": "9.3.0",
34
- "@instructure/ui-testable": "9.3.0",
35
- "@instructure/ui-view": "9.3.0",
27
+ "@instructure/console": "9.3.1-pr-snapshot-1721388565180",
28
+ "@instructure/emotion": "9.3.1-pr-snapshot-1721388565180",
29
+ "@instructure/shared-types": "9.3.1-pr-snapshot-1721388565180",
30
+ "@instructure/ui-color-utils": "9.3.1-pr-snapshot-1721388565180",
31
+ "@instructure/ui-dom-utils": "9.3.1-pr-snapshot-1721388565180",
32
+ "@instructure/ui-icons": "9.3.1-pr-snapshot-1721388565180",
33
+ "@instructure/ui-react-utils": "9.3.1-pr-snapshot-1721388565180",
34
+ "@instructure/ui-testable": "9.3.1-pr-snapshot-1721388565180",
35
+ "@instructure/ui-view": "9.3.1-pr-snapshot-1721388565180",
36
36
  "prop-types": "^15.8.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@instructure/ui-babel-preset": "9.3.0",
40
- "@instructure/ui-test-locator": "9.3.0",
41
- "@instructure/ui-test-utils": "9.3.0",
42
- "@instructure/ui-themes": "9.3.0"
39
+ "@instructure/ui-axe-check": "9.3.1-pr-snapshot-1721388565180",
40
+ "@instructure/ui-babel-preset": "9.3.1-pr-snapshot-1721388565180",
41
+ "@instructure/ui-test-utils": "9.3.1-pr-snapshot-1721388565180",
42
+ "@instructure/ui-themes": "9.3.1-pr-snapshot-1721388565180",
43
+ "@testing-library/jest-dom": "^6.4.5",
44
+ "@testing-library/react": "^15.0.7",
45
+ "@testing-library/user-event": "^14.5.2",
46
+ "vitest": "^1.6.0"
43
47
  },
44
48
  "peerDependencies": {
45
49
  "react": ">=16.8 <=18"
@@ -0,0 +1,132 @@
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 React, { ComponentType } from 'react'
26
+ import { render, screen, waitFor } from '@testing-library/react'
27
+ import { userEvent } from '@testing-library/user-event'
28
+ import '@testing-library/jest-dom'
29
+ import { vi } from 'vitest'
30
+
31
+ import { Tag } from '../index'
32
+ import { runAxeCheck } from '@instructure/ui-axe-check'
33
+ import type { ViewProps } from '@instructure/ui-view'
34
+ import { View } from '@instructure/ui-view'
35
+
36
+ const originalOmitViewProps = View.omitViewProps
37
+
38
+ describe('<Tag />', async () => {
39
+ beforeAll(() => {
40
+ // View component read Component.name instead of Component.displayName
41
+ // causing [undefined] in error messages
42
+ type TagComponentType = ComponentType & {
43
+ name: 'Tag'
44
+ }
45
+
46
+ View.omitViewProps = (props, Component) => {
47
+ const ModifiedComponent = {
48
+ ...Component,
49
+ name: 'Tag'
50
+ } as TagComponentType
51
+ return originalOmitViewProps(props, ModifiedComponent)
52
+ }
53
+ })
54
+ afterAll(() => {
55
+ View.omitViewProps = originalOmitViewProps
56
+ })
57
+
58
+ it('should display text', async () => {
59
+ render(<Tag text="Summer" />)
60
+ const tag = screen.getByText('Summer')
61
+
62
+ expect(tag).toBeInTheDocument()
63
+ })
64
+
65
+ it('should render as a button and respond to onClick event', async () => {
66
+ const onClick = vi.fn()
67
+ render(<Tag data-testid="summer-button" text="Summer" onClick={onClick} />)
68
+
69
+ const button = screen.getByTestId('summer-button')
70
+
71
+ userEvent.click(button)
72
+
73
+ await waitFor(() => {
74
+ expect(onClick).toHaveBeenCalledTimes(1)
75
+ expect(button.tagName).toBe('BUTTON')
76
+ })
77
+ })
78
+
79
+ it('should render a close icon when it is dismissible and clickable', async () => {
80
+ const onClick = vi.fn()
81
+ const { container } = render(
82
+ <Tag text="Summer" onClick={onClick} dismissible={true} />
83
+ )
84
+ const icon = container.querySelector('svg')
85
+
86
+ expect(icon).toHaveAttribute('name', 'IconX')
87
+ })
88
+
89
+ it('should meet a11y standards', async () => {
90
+ const { container } = render(<Tag text="Summer" />)
91
+ const axeCheck = await runAxeCheck(container)
92
+
93
+ expect(axeCheck).toBe(true)
94
+ })
95
+
96
+ describe('when passing down props to View', async () => {
97
+ const allowedProps: Partial<ViewProps> = {
98
+ margin: 'small',
99
+ elementRef: () => {}
100
+ }
101
+ View.allowedProps
102
+ .filter((prop) => prop !== 'children')
103
+ .forEach((prop) => {
104
+ if (Object.keys(allowedProps).indexOf(prop) < 0) {
105
+ it(`should NOT allow the '${prop}' prop`, async () => {
106
+ const props = {
107
+ [prop]: 'foo'
108
+ }
109
+ const consoleError = vi
110
+ .spyOn(console, 'error')
111
+ .mockImplementation(() => {})
112
+
113
+ render(<Tag text="Summer" {...props} />)
114
+ const warning = `Warning: [Tag] prop '${prop}' is not allowed.`
115
+
116
+ expect(consoleError.mock.calls[0][0]).toBe(warning)
117
+ consoleError.mockRestore()
118
+ })
119
+ } else {
120
+ it(`should allow the '${prop}' prop`, async () => {
121
+ const props = { [prop]: allowedProps[prop] }
122
+ const consoleError = vi.spyOn(console, 'error')
123
+
124
+ render(<Tag text="Summer" {...props} />)
125
+
126
+ expect(consoleError).not.toHaveBeenCalled()
127
+ consoleError.mockRestore()
128
+ })
129
+ }
130
+ })
131
+ })
132
+ })