import { Group, GroupProps } from "../../Layout/Group";
import { ButtonContext } from "../Button/Button.context";
import { CanHaveIcon } from "../../../types";
import { ButtonProps } from "@components/Internal/BaseButton";
type MinimalGroupProps = Omit<
GroupProps,
| "onBlur"
| "onFocus"
| "onMouseEnter"
| "onMouseLeave"
| "onKeyDown"
| "onKeyUp"
>;
type MinimalButtonProps = Omit<
ButtonProps,
"as" | "children" | "className" | "slot" | "style"
>;
export interface ButtonGroupProps
extends MinimalButtonProps,
MinimalGroupProps,
CanHaveIcon {}
/** Group a set of buttoons together & provide a common context to all buttons in the group
*
* @example
*
*
*
*
*/
export function ButtonGroup(props: ButtonGroupProps) {
const { children, isMerged, className, id, ...rest } = props;
const { buttonProps, groupProps } = partitionProps(rest);
return (
{children}
);
}
function partitionProps(props: Record) {
const buttonProps: Record = {};
const groupProps: Record = {};
for (const key in props) {
if (!key) continue;
if (!(typeof key === "string")) continue;
if (key.startsWith("$")) {
groupProps[key] = props[key];
} else {
buttonProps[key] = props[key];
}
}
return {
buttonProps: buttonProps as MinimalButtonProps,
groupProps: groupProps as MinimalGroupProps,
};
}