-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4562 from hotosm/develop
v4.4.5
- Loading branch information
Showing
77 changed files
with
2,265 additions
and
1,289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BanIcon, CheckIcon, InfoIcon, AlertIcon } from '../svgIcons'; | ||
|
||
export const Alert = ({ type = 'info', compact = false, inline = false, children }) => { | ||
const icons = { | ||
info: InfoIcon, | ||
success: CheckIcon, | ||
warning: AlertIcon, | ||
error: BanIcon, | ||
}; | ||
const Icon = icons[type]; | ||
|
||
const color = { | ||
info: 'b--blue bg-lightest-blue', | ||
success: 'b--dark-green bg-washed-green', | ||
warning: 'b--gold bg-washed-yellow', | ||
error: 'b--dark-red bg-washed-red', | ||
}; | ||
const iconColor = { | ||
info: 'blue', | ||
success: 'dark-green', | ||
warning: 'gold', | ||
error: 'dark-red', | ||
}; | ||
|
||
return ( | ||
<div | ||
className={`${inline ? 'di' : 'db'} blue-dark bl bw2 br2 ${compact ? 'pa2' : 'pa3'} ${ | ||
color[type] | ||
}`} | ||
> | ||
<Icon className={`h1 w1 v-top mr2 ${iconColor[type]}`} /> | ||
{children} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { Alert } from '../index'; | ||
|
||
describe('Alert Component', () => { | ||
it('with error type', () => { | ||
const { container } = render(<Alert type="error">An error message</Alert>); | ||
expect(container.querySelector('svg')).toBeInTheDocument(); // ban icon | ||
expect(container.querySelector('.dark-red')).toBeInTheDocument(); | ||
expect(container.querySelector('div').className).toBe( | ||
'db blue-dark bl bw2 br2 pa3 b--dark-red bg-washed-red', | ||
); | ||
expect(screen.queryByText(/An error message/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('with success type', () => { | ||
const { container } = render( | ||
<Alert type="success" inline={true}> | ||
Success message comes here | ||
</Alert>, | ||
); | ||
expect(container.querySelector('svg')).toBeInTheDocument(); | ||
expect(container.querySelector('.dark-green')).toBeInTheDocument(); | ||
const divClassName = container.querySelector('div').className; | ||
expect(divClassName).toContain('b--dark-green bg-washed-green'); | ||
expect(divClassName).toContain('di'); | ||
expect(divClassName).not.toContain('db'); | ||
expect(screen.queryByText(/Success message comes here/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('with info type', () => { | ||
const { container } = render( | ||
<Alert type="info" compact={true}> | ||
Information | ||
</Alert>, | ||
); | ||
expect(container.querySelector('svg')).toBeInTheDocument(); | ||
expect(container.querySelector('.blue')).toBeInTheDocument(); | ||
const divClassName = container.querySelector('div').className; | ||
expect(divClassName).toContain('b--blue bg-lightest-blue'); | ||
expect(divClassName).toContain('db'); | ||
expect(divClassName).not.toContain('di'); | ||
expect(divClassName).toContain('pa2'); | ||
expect(divClassName).not.toContain('pa3'); | ||
expect(screen.queryByText(/Information/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('with warning type', () => { | ||
const { container } = render( | ||
<Alert type="warning" inline={true} compact={true}> | ||
It's only a warning... | ||
</Alert>, | ||
); | ||
expect(container.querySelector('svg')).toBeInTheDocument(); | ||
expect(container.querySelector('.gold')).toBeInTheDocument(); | ||
const divClassName = container.querySelector('div').className; | ||
expect(divClassName).toContain('b--gold bg-washed-yellow'); | ||
expect(divClassName).toContain('di'); | ||
expect(divClassName).toContain('pa2'); | ||
expect(screen.queryByText(/It's only a warning.../)).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.