Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/guides/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ type: example

- theme variable `topMargin` is now removed

### Tag

- theme variable `defaultIconColor` is now removed
- theme variable `defaultIconHoverColor` is now removed
- theme variable `inlineIconColor` is now removed
- theme variable `inlineIconHoverColor` is now removed
- theme variable `focusOutlineColor` is now removed
- theme variable `focusOutlineStyle` is now removed
- theme variable `focusOutlineWidth` is now removed
- theme variable `padding` is now removed, `paddingHorizontal` can be used to set horizonal padding
- theme variable `paddingSmall` is now removed, `paddingHorizontalSmall` can be used to set horizonal padding

### TextArea

- theme variable `smallFontSize` is now renamed to `fontSizeSm`
Expand Down
1 change: 1 addition & 0 deletions packages/ui-tag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@instructure/ui-color-utils": "workspace:*",
"@instructure/ui-dom-utils": "workspace:*",
"@instructure/ui-icons": "workspace:*",
"@instructure/ui-icons-lucide": "workspace:*",
"@instructure/ui-react-utils": "workspace:*",
"@instructure/ui-view": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-tag/src/Tag/__tests__/Tag.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('<Tag />', async () => {
)
const icon = container.querySelector('svg')

expect(icon).toHaveAttribute('name', 'IconX')
expect(icon).toHaveAttribute('name', 'X')
})

it('should meet a11y standards', async () => {
Expand Down
44 changes: 38 additions & 6 deletions packages/ui-tag/src/Tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@

import { Component } from 'react'

import { IconXLine } from '@instructure/ui-icons'
import { XInstUIIcon } from '@instructure/ui-icons-lucide'
import { View } from '@instructure/ui-view'
import type { ViewProps } from '@instructure/ui-view'
import { omitProps } from '@instructure/ui-react-utils'
import { isActiveElement } from '@instructure/ui-dom-utils'
import { withStyleRework as withStyle } from '@instructure/emotion'
import { withStyle } from '@instructure/emotion'

import generateStyle from './styles'
import generateComponentTheme from './theme'
import type { TagProps } from './props'
import { allowedProps } from './props'

Expand All @@ -42,7 +41,7 @@ category: components
---
**/

@withStyle(generateStyle, generateComponentTheme)
@withStyle(generateStyle)
class Tag extends Component<TagProps> {
static readonly componentId = 'Tag'

Expand All @@ -55,6 +54,10 @@ class Tag extends Component<TagProps> {
readOnly: false
}

state = {
iconHovered: false
}

ref: Element | null = null

componentDidMount() {
Expand All @@ -73,6 +76,14 @@ class Tag extends Component<TagProps> {
this.ref && (this.ref as HTMLElement).focus()
}

handleIconMouseEnter = () => {
this.setState({ iconHovered: true })
}

handleIconMouseLeave = () => {
this.setState({ iconHovered: false })
}

handleClick = (e: React.MouseEvent<ViewProps & Element>) => {
const { disabled, readOnly, onClick } = this.props

Expand Down Expand Up @@ -102,14 +113,27 @@ class Tag extends Component<TagProps> {
title,
onClick,
margin,
styles
styles,
variant
} = this.props

const passthroughProps = View.omitViewProps(
omitProps(this.props, Tag.allowedProps),
Tag
)

const getIconColor = () => {
if (disabled) {
return 'mutedColor'
}
if (variant === 'inline') {
return this.state.iconHovered
? 'actionSecondaryHoverColor'
: 'actionSecondaryBaseColor'
}
return this.state.iconHovered ? 'actionSecondaryHoverColor' : 'baseColor'
}

return (
<View
{...passthroughProps}
Expand All @@ -124,9 +148,17 @@ class Tag extends Component<TagProps> {
display={undefined}
title={title || (typeof text === 'string' ? text : undefined)}
data-cid="Tag"
onMouseEnter={this.handleIconMouseEnter}
onMouseLeave={this.handleIconMouseLeave}
>
<span css={styles?.text}>{text}</span>
{onClick && dismissible ? <IconXLine css={styles?.icon} /> : null}
{onClick && dismissible ? (
<XInstUIIcon
css={styles?.icon}
size={variant === 'inline' ? 14 : 'sm'}
color={getIconColor()}
/>
) : null}
</View>
)
}
Expand Down
32 changes: 16 additions & 16 deletions packages/ui-tag/src/Tag/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
* SOFTWARE.
*/

import type { TagTheme } from '@instructure/shared-types'
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
import type { TagProps, TagStyle } from './props'
import { calcFocusOutlineStyles } from '@instructure/emotion'

/**
* ---
Expand All @@ -32,18 +33,23 @@ import type { TagProps, TagStyle } from './props'
* Generates the style object from the theme and provided additional information
* @param {Object} componentTheme The theme variable object.
* @param {Object} props the props of the component, the style is applied to
* @param {Object} state the state of the component, the style is applied to
* @param {Object} sharedTokens the state of the component, the style is applied to
* @return {Object} The final style object, which will be used in the component
*/
const generateStyle = (componentTheme: TagTheme, props: TagProps): TagStyle => {
const generateStyle = (
componentTheme: NewComponentTypes['Tag'],
props: TagProps,
sharedTokens: SharedTokens
): TagStyle => {
const { variant, size, dismissible, onClick, disabled } = props

const isButton = !!onClick

const sizeVariants = {
small: {
tag: {
padding: componentTheme.paddingSmall,
paddingLeft: componentTheme.paddingHorizontalSmall,
paddingRight: componentTheme.paddingHorizontalSmall,
fontSize: componentTheme.fontSizeSmall
},
text: {
Expand All @@ -53,7 +59,8 @@ const generateStyle = (componentTheme: TagTheme, props: TagProps): TagStyle => {
},
medium: {
tag: {
padding: componentTheme.padding,
paddingLeft: componentTheme.paddingHorizontal,
paddingRight: componentTheme.paddingHorizontal,
fontSize: `calc(${componentTheme.fontSizeMedium} - 0.0625rem)`
},
text: {
Expand All @@ -63,7 +70,8 @@ const generateStyle = (componentTheme: TagTheme, props: TagProps): TagStyle => {
},
large: {
tag: {
padding: componentTheme.padding,
paddingLeft: componentTheme.paddingHorizontalSmall,
paddingRight: componentTheme.paddingHorizontal,
fontSize: `calc(${componentTheme.fontSizeLarge} - 0.0625rem)`
},
text: {
Expand Down Expand Up @@ -99,7 +107,7 @@ const generateStyle = (componentTheme: TagTheme, props: TagProps): TagStyle => {
tagBefore: {
content: '""',
boxSizing: 'border-box',
border: `${componentTheme.focusOutlineWidth} ${componentTheme.focusOutlineStyle} ${componentTheme.focusOutlineColor}`,
border: calcFocusOutlineStyles(sharedTokens.focusOutline),
position: 'absolute',
top: '-0.3125rem',
bottom: '-0.3125rem',
Expand Down Expand Up @@ -151,15 +159,7 @@ const generateStyle = (componentTheme: TagTheme, props: TagProps): TagStyle => {
}

const iconVariantVariants = {
default: {
...(dismissible && {
color: componentTheme.defaultIconColor,

'[class$="-tag"]:hover > &': {
color: componentTheme.defaultIconHoverColor
}
})
},
default: {},
inline: {
...(dismissible && {
backgroundColor: componentTheme.inlineIconColor,
Expand Down
92 changes: 0 additions & 92 deletions packages/ui-tag/src/Tag/theme.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/ui-tag/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
{
"path": "../ui-icons/tsconfig.build.json"
},
{
"path": "../ui-icons-lucide/tsconfig.build.json"
},
{
"path": "../ui-react-utils/tsconfig.build.json"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading