mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-02 16:48:50 +01:00
If you've got a screen reader that is reading out the whole page, each icon button (i.e., `<button><SVG></button>`) will have both the button's aria-label read out as well as the title from the SVG (which is usually just "image"). Since we are pretty good about setting aria-labels, we should instead use `aria-hidden="true"` on these images, since they are not useful to be read out. I don't consider this a comprehensive review of all icons in the app, but I knocked out all the low hanging fruit in this commit.
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { forwardRef } from 'react';
|
|
import { CheckIcon } from 'lucide-react';
|
|
import { Spinner, DialogButton, InfoHoverCard, ESide } from '@librechat/client';
|
|
import type { TDangerButtonProps } from '~/common';
|
|
import type { ForwardedRef } from 'react';
|
|
import { useLocalize } from '~/hooks';
|
|
import { cn } from '~/utils';
|
|
|
|
const DangerButton = (props: TDangerButtonProps, ref: ForwardedRef<HTMLButtonElement>) => {
|
|
const {
|
|
id,
|
|
onClick,
|
|
mutation,
|
|
disabled,
|
|
confirmClear,
|
|
infoTextCode,
|
|
actionTextCode,
|
|
className = '',
|
|
showText = true,
|
|
dataTestIdInitial,
|
|
dataTestIdConfirm,
|
|
infoDescriptionCode,
|
|
confirmActionTextCode = 'com_ui_confirm_action',
|
|
} = props;
|
|
const localize = useLocalize();
|
|
|
|
const renderMutation = (node: React.ReactNode | string) => {
|
|
if (mutation && mutation.isLoading) {
|
|
return <Spinner className="h-5 w-5" />;
|
|
}
|
|
return node;
|
|
};
|
|
|
|
return (
|
|
<div className="flex items-center justify-between">
|
|
{showText && (
|
|
<div className={`flex items-center ${infoDescriptionCode ? 'space-x-2' : ''}`}>
|
|
<div>{localize(infoTextCode)}</div>
|
|
{infoDescriptionCode && <InfoHoverCard side={ESide.Bottom} text={infoDescriptionCode} />}
|
|
</div>
|
|
)}
|
|
<DialogButton
|
|
id={id}
|
|
ref={ref}
|
|
disabled={disabled}
|
|
onClick={onClick}
|
|
className={cn(
|
|
'btn relative border-none bg-red-500 text-white hover:bg-red-700 dark:hover:bg-red-700',
|
|
className,
|
|
)}
|
|
>
|
|
{confirmClear ? (
|
|
<div
|
|
className="flex w-full items-center justify-center gap-2"
|
|
id={`${id}-text`}
|
|
data-testid={dataTestIdConfirm}
|
|
>
|
|
{renderMutation(<CheckIcon className="h-5 w-5" aria-hidden="true" />)}
|
|
{mutation && mutation.isLoading ? null : localize(confirmActionTextCode)}
|
|
</div>
|
|
) : (
|
|
<div
|
|
className="flex w-full items-center justify-center gap-2"
|
|
id={`${id}-text`}
|
|
data-testid={dataTestIdInitial}
|
|
>
|
|
{renderMutation(localize(actionTextCode))}
|
|
</div>
|
|
)}
|
|
</DialogButton>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default forwardRef(DangerButton);
|