Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

### Bug Fixes

- `Button.Icon`: Preserve icon view boxes so icons with non-standard `viewBox` values are not clipped ([#78614](https://github.com/WordPress/gutenberg/pull/78614)).
- `IconButton`: Default `focusableWhenDisabled` to `true`, matching `Button` ([#78526](https://github.com/WordPress/gutenberg/pull/78526)).
- `Button`: Do not show the interactive cursor when disabled ([#78479](https://github.com/WordPress/gutenberg/pull/78479)).
- `Button`: Fix disabled and hover styles for neutral minimal buttons with `aria-pressed="true"` ([#78635](https://github.com/WordPress/gutenberg/pull/78635)).
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/src/button/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import { type ButtonIconProps } from './types';
import { Icon } from '../icon';
import styles from './style.module.css';

export const ButtonIcon = forwardRef< SVGSVGElement, ButtonIconProps >(
function ButtonIcon( { icon, ...props }, ref ) {
function ButtonIcon( { className, icon, ...props }, ref ) {
return (
<Icon
ref={ ref }
icon={ icon }
viewBox="4 4 16 16"
size={ 16 }
className={ clsx( styles.icon, className ) }
size={ 24 }
{ ...props }
/>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/button/stories/index.story.tsx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the demo 👍 Since it's for testing rather than public documentation, let's remove before merging though. I can add it to the e2e Storybook if necessary.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fragment } from '@wordpress/element';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { cog } from '@wordpress/icons';
import { wordpress } from '@wordpress/icons';
import { Button } from '../index';

const meta: Meta< typeof Button > = {
Expand Down Expand Up @@ -158,7 +158,7 @@ export const WithIcon: Story = {
...Default.args,
children: (
<>
<Button.Icon icon={ cog } />
<Button.Icon icon={ wordpress } />
Button
</>
),
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/src/button/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
--wp-ui-button-aspect-ratio: auto; /* Useful for overrides such as icon buttons */
--wp-ui-button-font-size: var(--wpds-typography-font-size-md);
--wp-ui-button-min-width: calc(4ch + 2 * var(--wp-ui-button-padding-inline));
/* Icons are rendered as 24px but need to occupy a 16px footprint */
/* TODO: replace hardcoded values with DS size tokens once available */
--wp-ui-button-icon-margin: calc((16px - 24px) / 2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made another tweak here to set the intended value right here, instead of turning it negative at the usage site. I think it fits the name better (icon-margin).


/* by default, borders have the same color as the background */
--wp-ui-button-border-color: var(--wp-ui-button-background-color);
Expand Down Expand Up @@ -142,6 +145,10 @@
--wp-ui-button-height: 24px;
}

.icon {
margin: var(--wp-ui-button-icon-margin);
}

/* Variants (`tone` + `variant`) overrides compared to default styles */

/* All outline buttons have a border */
Expand Down
Loading