2022-04-02 16:43:34 -07:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import React from 'react';
|
|
|
|
|
2022-04-07 11:47:06 -07:00
|
|
|
import { Text, Icon } from 'soapbox/components/ui';
|
2022-04-02 16:43:34 -07:00
|
|
|
import { shortNumberFormat } from 'soapbox/utils/numbers';
|
|
|
|
|
|
|
|
const COLORS = {
|
2022-04-02 18:14:46 -07:00
|
|
|
accent: 'accent',
|
|
|
|
success: 'success',
|
2022-04-02 16:43:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
type Color = keyof typeof COLORS;
|
|
|
|
|
|
|
|
interface IStatusActionCounter {
|
|
|
|
count: number,
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Action button numerical counter, eg "5" likes */
|
|
|
|
const StatusActionCounter: React.FC<IStatusActionCounter> = ({ count = 0 }): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<Text size='xs' weight='semibold' theme='inherit'>
|
|
|
|
{shortNumberFormat(count)}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IStatusActionButton extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
|
iconClassName?: string,
|
|
|
|
icon: string,
|
|
|
|
count?: number,
|
|
|
|
active?: boolean,
|
|
|
|
color?: Color,
|
2022-04-02 18:14:46 -07:00
|
|
|
filled?: boolean,
|
2022-04-02 16:43:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const StatusActionButton = React.forwardRef((props: IStatusActionButton, ref: React.ForwardedRef<HTMLButtonElement>): JSX.Element => {
|
2022-04-02 18:14:46 -07:00
|
|
|
const { icon, className, iconClassName, active, color, filled = false, count = 0, ...filteredProps } = props;
|
2022-04-02 16:43:34 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
ref={ref}
|
|
|
|
type='button'
|
|
|
|
className={classNames(
|
2022-04-20 14:48:17 -07:00
|
|
|
'flex items-center p-1 space-x-0.5 rounded-full',
|
2022-04-02 16:43:34 -07:00
|
|
|
'text-gray-400 hover:text-gray-600 dark:hover:text-white',
|
|
|
|
'bg-white dark:bg-transparent',
|
2022-04-20 14:48:17 -07:00
|
|
|
'focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 dark:ring-offset-0',
|
2022-04-02 16:43:34 -07:00
|
|
|
{
|
2022-04-02 18:14:46 -07:00
|
|
|
'text-accent-300 hover:text-accent-300 dark:hover:text-accent-300': active && color === COLORS.accent,
|
|
|
|
'text-success-600 hover:text-success-600 dark:hover:text-success-600': active && color === COLORS.success,
|
2022-04-02 16:43:34 -07:00
|
|
|
},
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
{...filteredProps}
|
|
|
|
>
|
2022-04-07 11:47:06 -07:00
|
|
|
<Icon
|
2022-04-02 16:43:34 -07:00
|
|
|
src={icon}
|
|
|
|
className={classNames(
|
2022-04-07 11:47:06 -07:00
|
|
|
'rounded-full',
|
2022-04-02 16:43:34 -07:00
|
|
|
{
|
2022-04-02 18:14:46 -07:00
|
|
|
'fill-accent-300 hover:fill-accent-300': active && filled && color === COLORS.accent,
|
2022-04-02 16:43:34 -07:00
|
|
|
},
|
|
|
|
iconClassName,
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{(count || null) && (
|
|
|
|
<StatusActionCounter count={count} />
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default StatusActionButton;
|