Skip to content

Commit e8a3997

Browse files
authored
Merge pull request #15 from axbg/fix/symbols-clipboard-copy
Fixed Symbols 'Copied to Clipboard' status
2 parents 9f0b937 + 4147719 commit e8a3997

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/apps/html-symbols/HtmlSymbols.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default function HtmlSymbols() {
3131
const lsType = useLocalStorage({ key: '@omatsuri/html-symbols/type', delay: 200 });
3232
const [query, setQuery] = useState(lsQuery.retrieve() || '');
3333
const [type, setType] = useState(lsType.retrieve() || 'Most used');
34+
const [copiedValue, setCopiedValue] = useState(null);
3435

3536
const handleQueryChange = (event) => {
3637
setQuery(event.target.value);
@@ -42,31 +43,38 @@ export default function HtmlSymbols() {
4243
lsType.save(value);
4344
};
4445

46+
const handleCopy = (value) => {
47+
setCopiedValue(value);
48+
clipboard.copy(value)
49+
}
50+
4551
const results = searchSymbols(query, type).map((item) => (
4652
<tr className={classes.item} key={item.entity}>
4753
<td className={classes.name}>{item.name}</td>
4854
<td>
4955
<button
50-
className={cx(classes.control, classes.symbol)}
56+
className={cx(classes.control, classes.symbol, { [classes.copied]: item.symbol === copiedValue && clipboard.copied })}
5157
type="button"
52-
onClick={() => clipboard.copy(item.symbol)}
58+
onClick={() => handleCopy(item.symbol)}
5359
>
5460
{item.symbol}
5561
</button>
5662
</td>
5763

5864
<td>
5965
<button
60-
className={classes.control}
66+
className={cx(classes.control, { [classes.copied]: item.entity === copiedValue && clipboard.copied })}
6167
type="button"
62-
onClick={() => clipboard.copy(item.entity)}
68+
onClick={() => handleCopy(item.entity)}
6369
>
6470
{item.entity}
6571
</button>
6672
</td>
6773

6874
<td>
69-
<button className={classes.control} type="button" onClick={() => clipboard.copy(item.css)}>
75+
<button className={cx(classes.control, { [classes.copied]: item.css === copiedValue && clipboard.copied })}
76+
type="button"
77+
onClick={() => handleCopy(item.css)}>
7078
{item.css}
7179
</button>
7280
</td>
@@ -85,7 +93,7 @@ export default function HtmlSymbols() {
8593
placeholder="Search symbols..."
8694
/>
8795
</div>
88-
<table className={cx(classes.results, { [classes.copied]: clipboard.copied })}>
96+
<table className={classes.results}>
8997
<thead>
9098
<tr>
9199
<th>Name</th>

src/apps/html-symbols/HtmlSymbols.styles.less

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@
6666
}
6767

6868
.copied {
69-
.symbol,
70-
.control {
71-
&::before {
72-
background-color: @oc-green-7;
73-
content: 'Copied to clipboard';
74-
}
69+
&::before {
70+
background-color: @oc-green-7;
71+
content: 'Copied to clipboard';
7572
}
7673
}
7774

@@ -138,11 +135,8 @@
138135
}
139136

140137
.copied {
141-
.symbol,
142-
.control {
143-
&::before {
144-
background-color: @oc-green-9;
145-
}
138+
&::before {
139+
background-color: @oc-green-9;
146140
}
147141
}
148-
}
142+
}

0 commit comments

Comments
 (0)