Skip to content
Draft
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
24 changes: 12 additions & 12 deletions src/components/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ export const Info: Story = {
export const Slim: Story = {
render: () => (
<>
<Alert type="success" headingLevel="h4" slim>
<Alert type="success" slim>
{testText}
</Alert>
<Alert type="warning" headingLevel="h4" slim>
<Alert type="warning" slim>
{testText}
</Alert>
<Alert type="error" headingLevel="h4" slim>
<Alert type="error" slim>
{testText}
</Alert>
<Alert type="info" headingLevel="h4" slim>
<Alert type="info" slim>
{testText}
</Alert>
</>
Expand All @@ -84,16 +84,16 @@ export const Slim: Story = {
export const NoIcon: Story = {
render: () => (
<>
<Alert type="success" headingLevel="h4" noIcon>
<Alert type="success" noIcon>
{testText}
</Alert>
<Alert type="warning" headingLevel="h4" noIcon>
<Alert type="warning" noIcon>
{testText}
</Alert>
<Alert type="error" headingLevel="h4" noIcon>
<Alert type="error" noIcon>
{testText}
</Alert>
<Alert type="info" headingLevel="h4" noIcon>
<Alert type="info" noIcon>
{testText}
</Alert>
</>
Expand All @@ -103,16 +103,16 @@ export const NoIcon: Story = {
export const SlimNoIcon: Story = {
render: () => (
<>
<Alert type="success" headingLevel="h4" slim noIcon>
<Alert type="success" slim noIcon>
{testText}
</Alert>
<Alert type="warning" headingLevel="h4" slim noIcon>
<Alert type="warning" slim noIcon>
{testText}
</Alert>
<Alert type="error" headingLevel="h4" slim noIcon>
<Alert type="error" slim noIcon>
{testText}
</Alert>
<Alert type="info" headingLevel="h4" slim noIcon>
<Alert type="info" slim noIcon>
{testText}
</Alert>
</>
Expand Down
12 changes: 5 additions & 7 deletions src/components/Alert/Alert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ describe('Alert component', () => {
})

it('renders without errors', () => {
const { queryByTestId } = render(<Alert type="success" headingLevel="h4" />)
const { queryByTestId } = render(<Alert type="success" />)
expect(queryByTestId('alert')).toBeInTheDocument()
})

it('renders children in <p> tag by default', () => {
const { queryByTestId } = render(
<Alert type="success" headingLevel="h4" className="myClass">
<Alert type="success" className="myClass">
Test children
</Alert>
)
Expand All @@ -26,7 +26,7 @@ describe('Alert component', () => {

it('renders validation style alert', () => {
const { queryByTestId } = render(
<Alert type="success" validation headingLevel="h4" className="myClass">
<Alert type="success" validation className="myClass">
Test children
</Alert>
)
Expand All @@ -37,7 +37,7 @@ describe('Alert component', () => {

it('accepts className prop', () => {
const { queryByTestId } = render(
<Alert type="success" headingLevel="h4" className="myClass" />
<Alert type="success" className="myClass" />
)
expect(queryByTestId('alert')).toHaveClass('myClass')
})
Expand Down Expand Up @@ -71,9 +71,7 @@ describe('Alert component', () => {
describe('with a CTA', () => {
it('renders the CTA', () => {
const testCTA = <button type="button">Click Here</button>
const { queryByText } = render(
<Alert type="success" headingLevel="h4" cta={testCTA} />
)
const { queryByText } = render(<Alert type="success" cta={testCTA} />)
expect(queryByText('Click Here')).toBeInTheDocument()
})
})
Expand Down
22 changes: 17 additions & 5 deletions src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ import { HeadingLevel } from '../../types/headingLevel'

import styles from './Alert.module.scss'

export type AlertProps = {
type AlertBaseProps = {
type: 'success' | 'warning' | 'error' | 'info'
heading?: React.ReactNode
headingLevel: HeadingLevel
children?: React.ReactNode
cta?: React.ReactNode
slim?: boolean
noIcon?: boolean
validation?: boolean
} & React.HTMLAttributes<HTMLDivElement>
}

type AlertWithHeadingProps = {
heading: React.ReactNode
headingLevel: HeadingLevel
}

type AlertWithoutHeadingProps = {
heading?: undefined
headingLevel?: HeadingLevel
}

export type AlertProps = AlertBaseProps &
(AlertWithHeadingProps | AlertWithoutHeadingProps) &
React.HTMLAttributes<HTMLDivElement>

export const Alert = ({
type,
Expand Down Expand Up @@ -43,7 +55,7 @@ export const Alert = ({
className
)

const Heading = headingLevel
const Heading = headingLevel ?? 'h4'

return (
<div className={classes} data-testid="alert" {...props}>
Expand Down
Loading