-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiCallOut] Add
onDismiss
prop (#7156)
Co-authored-by: Bree Hall <[email protected]> Co-authored-by: Cee Chen <[email protected]>
- Loading branch information
1 parent
4dcb28e
commit 4a83e0e
Showing
9 changed files
with
259 additions
and
56 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiSwitch, | ||
EuiSpacer, | ||
EuiButtonEmpty, | ||
EuiCallOut, | ||
} from '../../../../src'; | ||
|
||
export default () => { | ||
const [showCallOut, setShowCallOut] = useState( | ||
!localStorage.getItem('EuiCallOutOnDismissDemo') | ||
); | ||
const onDismiss = () => { | ||
setShowCallOut(false); | ||
localStorage.setItem('EuiCallOutOnDismissDemo', 'hidden'); | ||
}; | ||
const resetDemo = () => { | ||
setShowCallOut(true); | ||
localStorage.setItem('EuiCallOutOnDismissDemo', ''); | ||
}; | ||
|
||
// UI toggles | ||
const [showTitle, setShowTitle] = useState(true); | ||
const [showChildren, setShowChildren] = useState(true); | ||
const [smallSize, setSmallSize] = useState(false); | ||
|
||
return ( | ||
<div css={{ maxInlineSize: 500 }}> | ||
<EuiFlexGroup> | ||
<EuiSwitch | ||
label="Show title" | ||
checked={showTitle} | ||
onChange={(e) => setShowTitle(e.target.checked)} | ||
compressed | ||
/> | ||
<EuiSwitch | ||
label="Show children" | ||
checked={showChildren} | ||
onChange={(e) => setShowChildren(e.target.checked)} | ||
compressed | ||
/> | ||
<EuiSwitch | ||
label="Small size" | ||
checked={smallSize} | ||
onChange={(e) => setSmallSize(e.target.checked)} | ||
compressed | ||
/> | ||
</EuiFlexGroup> | ||
<EuiSpacer /> | ||
{showCallOut ? ( | ||
<EuiCallOut | ||
onDismiss={onDismiss} | ||
iconType="iInCircle" | ||
title={ | ||
showTitle | ||
? 'You can dismiss this callout by clicking the Close button in the top right corner' | ||
: '' | ||
} | ||
size={smallSize ? 's' : 'm'} | ||
> | ||
{showChildren && ( | ||
<> | ||
<p> | ||
Here’s more some stuff users need to know. But maybe users don't | ||
need to know it on every page refresh, so you could remember | ||
whether or not to display this callout in local storage. | ||
</p> | ||
{!showTitle && ( | ||
<p> | ||
This second paragraph is here to demonstrate that only the | ||
first one needs to account for the dismiss button in width. | ||
</p> | ||
)} | ||
</> | ||
)} | ||
</EuiCallOut> | ||
) : ( | ||
<EuiButtonEmpty onClick={resetDemo}> | ||
The callout has been dismissed. Click to reset the demo | ||
</EuiButtonEmpty> | ||
)} | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.