Make the encryption card more configurable:

- Change the icon
- Can set the destructive props
florianduros/advanced-section
Florian Duros 2024-12-23 14:58:07 +01:00
parent 1c00502e6b
commit d9b27306c9
No known key found for this signature in database
GPG Key ID: A5BBB4041B493F15
3 changed files with 24 additions and 8 deletions

View File

@ -18,6 +18,7 @@ import {
TextControl, TextControl,
} from "@vector-im/compound-web"; } from "@vector-im/compound-web";
import CopyIcon from "@vector-im/compound-design-tokens/assets/web/icons/copy"; import CopyIcon from "@vector-im/compound-design-tokens/assets/web/icons/copy";
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key-solid";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../../languageHandler"; import { _t } from "../../../../languageHandler";
@ -132,7 +133,12 @@ export function ChangeRecoveryKey({
pages={pages} pages={pages}
onPageClick={onCancelClick} onPageClick={onCancelClick}
/> />
<EncryptionCard title={labels.title} description={labels.description} className="mx_ChangeRecoveryKey"> <EncryptionCard
Icon={KeyIcon}
title={labels.title}
description={labels.description}
className="mx_ChangeRecoveryKey"
>
{content} {content}
</EncryptionCard> </EncryptionCard>
</> </>

View File

@ -5,9 +5,8 @@
* Please see LICENSE files in the repository root for full details. * Please see LICENSE files in the repository root for full details.
*/ */
import React, { JSX, PropsWithChildren } from "react"; import React, { JSX, PropsWithChildren, ComponentType, SVGAttributes } from "react";
import { BigIcon, Heading } from "@vector-im/compound-web"; import { BigIcon, Heading } from "@vector-im/compound-web";
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key-solid";
import classNames from "classnames"; import classNames from "classnames";
interface EncryptionCardProps { interface EncryptionCardProps {
@ -22,7 +21,15 @@ interface EncryptionCardProps {
/** /**
* The description of the card. * The description of the card.
*/ */
description: string; description?: string;
/**
* Whether this icon shows a destructive action.
*/
destructive?: boolean;
/**
* The icon to display.
*/
Icon: ComponentType<SVGAttributes<SVGElement>>;
} }
/** /**
@ -32,18 +39,20 @@ export function EncryptionCard({
title, title,
description, description,
className, className,
destructive = false,
Icon,
children, children,
}: PropsWithChildren<EncryptionCardProps>): JSX.Element { }: PropsWithChildren<EncryptionCardProps>): JSX.Element {
return ( return (
<div className={classNames("mx_EncryptionCard", className)}> <div className={classNames("mx_EncryptionCard", className)}>
<div className="mx_EncryptionCard_header"> <div className="mx_EncryptionCard_header">
<BigIcon> <BigIcon destructive={destructive}>
<KeyIcon /> <Icon />
</BigIcon> </BigIcon>
<Heading as="h2" size="sm" weight="semibold"> <Heading as="h2" size="sm" weight="semibold">
{title} {title}
</Heading> </Heading>
<span>{description}</span> {description && <span>{description}</span>}
</div> </div>
{children} {children}
</div> </div>

View File

@ -7,13 +7,14 @@
import React from "react"; import React from "react";
import { render } from "jest-matrix-react"; import { render } from "jest-matrix-react";
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key-solid";
import { EncryptionCard } from "../../../../../../src/components/views/settings/encryption/EncryptionCard"; import { EncryptionCard } from "../../../../../../src/components/views/settings/encryption/EncryptionCard";
describe("<EncryptionCard />", () => { describe("<EncryptionCard />", () => {
it("should render", () => { it("should render", () => {
const { asFragment } = render( const { asFragment } = render(
<EncryptionCard title="My title" description="My description"> <EncryptionCard Icon={KeyIcon} title="My title" description="My description">
Encryption card children Encryption card children
</EncryptionCard>, </EncryptionCard>,
); );