@vertisanpro/flowbite-react
Version:
Non-Official React components built for Flowbite and Tailwind CSS
15 lines (14 loc) • 820 B
JavaScript
import { twMerge } from '@vertisanpro/tailwind-merge';
import React, { Children, cloneElement, useMemo } from 'react';
import { mergeDeep } from '../../helpers/merge-deep';
import { getTheme } from '../../theme-store';
export const ButtonGroup = ({ children, className, outline, pill, theme: customTheme = {}, ...props }) => {
const items = useMemo(() => Children.map(children, (child, index) => cloneElement(child, {
outline,
pill,
positionInGroup: index === 0 ? 'start' : index === children.length - 1 ? 'end' : 'middle',
})), [children, outline, pill]);
const theme = mergeDeep(getTheme().buttonGroup, customTheme);
return (React.createElement("div", { className: twMerge(theme.base, className), role: "group", ...props }, items));
};
ButtonGroup.displayName = 'Button.Group';