Skip to content

Commit b5f61b0

Browse files
committed
feat: add option to make reactions non-interactive
1 parent 8f0b6c3 commit b5f61b0

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

packages/core/src/components.d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,20 @@ export namespace Components {
213213
* The reaction emoji image URL.
214214
*/
215215
"emoji": string;
216+
/**
217+
* Whether the reaction should be reactive.
218+
* @remark When the reaction is interactive left clicking it will add 1 to the counter. Whereas when holding the Shift key and left clicking it will decrease the counter. The counter cannot go below 1.
219+
* @default false
220+
*/
221+
"interactive": boolean;
216222
/**
217223
* The name of the emoji to use as alternative image text.
224+
* @default ':emoji'
218225
*/
219226
"name": string;
220227
/**
221228
* Whether the reaction should show as reacted by the user.
229+
* @default false
222230
*/
223231
"reacted": boolean;
224232
}
@@ -513,12 +521,20 @@ declare namespace LocalJSX {
513521
* The reaction emoji image URL.
514522
*/
515523
"emoji"?: string;
524+
/**
525+
* Whether the reaction should be reactive.
526+
* @remark When the reaction is interactive left clicking it will add 1 to the counter. Whereas when holding the Shift key and left clicking it will decrease the counter. The counter cannot go below 1.
527+
* @default false
528+
*/
529+
"interactive"?: boolean;
516530
/**
517531
* The name of the emoji to use as alternative image text.
532+
* @default ':emoji'
518533
*/
519534
"name"?: string;
520535
/**
521536
* Whether the reaction should show as reacted by the user.
537+
* @default false
522538
*/
523539
"reacted"?: boolean;
524540
}

packages/core/src/components/discord-reaction/discord-reaction.tsx

+21-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class DiscordReaction implements ComponentInterface {
2020

2121
/**
2222
* The name of the emoji to use as alternative image text.
23+
* @default ':emoji'
2324
*/
2425
@Prop()
2526
public name = ':emoji:';
@@ -33,10 +34,21 @@ export class DiscordReaction implements ComponentInterface {
3334

3435
/**
3536
* Whether the reaction should show as reacted by the user.
37+
* @default false
3638
*/
3739
@Prop()
3840
public reacted = false;
3941

42+
/**
43+
* Whether the reaction should be reactive.
44+
* @remark When the reaction is interactive left clicking it will add 1 to the counter.
45+
* Whereas when holding the Shift key and left clicking it will decrease the counter.
46+
* The counter cannot go below 1.
47+
* @default false
48+
*/
49+
@Prop()
50+
public interactive = false;
51+
4052
public render() {
4153
return (
4254
<div class={clsx('discord-reaction', { 'discord-reaction-reacted': this.reacted })} onClick={this.handleReactionClick.bind(this)}>
@@ -49,14 +61,16 @@ export class DiscordReaction implements ComponentInterface {
4961
}
5062

5163
private handleReactionClick(event: MouseEvent) {
52-
if (event.shiftKey) {
53-
this.count--;
54-
} else {
55-
this.count++;
56-
}
64+
if (this.interactive) {
65+
if (event.shiftKey) {
66+
this.count--;
67+
} else {
68+
this.count++;
69+
}
5770

58-
if (this.count <= 0) {
59-
this.count = 1;
71+
if (this.count <= 0) {
72+
this.count = 1;
73+
}
6074
}
6175
}
6276
}

packages/core/src/components/discord-reaction/readme.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
## Properties
66

7-
| Property | Attribute | Description | Type | Default |
8-
| --------- | --------- | -------------------------------------------------------- | --------- | ----------- |
9-
| `count` | `count` | The number of people who reacted. | `number` | `1` |
10-
| `emoji` | `emoji` | The reaction emoji image URL. | `string` | `undefined` |
11-
| `name` | `name` | The name of the emoji to use as alternative image text. | `string` | `':emoji:'` |
12-
| `reacted` | `reacted` | Whether the reaction should show as reacted by the user. | `boolean` | `false` |
7+
| Property | Attribute | Description | Type | Default |
8+
| ------------- | ------------- | -------------------------------------------------------- | --------- | ----------- |
9+
| `count` | `count` | The number of people who reacted. | `number` | `1` |
10+
| `emoji` | `emoji` | The reaction emoji image URL. | `string` | `undefined` |
11+
| `interactive` | `interactive` | Whether the reaction should be reactive. | `boolean` | `false` |
12+
| `name` | `name` | The name of the emoji to use as alternative image text. | `string` | `':emoji:'` |
13+
| `reacted` | `reacted` | Whether the reaction should show as reacted by the user. | `boolean` | `false` |
1314

1415
---
1516

packages/core/src/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ <h3 class="title">Reactions</h3>
177177
<discord-reactions slot="reactions">
178178
<discord-reaction name="👍" emoji="/static/thumbsup.svg" count="1"></discord-reaction>
179179
<discord-reaction name="👀" emoji="/static/eyes.svg" count="2" reacted></discord-reaction>
180-
<discord-reaction name="👀" emoji="/static/dragonite.png" count="10" reacted></discord-reaction>
180+
<discord-reaction interactive="true" name="dragonite" emoji="/static/dragonite.png" count="10" reacted></discord-reaction>
181181
</discord-reactions>
182182
</discord-message>
183183
</discord-messages>

0 commit comments

Comments
 (0)