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

Commit 949b3cc

Browse files
author
Germain
authored
Extract Tag to its own component (#8309)
1 parent c68515a commit 949b3cc

File tree

3 files changed

+94
-35
lines changed

3 files changed

+94
-35
lines changed

res/css/views/elements/_TagComposer.scss

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ limitations under the License.
2929
margin-left: 16px; // distance from <Field>
3030
}
3131

32-
.mx_Field, .mx_Field input, .mx_AccessibleButton {
32+
.mx_Field,
33+
.mx_Field input,
34+
.mx_AccessibleButton {
3335
// So they look related to each other by feeling the same
3436
border-radius: 8px;
3537
}
@@ -39,39 +41,48 @@ limitations under the License.
3941
display: flex;
4042
flex-wrap: wrap;
4143
margin-top: 12px; // this plus 12px from the tags makes 24px from the input
44+
}
4245

43-
.mx_TagComposer_tag {
44-
padding: 6px 8px 8px 12px;
45-
position: relative;
46-
margin-right: 12px;
47-
margin-top: 12px;
48-
49-
// Cheaty way to get an opacified variable colour background
50-
&::before {
51-
content: '';
52-
border-radius: 20px;
53-
background-color: $tertiary-content;
54-
opacity: 0.15;
55-
position: absolute;
56-
top: 0;
57-
left: 0;
58-
width: 100%;
59-
height: 100%;
60-
61-
// Pass through the pointer otherwise we have effectively put a whole div
62-
// on top of the component, which makes it hard to interact with buttons.
63-
pointer-events: none;
64-
}
65-
}
46+
.mx_Tag {
47+
margin-right: 12px;
48+
margin-top: 12px;
49+
}
50+
}
6651

67-
.mx_AccessibleButton {
68-
background-image: url('$(res)/img/subtract.svg');
69-
width: 16px;
70-
height: 16px;
71-
margin-left: 8px;
72-
display: inline-block;
52+
.mx_Tag {
53+
54+
font-size: $font-15px;
55+
56+
display: inline-flex;
57+
align-items: center;
58+
59+
gap: 8px;
60+
padding: 8px;
61+
border-radius: 8px;
62+
63+
color: $primary-content;
64+
background: $quinary-content;
65+
66+
>svg:first-child {
67+
width: 1em;
68+
color: $secondary-content;
69+
transform: scale(1.25);
70+
transform-origin: center;
71+
}
72+
73+
.mx_Tag_delete {
74+
border-radius: 50%;
75+
text-align: center;
76+
width: 1.066666em; // 16px;
77+
height: 1.066666em;
78+
line-height: 1em;
79+
color: $secondary-content;
80+
background: $system;
81+
position: relative;
82+
83+
svg {
84+
width: .5em;
7385
vertical-align: middle;
74-
cursor: pointer;
7586
}
7687
}
7788
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 from "react";
18+
19+
import AccessibleButton from "./AccessibleButton";
20+
import { Icon as CancelRounded } from "../../../../res/img/element-icons/cancel-rounded.svg";
21+
22+
interface IProps {
23+
icon?: () => JSX.Element;
24+
label: string;
25+
onDeleteClick?: () => void;
26+
disabled?: boolean;
27+
}
28+
29+
export const Tag = ({
30+
icon,
31+
label,
32+
onDeleteClick,
33+
disabled = false,
34+
}: IProps) => {
35+
return <div className='mx_Tag'>
36+
{ icon?.() }
37+
{ label }
38+
{ onDeleteClick && (
39+
<AccessibleButton className="mx_Tag_delete" onClick={onDeleteClick} disabled={disabled}>
40+
<CancelRounded />
41+
</AccessibleButton>
42+
) }
43+
</div>;
44+
};

src/components/views/elements/TagComposer.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import React, { ChangeEvent, FormEvent } from "react";
1919
import Field from "./Field";
2020
import { _t } from "../../../languageHandler";
2121
import AccessibleButton from "./AccessibleButton";
22+
import { Tag } from "./Tag";
2223

2324
interface IProps {
2425
tags: string[];
@@ -80,10 +81,13 @@ export default class TagComposer extends React.PureComponent<IProps, IState> {
8081
</AccessibleButton>
8182
</form>
8283
<div className='mx_TagComposer_tags'>
83-
{ this.props.tags.map((t, i) => (<div className='mx_TagComposer_tag' key={i}>
84-
<span>{ t }</span>
85-
<AccessibleButton onClick={this.onRemove.bind(this, t)} disabled={this.props.disabled} />
86-
</div>)) }
84+
{ this.props.tags.map((t, i) => (
85+
<Tag
86+
label={t}
87+
key={t}
88+
onDeleteClick={this.onRemove.bind(this, t)}
89+
disabled={this.props.disabled} />
90+
)) }
8791
</div>
8892
</div>;
8993
}

0 commit comments

Comments
 (0)