Skip to content

Commit 14c327d

Browse files
committed
feat(ui-alerts): rework Alert
INSTUI-4782
1 parent e01d087 commit 14c327d

5 files changed

Lines changed: 47 additions & 115 deletions

File tree

docs/guides/upgrade-guide.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ type: embed
9090
{oldName:"titleCardMini",newName:"titleCardMini",note:"now returns a full typography object instead of just a font size"},
9191
{oldName:"label",newName:"label",note:"now returns a full typography object instead of just a font size"},
9292
{oldName:"labelInline",newName:"labelInline",note:"now returns a full typography object instead of just a font size"}
93+
]}
94+
/>
95+
96+
```
97+
98+
### Alert
99+
100+
```js
101+
---
102+
type: embed
103+
---
104+
<V12ChangelogTable
105+
removed={[
106+
{name:"boxShadow",note:"now uses sharedTokens.boxShadow.elevation4"},
107+
{name:"contentPadding",note:"split into contentPaddingVertical and contentPaddingHorizontal"}
93108
]}
94109
/>
95110

packages/ui-alerts/src/Alert/__tests__/Alert.test.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import '@testing-library/jest-dom'
2929
import userEvent from '@testing-library/user-event'
3030
import { Alert } from '../index'
3131
import type { AlertProps } from '../props'
32-
import { IconGroupLine } from '@instructure/ui-icons'
32+
import { GroupInstUIIcon } from '@instructure/ui-icons'
3333

3434
describe('<Alert />', () => {
3535
let srdiv: HTMLDivElement | null
@@ -97,10 +97,10 @@ describe('<Alert />', () => {
9797
NonNullable<AlertProps['variant']>,
9898
string
9999
> = {
100-
error: 'IconNo',
101-
info: 'IconInfoBorderless',
102-
success: 'IconCheckMark',
103-
warning: 'IconWarningBorderless'
100+
error: 'CircleX',
101+
info: 'Info',
102+
success: 'CircleCheck',
103+
warning: 'TriangleAlert'
104104
}
105105

106106
;(
@@ -115,7 +115,7 @@ describe('<Alert />', () => {
115115
Success: Sample alert text.
116116
</Alert>
117117
)
118-
const icon = container.querySelector('svg[class$="-svgIcon"]')
118+
const icon = container.querySelector('svg[class^="lucide"]')
119119

120120
expect(icon).toHaveAttribute('name', iconComponent)
121121
})
@@ -167,10 +167,12 @@ describe('<Alert />', () => {
167167
})
168168

169169
it('should render an icon when provided as the `renderIcon` prop', () => {
170-
const { container } = render(<Alert renderCustomIcon={<IconGroupLine />} />)
171-
const icon = container.querySelector('svg[class$="-svgIcon"]')
170+
const { container } = render(
171+
<Alert renderCustomIcon={<GroupInstUIIcon />} />
172+
)
173+
const icon = container.querySelector('svg[class^="lucide"]')
172174

173-
expect(icon).toHaveAttribute('name', 'IconGroup')
175+
expect(icon).toHaveAttribute('name', 'Group')
174176
expect(icon).toBeInTheDocument()
175177
})
176178

packages/ui-alerts/src/Alert/index.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ import { View } from '@instructure/ui-view'
3636
import type { ViewOwnProps } from '@instructure/ui-view'
3737
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
3838
import {
39-
IconCheckMarkSolid,
40-
IconInfoBorderlessSolid,
41-
IconWarningBorderlessSolid,
42-
IconNoSolid
39+
InfoInstUIIcon,
40+
XCircleInstUIIcon,
41+
CircleCheckInstUIIcon,
42+
TriangleAlertInstUIIcon
4343
} from '@instructure/ui-icons'
4444
import { Transition } from '@instructure/ui-motion'
4545
import { logError as error } from '@instructure/console'
46-
import { withStyleRework as withStyle } from '@instructure/emotion'
46+
import { withStyle } from '@instructure/emotion'
4747

4848
import generateStyle from './styles'
49-
import generateComponentTheme from './theme'
5049

5150
import { allowedProps } from './props'
5251
import type { AlertProps, AlertState } from './props'
@@ -57,7 +56,7 @@ category: components
5756
---
5857
**/
5958
@withDeterministicId()
60-
@withStyle(generateStyle, generateComponentTheme)
59+
@withStyle(generateStyle)
6160
class Alert extends Component<AlertProps, AlertState> {
6261
static readonly componentId = 'Alert'
6362

@@ -88,10 +87,10 @@ class Alert extends Component<AlertProps, AlertState> {
8887
srid: string
8988

9089
variantUI = {
91-
error: IconNoSolid,
92-
info: IconInfoBorderlessSolid,
93-
success: IconCheckMarkSolid,
94-
warning: IconWarningBorderlessSolid
90+
error: XCircleInstUIIcon,
91+
info: InfoInstUIIcon,
92+
success: CircleCheckInstUIIcon,
93+
warning: TriangleAlertInstUIIcon
9594
}
9695

9796
ref: Element | null = null

packages/ui-alerts/src/Alert/styles.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import type { AlertTheme } from '@instructure/shared-types'
25+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
26+
import { boxShadowObjectsToCSSString } from '@instructure/ui-themes'
2627
import type { AlertProps, AlertStyle } from './props'
2728

2829
/**
@@ -36,8 +37,9 @@ import type { AlertProps, AlertStyle } from './props'
3637
* @return {Object} The final style object, which will be used in the component
3738
*/
3839
const generateStyle = (
39-
componentTheme: AlertTheme,
40-
props: AlertProps
40+
componentTheme: NewComponentTypes['Alert'],
41+
props: AlertProps,
42+
sharedTokens: SharedTokens
4143
): AlertStyle => {
4244
const { variant, hasShadow } = props
4345

@@ -84,7 +86,11 @@ const generateStyle = (
8486
borderStyle: componentTheme.borderStyle,
8587
borderRadius: componentTheme.borderRadius,
8688
...variantStyles[variant!].alert,
87-
...(hasShadow && { boxShadow: componentTheme.boxShadow })
89+
...(hasShadow && {
90+
boxShadow: boxShadowObjectsToCSSString(
91+
sharedTokens.boxShadow.elevation4
92+
)
93+
})
8894
},
8995
icon: {
9096
color: componentTheme.iconColor,
@@ -116,7 +122,7 @@ const generateStyle = (
116122
fontFamily: componentTheme.contentFontFamily,
117123
fontWeight: componentTheme.contentFontWeight,
118124
lineHeight: componentTheme.contentLineHeight,
119-
padding: componentTheme.contentPadding
125+
padding: `${componentTheme.contentPaddingVertical} ${componentTheme.contentPaddingHorizontal}`
120126
},
121127
variantScreenReaderLabel: {
122128
position: 'absolute',

packages/ui-alerts/src/Alert/theme.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)