2024-02-09 22:16:00 +03:00
|
|
|
import React, { forwardRef } from 'react';
|
|
|
|
import {
|
|
|
|
SegmentedButton,
|
|
|
|
SegmentedButtonsProps,
|
|
|
|
} from './segmented-buttons.types';
|
|
|
|
import { string } from 'prop-types';
|
|
|
|
import { ButtonLayout } from '../../components';
|
|
|
|
import { ButtonLayoutProps } from '../button-layout/button-layout.types';
|
|
|
|
import { IconWrapper } from '../../icon/icon-wrapper';
|
|
|
|
|
|
|
|
export const SegmentButton = forwardRef<
|
|
|
|
HTMLButtonElement,
|
|
|
|
ButtonLayoutProps & SegmentedButton
|
|
|
|
>(({ centralRipple = false, iconPlace = 'left', icon, ...props }, ref) => {
|
|
|
|
const classes = `m3-button-segment ${props.className ?? ''}`.trimEnd();
|
|
|
|
return (
|
|
|
|
<ButtonLayout
|
|
|
|
{...props}
|
|
|
|
centralRipple={centralRipple}
|
|
|
|
className={classes}
|
|
|
|
ref={ref}
|
|
|
|
>
|
|
|
|
<IconWrapper icon={icon} iconPlace={iconPlace}>
|
2024-02-09 22:25:46 +03:00
|
|
|
<span className={'label-large'}>{props.children}</span>
|
2024-02-09 22:16:00 +03:00
|
|
|
</IconWrapper>
|
|
|
|
<span className={'m3 m3-button-segment-state-layer'} />
|
|
|
|
</ButtonLayout>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
SegmentButton.propTypes = {
|
|
|
|
children: string,
|
|
|
|
};
|
2024-02-02 01:52:36 +03:00
|
|
|
|
|
|
|
export const SegmentedButtons = forwardRef<
|
|
|
|
HTMLDivElement,
|
2024-02-09 22:16:00 +03:00
|
|
|
SegmentedButtonsProps
|
2024-02-02 01:52:36 +03:00
|
|
|
>(({ children, ...props }, ref) => {
|
|
|
|
if (children.length <= 1) {
|
2024-02-02 13:39:02 +03:00
|
|
|
throw 'You must build segmented button with 2 or more buttton';
|
2024-02-02 01:52:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`m3 m3-segmented-buttons ${props.className ?? ''}`.trimEnd()}
|
|
|
|
ref={ref}
|
|
|
|
>
|
2024-02-09 22:16:00 +03:00
|
|
|
{children}
|
2024-02-02 01:52:36 +03:00
|
|
|
</div>
|
|
|
|
);
|
2024-02-08 11:49:46 +03:00
|
|
|
});
|