Skip to content

Commit

Permalink
Storybook: Add DateFormatPicker Stories
Browse files Browse the repository at this point in the history
  • Loading branch information
SainathPoojary committed Nov 26, 2024
1 parent 9b0e2d9 commit 767ee83
Showing 1 changed file with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Internal dependencies
*/
import DateFormatPicker from '..';

/**
* WordPress dependencies
*/
import { useEffect, useState } from '@wordpress/element';

/**
* Date format options
*/
const FORMAT_OPTIONS = [
null,
'Y-m-d',
'n/j/Y',
'n/j/Y g:i A',
'M j, Y',
'M j, Y g:i A',
'F j, Y',
'M j',
];

/**
* Storybook configuration for DateFormatPicker component
*/
export default {
title: 'BlockEditor/DateFormatPicker',
component: DateFormatPicker,
argTypes: {
defaultFormat: {
control: 'text',
description: 'Default date format to display',
},
format: {
control: 'select',
options: FORMAT_OPTIONS,
description: 'Selected date format',
},
onChange: {
action: 'onChange',
control: {
type: null,
},
description: 'Callback function when date format changes',
},
},
render: function Render( { onChange, format, defaultFormat } ) {
const [ selectedFormat, setSelectedFormat ] = useState( format );

useEffect( () => {
setSelectedFormat( format );
}, [ format ] );

const handleFormatChange = ( newValue ) => {
setSelectedFormat( newValue );
if ( onChange ) {
onChange( newValue );
}
};

return (
<DateFormatPicker
defaultFormat={ defaultFormat }
format={ selectedFormat }
onChange={ handleFormatChange }
/>
);
},
};

/**
* Story demonstrating DateFormatPicker with default settings
*/
export const Default = {
args: {
defaultFormat: 'M j, Y',
format: 'Y-m-d',
},
};

/**
* DateFormatPicker with format set to null and defaultFormat set to 'M j, Y'
*/
export const WithFormatNull = {
args: {
defaultFormat: 'M j, Y',
format: null,
},
};

/**
* DateFormatPicker with defaultFormat set to empty string and format set to 'Y-m-d'
*/
export const WithDefaultFormatEmpty = {
args: {
defaultFormat: '',
format: 'Y-m-d',
},
};

0 comments on commit 767ee83

Please sign in to comment.