2021-12-21 09:37:06 +00:00
|
|
|
/*
|
|
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-01-31 16:05:05 +00:00
|
|
|
import React, { ComponentProps, useContext } from "react";
|
|
|
|
|
import classNames from "classnames";
|
2021-12-21 09:37:06 +00:00
|
|
|
|
2023-12-21 08:50:42 +00:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2021-12-21 09:37:06 +00:00
|
|
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
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
|
|
|
|
2023-12-21 08:50:42 +00:00
|
|
|
interface Props extends Omit<ComponentProps<typeof AccessibleButton>, "element"> {
|
|
|
|
|
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 (
|
2023-12-21 08:50:42 +00:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
|
{...props}
|
|
|
|
|
title={title}
|
|
|
|
|
className={classNames(className, iconClassName)}
|
|
|
|
|
ref={inputRef}
|
|
|
|
|
>
|
2022-02-02 09:30:53 +00:00
|
|
|
{children}
|
|
|
|
|
</AccessibleTooltipButton>
|
|
|
|
|
);
|
2021-12-21 09:37:06 +00:00
|
|
|
};
|