Skip to content

Commit

Permalink
refactor: Removed the sample text, and extra stories and used story p…
Browse files Browse the repository at this point in the history
…attern
  • Loading branch information
im3dabasia committed Dec 19, 2024
1 parent 798406b commit 236dc2c
Showing 1 changed file with 32 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,24 @@ import TextTransformControl from '../';
/**
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import { useState } from '@wordpress/element';

/**
* Text transform options
* Meta configuration for Storybook
*/
const TRANSFORM_OPTIONS = [ 'none', 'uppercase', 'lowercase', 'capitalize' ];

/**
* Demo text component to show text transform effect
*/
const DemoText = ( { transform } ) => (
<p style={ { textTransform: transform } }>
This is a sample text to demonstrate the text transformation.
</p>
);

/**
* TextTransformControl Properties
*/
export default {
const meta = {
title: 'BlockEditor/TextTransformControl',
component: TextTransformControl,
argTypes: {
value: {
control: 'select',
options: TRANSFORM_OPTIONS,
description: 'Currently selected text transform value',
table: {
type: {
summary: 'string',
},
defaultValue: { summary: 'none' },
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'Control to facilitate text transformation selections.',
},
},
},
argTypes: {
onChange: {
action: 'onChange',
control: {
Expand All @@ -53,84 +37,38 @@ export default {
},
},
className: {
control: 'text',
control: { type: 'text' },
description: 'Additional CSS class name to apply',
table: {
type: { summary: 'string' },
},
},
},
render: function Render( { onChange, value, className } ) {
const [ selectedTransform, setSelectedTransform ] = useState( value );

useEffect( () => {
setSelectedTransform( value );
}, [ value ] );

const handleTransformChange = ( newValue ) => {
const updatedValue =
newValue === selectedTransform ? undefined : newValue;
setSelectedTransform( updatedValue );
if ( onChange ) {
onChange( updatedValue );
}
};

return (
<div>
<TextTransformControl
value={ selectedTransform }
onChange={ handleTransformChange }
className={ className }
/>
<DemoText transform={ selectedTransform } />
</div>
);
},
};

/**
* Story demonstrating TextTransformControl with default settings
*/
export const Default = {
args: {
value: 'none',
value: {
control: { type: null },
description: 'Currently selected writing mode.',
table: { type: { summary: 'string' } },
},
},
};

/**
* TextTransformControl with uppercase transform selected
*/
export const WithUppercase = {
args: {
value: 'uppercase',
},
};
export default meta;

/**
* TextTransformControl with lowercase transform selected
* Default Story Export
*/
export const WithLowercase = {
args: {
value: 'lowercase',
},
};

/**
* TextTransformControl with capitalize transform selected
*/
export const WithCapitalize = {
args: {
value: 'capitalize',
},
};
export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState();

/**
* TextTransformControl with custom className
*/
export const WithCustomClass = {
args: {
value: 'none',
className: 'custom-text-transform-control',
return (
<TextTransformControl
{ ...args }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
value={ value }
/>
);
},
};

0 comments on commit 236dc2c

Please sign in to comment.