-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fixup! fixup! fixup! Feat(web-react): Introduce Toast c…
…omponent
- Loading branch information
1 parent
211ebe4
commit 4e99ddc
Showing
9 changed files
with
62 additions
and
32 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
26 changes: 26 additions & 0 deletions
26
packages/web-react/src/components/Toast/__tests__/useToastIcon.test.tsx
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,26 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { SpiritToastBarProps } from '../../../types'; | ||
import { useToastIcon } from '../useToastIcon'; | ||
|
||
describe('useToastIcon', () => { | ||
it('should return defaults', () => { | ||
const props = {}; | ||
const { result } = renderHook(() => useToastIcon(props)); | ||
|
||
expect(result.current).toBe('info'); | ||
}); | ||
|
||
it.each([ | ||
// color, expected icon name | ||
['danger', 'danger'], | ||
['informative', 'info'], | ||
['inverted', 'info'], | ||
['success', 'check-plain'], | ||
['warning', 'warning'], | ||
])('danger alert should return warning icon', (color, iconName) => { | ||
const props = { color } as Partial<SpiritToastBarProps>; | ||
const { result } = renderHook(() => useToastIcon(props)); | ||
|
||
expect(result.current).toBe(iconName); | ||
}); | ||
}); |
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,18 @@ | ||
import { useIconName } from '../../hooks/useIconName'; | ||
import { SpiritToastBarProps } from '../../types'; | ||
|
||
export function useToastIcon({ color, iconName }: Partial<SpiritToastBarProps>) { | ||
const iconNameValue = useIconName( | ||
color as string, | ||
{ | ||
danger: 'danger', | ||
informative: 'info', | ||
inverted: 'info', | ||
success: 'check-plain', | ||
warning: 'warning', | ||
}, | ||
'inverted', | ||
); | ||
|
||
return iconName || iconNameValue; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export function useIconName(key: string | undefined, iconMap: Record<string, string>) { | ||
return key && iconMap[key] ? iconMap[key] : iconMap.default; | ||
export function useIconName(key: string | undefined, iconMap: Record<string, string>, defaultKey: string = 'default') { | ||
return key && iconMap[key] ? iconMap[key] : iconMap[defaultKey]; | ||
} |