Use semantic headings in user settings Labs (#10773)
* allow testids in settings sections * use semantic headings in LabsUserSettingsTab * put back margin var * explicit cast to boolean * Update src/components/views/settings/shared/SettingsSubsection.tsx Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
38c13509fd
commit
9bab356e20
10 changed files with 164 additions and 156 deletions
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import classNames from "classnames";
|
||||
import React, { HTMLAttributes } from "react";
|
||||
|
||||
import { SettingsSubsectionHeading } from "./SettingsSubsectionHeading";
|
||||
|
@ -22,6 +23,8 @@ export interface SettingsSubsectionProps extends HTMLAttributes<HTMLDivElement>
|
|||
heading: string | React.ReactNode;
|
||||
description?: string | React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
// when true content will be justify-items: stretch, which will make items within the section stretch to full width.
|
||||
stretchContent?: boolean;
|
||||
}
|
||||
|
||||
export const SettingsSubsectionText: React.FC<HTMLAttributes<HTMLDivElement>> = ({ children, ...rest }) => (
|
||||
|
@ -30,7 +33,13 @@ export const SettingsSubsectionText: React.FC<HTMLAttributes<HTMLDivElement>> =
|
|||
</div>
|
||||
);
|
||||
|
||||
export const SettingsSubsection: React.FC<SettingsSubsectionProps> = ({ heading, description, children, ...rest }) => (
|
||||
export const SettingsSubsection: React.FC<SettingsSubsectionProps> = ({
|
||||
heading,
|
||||
description,
|
||||
children,
|
||||
stretchContent,
|
||||
...rest
|
||||
}) => (
|
||||
<div {...rest} className="mx_SettingsSubsection">
|
||||
{typeof heading === "string" ? <SettingsSubsectionHeading heading={heading} /> : <>{heading}</>}
|
||||
{!!description && (
|
||||
|
@ -38,7 +47,13 @@ export const SettingsSubsection: React.FC<SettingsSubsectionProps> = ({ heading,
|
|||
<SettingsSubsectionText>{description}</SettingsSubsectionText>
|
||||
</div>
|
||||
)}
|
||||
<div className="mx_SettingsSubsection_content">{children}</div>
|
||||
<div
|
||||
className={classNames("mx_SettingsSubsection_content", {
|
||||
mx_SettingsSubsection_contentStretch: !!stretchContent,
|
||||
})}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ 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.
|
||||
*/
|
||||
import React from "react";
|
||||
import React, { HTMLAttributes } from "react";
|
||||
|
||||
export interface SettingsTabProps {
|
||||
export interface SettingsTabProps extends Omit<HTMLAttributes<HTMLDivElement>, "className"> {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,8 @@ export interface SettingsTabProps {
|
|||
* </SettingsTab>
|
||||
* ```
|
||||
*/
|
||||
const SettingsTab: React.FC<SettingsTabProps> = ({ children }) => (
|
||||
<div className="mx_SettingsTab">
|
||||
const SettingsTab: React.FC<SettingsTabProps> = ({ children, ...rest }) => (
|
||||
<div {...rest} className="mx_SettingsTab">
|
||||
<div className="mx_SettingsTab_sections">{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -25,6 +25,9 @@ import BetaCard from "../../../beta/BetaCard";
|
|||
import SettingsFlag from "../../../elements/SettingsFlag";
|
||||
import { LabGroup, labGroupNames } from "../../../../../settings/Settings";
|
||||
import { EnhancedMap } from "../../../../../utils/maps";
|
||||
import { SettingsSection } from "../../shared/SettingsSection";
|
||||
import SettingsSubsection, { SettingsSubsectionText } from "../../shared/SettingsSubsection";
|
||||
import SettingsTab from "../SettingsTab";
|
||||
|
||||
export default class LabsUserSettingsTab extends React.Component<{}> {
|
||||
private readonly labs: string[];
|
||||
|
@ -54,11 +57,11 @@ export default class LabsUserSettingsTab extends React.Component<{}> {
|
|||
let betaSection: JSX.Element | undefined;
|
||||
if (this.betas.length) {
|
||||
betaSection = (
|
||||
<div data-testid="labs-beta-section" className="mx_SettingsTab_section">
|
||||
<>
|
||||
{this.betas.map((f) => (
|
||||
<BetaCard key={f} featureId={f} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -93,31 +96,35 @@ export default class LabsUserSettingsTab extends React.Component<{}> {
|
|||
labsSections = (
|
||||
<>
|
||||
{sortBy(Array.from(groups.entries()), "0").map(([group, flags]) => (
|
||||
<div className="mx_SettingsTab_section" key={group} data-testid={`labs-group-${group}`}>
|
||||
<span className="mx_SettingsTab_subheading">{_t(labGroupNames[group])}</span>
|
||||
<SettingsSubsection
|
||||
key={group}
|
||||
data-testid={`labs-group-${group}`}
|
||||
heading={_t(labGroupNames[group])}
|
||||
>
|
||||
{flags}
|
||||
</div>
|
||||
</SettingsSubsection>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx_SettingsTab mx_LabsUserSettingsTab">
|
||||
<div className="mx_SettingsTab_heading">{_t("Upcoming features")}</div>
|
||||
<div className="mx_SettingsTab_subsectionText">
|
||||
{_t(
|
||||
"What's next for %(brand)s? " +
|
||||
"Labs are the best way to get things early, " +
|
||||
"test out new features and help shape them before they actually launch.",
|
||||
{ brand: SdkConfig.get("brand") },
|
||||
)}
|
||||
</div>
|
||||
{betaSection}
|
||||
<SettingsTab>
|
||||
<SettingsSection heading={_t("Upcoming features")}>
|
||||
<SettingsSubsectionText>
|
||||
{_t(
|
||||
"What's next for %(brand)s? " +
|
||||
"Labs are the best way to get things early, " +
|
||||
"test out new features and help shape them before they actually launch.",
|
||||
{ brand: SdkConfig.get("brand") },
|
||||
)}
|
||||
</SettingsSubsectionText>
|
||||
{betaSection}
|
||||
</SettingsSection>
|
||||
|
||||
{labsSections && (
|
||||
<>
|
||||
<div className="mx_SettingsTab_heading">{_t("Early previews")}</div>
|
||||
<div className="mx_SettingsTab_subsectionText">
|
||||
<SettingsSection heading={_t("Early previews")}>
|
||||
<SettingsSubsectionText>
|
||||
{_t(
|
||||
"Feeling experimental? " +
|
||||
"Try out our latest ideas in development. " +
|
||||
|
@ -139,11 +146,11 @@ export default class LabsUserSettingsTab extends React.Component<{}> {
|
|||
},
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
</SettingsSubsectionText>
|
||||
{labsSections}
|
||||
</>
|
||||
</SettingsSection>
|
||||
)}
|
||||
</div>
|
||||
</SettingsTab>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue