Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions packages/ui/src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import resetStyles from '../utils/css/resets.module.css';
import focusStyles from '../utils/css/focus.module.css';
import defenseStyles from '../utils/css/global-css-defense.module.css';

/**
* A versatile button component with multiple variants, tones, and sizes.
* Built on design tokens for consistent theming and accessibility.
Comment thread
mirka marked this conversation as resolved.
Resolved
*/
export const Button = forwardRef< HTMLButtonElement, ButtonProps >(
function Button(
{
Expand Down
9 changes: 1 addition & 8 deletions packages/ui/src/button/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { forwardRef } from '@wordpress/element';
import { type IconProps } from '../icon/types';
import { type ButtonIconProps } from './types';
import { Icon } from '../icon';

interface ButtonIconProps extends IconProps {
/**
* The icon to display, from the `@wordpress/icons` package.
*/
icon: IconProps[ 'icon' ];
}

export const ButtonIcon = forwardRef< SVGSVGElement, ButtonIconProps >(
function ButtonIcon( { icon, ...props }, ref ) {
return (
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/button/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Button as ButtonButton } from './button';
import { Button as _Button } from './button';
import { ButtonIcon } from './icon';

ButtonIcon.displayName = 'Button.Icon';

/**
* A versatile button component with multiple variants, tones, and sizes.
* Built on design tokens for consistent theming and accessibility.
*/
export const Button = Object.assign( ButtonButton, {
export const Button = Object.assign( _Button, {
/**
* An icon component specifically designed to work well when rendered inside
* a `Button` component.
*/
Icon: ButtonIcon,
} ) as typeof ButtonButton & {
Icon: typeof ButtonIcon;
};
Comment on lines -14 to -16

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Apparently this cast was only needed because the ButtonIconProps type wasn't colocated in the main types file.

} );
3 changes: 3 additions & 0 deletions packages/ui/src/button/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Button } from '../index';
const meta: Meta< typeof Button > = {
title: 'Design System/Components/Button',
component: Button,
subcomponents: {
Icon: Button.Icon,
},
argTypes: {
'aria-pressed': {
control: { type: 'boolean' },
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/src/button/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type ReactNode, type HTMLAttributes } from 'react';
import type { Button as _Button } from '@base-ui/react/button';
import { type IconProps } from '../icon/types';
import type { ComponentProps } from '../utils/types';

type _ButtonProps = ComponentProps< typeof _Button >;
Expand Down Expand Up @@ -70,3 +71,10 @@ export interface ButtonProps
*/
loadingAnnouncement?: string;
}

export interface ButtonIconProps extends IconProps {
/**
* The icon to display, from the `@wordpress/icons` package.
*/
icon: IconProps[ 'icon' ];
}
Loading