diff --git a/src-docs/src/views/call_out/info.js b/src-docs/src/views/call_out/info.js index 27feb2d164..2afe71e4df 100644 --- a/src-docs/src/views/call_out/info.js +++ b/src-docs/src/views/call_out/info.js @@ -9,42 +9,65 @@ * GitHub history for details. */ -import React from 'react'; +import React, { useState } from 'react'; import { OuiCallOut, OuiLink, OuiSpacer } from '../../../../src/components'; -export default () => ( -
- -

- Here’s some stuff that you need to know. We can make this text - really long so that, when viewed within a browser that’s fairly - narrow, it will wrap, too. -

-

- When possible, its recommended to include links to product{' '} - - documentation - - . -

-
- - - - - - - - -
-); +export default () => { + const [isCallOutVisible, setIsCallOutVisible] = useState(true); + + const closeCallOut = () => setIsCallOutVisible(false); + + let callOut; + + if (isCallOutVisible) { + callOut = ( + + ); + } + + return ( +
+ +

+ Here’s some stuff that you need to know. We can make this text + really long so that, when viewed within a browser that’s fairly + narrow, it will wrap, too. +

+

+ When possible, its recommended to include links to product{' '} + + documentation + + . +

+
+ + + + + + + + {callOut} + + + + +
+ ); +}; diff --git a/src/components/call_out/__snapshots__/call_out.test.tsx.snap b/src/components/call_out/__snapshots__/call_out.test.tsx.snap index 6860aa91bb..89a412f4ca 100644 --- a/src/components/call_out/__snapshots__/call_out.test.tsx.snap +++ b/src/components/call_out/__snapshots__/call_out.test.tsx.snap @@ -42,6 +42,92 @@ exports[`OuiCallOut props color warning is rendered 1`] = ` /> `; +exports[`OuiCallOut props dismissible close callout after click 1`] = ` + +
+
+ + This is a callout + +
+ + + +
+
+`; + +exports[`OuiCallOut props dismissible is not rendered when in danger color 1`] = ` +
+`; + +exports[`OuiCallOut props dismissible is not rendered when in warning color 1`] = ` +
+`; + +exports[`OuiCallOut props dismissible is rendered when set to true 1`] = ` +
+ +
+`; + exports[`OuiCallOut props heading h1 is rendered 1`] = `
{ test('is rendered', () => { @@ -81,5 +82,43 @@ describe('OuiCallOut', () => { }); }); }); + + describe('dismissible', () => { + it('is rendered when set to true', () => { + const component = render(); + + expect(component).toMatchSnapshot(); + }); + + it('is not rendered when in warning color', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); + + it('is not rendered when in danger color', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); + + it('close callout after click', () => { + const onDismissible = jest.fn(); + const component = mount( + + ); + expect(component).toMatchSnapshot(); + findTestSubject(component, 'closeCallOutButton').simulate('click'); + expect(onDismissible).toBeCalled(); + }); + }); }); }); diff --git a/src/components/call_out/call_out.tsx b/src/components/call_out/call_out.tsx index 1c6b57c0ef..24b796e89d 100644 --- a/src/components/call_out/call_out.tsx +++ b/src/components/call_out/call_out.tsx @@ -36,6 +36,7 @@ import { CommonProps, keysOf } from '../common'; import { IconType, OuiIcon } from '../icon'; import { OuiText } from '../text'; +import { OuiButtonIcon } from '../button'; type Color = 'primary' | 'success' | 'warning' | 'danger'; type Size = 's' | 'm'; @@ -48,6 +49,12 @@ export type OuiCallOutProps = CommonProps & color?: Color; size?: Size; heading?: Heading; + dismissible?: boolean; + onDismissible?: ( + event?: + | React.KeyboardEvent + | React.MouseEvent + ) => void; }; const colorToClassNameMap: { [color in Color]: string } = { @@ -75,6 +82,8 @@ export const OuiCallOut = forwardRef( children, className, heading, + dismissible = false, + onDismissible = () => {}, ...rest }, ref: Ref @@ -100,6 +109,19 @@ export const OuiCallOut = forwardRef( ); } + let dismissibleIcon; + if (dismissible && color !== 'warning' && color !== 'danger') { + dismissibleIcon = ( + + ); + } + let optionalChildren; if (children && size === 's') { optionalChildren = ( @@ -126,10 +148,13 @@ export const OuiCallOut = forwardRef(
); } + return (
{header} + {dismissibleIcon} + {optionalChildren}
);