2025-02-19 17:31:33 -08:00
|
|
|
// Copyright 2025 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2025-04-10 12:32:36 -07:00
|
|
|
import type { ForwardedRef, MouseEvent, ReactNode } from 'react';
|
|
|
|
import React, { forwardRef } from 'react';
|
|
|
|
import {
|
|
|
|
mergeProps,
|
|
|
|
type PressEvent,
|
|
|
|
useLongPress,
|
|
|
|
usePress,
|
|
|
|
} from 'react-aria';
|
|
|
|
import type { LongPressEvent } from '@react-types/shared';
|
2025-02-19 17:31:33 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Button
|
|
|
|
*/
|
|
|
|
|
2025-04-10 12:32:36 -07:00
|
|
|
export type FunItemButtonLongPressProps = Readonly<
|
|
|
|
| {
|
|
|
|
longPressAccessibilityDescription?: never;
|
|
|
|
onLongPress?: never;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
longPressAccessibilityDescription: string;
|
|
|
|
onLongPress: (event: LongPressEvent) => void;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
|
|
|
export type FunItemButtonProps = Readonly<
|
|
|
|
{
|
|
|
|
'aria-label': string;
|
|
|
|
tabIndex: number;
|
|
|
|
onPress: (event: PressEvent) => void;
|
|
|
|
onContextMenu?: (event: MouseEvent) => void;
|
|
|
|
children: ReactNode;
|
|
|
|
} & FunItemButtonLongPressProps
|
|
|
|
>;
|
|
|
|
|
|
|
|
export const FunItemButton = forwardRef(function FunItemButton(
|
|
|
|
props: FunItemButtonProps,
|
|
|
|
ref: ForwardedRef<HTMLButtonElement>
|
|
|
|
): JSX.Element {
|
|
|
|
const { pressProps } = usePress({
|
|
|
|
onPress: props.onPress,
|
|
|
|
});
|
|
|
|
|
|
|
|
const { longPressProps } = useLongPress({
|
|
|
|
isDisabled: props.onLongPress == null,
|
|
|
|
accessibilityDescription: props.longPressAccessibilityDescription,
|
|
|
|
onLongPress: props.onLongPress,
|
|
|
|
});
|
2025-02-19 17:31:33 -08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
2025-04-10 12:32:36 -07:00
|
|
|
ref={ref}
|
2025-02-19 17:31:33 -08:00
|
|
|
type="button"
|
|
|
|
className="FunItem__Button"
|
|
|
|
aria-label={props['aria-label']}
|
|
|
|
tabIndex={props.tabIndex}
|
2025-04-10 12:32:36 -07:00
|
|
|
{...mergeProps(pressProps, longPressProps)}
|
|
|
|
onContextMenu={props.onContextMenu}
|
2025-02-19 17:31:33 -08:00
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
</button>
|
|
|
|
);
|
2025-04-10 12:32:36 -07:00
|
|
|
});
|