2021-12-21 09:37:06 +00:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2021-12-21 09:37:06 +00:00
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-12-21 09:37:06 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-06-25 16:59:07 +01:00
|
|
|
import React, { useContext } from "react";
|
2022-01-31 16:05:05 +00:00
|
|
|
import classNames from "classnames";
|
2021-12-21 09:37:06 +00:00
|
|
|
|
2024-06-25 16:59:07 +01:00
|
|
|
import AccessibleButton, { ButtonProps } from "../elements/AccessibleButton";
|
2022-01-31 16:05:05 +00:00
|
|
|
import { OverflowMenuContext } from "./MessageComposerButtons";
|
2022-05-04 17:22:09 +02:00
|
|
|
import { IconizedContextMenuOption } from "../context_menus/IconizedContextMenu";
|
2023-12-21 08:50:42 +00:00
|
|
|
import { Ref } from "../../../accessibility/roving/types";
|
2021-12-21 09:37:06 +00:00
|
|
|
|
2024-06-25 16:59:07 +01:00
|
|
|
interface Props extends Omit<ButtonProps<"div">, "element"> {
|
2023-12-21 08:50:42 +00:00
|
|
|
inputRef?: Ref;
|
2021-12-21 09:37:06 +00:00
|
|
|
title: string;
|
2022-05-04 17:22:09 +02:00
|
|
|
iconClassName: string;
|
2021-12-21 09:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-21 08:50:42 +00:00
|
|
|
export const CollapsibleButton: React.FC<Props> = ({
|
2023-01-12 13:25:14 +00:00
|
|
|
title,
|
|
|
|
|
children,
|
|
|
|
|
className,
|
|
|
|
|
iconClassName,
|
2023-12-21 08:50:42 +00:00
|
|
|
inputRef,
|
2023-01-12 13:25:14 +00:00
|
|
|
...props
|
|
|
|
|
}) => {
|
2022-01-31 16:05:05 +00:00
|
|
|
const inOverflowMenu = !!useContext(OverflowMenuContext);
|
|
|
|
|
if (inOverflowMenu) {
|
2023-12-21 08:50:42 +00:00
|
|
|
return <IconizedContextMenuOption {...props} iconClassName={iconClassName} label={title} inputRef={inputRef} />;
|
2022-01-31 16:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 09:30:53 +00:00
|
|
|
return (
|
2024-05-07 12:20:46 +02:00
|
|
|
<AccessibleButton {...props} title={title} className={classNames(className, iconClassName)} ref={inputRef}>
|
2022-02-02 09:30:53 +00:00
|
|
|
{children}
|
2024-05-07 12:20:46 +02:00
|
|
|
</AccessibleButton>
|
2022-02-02 09:30:53 +00:00
|
|
|
);
|
2021-12-21 09:37:06 +00:00
|
|
|
};
|