Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToggleGroupControl: Decouple borderless style with icon use #43771

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function TextDecorationControl( {
'block-editor-text-decoration-control',
className
) }
__experimentalIsIconGroup
__experimentalIsBorderless
label={ __( 'Decoration' ) }
value={ value }
onChange={ onChange }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function TextTransformControl( { value, onChange, ...props } ) {
<ToggleGroupControl
{ ...props }
className="block-editor-text-transform-control"
__experimentalIsIconGroup
__experimentalIsBorderless
label={ __( 'Letter case' ) }
value={ value }
onChange={ onChange }
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Internal

- Remove unused `normalizeArrowKey` utility function ([#43640](https://github.com/WordPress/gutenberg/pull/43640/)).
- `ToggleGroupControl`: Rename `__experimentalIsIconGroup` prop to `__experimentalIsBorderless` ([#43771](https://github.com/WordPress/gutenberg/pull/43771/)).
- Refactor `FocalPointPicker` to function component ([#39168](https://github.com/WordPress/gutenberg/pull/39168)).
- `Guide`: use `code` instead of `keyCode` for keyboard events ([#43604](https://github.com/WordPress/gutenberg/pull/43604/)).
- `ToggleControl`: Convert to TypeScript and streamline CSS ([#43717](https://github.com/WordPress/gutenberg/pull/43717)).
Expand Down
13 changes: 10 additions & 3 deletions packages/components/src/toggle-group-control/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,23 @@ WithTooltip.args = {
/**
* The `ToggleGroupControlOptionIcon` component can be used for icon options. A `label` is required
* on each option for accessibility, which will be shown in a tooltip.
*
* When using icon options within `ToggleGroupControl`, the `__experimentalIsIconGroup` style is preferred.
*/
export const WithIcons: ComponentStory< typeof ToggleGroupControl > =
Template.bind( {} );
WithIcons.args = {
...Default.args,
__experimentalIsIconGroup: true,
children: [
{ value: 'uppercase', label: 'Uppercase', icon: formatUppercase },
{ value: 'lowercase', label: 'Lowercase', icon: formatLowercase },
].map( mapPropsToOptionIconComponent ),
};

/**
* A borderless style may be preferred in some contexts.
*/
export const Borderless: ComponentStory< typeof ToggleGroupControl > =
Template.bind( {} );
Borderless.args = {
...WithIcons.args,
__experimentalIsBorderless: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { formatLowercase, formatUppercase } from '@wordpress/icons';

function Example() {
return (
<ToggleGroupControl __experimentalIsIconGroup>
<ToggleGroupControl>
<ToggleGroupControlOptionIcon
value="uppercase"
icon={ formatUppercase }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function UnforwardedToggleGroupControlOptionIcon(
*
* function Example() {
* return (
* <ToggleGroupControl __experimentalIsIconGroup>
* <ToggleGroupControl>
* <ToggleGroupControlOptionIcon
* value="uppercase"
* label="Uppercase"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function UnconnectedToggleGroupControl(
className,
isAdaptiveWidth = false,
isBlock = false,
__experimentalIsIconGroup = false,
__experimentalIsBorderless = false,
label,
hideLabelFromVision = false,
help,
Expand Down Expand Up @@ -88,11 +88,11 @@ function UnconnectedToggleGroupControl(
() =>
cx(
styles.ToggleGroupControl( { size } ),
! __experimentalIsIconGroup && styles.border,
! __experimentalIsBorderless && styles.border,
isBlock && styles.block,
className
),
[ className, cx, isBlock, __experimentalIsIconGroup, size ]
[ className, cx, isBlock, __experimentalIsBorderless, size ]
);
return (
<BaseControl
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/toggle-group-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ export type ToggleGroupControlProps = Omit<
*/
isBlock?: boolean;
/**
* Style for use with `ToggleGroupControlOptionIcon`s.
* Borderless style that may be preferred in some contexts.
*
* @default false
*/
__experimentalIsIconGroup?: boolean; // TODO: Refactor so this can be private
__experimentalIsBorderless?: boolean;
/**
* Callback when a segment is selected.
*/
Expand Down