Skip to content

Commit

Permalink
Feat: Button groups in Typography tools should use ToggleGroupControl (
Browse files Browse the repository at this point in the history
…#64529)

* Update the letterCase typogrpahy panel to use toggleGroupOption component

* Remove unecessary style for segmented text control and match height with components

* Remove SegmentedTextControl component and use toggleControl

* Reduce the diff change in the PR

Co-authored-by: hbhalodia <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
6 people authored Aug 16, 2024
1 parent a095188 commit c459a7b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 111 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import {
alignJustify,
} from '@wordpress/icons';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
import SegmentedTextControl from '../segmented-text-control';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';

const TEXT_ALIGNMENT_OPTIONS = [
{
Expand Down Expand Up @@ -75,9 +74,11 @@ export default function TextAlignmentControl( {
}

return (
<SegmentedTextControl
<ToggleGroupControl
isDeselectable
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Text alignment' ) }
options={ validOptions }
className={ clsx(
'block-editor-text-alignment-control',
className
Expand All @@ -86,6 +87,17 @@ export default function TextAlignmentControl( {
onChange={ ( newValue ) => {
onChange( newValue === value ? undefined : newValue );
} }
/>
>
{ validOptions.map( ( option ) => {
return (
<ToggleGroupControlOptionIcon
key={ option.value }
value={ option.value }
icon={ option.icon }
label={ option.label }
/>
);
} ) }
</ToggleGroupControl>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import clsx from 'clsx';
*/
import { reset, formatStrikethrough, formatUnderline } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import SegmentedTextControl from '../segmented-text-control';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';

const TEXT_DECORATIONS = [
{
Expand Down Expand Up @@ -48,9 +47,11 @@ export default function TextDecorationControl( {
className,
} ) {
return (
<SegmentedTextControl
<ToggleGroupControl
isDeselectable
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Decoration' ) }
options={ TEXT_DECORATIONS }
className={ clsx(
'block-editor-text-decoration-control',
className
Expand All @@ -59,6 +60,17 @@ export default function TextDecorationControl( {
onChange={ ( newValue ) => {
onChange( newValue === value ? undefined : newValue );
} }
/>
>
{ TEXT_DECORATIONS.map( ( option ) => {
return (
<ToggleGroupControlOptionIcon
key={ option.value }
value={ option.value }
icon={ option.icon }
label={ option.label }
/>
);
} ) }
</ToggleGroupControl>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {
formatLowercase,
formatUppercase,
} from '@wordpress/icons';

/**
* Internal dependencies
*/
import SegmentedTextControl from '../segmented-text-control';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';

const TEXT_TRANSFORMS = [
{
Expand Down Expand Up @@ -54,9 +53,11 @@ const TEXT_TRANSFORMS = [
*/
export default function TextTransformControl( { className, value, onChange } ) {
return (
<SegmentedTextControl
<ToggleGroupControl
isDeselectable
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Letter case' ) }
options={ TEXT_TRANSFORMS }
className={ clsx(
'block-editor-text-transform-control',
className
Expand All @@ -65,6 +66,17 @@ export default function TextTransformControl( { className, value, onChange } ) {
onChange={ ( newValue ) => {
onChange( newValue === value ? undefined : newValue );
} }
/>
>
{ TEXT_TRANSFORMS.map( ( option ) => {
return (
<ToggleGroupControlOptionIcon
key={ option.value }
value={ option.value }
icon={ option.icon }
label={ option.label }
/>
);
} ) }
</ToggleGroupControl>
);
}
28 changes: 20 additions & 8 deletions packages/block-editor/src/components/writing-mode-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import clsx from 'clsx';
*/
import { __, isRTL } from '@wordpress/i18n';
import { textHorizontal, textVertical } from '@wordpress/icons';

/**
* Internal dependencies
*/
import SegmentedTextControl from '../segmented-text-control';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';

const WRITING_MODES = [
{
Expand All @@ -39,14 +38,27 @@ const WRITING_MODES = [
*/
export default function WritingModeControl( { className, value, onChange } ) {
return (
<SegmentedTextControl
<ToggleGroupControl
isDeselectable
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Orientation' ) }
options={ WRITING_MODES }
className={ clsx( 'block-editor-writing-mode-control', className ) }
value={ value }
onChange={ ( newValue ) => {
onChange( newValue === value ? undefined : newValue );
} }
/>
>
{ WRITING_MODES.map( ( option ) => {
return (
<ToggleGroupControlOptionIcon
key={ option.value }
value={ option.value }
icon={ option.icon }
label={ option.label }
/>
);
} ) }
</ToggleGroupControl>
);
}
1 change: 0 additions & 1 deletion packages/block-editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
@import "./components/multi-selection-inspector/style.scss";
@import "./components/responsive-block-control/style.scss";
@import "./components/rich-text/style.scss";
@import "./components/segmented-text-control/style.scss";
@import "./components/skip-to-selected-block/style.scss";
@import "./components/tabbed-sidebar/style.scss";
@import "./components/tool-selector/style.scss";
Expand Down

0 comments on commit c459a7b

Please sign in to comment.