Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use actions in storybook example rather than outputting to a heading
  • Loading branch information
talldan committed Jun 23, 2023
commit 00d17b300730228e533d1cf8169a7890270739f7
23 changes: 8 additions & 15 deletions packages/components/src/confirm-dialog/stories/index.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

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