Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 58c942b

Browse files
author
Kerry
authored
split SettingsSection out of SettingsTab, replace usage (#10735)
* split SettingsSection out of SettingsTab, replace usage * correct copyright * fix VoipRoomSettingsTab
1 parent 3537699 commit 58c942b

File tree

9 files changed

+174
-72
lines changed

9 files changed

+174
-72
lines changed

res/css/_components.pcss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
@import "./views/settings/_SpellCheckLanguages.pcss";
340340
@import "./views/settings/_ThemeChoicePanel.pcss";
341341
@import "./views/settings/_UpdateCheckButton.pcss";
342+
@import "./views/settings/tabs/_SettingsSection.pcss";
342343
@import "./views/settings/tabs/_SettingsTab.pcss";
343344
@import "./views/settings/tabs/room/_GeneralRoomSettingsTab.pcss";
344345
@import "./views/settings/tabs/room/_NotificationSettingsTab.pcss";

res/css/views/settings/_SettingsFieldset.pcss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ limitations under the License.
2020
}
2121

2222
.mx_SettingsFieldset_legend {
23-
font-size: $font-16px;
24-
display: block;
23+
// matches h3
24+
font-size: $font-18px;
2525
font-weight: var(--font-semi-bold);
26+
line-height: $font-22px;
27+
display: block;
2628
color: $primary-content;
2729
margin-bottom: 10px;
2830
margin-top: 12px;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023 New Vector Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_SettingsSection {
18+
--SettingsTab_section-margin-bottom-preferences-labs: 30px;
19+
--SettingsTab_heading_nth_child-margin-top: 30px; /* TODO: Use a spacing variable */
20+
--SettingsTab_fullWidthField-margin-inline-end: 100px;
21+
--SettingsTab_tooltip-max-width: 120px; /* So it fits in the space provided by the page */
22+
23+
color: $primary-content;
24+
25+
a {
26+
color: $links;
27+
}
28+
}
29+
30+
.mx_SettingsSection_subSections {
31+
display: grid;
32+
grid-template-columns: 1fr;
33+
grid-gap: $spacing-32;
34+
35+
padding: $spacing-16 0;
36+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { HTMLAttributes } from "react";
18+
19+
import Heading from "../../typography/Heading";
20+
21+
export interface SettingsSectionProps extends HTMLAttributes<HTMLDivElement> {
22+
heading: string | React.ReactNode;
23+
children?: React.ReactNode;
24+
}
25+
26+
/**
27+
* A section of settings content
28+
* A SettingsTab may contain one or more SettingsSections
29+
* Eg:
30+
* ```
31+
* <SettingsTab>
32+
* <SettingsSection heading="General">
33+
* <SettingsSubsection heading="Profile">
34+
* // profile settings form
35+
* <SettingsSubsection>
36+
* <SettingsSubsection heading="Account">
37+
* // account settings
38+
* <SettingsSubsection>
39+
* </SettingsSection>
40+
* </SettingsTab>
41+
* ```
42+
*/
43+
export const SettingsSection: React.FC<SettingsSectionProps> = ({ heading, children, ...rest }) => (
44+
<div {...rest} className="mx_SettingsSection">
45+
{typeof heading === "string" ? <Heading size="h2">{heading}</Heading> : <>{heading}</>}
46+
<div className="mx_SettingsSection_subSections">{children}</div>
47+
</div>
48+
);

src/components/views/settings/tabs/SettingsTab.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,30 @@ limitations under the License.
1515
*/
1616
import React from "react";
1717

18-
import Heading from "../../typography/Heading";
19-
2018
export interface SettingsTabProps {
21-
heading: string;
2219
children?: React.ReactNode;
2320
}
2421

25-
const SettingsTab: React.FC<SettingsTabProps> = ({ heading, children }) => (
22+
/**
23+
* Container for a tab of settings panel content
24+
* Should contain one or more SettingsSection
25+
* Settings width, padding and spacing between sections
26+
* Eg:
27+
* ```
28+
* <SettingsTab>
29+
* <SettingsSection heading="General">
30+
* <SettingsSubsection heading="Profile">
31+
* // profile settings form
32+
* <SettingsSubsection>
33+
* <SettingsSubsection heading="Account">
34+
* // account settings
35+
* <SettingsSubsection>
36+
* </SettingsSection>
37+
* </SettingsTab>
38+
* ```
39+
*/
40+
const SettingsTab: React.FC<SettingsTabProps> = ({ children }) => (
2641
<div className="mx_SettingsTab">
27-
<Heading size="h2">{heading}</Heading>
2842
<div className="mx_SettingsTab_sections">{children}</div>
2943
</div>
3044
);

src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import SettingsTab from "../SettingsTab";
2828
import { ElementCall } from "../../../../../models/Call";
2929
import { useRoomState } from "../../../../../hooks/useRoomState";
3030
import SdkConfig, { DEFAULTS } from "../../../../../SdkConfig";
31+
import { SettingsSection } from "../../shared/SettingsSection";
3132

3233
interface ElementCallSwitchProps {
3334
room: Room;
@@ -100,10 +101,12 @@ interface Props {
100101

101102
export const VoipRoomSettingsTab: React.FC<Props> = ({ room }) => {
102103
return (
103-
<SettingsTab heading={_t("Voice & Video")}>
104-
<SettingsSubsection heading={_t("Call type")}>
105-
<ElementCallSwitch room={room} />
106-
</SettingsSubsection>
104+
<SettingsTab>
105+
<SettingsSection heading={_t("Voice & Video")}>
106+
<SettingsSubsection heading={_t("Call type")}>
107+
<ElementCallSwitch room={room} />
108+
</SettingsSubsection>
109+
</SettingsSection>
107110
</SettingsTab>
108111
);
109112
};

src/components/views/settings/tabs/user/SessionManagerTab.tsx

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { useAsyncMemo } from "../../../../../hooks/useAsyncMemo";
3838
import QuestionDialog from "../../../dialogs/QuestionDialog";
3939
import { FilterVariation } from "../../devices/filter";
4040
import { OtherSessionsSectionHeading } from "../../devices/OtherSessionsSectionHeading";
41+
import { SettingsSection } from "../../shared/SettingsSection";
4142

4243
const confirmSignOut = async (sessionsToSignOutCount: number): Promise<boolean> => {
4344
const { finished } = Modal.createDialog(QuestionDialog, {
@@ -225,62 +226,64 @@ const SessionManagerTab: React.FC = () => {
225226
}
226227

227228
return (
228-
<SettingsTab heading={_t("Sessions")}>
229-
<SecurityRecommendations
230-
devices={devices}
231-
goToFilteredList={onGoToFilteredList}
232-
currentDeviceId={currentDeviceId}
233-
/>
234-
<CurrentDeviceSection
235-
device={currentDevice}
236-
localNotificationSettings={localNotificationSettings.get(currentDeviceId)}
237-
setPushNotifications={setPushNotifications}
238-
isSigningOut={signingOutDeviceIds.includes(currentDeviceId)}
239-
isLoading={isLoadingDeviceList}
240-
saveDeviceName={(deviceName) => saveDeviceName(currentDeviceId, deviceName)}
241-
onVerifyCurrentDevice={onVerifyCurrentDevice}
242-
onSignOutCurrentDevice={onSignOutCurrentDevice}
243-
signOutAllOtherSessions={signOutAllOtherSessions}
244-
otherSessionsCount={otherSessionsCount}
245-
/>
246-
{shouldShowOtherSessions && (
247-
<SettingsSubsection
248-
heading={
249-
<OtherSessionsSectionHeading
250-
otherSessionsCount={otherSessionsCount}
251-
signOutAllOtherSessions={signOutAllOtherSessions!}
252-
disabled={!!signingOutDeviceIds.length}
253-
/>
254-
}
255-
description={_t(
256-
`For best security, verify your sessions and sign out ` +
257-
`from any session that you don't recognize or use anymore.`,
258-
)}
259-
data-testid="other-sessions-section"
260-
>
261-
<FilteredDeviceList
262-
devices={otherDevices}
263-
pushers={pushers}
264-
localNotificationSettings={localNotificationSettings}
265-
filter={filter}
266-
expandedDeviceIds={expandedDeviceIds}
267-
signingOutDeviceIds={signingOutDeviceIds}
268-
selectedDeviceIds={selectedDeviceIds}
269-
setSelectedDeviceIds={setSelectedDeviceIds}
270-
onFilterChange={setFilter}
271-
onDeviceExpandToggle={onDeviceExpandToggle}
272-
onRequestDeviceVerification={
273-
requestDeviceVerification ? onTriggerDeviceVerification : undefined
229+
<SettingsTab>
230+
<SettingsSection heading={_t("Sessions")}>
231+
<SecurityRecommendations
232+
devices={devices}
233+
goToFilteredList={onGoToFilteredList}
234+
currentDeviceId={currentDeviceId}
235+
/>
236+
<CurrentDeviceSection
237+
device={currentDevice}
238+
localNotificationSettings={localNotificationSettings.get(currentDeviceId)}
239+
setPushNotifications={setPushNotifications}
240+
isSigningOut={signingOutDeviceIds.includes(currentDeviceId)}
241+
isLoading={isLoadingDeviceList}
242+
saveDeviceName={(deviceName) => saveDeviceName(currentDeviceId, deviceName)}
243+
onVerifyCurrentDevice={onVerifyCurrentDevice}
244+
onSignOutCurrentDevice={onSignOutCurrentDevice}
245+
signOutAllOtherSessions={signOutAllOtherSessions}
246+
otherSessionsCount={otherSessionsCount}
247+
/>
248+
{shouldShowOtherSessions && (
249+
<SettingsSubsection
250+
heading={
251+
<OtherSessionsSectionHeading
252+
otherSessionsCount={otherSessionsCount}
253+
signOutAllOtherSessions={signOutAllOtherSessions!}
254+
disabled={!!signingOutDeviceIds.length}
255+
/>
274256
}
275-
onSignOutDevices={onSignOutOtherDevices}
276-
saveDeviceName={saveDeviceName}
277-
setPushNotifications={setPushNotifications}
278-
ref={filteredDeviceListRef}
279-
supportsMSC3881={supportsMSC3881}
280-
/>
281-
</SettingsSubsection>
282-
)}
283-
<LoginWithQRSection onShowQr={onShowQrClicked} versions={clientVersions} capabilities={capabilities} />
257+
description={_t(
258+
`For best security, verify your sessions and sign out ` +
259+
`from any session that you don't recognize or use anymore.`,
260+
)}
261+
data-testid="other-sessions-section"
262+
>
263+
<FilteredDeviceList
264+
devices={otherDevices}
265+
pushers={pushers}
266+
localNotificationSettings={localNotificationSettings}
267+
filter={filter}
268+
expandedDeviceIds={expandedDeviceIds}
269+
signingOutDeviceIds={signingOutDeviceIds}
270+
selectedDeviceIds={selectedDeviceIds}
271+
setSelectedDeviceIds={setSelectedDeviceIds}
272+
onFilterChange={setFilter}
273+
onDeviceExpandToggle={onDeviceExpandToggle}
274+
onRequestDeviceVerification={
275+
requestDeviceVerification ? onTriggerDeviceVerification : undefined
276+
}
277+
onSignOutDevices={onSignOutOtherDevices}
278+
saveDeviceName={saveDeviceName}
279+
setPushNotifications={setPushNotifications}
280+
ref={filteredDeviceListRef}
281+
supportsMSC3881={supportsMSC3881}
282+
/>
283+
</SettingsSubsection>
284+
)}
285+
<LoginWithQRSection onShowQr={onShowQrClicked} versions={clientVersions} capabilities={capabilities} />
286+
</SettingsSection>
284287
</SettingsTab>
285288
);
286289
};

test/components/views/settings/tabs/SettingsTab-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import SettingsTab, { SettingsTabProps } from "../../../../../src/components/vie
2222
describe("<SettingsTab />", () => {
2323
const getComponent = (props: SettingsTabProps): ReactElement => <SettingsTab {...props} />;
2424
it("renders tab", () => {
25-
const { container } = render(getComponent({ heading: "Test Tab", children: <div>test</div> }));
25+
const { container } = render(getComponent({ children: <div>test</div> }));
2626

2727
expect(container).toMatchSnapshot();
2828
});

test/components/views/settings/tabs/__snapshots__/SettingsTab-test.tsx.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ exports[`<SettingsTab /> renders tab 1`] = `
55
<div
66
class="mx_SettingsTab"
77
>
8-
<h2
9-
class="mx_Heading_h2"
10-
>
11-
Test Tab
12-
</h2>
138
<div
149
class="mx_SettingsTab_sections"
1510
>

0 commit comments

Comments
 (0)