2024-02-01 00:58:19 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
import { bool, string } from 'prop-types';
|
2024-02-01 00:58:19 +03:00
|
|
|
import { RippleArea } from '../ripple/ripple-area';
|
2024-02-01 15:23:59 +03:00
|
|
|
import { ButtonLayoutProps } from './button-layout.types';
|
2024-02-01 00:58:19 +03:00
|
|
|
import useRippleEffect from '../ripple/hooks/useRippleEffect';
|
2024-02-01 15:23:59 +03:00
|
|
|
import React, { forwardRef, useId, useRef, useState } from 'react';
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
export const ButtonLayout = forwardRef<HTMLButtonElement, ButtonLayoutProps>(
|
|
|
|
function ButtonBase({ centralRipple = false, ...props }, ref) {
|
|
|
|
const [isActive, setIsActive] = useState<boolean>(false),
|
|
|
|
ripplesRef = useRef(null),
|
|
|
|
buttonId = useId(),
|
|
|
|
events = useRippleEffect(ripplesRef, setIsActive);
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
const { variant, disabled, className } = props;
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
const classes = className
|
|
|
|
? `m3 ${className} ${variant}${isActive ? ' is-active' : ''}`
|
|
|
|
: `m3 ${variant}${isActive ? ' is-active' : ''}`;
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
{...props}
|
|
|
|
{...events}
|
|
|
|
className={classes}
|
|
|
|
disabled={disabled}
|
|
|
|
id={buttonId}
|
|
|
|
ref={ref}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
<RippleArea
|
|
|
|
callback={setIsActive}
|
|
|
|
central={centralRipple}
|
|
|
|
ref={ripplesRef}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2024-02-01 00:58:19 +03:00
|
|
|
|
2024-02-01 15:23:59 +03:00
|
|
|
ButtonLayout.propTypes = {
|
|
|
|
centralRipple: bool,
|
|
|
|
children: string,
|
|
|
|
};
|