-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dismissible prop to OuiCallOut #985
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,21 @@ | |
* under the License. | ||
*/ | ||
|
||
import React, { forwardRef, Ref, HTMLAttributes, ReactNode } from 'react'; | ||
import React, { | ||
forwardRef, | ||
Ref, | ||
HTMLAttributes, | ||
ReactNode, | ||
useState, | ||
} from 'react'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
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 +55,7 @@ export type OuiCallOutProps = CommonProps & | |
color?: Color; | ||
size?: Size; | ||
heading?: Heading; | ||
dismissible?: boolean; | ||
}; | ||
|
||
const colorToClassNameMap: { [color in Color]: string } = { | ||
|
@@ -75,10 +83,12 @@ export const OuiCallOut = forwardRef<HTMLDivElement, OuiCallOutProps>( | |
children, | ||
className, | ||
heading, | ||
dismissible = false, | ||
...rest | ||
}, | ||
ref: Ref<HTMLDivElement> | ||
) => { | ||
const [isCalloutVisible, setIsCalloutVisible] = useState(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we persist this value in session storage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is any precedence of using any sort of storage in OUI. In fact, I feel like a more common pattern would be to have a prop like |
||
const classes = classNames( | ||
'ouiCallOut', | ||
colorToClassNameMap[color], | ||
|
@@ -100,6 +110,21 @@ export const OuiCallOut = forwardRef<HTMLDivElement, OuiCallOutProps>( | |
); | ||
} | ||
|
||
const onClose = () => setIsCalloutVisible(false); | ||
|
||
let dismissibleIcon; | ||
if (dismissible && color !== 'warning' && color !== 'danger') { | ||
dismissibleIcon = ( | ||
<OuiButtonIcon | ||
iconType="cross" | ||
onClick={onClose} | ||
className="ouiCallOut__closeIcon" | ||
aria-label="dismissible_icon" | ||
data-test-subj="closeCallOutButton" | ||
/> | ||
); | ||
} | ||
|
||
let optionalChildren; | ||
if (children && size === 's') { | ||
optionalChildren = ( | ||
|
@@ -126,10 +151,17 @@ export const OuiCallOut = forwardRef<HTMLDivElement, OuiCallOutProps>( | |
</div> | ||
); | ||
} | ||
|
||
if (!isCalloutVisible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={classes} ref={ref} {...rest}> | ||
{header} | ||
|
||
{dismissibleIcon} | ||
|
||
{optionalChildren} | ||
</div> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should use
$ouiSize
in some way. Maybecalc($ouiSizeM / 2)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to
$ouiSizeS / 2