@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.
- package/CHANGELOG.md +36 -284
- package/es/Tag/{index.js → v1/index.js} +2 -2
- package/es/Tag/v2/index.js +163 -0
- package/es/Tag/v2/props.js +26 -0
- package/es/Tag/v2/styles.js +208 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/Tag/{index.js → v1/index.js} +5 -5
- package/lib/Tag/v2/index.js +168 -0
- package/lib/Tag/v2/props.js +31 -0
- package/lib/Tag/v2/styles.js +213 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +41 -19
- package/src/Tag/{index.tsx → v1/index.tsx} +3 -3
- package/src/Tag/{props.ts → v1/props.ts} +1 -1
- package/src/Tag/v2/README.md +119 -0
- package/src/Tag/v2/index.tsx +180 -0
- package/src/Tag/v2/props.ts +93 -0
- package/src/Tag/v2/styles.ts +219 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Tag/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Tag/v1/index.d.ts.map +1 -0
- package/types/Tag/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Tag/v1/props.d.ts.map +1 -0
- package/types/Tag/v1/styles.d.ts.map +1 -0
- package/types/Tag/v1/theme.d.ts.map +1 -0
- package/types/Tag/v2/index.d.ts +48 -0
- package/types/Tag/v2/index.d.ts.map +1 -0
- package/types/Tag/v2/props.d.ts +46 -0
- package/types/Tag/v2/props.d.ts.map +1 -0
- package/types/Tag/v2/styles.d.ts +15 -0
- package/types/Tag/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Tag/index.d.ts.map +0 -1
- package/types/Tag/props.d.ts.map +0 -1
- package/types/Tag/styles.d.ts.map +0 -1
- package/types/Tag/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Tag/{props.js → v1/props.js} +0 -0
- /package/es/Tag/{styles.js → v1/styles.js} +0 -0
- /package/es/Tag/{theme.js → v1/theme.js} +0 -0
- /package/lib/Tag/{props.js → v1/props.js} +0 -0
- /package/lib/Tag/{styles.js → v1/styles.js} +0 -0
- /package/lib/Tag/{theme.js → v1/theme.js} +0 -0
- /package/src/Tag/{README.md → v1/README.md} +0 -0
- /package/src/Tag/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Tag/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Tag/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Tag/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _emotion = require("@instructure/emotion");
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ---
|
|
34
|
+
* private: true
|
|
35
|
+
* ---
|
|
36
|
+
* Generates the style object from the theme and provided additional information
|
|
37
|
+
* @param {Object} componentTheme The theme variable object.
|
|
38
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
39
|
+
* @param {Object} sharedTokens the state of the component, the style is applied to
|
|
40
|
+
* @return {Object} The final style object, which will be used in the component
|
|
41
|
+
*/
|
|
42
|
+
const generateStyle = (componentTheme, props, sharedTokens) => {
|
|
43
|
+
const variant = props.variant,
|
|
44
|
+
size = props.size,
|
|
45
|
+
dismissible = props.dismissible,
|
|
46
|
+
onClick = props.onClick,
|
|
47
|
+
disabled = props.disabled;
|
|
48
|
+
const isButton = !!onClick;
|
|
49
|
+
const sizeVariants = {
|
|
50
|
+
small: {
|
|
51
|
+
tag: {
|
|
52
|
+
paddingLeft: componentTheme.paddingHorizontalSmall,
|
|
53
|
+
paddingRight: componentTheme.paddingHorizontalSmall,
|
|
54
|
+
fontSize: componentTheme.fontSizeSmall
|
|
55
|
+
},
|
|
56
|
+
text: {
|
|
57
|
+
lineHeight: `calc(${componentTheme.heightSmall} - (${componentTheme.defaultBorderWidth} * 2))`
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
medium: {
|
|
61
|
+
tag: {
|
|
62
|
+
paddingLeft: componentTheme.paddingHorizontal,
|
|
63
|
+
paddingRight: componentTheme.paddingHorizontal,
|
|
64
|
+
fontSize: `calc(${componentTheme.fontSizeMedium} - 0.0625rem)`
|
|
65
|
+
},
|
|
66
|
+
text: {
|
|
67
|
+
lineHeight: `calc(${componentTheme.heightMedium} - (${componentTheme.defaultBorderWidth} * 2))`
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
large: {
|
|
71
|
+
tag: {
|
|
72
|
+
paddingLeft: componentTheme.paddingHorizontalSmall,
|
|
73
|
+
paddingRight: componentTheme.paddingHorizontal,
|
|
74
|
+
fontSize: `calc(${componentTheme.fontSizeLarge} - 0.0625rem)`
|
|
75
|
+
},
|
|
76
|
+
text: {
|
|
77
|
+
lineHeight: `calc(${componentTheme.heightLarge} - (${componentTheme.defaultBorderWidth} * 2))`
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const buttonVariant = isButton ? {
|
|
82
|
+
tag: {
|
|
83
|
+
touchAction: 'manipulation',
|
|
84
|
+
outline: 'none',
|
|
85
|
+
position: 'relative',
|
|
86
|
+
overflow: 'visible',
|
|
87
|
+
transition: `background-color ${componentTheme.transitionTiming}`,
|
|
88
|
+
...(!dismissible && {
|
|
89
|
+
cursor: 'pointer'
|
|
90
|
+
}),
|
|
91
|
+
'&:focus': {
|
|
92
|
+
'&::before': {
|
|
93
|
+
opacity: 1,
|
|
94
|
+
transform: 'scale(1)'
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
...(disabled && {
|
|
98
|
+
cursor: 'not-allowed',
|
|
99
|
+
pointerEvents: 'none',
|
|
100
|
+
opacity: 0.5
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
tagBefore: {
|
|
104
|
+
content: '""',
|
|
105
|
+
boxSizing: 'border-box',
|
|
106
|
+
border: (0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline),
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
top: '-0.3125rem',
|
|
109
|
+
bottom: '-0.3125rem',
|
|
110
|
+
left: '-0.3125rem',
|
|
111
|
+
right: '-0.3125rem',
|
|
112
|
+
opacity: 0,
|
|
113
|
+
transform: 'scale(0.9)',
|
|
114
|
+
transition: `all ${componentTheme.transitionTiming}`,
|
|
115
|
+
pointerEvents: 'none'
|
|
116
|
+
}
|
|
117
|
+
} : {};
|
|
118
|
+
const tagVariantVariants = {
|
|
119
|
+
default: {
|
|
120
|
+
tag: {
|
|
121
|
+
backgroundColor: componentTheme.defaultBackground,
|
|
122
|
+
border: `${componentTheme.defaultBorderWidth} ${componentTheme.defaultBorderStyle} ${componentTheme.defaultBorderColor}`,
|
|
123
|
+
borderRadius: componentTheme.defaultBorderRadius,
|
|
124
|
+
color: componentTheme.defaultColor,
|
|
125
|
+
...(isButton && {
|
|
126
|
+
'&:hover': {
|
|
127
|
+
backgroundColor: componentTheme.defaultBackgroundHover
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
tagBefore: {
|
|
132
|
+
...(isButton && {
|
|
133
|
+
borderRadius: componentTheme.defaultBorderRadius
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
inline: {
|
|
138
|
+
tag: {
|
|
139
|
+
backgroundColor: componentTheme.inlineBackground,
|
|
140
|
+
border: `${componentTheme.inlineBorderWidth} ${componentTheme.inlineBorderStyle} ${componentTheme.inlineBorderColor}`,
|
|
141
|
+
borderRadius: componentTheme.inlineBorderRadius,
|
|
142
|
+
color: componentTheme.inlineColor,
|
|
143
|
+
cursor: 'text',
|
|
144
|
+
margin: '0 0.1875rem 0.1875rem',
|
|
145
|
+
...(isButton && {
|
|
146
|
+
'&:hover': {
|
|
147
|
+
backgroundColor: componentTheme.inlineBackgroundHover
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
},
|
|
151
|
+
tagBefore: {
|
|
152
|
+
...(isButton && {
|
|
153
|
+
borderRadius: `calc(${componentTheme.inlineBorderRadius} * 1.5)`
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const inlineIconVariant = variant === 'inline' && dismissible ? {
|
|
159
|
+
backgroundColor: componentTheme.inlineIconColor,
|
|
160
|
+
borderRadius: '50%',
|
|
161
|
+
padding: '0.25rem',
|
|
162
|
+
position: 'absolute',
|
|
163
|
+
insetInlineEnd: 0,
|
|
164
|
+
insetInlineStart: 'auto',
|
|
165
|
+
top: 0,
|
|
166
|
+
transform: 'translate(40%, -40%)',
|
|
167
|
+
display: 'flex',
|
|
168
|
+
alignItems: 'center',
|
|
169
|
+
justifyContent: 'center',
|
|
170
|
+
'[class$="-tag"]:hover > &': {
|
|
171
|
+
backgroundColor: componentTheme.inlineIconHoverColor
|
|
172
|
+
},
|
|
173
|
+
'[dir="rtl"] &': {
|
|
174
|
+
transform: 'translate(-40%, -40%)'
|
|
175
|
+
}
|
|
176
|
+
} : {};
|
|
177
|
+
return {
|
|
178
|
+
tag: {
|
|
179
|
+
label: 'tag',
|
|
180
|
+
boxSizing: 'border-box',
|
|
181
|
+
fontFamily: componentTheme.fontFamily,
|
|
182
|
+
display: 'inline-flex',
|
|
183
|
+
alignItems: 'center',
|
|
184
|
+
textAlign: 'center',
|
|
185
|
+
verticalAlign: 'middle',
|
|
186
|
+
userSelect: 'none',
|
|
187
|
+
...sizeVariants[size].tag,
|
|
188
|
+
...buttonVariant.tag,
|
|
189
|
+
...tagVariantVariants[variant].tag,
|
|
190
|
+
'&::before': {
|
|
191
|
+
...buttonVariant.tagBefore,
|
|
192
|
+
...tagVariantVariants[variant].tagBefore
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
text: {
|
|
196
|
+
label: 'tag__text',
|
|
197
|
+
whiteSpace: 'nowrap',
|
|
198
|
+
overflow: 'hidden',
|
|
199
|
+
textOverflow: 'ellipsis',
|
|
200
|
+
maxWidth: componentTheme.maxWidth,
|
|
201
|
+
...sizeVariants[size].text
|
|
202
|
+
},
|
|
203
|
+
icon: {
|
|
204
|
+
label: 'tag__icon',
|
|
205
|
+
marginInlineStart: componentTheme.iconMargin,
|
|
206
|
+
marginInlineEnd: 0,
|
|
207
|
+
transition: `all ${componentTheme.transitionTiming}`,
|
|
208
|
+
cursor: 'pointer',
|
|
209
|
+
...inlineIconVariant
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
var _default = exports.default = generateStyle;
|
package/lib/exports/b.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-tag",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A tag component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,23 +15,23 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/emotion": "11.6.
|
|
19
|
-
"@instructure/
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/ui-
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-
|
|
24
|
-
"@instructure/ui-
|
|
25
|
-
"@instructure/ui-view": "11.6.
|
|
18
|
+
"@instructure/emotion": "11.6.1-snapshot-129",
|
|
19
|
+
"@instructure/console": "11.6.1-snapshot-129",
|
|
20
|
+
"@instructure/ui-color-utils": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/ui-dom-utils": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-icons": "11.6.1-snapshot-129",
|
|
24
|
+
"@instructure/ui-react-utils": "11.6.1-snapshot-129",
|
|
25
|
+
"@instructure/ui-view": "11.6.1-snapshot-129"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@testing-library/jest-dom": "^6.6.3",
|
|
29
29
|
"@testing-library/react": "15.0.7",
|
|
30
30
|
"@testing-library/user-event": "^14.6.1",
|
|
31
31
|
"vitest": "^3.2.2",
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-themes": "11.6.
|
|
34
|
-
"@instructure/ui-
|
|
32
|
+
"@instructure/ui-axe-check": "11.6.1-snapshot-129",
|
|
33
|
+
"@instructure/ui-themes": "11.6.1-snapshot-129",
|
|
34
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": ">=18 <=19"
|
|
@@ -41,17 +41,39 @@
|
|
|
41
41
|
},
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"exports": {
|
|
44
|
-
".": {
|
|
45
|
-
"types": "./types/index.d.ts",
|
|
46
|
-
"import": "./es/index.js",
|
|
47
|
-
"require": "./lib/index.js",
|
|
48
|
-
"default": "./es/index.js"
|
|
49
|
-
},
|
|
50
44
|
"./lib/*": "./lib/*",
|
|
51
45
|
"./es/*": "./es/*",
|
|
52
46
|
"./types/*": "./types/*",
|
|
53
47
|
"./package.json": "./package.json",
|
|
54
|
-
"./src/*": "./src/*"
|
|
48
|
+
"./src/*": "./src/*",
|
|
49
|
+
".": {
|
|
50
|
+
"src": "./src/exports/a.ts",
|
|
51
|
+
"types": "./types/exports/a.d.ts",
|
|
52
|
+
"import": "./es/exports/a.js",
|
|
53
|
+
"require": "./lib/exports/a.js",
|
|
54
|
+
"default": "./es/exports/a.js"
|
|
55
|
+
},
|
|
56
|
+
"./v11_6": {
|
|
57
|
+
"src": "./src/exports/a.ts",
|
|
58
|
+
"types": "./types/exports/a.d.ts",
|
|
59
|
+
"import": "./es/exports/a.js",
|
|
60
|
+
"require": "./lib/exports/a.js",
|
|
61
|
+
"default": "./es/exports/a.js"
|
|
62
|
+
},
|
|
63
|
+
"./v11_7": {
|
|
64
|
+
"src": "./src/exports/b.ts",
|
|
65
|
+
"types": "./types/exports/b.d.ts",
|
|
66
|
+
"import": "./es/exports/b.js",
|
|
67
|
+
"require": "./lib/exports/b.js",
|
|
68
|
+
"default": "./es/exports/b.js"
|
|
69
|
+
},
|
|
70
|
+
"./latest": {
|
|
71
|
+
"src": "./src/exports/b.ts",
|
|
72
|
+
"types": "./types/exports/b.d.ts",
|
|
73
|
+
"import": "./es/exports/b.js",
|
|
74
|
+
"require": "./lib/exports/b.js",
|
|
75
|
+
"default": "./es/exports/b.js"
|
|
76
|
+
}
|
|
55
77
|
},
|
|
56
78
|
"scripts": {
|
|
57
79
|
"lint": "ui-scripts lint",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
import { Component } from 'react'
|
|
26
26
|
|
|
27
27
|
import { IconXLine } from '@instructure/ui-icons'
|
|
28
|
-
import { View } from '@instructure/ui-view'
|
|
29
|
-
import type { ViewProps } from '@instructure/ui-view'
|
|
28
|
+
import { View } from '@instructure/ui-view/v11_6'
|
|
29
|
+
import type { ViewProps } from '@instructure/ui-view/v11_6'
|
|
30
30
|
import { omitProps } from '@instructure/ui-react-utils'
|
|
31
31
|
import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
32
|
-
import { withStyle } from '@instructure/emotion'
|
|
32
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
33
33
|
|
|
34
34
|
import generateStyle from './styles'
|
|
35
35
|
import generateComponentTheme from './theme'
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Tag
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Use `<Tag />` to represent a category or group in a form.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
---
|
|
9
|
+
type: example
|
|
10
|
+
---
|
|
11
|
+
<Tag text="Static" margin="0 xx-small 0 0" />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Dismissible
|
|
15
|
+
|
|
16
|
+
When the `dismissible` prop is added to a clickable Tag, the button
|
|
17
|
+
renders an X/close icon (the Tag should be dismissed via the `onClick`
|
|
18
|
+
prop). When implementing dismissable tags, be sure to add [AccessibleContent](AccessibleContent) to clarify that the tag is dismissible to screen readers.
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
---
|
|
22
|
+
type: example
|
|
23
|
+
---
|
|
24
|
+
<Tag
|
|
25
|
+
text={
|
|
26
|
+
<AccessibleContent alt="Remove dismissible tag">
|
|
27
|
+
Dismissible tag
|
|
28
|
+
</AccessibleContent>
|
|
29
|
+
}
|
|
30
|
+
dismissible
|
|
31
|
+
margin="0 xx-small 0 0"
|
|
32
|
+
onClick={function () {
|
|
33
|
+
alert("This Tag was dismissed")
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Disabled
|
|
39
|
+
|
|
40
|
+
A `disabled` Tag.
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
---
|
|
44
|
+
type: example
|
|
45
|
+
---
|
|
46
|
+
<Tag
|
|
47
|
+
text="Dismissible Disabled"
|
|
48
|
+
dismissible
|
|
49
|
+
disabled
|
|
50
|
+
margin="0 xx-small 0 0"
|
|
51
|
+
onClick={function () {
|
|
52
|
+
alert("This Tag was dismissed. This shouldn't happen")
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Sizes
|
|
58
|
+
|
|
59
|
+
`medium` is the default Tag size.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
---
|
|
63
|
+
type: example
|
|
64
|
+
---
|
|
65
|
+
<div>
|
|
66
|
+
<Tag text="Small" size="small" margin="0 xx-small 0 0" />
|
|
67
|
+
<Tag text="Medium" margin="0 xx-small 0 0" />
|
|
68
|
+
<Tag text="Large" size="large" margin="0 xx-small 0 0" />
|
|
69
|
+
</div>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Max-width
|
|
73
|
+
|
|
74
|
+
> **DEPRECATED** Please do not make Tags that have overflowing text, it's an a11y anti-pattern. The issue is if text overflows it cannot be read by keyboard-only users. We could make the Tag focusable, but that would be an anti-pattern too because only elements that are interactive should be focusable (and just displaying a tooltip is not a real interaction)
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
---
|
|
78
|
+
type: example
|
|
79
|
+
---
|
|
80
|
+
<Tag
|
|
81
|
+
text="Long string of text designed to trigger overflow"
|
|
82
|
+
/>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Inline variant
|
|
86
|
+
|
|
87
|
+
This variant is designed to look similar to the surrounding text.
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
---
|
|
91
|
+
type: example
|
|
92
|
+
---
|
|
93
|
+
<Text as="p">
|
|
94
|
+
This is an
|
|
95
|
+
<Tag
|
|
96
|
+
dismissible
|
|
97
|
+
onClick={() => alert('Tag dismissed')}
|
|
98
|
+
size="large"
|
|
99
|
+
text={<AccessibleContent alt="Remove 'inline'">
|
|
100
|
+
inline
|
|
101
|
+
</AccessibleContent>}
|
|
102
|
+
variant="inline"
|
|
103
|
+
/>
|
|
104
|
+
tag.
|
|
105
|
+
</Text>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Guidelines
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
---
|
|
112
|
+
type: embed
|
|
113
|
+
---
|
|
114
|
+
<Guidelines>
|
|
115
|
+
<Figure recommendation="a11y" title="Accessibility">
|
|
116
|
+
<Figure.Item>When implementing dismissable tags, be sure to add AccessibleContent to clarify that the tag is dismissible to screen readers</Figure.Item>
|
|
117
|
+
</Figure>
|
|
118
|
+
</Guidelines>
|
|
119
|
+
```
|
|
@@ -0,0 +1,180 @@
|
|
|
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 { Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { XInstUIIcon } from '@instructure/ui-icons'
|
|
28
|
+
import { View } from '@instructure/ui-view/latest'
|
|
29
|
+
import type { ViewProps } from '@instructure/ui-view/latest'
|
|
30
|
+
import { omitProps } from '@instructure/ui-react-utils'
|
|
31
|
+
import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
32
|
+
import { withStyle } from '@instructure/emotion'
|
|
33
|
+
|
|
34
|
+
import generateStyle from './styles'
|
|
35
|
+
import type { TagProps } from './props'
|
|
36
|
+
import { allowedProps } from './props'
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
---
|
|
40
|
+
category: components
|
|
41
|
+
---
|
|
42
|
+
**/
|
|
43
|
+
|
|
44
|
+
@withStyle(generateStyle)
|
|
45
|
+
class Tag extends Component<TagProps> {
|
|
46
|
+
static readonly componentId = 'Tag'
|
|
47
|
+
|
|
48
|
+
static allowedProps = allowedProps
|
|
49
|
+
static defaultProps = {
|
|
50
|
+
size: 'medium',
|
|
51
|
+
dismissible: false,
|
|
52
|
+
variant: 'default',
|
|
53
|
+
disabled: false,
|
|
54
|
+
readOnly: false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
state = {
|
|
58
|
+
iconHovered: false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
ref: Element | null = null
|
|
62
|
+
|
|
63
|
+
componentDidMount() {
|
|
64
|
+
this.props.makeStyles?.()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
componentDidUpdate() {
|
|
68
|
+
this.props.makeStyles?.()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get focused() {
|
|
72
|
+
return isActiveElement(this.ref)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
focus = () => {
|
|
76
|
+
this.ref && (this.ref as HTMLElement).focus()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
handleIconMouseEnter = () => {
|
|
80
|
+
this.setState({ iconHovered: true })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
handleIconMouseLeave = () => {
|
|
84
|
+
this.setState({ iconHovered: false })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
handleClick = (e: React.MouseEvent<ViewProps & Element>) => {
|
|
88
|
+
const { disabled, readOnly, onClick } = this.props
|
|
89
|
+
|
|
90
|
+
if (disabled || readOnly) {
|
|
91
|
+
e.preventDefault()
|
|
92
|
+
e.stopPropagation()
|
|
93
|
+
} else if (typeof onClick === 'function') {
|
|
94
|
+
onClick(e)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
handleRef = (element: Element | null) => {
|
|
99
|
+
this.ref = element
|
|
100
|
+
|
|
101
|
+
if (typeof this.props.elementRef === 'function') {
|
|
102
|
+
this.props.elementRef(element)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getIconSize = () => {
|
|
107
|
+
const { size, variant } = this.props
|
|
108
|
+
|
|
109
|
+
if (variant === 'inline') {
|
|
110
|
+
return 'xs'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const sizeMap = {
|
|
114
|
+
small: 'xs',
|
|
115
|
+
medium: 'sm',
|
|
116
|
+
large: 'md'
|
|
117
|
+
} as const
|
|
118
|
+
|
|
119
|
+
return sizeMap[size!]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
render() {
|
|
123
|
+
const {
|
|
124
|
+
className,
|
|
125
|
+
dismissible,
|
|
126
|
+
disabled,
|
|
127
|
+
readOnly,
|
|
128
|
+
text,
|
|
129
|
+
title,
|
|
130
|
+
onClick,
|
|
131
|
+
margin,
|
|
132
|
+
styles,
|
|
133
|
+
variant
|
|
134
|
+
} = this.props
|
|
135
|
+
|
|
136
|
+
const passthroughProps = View.omitViewProps(
|
|
137
|
+
omitProps(this.props, Tag.allowedProps),
|
|
138
|
+
Tag
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
const getIconColor = () => {
|
|
142
|
+
if (disabled) {
|
|
143
|
+
return 'mutedColor'
|
|
144
|
+
}
|
|
145
|
+
if (variant === 'inline') {
|
|
146
|
+
return 'inverseColor'
|
|
147
|
+
}
|
|
148
|
+
return this.state.iconHovered ? 'actionSecondaryHoverColor' : 'baseColor'
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<View
|
|
153
|
+
{...passthroughProps}
|
|
154
|
+
elementRef={this.handleRef}
|
|
155
|
+
css={styles?.tag}
|
|
156
|
+
className={className}
|
|
157
|
+
as={onClick ? 'button' : 'span'}
|
|
158
|
+
margin={margin}
|
|
159
|
+
type={onClick ? 'button' : undefined}
|
|
160
|
+
{...(onClick && { onClick: this.handleClick })}
|
|
161
|
+
disabled={disabled || readOnly}
|
|
162
|
+
display={undefined}
|
|
163
|
+
title={title || (typeof text === 'string' ? text : undefined)}
|
|
164
|
+
data-cid="Tag"
|
|
165
|
+
onMouseEnter={this.handleIconMouseEnter}
|
|
166
|
+
onMouseLeave={this.handleIconMouseLeave}
|
|
167
|
+
>
|
|
168
|
+
<span css={styles?.text}>{text}</span>
|
|
169
|
+
{onClick && dismissible ? (
|
|
170
|
+
<span css={styles?.icon}>
|
|
171
|
+
<XInstUIIcon size={this.getIconSize()} color={getIconColor()} />
|
|
172
|
+
</span>
|
|
173
|
+
) : null}
|
|
174
|
+
</View>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export default Tag
|
|
180
|
+
export { Tag }
|