File tree Expand file tree Collapse file tree 4 files changed +25
-5
lines changed
packages/ui-alerts/src/Alert Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import '@testing-library/jest-dom'
2929import userEvent from '@testing-library/user-event'
3030import { Alert } from '../index'
3131import type { AlertProps } from '../props'
32+ import { IconGroupLine } from '@instructure/ui-icons'
3233
3334describe ( '<Alert />' , ( ) => {
3435 let srdiv : HTMLDivElement | null
@@ -147,6 +148,14 @@ describe('<Alert />', () => {
147148 expect ( liveRegion ) . toHaveAttribute ( 'aria-live' , 'polite' )
148149 } )
149150
151+ it ( 'should render an icon when provided as the `renderIcon` prop' , ( ) => {
152+ const { container } = render ( < Alert renderCustomIcon = { < IconGroupLine /> } /> )
153+ const icon = container . querySelector ( 'svg[class$="-svgIcon"]' )
154+
155+ expect ( icon ) . toHaveAttribute ( 'name' , 'IconGroup' )
156+ expect ( icon ) . toBeInTheDocument ( )
157+ } )
158+
150159 describe ( 'with `screenReaderOnly' , ( ) => {
151160 it ( 'should not render anything when using `liveRegion`' , async ( ) => {
152161 const liveRegion = document . getElementById ( '_alertLiveRegion' ) !
Original file line number Diff line number Diff line change @@ -237,10 +237,11 @@ class Alert extends Component<AlertProps, AlertState> {
237237 }
238238
239239 renderIcon ( ) {
240- const Icon = this . variantUI [ this . props . variant ! ]
240+ const { renderCustomIcon, variant, styles } = this . props
241+ const Icon = this . variantUI [ variant ! ]
241242 return (
242- < div css = { this . props . styles ?. icon } >
243- < Icon />
243+ < div css = { styles ?. icon } >
244+ { renderCustomIcon ? callRenderProp ( renderCustomIcon ) : < Icon /> }
244245 </ div >
245246 )
246247 }
Original file line number Diff line number Diff line change @@ -109,6 +109,11 @@ type AlertOwnProps = {
109109 * If the alert should have a shadow.
110110 */
111111 hasShadow : boolean
112+
113+ /**
114+ * An icon, or function that returns an icon. Setting it will override the variant's icon.
115+ */
116+ renderCustomIcon ?: Renderable
112117}
113118
114119type PropKeys = keyof AlertOwnProps
@@ -137,7 +142,8 @@ const propTypes: PropValidators<PropKeys> = {
137142 transition : PropTypes . oneOf ( [ 'none' , 'fade' ] ) ,
138143 open : PropTypes . bool ,
139144 hasShadow : PropTypes . bool ,
140- variantScreenReaderLabel : PropTypes . string
145+ variantScreenReaderLabel : PropTypes . string ,
146+ renderCustomIcon : PropTypes . oneOfType ( [ PropTypes . node , PropTypes . func ] )
141147}
142148
143149const allowedProps : AllowedPropKeys = [
@@ -153,7 +159,8 @@ const allowedProps: AllowedPropKeys = [
153159 'onDismiss' ,
154160 'transition' ,
155161 'open' ,
156- 'hasShadow'
162+ 'hasShadow' ,
163+ 'renderCustomIcon'
157164]
158165
159166type AlertState = {
Original file line number Diff line number Diff line change @@ -95,6 +95,9 @@ const generateStyle = (
9595 justifyContent : 'center' ,
9696 fontSize : '1.125rem' ,
9797 borderRight : `${ componentTheme . borderWidth } ${ componentTheme . borderStyle } ` ,
98+ margin : - 1 ,
99+ borderStartStartRadius : componentTheme . borderRadius ,
100+ borderEndStartRadius : componentTheme . borderRadius ,
98101 ...variantStyles [ variant ! ] . icon
99102 } ,
100103 closeButton : {
You can’t perform that action at this time.
0 commit comments