Skip to content

Commit 01375e9

Browse files
committed
align title props
1 parent 878a0ca commit 01375e9

File tree

4 files changed

+14
-65
lines changed

4 files changed

+14
-65
lines changed

src/Toast/Toast.jsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,9 @@ import classNames from 'classnames';
55

66
import { Alert } from 'src/Alert';
77
import FadeTransition from 'src/FadeTransition';
8-
import { isObject } from '../utils';
98

109
import './Toast.scss';
1110

12-
function buildAlertMessageProps(message) {
13-
if (isObject(message) && !React.isValidElement(message)) {
14-
return {
15-
title: message.title,
16-
message: message.body,
17-
};
18-
}
19-
20-
return { message };
21-
}
22-
2311
export default function Toast(props) {
2412
const groupClassNames = classNames(
2513
'Toast',
@@ -35,9 +23,10 @@ export default function Toast(props) {
3523
action={message.action}
3624
autoDismiss={props.autoDismiss}
3725
id={message.id}
26+
message={message.message}
27+
title={message.title}
3828
type={message.type}
3929
onDismiss={props.onToastClosed}
40-
{...buildAlertMessageProps(message.message)}
4130
/>
4231
</FadeTransition>
4332
))
@@ -52,14 +41,8 @@ Toast.propTypes = {
5241
messages: PropTypes.arrayOf(
5342
PropTypes.shape({
5443
id: PropTypes.string,
55-
message: PropTypes.oneOfType([
56-
PropTypes.string,
57-
PropTypes.node,
58-
PropTypes.shape({
59-
body: PropTypes.string,
60-
title: PropTypes.string,
61-
}),
62-
]),
44+
message: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
45+
title: PropTypes.string,
6346
type: PropTypes.string,
6447
}),
6548
).isRequired,

src/Toast/Toast.test.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,33 @@ describe('Toast', () => {
1919
expect(props.className).toContain('Toast--no-header');
2020
});
2121

22-
describe('when building alert message props', () => {
23-
const setup = (message) => create(
22+
describe('when building alert props', () => {
23+
const setup = (props) => create(
2424
<Toast
2525
messages={[
26-
{ id: '1', type: 'success', message },
26+
{ id: '1', type: 'success', ...props },
2727
]}
2828
/>,
2929
);
3030

3131
test('builds props from string message', () => {
32-
const { root } = setup('hello');
32+
const { root } = setup({ message: 'hello' });
3333

3434
expect(root.findByType(Alert).props.message).toBe('hello');
3535
});
3636

3737
test('builds props from node message', () => {
38-
const { root } = setup(<div>hello</div>);
38+
const { root } = setup({ message: <div>hello</div> });
3939

4040
expect(root.findByType(Alert).props.message).toEqual(<div>hello</div>);
4141
});
4242

43-
test('builds props from object message', () => {
44-
const { root } = setup({ title: 'woohoo', body: 'you did it!' });
43+
describe('when title prop is passed', () => {
44+
test('builds title prop', () => {
45+
const { root } = setup({ title: 'woohoo', message: 'you did it!' });
4546

46-
expect(root.findByType(Alert).props.message).toBe('you did it!');
47-
expect(root.findByType(Alert).props.title).toBe('woohoo');
47+
expect(root.findByType(Alert).props.title).toBe('woohoo');
48+
});
4849
});
4950
});
5051
});

src/utils.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/utils.test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)