-
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.
Feat(web-react): Use Icon in Alert and add centered variant #DS-304
- Loading branch information
Showing
14 changed files
with
120 additions
and
13 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
19 changes: 19 additions & 0 deletions
19
packages/web-react/src/components/Alert/__tests__/useAlertIcon.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,19 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { SpiritAlertProps } from '../../../types'; | ||
import { useAlertIcon } from '../useAlertIcon'; | ||
|
||
describe('useAlertIcon', () => { | ||
it('should return defaults', () => { | ||
const props = {}; | ||
const { result } = renderHook(() => useAlertIcon(props)); | ||
|
||
expect(result.current).toBe('info'); | ||
}); | ||
|
||
it('danger alert should return warning icon', () => { | ||
const props = { color: 'danger' } as SpiritAlertProps; | ||
const { result } = renderHook(() => useAlertIcon(props)); | ||
|
||
expect(result.current).toBe('warning'); | ||
}); | ||
}); |
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
10 changes: 8 additions & 2 deletions
10
packages/web-react/src/components/Alert/stories/AlertColors.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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
// Because there is no `dist` directory during the CI run | ||
/* eslint-disable import/no-extraneous-dependencies, import/extensions, import/no-unresolved */ | ||
import React from 'react'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore: No declaration file | ||
import icons from '@lmc-eu/spirit-icons/dist/icons'; | ||
import { IconsProvider } from '../../../context'; | ||
import Alert from '../Alert'; | ||
|
||
// @see: https://github.com/storybookjs/storybook/issues/8104#issuecomment-932310244 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const Story = (props: unknown) => ( | ||
<> | ||
<IconsProvider value={icons}> | ||
<Alert color="success">This is a success alert — check it out!</Alert> | ||
<div className="mb-500" /> | ||
<Alert color="danger">This is a danger alert — check it out!</Alert> | ||
<div className="mb-500" /> | ||
<Alert color="informative">This is an informative alert — check it out!</Alert> | ||
</> | ||
</IconsProvider> | ||
); | ||
|
||
export default Story; |
28 changes: 28 additions & 0 deletions
28
packages/web-react/src/components/Alert/stories/AlertIcons.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,28 @@ | ||
// Because there is no `dist` directory during the CI run | ||
/* eslint-disable import/no-extraneous-dependencies, import/extensions, import/no-unresolved */ | ||
import React from 'react'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore: No declaration file | ||
import icons from '@lmc-eu/spirit-icons/dist/icons'; | ||
import { IconsProvider } from '../../../context'; | ||
import Alert from '../Alert'; | ||
|
||
// @see: https://github.com/storybookjs/storybook/issues/8104#issuecomment-932310244 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const Story = (props: unknown) => ( | ||
<IconsProvider value={icons}> | ||
<Alert color="success" iconName="profile"> | ||
This is a success alert — check it out! | ||
</Alert> | ||
<div className="mb-500" /> | ||
<Alert color="danger" iconName="close"> | ||
This is a danger alert — check it out! | ||
</Alert> | ||
<div className="mb-500" /> | ||
<Alert color="informative" iconName="warning"> | ||
This is an informative alert — check it out! | ||
</Alert> | ||
</IconsProvider> | ||
); | ||
|
||
export default Story; |
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,11 @@ | ||
import { useIconName } from '../../hooks/useIconName'; | ||
import { SpiritAlertProps } from '../../types'; | ||
|
||
export function useAlertIcon({ color, iconName }: SpiritAlertProps) { | ||
const iconNameValue = useIconName(color, { | ||
default: 'info', | ||
danger: 'warning', | ||
}); | ||
|
||
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
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,3 @@ | ||
export function useIconName(key: string | undefined, iconMap: Record<string, string>) { | ||
return key && iconMap[key] ? iconMap[key] : iconMap.default; | ||
} |
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