-
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): Add Message and Link for ToastBar #DS-1213
- Loading branch information
Showing
10 changed files
with
70 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
import React from 'react'; | ||
import { ChildrenProps, ToastColorType } from '../../types'; | ||
import { ChildrenProps, SpiritButtonProps, SpiritLinkProps } from '../../types'; | ||
import { Link } from '../Link'; | ||
import { useToastBarStyleProps } from './useToastBarStyleProps'; | ||
import { DEFAULT_TOAST_COLOR } from './constants'; | ||
import { Button } from '../Button'; | ||
|
||
type ToastBarLinkProps = { | ||
href: string; | ||
color?: ToastColorType; | ||
isUnderlined?: boolean; | ||
} & ChildrenProps; | ||
type ToastBarLinkProps<T extends React.ElementType = typeof Link> = { | ||
elementType?: T; | ||
} & ChildrenProps & | ||
SpiritLinkProps & | ||
SpiritButtonProps<typeof Button>; | ||
|
||
const ToastBarLink = (props: ToastBarLinkProps) => { | ||
const { href, color = DEFAULT_TOAST_COLOR, isUnderlined = false, children, ...restProps } = props; | ||
const { classProps } = useToastBarStyleProps({ ...restProps }); | ||
export const ToastBarLink = <T extends React.ElementType = typeof Link | typeof Button>( | ||
props: ToastBarLinkProps<T>, | ||
): JSX.Element => { | ||
const { elementType: ElementTag = Link, children, ...restProps } = props; | ||
|
||
return ( | ||
<Link UNSAFE_className={classProps.link} href={href} color={color} {...restProps} isUnderlined={isUnderlined}> | ||
{children} | ||
</Link> | ||
); | ||
return <ElementTag {...restProps}>{children}</ElementTag>; | ||
}; | ||
|
||
export default ToastBarLink; |
12 changes: 3 additions & 9 deletions
12
packages/web-react/src/components/Toast/ToastBarMessage.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,14 +1,8 @@ | ||
import React from 'react'; | ||
import { BaseToastBarProps, ChildrenProps } from '../../types'; | ||
import { useToastBarStyleProps } from './useToastBarStyleProps'; | ||
import { ChildrenProps } from '../../types'; | ||
|
||
type ToastBarMessageProps = Omit<BaseToastBarProps, 'id'> & ChildrenProps; | ||
|
||
const ToastBarMessage = (props: ToastBarMessageProps) => { | ||
const { children, ...restProps } = props; | ||
const { classProps } = useToastBarStyleProps({ ...restProps }); | ||
|
||
return <div className={classProps.message}>{children}</div>; | ||
const ToastBarMessage = ({ children }: ChildrenProps) => { | ||
return <div>{children}</div>; | ||
}; | ||
|
||
export default ToastBarMessage; |
31 changes: 31 additions & 0 deletions
31
packages/web-react/src/components/Toast/__tests__/ToastBarLink.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,31 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import ToastBarLink from '../ToastBarLink'; | ||
|
||
describe('ToastBarLink', () => { | ||
restPropsTest((props) => <ToastBarLink {...props} id="test" />, 'a'); | ||
|
||
beforeEach(() => { | ||
render( | ||
<ToastBarLink href="www.example.com" color="inverted" isUnderlined> | ||
Action | ||
</ToastBarLink>, | ||
); | ||
}); | ||
|
||
it('should render as link', () => { | ||
const element = screen.getByRole('link'); | ||
|
||
expect(element).toBeInTheDocument(); | ||
expect(element).toHaveAttribute('href', 'www.example.com'); | ||
expect(element).toHaveClass('link-inverted link-underlined'); | ||
}); | ||
|
||
it('should render children', () => { | ||
const element = screen.getByText('Action'); | ||
|
||
expect(element).toBeInTheDocument(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/web-react/src/components/Toast/__tests__/ToastBarMessage.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,14 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import ToastBarMessage from '../ToastBarMessage'; | ||
|
||
describe('ToastBarMessage', () => { | ||
it('should render children', () => { | ||
render(<ToastBarMessage>Example children</ToastBarMessage>); | ||
|
||
const element = screen.getByText('Example children'); | ||
|
||
expect(element).toBeInTheDocument(); | ||
}); | ||
}); |
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