-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds specification for Banner UI component. ![Screenshot 2024-12-17 at 11 43 18](https://github.com/user-attachments/assets/562417fb-b0cb-49be-a68f-7e405e0e5f37)
- Loading branch information
Showing
8 changed files
with
195 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Banner } from './Banner'; | ||
import { Button } from './form/Button'; | ||
import { Bold } from './formatting/Bold'; | ||
import { Italic } from './formatting/Italic'; | ||
import { Icon } from './Icon'; | ||
import { Link } from './Link'; | ||
import { Text } from './Text'; | ||
|
||
describe('Banner', () => { | ||
it('renders a banner component', () => { | ||
const result = ( | ||
<Banner title="Test Banner" severity="info"> | ||
<Text>Example test banner.</Text> | ||
<Link href="https://example.com">foo</Link> | ||
<Button type="button">foo</Button> | ||
<Icon name="arrow-left" color="primary" size="md" /> | ||
<Bold>foo</Bold> | ||
<Italic>bar</Italic> | ||
</Banner> | ||
); | ||
|
||
expect(result).toStrictEqual({ | ||
type: 'Banner', | ||
key: null, | ||
props: { | ||
title: 'Test Banner', | ||
severity: 'info', | ||
children: [ | ||
{ | ||
type: 'Text', | ||
props: { | ||
children: 'Example test banner.', | ||
}, | ||
key: null, | ||
}, | ||
{ | ||
type: 'Link', | ||
props: { | ||
href: 'https://example.com', | ||
children: 'foo', | ||
}, | ||
key: null, | ||
}, | ||
{ | ||
type: 'Button', | ||
props: { | ||
type: 'button', | ||
children: 'foo', | ||
}, | ||
key: null, | ||
}, | ||
{ | ||
type: 'Icon', | ||
props: { | ||
name: 'arrow-left', | ||
color: 'primary', | ||
size: 'md', | ||
}, | ||
key: null, | ||
}, | ||
{ | ||
type: 'Bold', | ||
props: { | ||
children: 'foo', | ||
}, | ||
key: null, | ||
}, | ||
{ | ||
type: 'Italic', | ||
props: { | ||
children: 'bar', | ||
}, | ||
key: null, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |
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,53 @@ | ||
import { createSnapComponent, type SnapsChildren } from '../component'; | ||
import type { ButtonElement } from './form/Button'; | ||
import type { StandardFormattingElement } from './formatting'; | ||
import type { IconElement } from './Icon'; | ||
import type { LinkElement } from './Link'; | ||
import type { TextElement } from './Text'; | ||
|
||
/** | ||
* Types of children components that can be used with Banner. | ||
*/ | ||
export type BannerChildren = SnapsChildren< | ||
| TextElement | ||
| StandardFormattingElement | ||
| LinkElement | ||
| IconElement | ||
| ButtonElement | ||
>; | ||
|
||
/** | ||
* The props of the {@link Banner} component. | ||
* | ||
* @param children - The content to display in the banner. | ||
* @param title - Title of the banner. | ||
* @param severity - Severity level of the banner. | ||
*/ | ||
export type BannerProps = { | ||
children: BannerChildren; | ||
title: string; | ||
severity: 'danger' | 'info' | 'success' | 'warning'; | ||
}; | ||
|
||
const TYPE = 'Banner'; | ||
|
||
/** | ||
* A Banner component, which is used to display custom banner alerts. | ||
* | ||
* @param props - The props of the component. | ||
* @param props.children - The content to display in the banner. | ||
* @param props.title - Title of the banner. | ||
* @param props.severity - Severity level of the banner. | ||
* @example | ||
* <Banner title="Success banner" severity="success"> | ||
* <Text>Here is the banner content!</Text> | ||
* </Banner> | ||
*/ | ||
export const Banner = createSnapComponent<BannerProps, typeof TYPE>(TYPE); | ||
|
||
/** | ||
* A Banner element. | ||
* | ||
* @see Banner | ||
*/ | ||
export type BannerElement = ReturnType<typeof Banner>; |
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