@gechiui/block-editor
Version:
66 lines (63 loc) • 1.51 kB
JavaScript
/**
* GeChiUI dependencies
*/
import { Button } from '@gechiui/components';
import { __ } from '@gechiui/i18n';
import {
formatCapitalize,
formatLowercase,
formatUppercase,
} from '@gechiui/icons';
const TEXT_TRANSFORMS = [
{
name: __( '大写' ),
value: 'uppercase',
icon: formatUppercase,
},
{
name: __( '小写' ),
value: 'lowercase',
icon: formatLowercase,
},
{
name: __( '首字母大写' ),
value: 'capitalize',
icon: formatCapitalize,
},
];
/**
* Control to facilitate text transform selections.
*
* @param {Object} props Component props.
* @param {string} props.value Currently selected text transform.
* @param {Function} props.onChange Handles change in text transform selection.
*
* @return {GCElement} Text transform control.
*/
export default function TextTransformControl( { value, onChange } ) {
return (
<fieldset className="block-editor-text-transform-control">
<legend>{ __( '字母实例' ) }</legend>
<div className="block-editor-text-transform-control__buttons">
{ TEXT_TRANSFORMS.map( ( textTransform ) => {
return (
<Button
key={ textTransform.value }
icon={ textTransform.icon }
isSmall
isPressed={ value === textTransform.value }
aria-label={ textTransform.name }
onClick={ () =>
onChange(
value === textTransform.value
? undefined
: textTransform.value
)
}
/>
);
} ) }
</div>
</fieldset>
);
}