Skip to content

Commit

Permalink
Hoist ButtonGroup's size prop (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Jan 3, 2024
1 parent 9ec8efc commit 8f6dfee
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-pugs-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': minor
---

Deprecated the ButtonGroup's `actions.[primary|secondary].size` prop. Use the top-level `size` prop instead.
58 changes: 45 additions & 13 deletions packages/circuit-ui/components/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ import { forwardRef, HTMLAttributes } from 'react';

import Button, { ButtonProps } from '../Button/index.js';
import { clsx } from '../../styles/clsx.js';
import { deprecate } from '../../util/logger.js';

import styles from './ButtonGroup.module.css';

type Action = Omit<ButtonProps, 'variant'>;
type Action = Omit<ButtonProps, 'variant' | 'size'> & {
/**
* @deprecated
*/
size?: ButtonProps['size'];
};

export interface ButtonGroupProps
extends Omit<HTMLAttributes<HTMLDivElement>, 'align'> {
Expand All @@ -35,29 +41,55 @@ export interface ButtonGroupProps
* Direction to align the buttons. Defaults to `center`.
*/
align?: 'left' | 'center' | 'right';
/**
* Choose from 2 sizes. Default: 'm'.
*/
size?: ButtonProps['size'];
}

/**
* The ButtonGroup component groups and formats two buttons.
*/
export const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>(
(
{ actions, className, align = 'center', ...props }: ButtonGroupProps,
{ actions, className, align = 'center', size, ...props }: ButtonGroupProps,
ref,
) => (
<div {...props} className={clsx(styles.container, className)} ref={ref}>
<div className={clsx(styles.base, styles[align])}>
<Button {...actions.primary} variant="primary" />
{actions.secondary && (
) => {
if (process.env.NODE_ENV !== 'production') {
if (actions.primary.size) {
deprecate(
'ButtonGroup',
'The `actions.primary.size` prop has been deprecated. Use the top-level `size` prop instead.',
);
}
if (actions.secondary?.size) {
deprecate(
'ButtonGroup',
'The `actions.secondary.size` prop has been deprecated. Use the top-level `size` prop instead.',
);
}
}

return (
<div {...props} className={clsx(styles.container, className)} ref={ref}>
<div className={clsx(styles.base, styles[align])}>
<Button
{...actions.secondary}
className={clsx(styles.secondary, actions.secondary.className)}
variant="tertiary"
{...actions.primary}
size={size || actions.primary.size}
variant="primary"
/>
)}
{actions.secondary && (
<Button
{...actions.secondary}
size={size || actions.secondary.size}
className={clsx(styles.secondary, actions.secondary.className)}
variant="tertiary"
/>
)}
</div>
</div>
</div>
),
);
},
);

ButtonGroup.displayName = 'ButtonGroup';

0 comments on commit 8f6dfee

Please sign in to comment.