'use client'; import { SegmentButton } from './segment-button'; import { SegmentedButtonsProps } from './segmented-buttons.types'; import React, { cloneElement, forwardRef, ReactElement } from 'react'; export const SegmentedButtons = forwardRef< HTMLDivElement, SegmentedButtonsProps >(({ toggled = false, children, ...props }, ref) => { if (children.length <= 1) { throw 'You must build segmented button with 2 or more button'; } const SegmentedButtons: Array = children.map( (Button: ReactElement, index: number) => { return cloneElement(, { ...Button.props, toggled: Button.props.toggled ?? toggled, key: index, }); }, ); return (
{SegmentedButtons}
); });