Skip to content

Commit

Permalink
Use actions in storybook example rather than outputting to a heading
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jun 23, 2023
1 parent acde51c commit 00d17b3
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions packages/components/src/confirm-dialog/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useState } from '@wordpress/element';
* Internal dependencies
*/
import Button from '../../button';
import { Heading } from '../../heading';
import { ConfirmDialog } from '..';

const meta = {
Expand All @@ -26,12 +25,8 @@ const meta = {
isOpen: {
control: { type: null },
},
onConfirm: {
control: { type: null },
},
onCancel: {
control: { type: null },
},
onConfirm: { action: 'onConfirm' },
onCancel: { action: 'onCancel' },
},
args: {
children: 'Would you like to privately publish the post now?',
Expand All @@ -43,19 +38,19 @@ const meta = {

export default meta;

const Template = ( args ) => {
const Template = ( { onConfirm, onCancel, ...args } ) => {
const [ isOpen, setIsOpen ] = useState( false );
const [ confirmVal, setConfirmVal ] = useState( '' );

const handleConfirm = () => {
setConfirmVal( 'Confirmed!' );
const handleConfirm = ( ...confirmArgs ) => {
onConfirm( ...confirmArgs );
setIsOpen( false );
};

const handleCancel = () => {
setConfirmVal( 'Cancelled' );
const handleCancel = ( ...cancelArgs ) => {
onCancel( ...cancelArgs );
setIsOpen( false );
};

return (
<>
<Button variant="primary" onClick={ () => setIsOpen( true ) }>
Expand All @@ -70,8 +65,6 @@ const Template = ( args ) => {
>
{ args.children }
</ConfirmDialog>

<Heading level={ 1 }>{ confirmVal }</Heading>
</>
);
};
Expand Down

0 comments on commit 00d17b3

Please sign in to comment.