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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Update Button types to allow for no children on iconOnly buttons #23735

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions code/ui/components/src/new/Button/Button.tsx
Expand Up @@ -4,18 +4,30 @@ import { styled } from '@storybook/theming';
import { darken, lighten, rgba, transparentize } from 'polished';
import type { PropsOf } from '../utils/types';

export interface ButtonProps<T extends React.ElementType = React.ElementType> {
interface CommonProps<T extends React.ElementType = React.ElementType> {
as?: T;
children: string;
size?: 'small' | 'medium';
variant?: 'primary' | 'secondary' | 'tertiary';
icon?: ReactNode;
iconOnly?: boolean;
onClick?: () => void;
disabled?: boolean;
active?: boolean;
}

type ButtonIconOnlyProps = {
iconOnly: true;
icon: ReactNode;
children?: never;
};

type ButtonWithTextProps = {
iconOnly?: false;
icon?: ReactNode;
children: string;
};

type ButtonProps<T extends React.ElementType = React.ElementType> = CommonProps<T> &
(ButtonIconOnlyProps | ButtonWithTextProps);

export const Button: {
<E extends React.ElementType = 'button'>(
props: ButtonProps<E> & Omit<PropsOf<E>, keyof ButtonProps>
Expand Down