2021-11-16 12:33:01 +00:00
|
|
|
import { PropsWithChildren } from 'react';
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2021-11-21 09:39:26 +00:00
|
|
|
export type Size = 'xsmall' | 'small' | 'large';
|
2021-11-16 12:33:01 +00:00
|
|
|
export interface Props {
|
|
|
|
size?: Size;
|
2021-11-21 09:39:26 +00:00
|
|
|
className?: string;
|
2023-09-21 02:31:00 +00:00
|
|
|
'aria-label'?: string;
|
2021-11-16 12:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function ButtonGroup({
|
|
|
|
size = 'small',
|
|
|
|
children,
|
2021-11-21 09:39:26 +00:00
|
|
|
className,
|
2023-09-21 02:31:00 +00:00
|
|
|
'aria-label': ariaLabel,
|
2021-11-16 12:33:01 +00:00
|
|
|
}: PropsWithChildren<Props>) {
|
|
|
|
return (
|
2023-09-21 02:31:00 +00:00
|
|
|
<div
|
|
|
|
className={clsx('btn-group', sizeClass(size), className)}
|
|
|
|
role="group"
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
>
|
2021-11-16 12:33:01 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sizeClass(size: Size | undefined) {
|
|
|
|
switch (size) {
|
2023-02-22 20:13:33 +00:00
|
|
|
case 'small':
|
|
|
|
return 'btn-group-sm';
|
2021-11-16 12:33:01 +00:00
|
|
|
case 'xsmall':
|
|
|
|
return 'btn-group-xs';
|
|
|
|
case 'large':
|
|
|
|
return 'btn-group-lg';
|
|
|
|
default:
|
2022-01-04 12:16:09 +00:00
|
|
|
return '';
|
2021-11-16 12:33:01 +00:00
|
|
|
}
|
|
|
|
}
|