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

Commit 6c4c7ad

Browse files
committed
Extract VisualList into a more reusable component
1 parent 3d4a509 commit 6c4c7ad

File tree

4 files changed

+90
-30
lines changed

4 files changed

+90
-30
lines changed

frontend/src/components/SessionDetail/SessionDetails.module.css

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,3 @@
3939
text-overflow: ellipsis;
4040
overflow: hidden;
4141
}
42-
43-
.scope-list {
44-
display: flex;
45-
flex-direction: column;
46-
gap: var(--cpd-space-scale);
47-
border-radius: var(--cpd-space-5x);
48-
overflow: hidden;
49-
}
50-
51-
.scope {
52-
background: var(--cpd-color-bg-subtle-secondary);
53-
padding: var(--cpd-space-3x) var(--cpd-space-5x);
54-
display: flex;
55-
align-items: center;
56-
gap: var(--cpd-space-3x);
57-
}
58-
59-
.scope svg {
60-
inline-size: var(--cpd-space-6x);
61-
block-size: var(--cpd-space-6x);
62-
color: var(--cpd-color-icon-tertiary);
63-
}

frontend/src/components/SessionDetail/SessionDetails.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { useTranslation } from "react-i18next";
2525
import Block from "../Block/Block";
2626
import DateTime from "../DateTime";
2727
import LastActive from "../Session/LastActive";
28+
import { VisualList, VisualListItem } from "../VisualList/VisualList";
2829

2930
import styles from "./SessionDetails.module.css";
3031

@@ -68,12 +69,7 @@ const Scope: React.FC<{ scope: string }> = ({ scope }) => {
6869
return (
6970
<>
7071
{mappedScopes.map(([Icon, text], i) => (
71-
<li className={styles.scope} key={i}>
72-
<Icon />
73-
<Text size="md" weight="medium">
74-
{text}
75-
</Text>
76-
</li>
72+
<VisualListItem key={i} Icon={Icon} label={text} />
7773
))}
7874
</>
7975
);
@@ -153,11 +149,11 @@ const SessionDetails: React.FC<Props> = ({
153149
<Datum
154150
label={t("frontend.session.scopes_label")}
155151
value={
156-
<ul className={styles.scopeList}>
152+
<VisualList>
157153
{scopes.map((scope) => (
158154
<Scope key={scope} scope={scope} />
159155
))}
160-
</ul>
156+
</VisualList>
161157
}
162158
/>
163159
)}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Copyright 2024 The Matrix.org Foundation C.I.C.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
.scope-list {
17+
display: flex;
18+
flex-direction: column;
19+
gap: var(--cpd-space-scale);
20+
border-radius: var(--cpd-space-5x);
21+
overflow: hidden;
22+
}
23+
24+
.scope {
25+
background: var(--cpd-color-bg-subtle-secondary);
26+
padding: var(--cpd-space-3x) var(--cpd-space-5x);
27+
display: flex;
28+
align-items: center;
29+
gap: var(--cpd-space-3x);
30+
}
31+
32+
.scope svg {
33+
inline-size: var(--cpd-space-6x);
34+
block-size: var(--cpd-space-6x);
35+
flex-shrink: 0;
36+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2024 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { Text } from "@vector-im/compound-web";
16+
import {
17+
FC,
18+
ForwardRefExoticComponent,
19+
ReactNode,
20+
RefAttributes,
21+
SVGProps,
22+
} from "react";
23+
24+
import styles from "./VisualList.module.css";
25+
26+
type Props = {
27+
children: ReactNode;
28+
};
29+
30+
export const VisualListItem: FC<{
31+
Icon: ForwardRefExoticComponent<
32+
Omit<SVGProps<SVGSVGElement>, "ref" | "children"> &
33+
RefAttributes<SVGSVGElement>
34+
>;
35+
iconColor?: string;
36+
label: string;
37+
}> = ({ Icon, iconColor, label }) => {
38+
return (
39+
<li className={styles.scope}>
40+
<Icon color={iconColor ?? "var(--cpd-color-icon-tertiary)"} />
41+
<Text size="md" weight="medium">
42+
{label}
43+
</Text>
44+
</li>
45+
);
46+
};
47+
48+
export const VisualList: React.FC<Props> = ({ children }) => {
49+
return <ul className={styles.scopeList}>{children}</ul>;
50+
};

0 commit comments

Comments
 (0)