/* Copyright 2024 New Vector Ltd. Copyright 2022, 2023 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import classnames from "classnames"; import React, { HTMLAttributes } from "react"; import Heading from "../../typography/Heading"; import { SettingsHeader } from "../SettingsHeader"; export interface SettingsSectionProps extends HTMLAttributes { heading?: string | React.ReactNode; subHeading?: string | React.ReactNode; children?: React.ReactNode; legacy?: boolean; } function renderHeading(heading: string | React.ReactNode | undefined, legacy: boolean): React.ReactNode | undefined { switch (typeof heading) { case "string": return legacy ? ( {heading} ) : ( ); case "undefined": return undefined; default: return heading; } } /** * A section of settings content * A SettingsTab may contain one or more SettingsSections * Eg: * ``` * * * * // profile settings form * * * // account settings * * * * ``` */ export const SettingsSection: React.FC = ({ className, heading, subHeading, legacy = true, children, ...rest }) => (
{heading && (subHeading ? (
{renderHeading(heading, legacy)} {subHeading}
) : ( renderHeading(heading, legacy) ))} {legacy ?
{children}
: children}
);