Skip to content
Merged
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
9 changes: 9 additions & 0 deletions packages/ui-alerts/src/Alert/__tests__/Alert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import '@testing-library/jest-dom'
import userEvent from '@testing-library/user-event'
import { Alert } from '../index'
import type { AlertProps } from '../props'
import { IconGroupLine } from '@instructure/ui-icons'

describe('<Alert />', () => {
let srdiv: HTMLDivElement | null
Expand Down Expand Up @@ -147,6 +148,14 @@ describe('<Alert />', () => {
expect(liveRegion).toHaveAttribute('aria-live', 'polite')
})

it('should render an icon when provided as the `renderIcon` prop', () => {
const { container } = render(<Alert renderCustomIcon={<IconGroupLine />} />)
const icon = container.querySelector('svg[class$="-svgIcon"]')

expect(icon).toHaveAttribute('name', 'IconGroup')
expect(icon).toBeInTheDocument()
})

describe('with `screenReaderOnly', () => {
it('should not render anything when using `liveRegion`', async () => {
const liveRegion = document.getElementById('_alertLiveRegion')!
Expand Down
7 changes: 4 additions & 3 deletions packages/ui-alerts/src/Alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ class Alert extends Component<AlertProps, AlertState> {
}

renderIcon() {
const Icon = this.variantUI[this.props.variant!]
const { renderCustomIcon, variant, styles } = this.props
const Icon = this.variantUI[variant!]
return (
<div css={this.props.styles?.icon}>
<Icon />
<div css={styles?.icon}>
{renderCustomIcon ? callRenderProp(renderCustomIcon) : <Icon />}
</div>
)
}
Expand Down
11 changes: 9 additions & 2 deletions packages/ui-alerts/src/Alert/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ type AlertOwnProps = {
* If the alert should have a shadow.
*/
hasShadow: boolean

/**
* An icon, or function that returns an icon. Setting it will override the variant's icon.
*/
renderCustomIcon?: Renderable
}

type PropKeys = keyof AlertOwnProps
Expand Down Expand Up @@ -137,7 +142,8 @@ const propTypes: PropValidators<PropKeys> = {
transition: PropTypes.oneOf(['none', 'fade']),
open: PropTypes.bool,
hasShadow: PropTypes.bool,
variantScreenReaderLabel: PropTypes.string
variantScreenReaderLabel: PropTypes.string,
renderCustomIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
}

const allowedProps: AllowedPropKeys = [
Expand All @@ -153,7 +159,8 @@ const allowedProps: AllowedPropKeys = [
'onDismiss',
'transition',
'open',
'hasShadow'
'hasShadow',
'renderCustomIcon'
]

type AlertState = {
Expand Down
3 changes: 3 additions & 0 deletions packages/ui-alerts/src/Alert/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const generateStyle = (
justifyContent: 'center',
fontSize: '1.125rem',
borderRight: `${componentTheme.borderWidth} ${componentTheme.borderStyle}`,
Comment thread
ToMESSKa marked this conversation as resolved.
Outdated
margin: -1,

@ToMESSKa ToMESSKa Jun 13, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed to make a white line between the Alert's and the icon's border to disappear

borderStartStartRadius: componentTheme.borderRadius,
borderEndStartRadius: componentTheme.borderRadius,
...variantStyles[variant!].icon
},
closeButton: {
Expand Down
Loading