-
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
17 changed files
with
246 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { ElementType, ForwardedRef, forwardRef } from 'react'; | ||
import classNames from 'classnames'; | ||
import { SpiritLinkProps } from '../../types'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { Link } from '../Link'; | ||
import { useToastBarStyleProps } from './useToastBarStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritLinkProps> = { | ||
color: 'inverted', | ||
isUnderlined: true, | ||
}; | ||
|
||
/* We need an exception for components exported with forwardRef */ | ||
/* eslint no-underscore-dangle: ['error', { allow: ['_ToastBarLink'] }] */ | ||
const _ToastBarLink = <E extends ElementType = typeof Link, C = void>( | ||
props: SpiritLinkProps<E, C>, | ||
ref: ForwardedRef<HTMLAnchorElement>, | ||
) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { children, ...restProps } = propsWithDefaults; | ||
const { classProps, props: modifiedProps } = useToastBarStyleProps({ ...restProps }); | ||
const { styleProps, props: otherProps } = useStyleProps(modifiedProps); | ||
|
||
return ( | ||
<Link | ||
{...propsWithDefaults} | ||
{...otherProps} | ||
ref={ref} | ||
UNSAFE_className={classNames(classProps.link, styleProps.className)} | ||
style={styleProps.style} | ||
> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export const ToastBarLink = forwardRef<HTMLAnchorElement, SpiritLinkProps<ElementType>>(_ToastBarLink); | ||
|
||
export default ToastBarLink; |
21 changes: 21 additions & 0 deletions
21
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { useClassNamePrefix, useStyleProps } from '../../hooks'; | ||
import { ChildrenProps } from '../../types'; | ||
|
||
const ToastBarMessage = (props: ChildrenProps) => { | ||
const { children, ...restProps } = props; | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<div | ||
{...styleProps} | ||
{...otherProps} | ||
className={classNames(useClassNamePrefix('text-truncate-multiline'), styleProps.className)} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ToastBarMessage; |
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import ToastBarLink from '../ToastBarLink'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest'; | ||
|
||
describe('ToastBarLink', () => { | ||
stylePropsTest(ToastBarLink); | ||
|
||
restPropsTest(ToastBarLink, 'a'); | ||
|
||
beforeEach(() => { | ||
render(<ToastBarLink href="example-href">Example action</ToastBarLink>); | ||
}); | ||
|
||
it('should render with correct href', () => { | ||
const element = screen.getByRole('link'); | ||
|
||
expect(element).toBeInTheDocument(); | ||
expect(element).toHaveAttribute('href', 'example-href'); | ||
}); | ||
|
||
it('should render children', () => { | ||
expect(screen.getByText('Example action')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render with correct classnames', () => { | ||
const element = screen.getByRole('link'); | ||
|
||
expect(element).toHaveClass('link-inverted'); | ||
expect(element).toHaveClass('link-underlined'); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import ToastBarMessage from '../ToastBarMessage'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest'; | ||
|
||
describe('ToastBarMessage', () => { | ||
stylePropsTest(ToastBarMessage); | ||
|
||
restPropsTest(ToastBarMessage, 'div'); | ||
|
||
beforeEach(() => { | ||
render(<ToastBarMessage>Example children</ToastBarMessage>); | ||
}); | ||
|
||
it('should render children', () => { | ||
expect(screen.getByText('Example children')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render with truncate className', () => { | ||
expect(screen.getByText('Example children')).toHaveClass('text-truncate-multiline'); | ||
}); | ||
}); |
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
33 changes: 12 additions & 21 deletions
33
packages/web-react/src/components/Toast/demo/ToastColors.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
Oops, something went wrong.