Skip to content

Commit b7fea97

Browse files
authored
Factor out duplicated CSS for buttons in encryption settings (#29269)
* Factor out duplicated CSS for buttons in encryption settings By adding a component to hold the common CSS * Update snapshot * Update snapshot * More snapshots * Split EncryptionCardButtons out to separate component * Update imports
1 parent 90801eb commit b7fea97

File tree

9 files changed

+41
-30
lines changed

9 files changed

+41
-30
lines changed

res/css/views/settings/encryption/_ChangeRecoveryKey.pcss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,4 @@
6969
flex-direction: column;
7070
gap: var(--cpd-space-8x);
7171
}
72-
73-
.mx_ChangeRecoveryKey_footer {
74-
display: flex;
75-
flex-direction: column;
76-
gap: var(--cpd-space-4x);
77-
justify-content: center;
78-
}
7972
}

res/css/views/settings/encryption/_EncryptionCard.pcss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@
3131
}
3232
}
3333
}
34+
35+
.mx_EncryptionCard_buttons {
36+
display: flex;
37+
flex-direction: column;
38+
gap: var(--cpd-space-4x);
39+
justify-content: center;
40+
}

res/css/views/settings/encryption/_ResetIdentityPanel.pcss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,4 @@
1616
text-align: center;
1717
}
1818
}
19-
20-
.mx_ResetIdentityPanel_footer {
21-
display: flex;
22-
flex-direction: column;
23-
gap: var(--cpd-space-4x);
24-
justify-content: center;
25-
}
2619
}

src/components/views/settings/encryption/ChangeRecoveryKey.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useAsyncMemo } from "../../../../hooks/useAsyncMemo";
2727
import { copyPlaintext } from "../../../../utils/strings";
2828
import { initialiseDehydrationIfEnabled } from "../../../../utils/device/dehydration.ts";
2929
import { withSecretStorageKeyCache } from "../../../../SecurityManager";
30+
import { EncryptionCardButtons } from "./EncryptionCardButtons";
3031
import { logErrorAndShowErrorDialog } from "../../../../utils/ErrorUtils.tsx";
3132

3233
/**
@@ -239,12 +240,12 @@ function InformationPanel({ onContinueClick, onCancelClick }: InformationPanelPr
239240
<Text as="span" weight="medium" className="mx_InformationPanel_description">
240241
{_t("settings|encryption|recovery|set_up_recovery_secondary_description")}
241242
</Text>
242-
<div className="mx_ChangeRecoveryKey_footer">
243+
<EncryptionCardButtons>
243244
<Button onClick={onContinueClick}>{_t("action|continue")}</Button>
244245
<Button kind="tertiary" onClick={onCancelClick}>
245246
{_t("action|cancel")}
246247
</Button>
247-
</div>
248+
</EncryptionCardButtons>
248249
</>
249250
);
250251
}
@@ -286,12 +287,12 @@ function KeyPanel({ recoveryKey, onConfirmClick, onCancelClick }: KeyPanelProps)
286287
<CopyIcon />
287288
</IconButton>
288289
</div>
289-
<div className="mx_ChangeRecoveryKey_footer">
290+
<EncryptionCardButtons>
290291
<Button onClick={onConfirmClick}>{_t("action|continue")}</Button>
291292
<Button kind="tertiary" onClick={onCancelClick}>
292293
{_t("action|cancel")}
293294
</Button>
294-
</div>
295+
</EncryptionCardButtons>
295296
</>
296297
);
297298
}
@@ -349,12 +350,12 @@ function KeyForm({ onCancelClick, onSubmit, recoveryKey, submitButtonLabel }: Ke
349350
<ErrorMessage>{_t("settings|encryption|recovery|enter_key_error")}</ErrorMessage>
350351
)}
351352
</Field>
352-
<div className="mx_ChangeRecoveryKey_footer">
353+
<EncryptionCardButtons>
353354
<Button disabled={!isKeyValid}>{submitButtonLabel}</Button>
354355
<Button kind="tertiary" onClick={onCancelClick}>
355356
{_t("action|cancel")}
356357
</Button>
357-
</div>
358+
</EncryptionCardButtons>
358359
</Root>
359360
);
360361
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2024 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import React, { type PropsWithChildren } from "react";
9+
10+
/**
11+
* A component to present action buttons at the bottom of an {@link EncryptionCard}
12+
* (mostly as somewhere for the common CSS to live).
13+
*/
14+
export function EncryptionCardButtons({ children }: PropsWithChildren): JSX.Element {
15+
return <div className="mx_EncryptionCard_buttons">{children}</div>;
16+
}

src/components/views/settings/encryption/ResetIdentityPanel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { _t } from "../../../../languageHandler";
1515
import { EncryptionCard } from "./EncryptionCard";
1616
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext";
1717
import { uiAuthCallback } from "../../../../CreateCrossSigning";
18+
import { EncryptionCardButtons } from "./EncryptionCardButtons";
1819

1920
interface ResetIdentityPanelProps {
2021
/**
@@ -74,7 +75,7 @@ export function ResetIdentityPanel({ onCancelClick, onFinish, variant }: ResetId
7475
</VisualList>
7576
{variant === "compromised" && <span>{_t("settings|encryption|advanced|breadcrumb_warning")}</span>}
7677
</div>
77-
<div className="mx_ResetIdentityPanel_footer">
78+
<EncryptionCardButtons>
7879
<Button
7980
destructive={true}
8081
onClick={async (evt) => {
@@ -89,7 +90,7 @@ export function ResetIdentityPanel({ onCancelClick, onFinish, variant }: ResetId
8990
<Button kind="tertiary" onClick={onCancelClick}>
9091
{_t("action|cancel")}
9192
</Button>
92-
</div>
93+
</EncryptionCardButtons>
9394
</EncryptionCard>
9495
</>
9596
);

test/unit-tests/components/views/settings/encryption/__snapshots__/ChangeRecoveryKey-test.tsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ exports[`<ChangeRecoveryKey /> flow to change the recovery key should display th
135135
</button>
136136
</div>
137137
<div
138-
class="mx_ChangeRecoveryKey_footer"
138+
class="mx_EncryptionCard_buttons"
139139
>
140140
<button
141141
class="_button_i91xf_17"
@@ -266,7 +266,7 @@ exports[`<ChangeRecoveryKey /> flow to set up a recovery key should ask the user
266266
/>
267267
</div>
268268
<div
269-
class="mx_ChangeRecoveryKey_footer"
269+
class="mx_EncryptionCard_buttons"
270270
>
271271
<button
272272
aria-disabled="true"
@@ -421,7 +421,7 @@ exports[`<ChangeRecoveryKey /> flow to set up a recovery key should ask the user
421421
</span>
422422
</div>
423423
<div
424-
class="mx_ChangeRecoveryKey_footer"
424+
class="mx_EncryptionCard_buttons"
425425
>
426426
<button
427427
aria-disabled="true"
@@ -539,7 +539,7 @@ exports[`<ChangeRecoveryKey /> flow to set up a recovery key should display info
539539
After clicking continue, we’ll generate a recovery key for you.
540540
</span>
541541
<div
542-
class="mx_ChangeRecoveryKey_footer"
542+
class="mx_EncryptionCard_buttons"
543543
>
544544
<button
545545
class="_button_i91xf_17"
@@ -699,7 +699,7 @@ exports[`<ChangeRecoveryKey /> flow to set up a recovery key should display the
699699
</button>
700700
</div>
701701
<div
702-
class="mx_ChangeRecoveryKey_footer"
702+
class="mx_EncryptionCard_buttons"
703703
>
704704
<button
705705
class="_button_i91xf_17"

test/unit-tests/components/views/settings/encryption/__snapshots__/ResetIdentityPanel-test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ exports[`<ResetIdentityPanel /> should display the 'forgot recovery key' variant
155155
</ul>
156156
</div>
157157
<div
158-
class="mx_ResetIdentityPanel_footer"
158+
class="mx_EncryptionCard_buttons"
159159
>
160160
<button
161161
class="_button_i91xf_17 _destructive_i91xf_116"
@@ -338,7 +338,7 @@ exports[`<ResetIdentityPanel /> should reset the encryption when the continue bu
338338
</span>
339339
</div>
340340
<div
341-
class="mx_ResetIdentityPanel_footer"
341+
class="mx_EncryptionCard_buttons"
342342
>
343343
<button
344344
class="_button_i91xf_17 _destructive_i91xf_116"

test/unit-tests/components/views/settings/tabs/user/__snapshots__/EncryptionUserSettingsTab-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ exports[`<EncryptionUserSettingsTab /> should display the reset identity panel w
329329
</span>
330330
</div>
331331
<div
332-
class="mx_ResetIdentityPanel_footer"
332+
class="mx_EncryptionCard_buttons"
333333
>
334334
<button
335335
class="_button_i91xf_17 _destructive_i91xf_116"

0 commit comments

Comments
 (0)