material-you-react/src/primitive-components/button-components/fab/fab.tsx

60 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-02-01 00:58:19 +03:00
'use client';
import { forwardRef } from 'react';
import { Icon } from '../../components';
2024-02-01 15:23:59 +03:00
import { FABProps } from './fab.types';
2024-02-02 13:39:02 +03:00
import { bool, oneOf, string } from 'prop-types';
2024-02-01 00:58:19 +03:00
import { ButtonLayout } from '../button-layout/button-layout';
/**
* FABs component
** description
*/
const sizes = {
small: 24,
default: 24,
large: 36,
extended: 24,
};
2024-02-01 15:23:59 +03:00
export const FAB = forwardRef<HTMLButtonElement, FABProps>(
2024-02-01 00:58:19 +03:00
(
{
2024-02-02 13:39:02 +03:00
icon = 'edit',
className = '',
2024-02-01 00:58:19 +03:00
size = 'default',
2024-02-02 13:39:02 +03:00
elevated = false,
disabled = false,
variant = 'surface',
centralRipple = false,
2024-02-01 00:58:19 +03:00
...props
},
ref,
) => (
<ButtonLayout
{...props}
centralRipple={centralRipple}
2024-02-02 13:39:02 +03:00
className={`m3-fab m3-${size}-fab${!elevated ? ' without-elevation' : ''} ${variant} ${className}`}
2024-02-01 00:58:19 +03:00
disabled={disabled}
ref={ref}
>
<Icon iconSize={sizes[size]} svgSize={sizes[size]}>
{icon}
</Icon>
{size === 'extended' ? (
<span className={'label-large'}>{props.children}</span>
) : (
<></>
)}
</ButtonLayout>
),
);
2024-02-02 13:39:02 +03:00
FAB.propTypes = {
icon: string,
elevated: bool,
size: oneOf(['small', 'default', 'large', 'extended']),
variant: oneOf(['surface', 'primary', 'secondary', 'tertiary']),
};