'use client'; import { string } from 'prop-types'; import React, { forwardRef, useState } from 'react'; import { IconWrapper } from '../../icon/icon-wrapper'; import { Typography } from '../../typography/typography'; import { SegmentedButton } from './segmented-buttons.types'; import { ButtonLayout } from '../button-layout/button-layout'; import { ButtonLayoutProps } from '../button-layout/button-layout.types'; import { Icon } from '../../components'; /** * Segment button */ export const SegmentButton = forwardRef< HTMLButtonElement, ButtonLayoutProps & SegmentedButton >( ( { type, icon, grade, weight, svgSize, fillIcon, children, iconSize, opticalSize, selectable = false, iconPlace = 'left', centralRipple = false, ...props }, ref, ) => { const [selectedState, setSelectedState] = useState(false); const classes = `m3-button-segment${selectedState ? ' selected' : ''} ${props.className ?? ''}`.trimEnd(); const ButtonLabel = ( {children} ); const iconProps = { grade: grade, fillIcon: fillIcon, iconSize: iconSize, opticalSize: opticalSize, svgSize: svgSize, type: type, weight: weight, }; return ( { if (selectable) { setSelectedState(state => !state); } props.onClick?.apply(this, props.onClick.arguments); }} ref={ref} > {ButtonLabel} {icon && selectable && {icon}} {ButtonLabel} ); }, ); SegmentButton.propTypes = { children: string, };