Skip to content

Commit

Permalink
fix: Add radio for value and defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
im3dabasia committed Dec 25, 2024
1 parent bcb75c2 commit f8933b6
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import {
Panel,
__experimentalToolsPanel as ToolsPanel,
Expand All @@ -26,7 +26,8 @@ const meta = {
},
argTypes: {
value: {
control: { type: null },
control: 'radio',
options: [ 'thumbnail', 'medium', 'large', 'full' ],
description: 'Currently selected resolution value.',
table: {
type: { summary: 'string' },
Expand Down Expand Up @@ -87,22 +88,32 @@ const meta = {
export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ resolution, setResolution ] = useState();
render: function Template( { onChange, defaultValue, value, ...args } ) {
const [ resolution, setResolution ] = useState( value ?? defaultValue );

useEffect( () => {
if ( value !== resolution ) {
setResolution( value );
}
}, [ value, resolution ] );

const handleChange = ( newValue ) => {
setResolution( newValue );
onChange?.( newValue );
};

return (
<Panel>
<ToolsPanel
resetAll={ () => {
setResolution( undefined );
onChange?.( undefined );
setResolution( defaultValue );
onChange?.( defaultValue );
} }
>
<ResolutionTool
{ ...args }
onChange={ ( newValue ) => {
onChange?.( newValue );
setResolution( newValue );
} }
defaultValue={ defaultValue }
onChange={ handleChange }
value={ resolution }
/>
</ToolsPanel>
Expand Down

0 comments on commit f8933b6

Please sign in to comment.