Files
ThreadNet-Web/src/components/views/elements/JoinRuleDropdown.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.2 KiB
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2021 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
*/
2025-02-05 13:25:06 +00:00
import React, { type ReactElement } from "react";
import { JoinRule } from "matrix-js-sdk/src/matrix";
import Dropdown from "./Dropdown";
2025-02-05 13:25:06 +00:00
import { type NonEmptyArray } from "../../../@types/common";
2023-07-10 10:01:03 +02:00
import { Icon as AskToJoinIcon } from "../../../../res/img/element-icons/ask-to-join.svg";
interface IProps {
value: JoinRule;
label: string;
width?: number;
labelInvite: string;
2023-07-10 10:01:03 +02:00
labelKnock?: string;
labelPublic: string;
labelRestricted?: string; // if omitted then this option will be hidden, e.g if unsupported
onChange(value: JoinRule): void;
}
const JoinRuleDropdown: React.FC<IProps> = ({
label,
labelInvite,
2023-07-10 10:01:03 +02:00
labelKnock,
labelPublic,
labelRestricted,
value,
width = 448,
onChange,
}) => {
const options = [
<div key={JoinRule.Invite} className="mx_JoinRuleDropdown_invite">
{labelInvite}
</div>,
<div key={JoinRule.Public} className="mx_JoinRuleDropdown_public">
{labelPublic}
</div>,
] as NonEmptyArray<ReactElement & { key: string }>;
2023-07-10 10:01:03 +02:00
if (labelKnock) {
options.unshift(
(
<div key={JoinRule.Knock} className="mx_JoinRuleDropdown_knock">
<AskToJoinIcon className="mx_Icon mx_Icon_16 mx_JoinRuleDropdown_icon" />
{labelKnock}
</div>
) as ReactElement & { key: string },
);
}
if (labelRestricted) {
options.unshift(
(
<div key={JoinRule.Restricted} className="mx_JoinRuleDropdown_restricted">
{labelRestricted}
</div>
) as ReactElement & { key: string },
);
}
return (
<Dropdown
id="mx_JoinRuleDropdown"
className="mx_JoinRuleDropdown"
onOptionChange={onChange}
menuWidth={width}
value={value}
label={label}
>
{options}
</Dropdown>
);
};
export default JoinRuleDropdown;